Skip to content

Commit

Permalink
Add updating built packages to sysroot initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mikusaq committed Nov 30, 2024
1 parent 42beb6e commit 683cd3e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
37 changes: 37 additions & 0 deletions bap-builder/PackageMode.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ func buildSinglePackage(
packageJsonPaths = append(packageJsonPaths, paths...)
}
if *cmdLine.BuildDepsOn {
if !*cmdLine.BuildDeps {
value, err := isPackageWithDepsInSysroot(packageName, &contextManager, platformString)
if err != nil {
return err
}
if !value {
return fmt.Errorf("--build-deps-on set but base package or its dependencies are not in sysroot")
}
}
paths, err := contextManager.GetDepsOnJsonDefPaths(packageName)
if err != nil {
return err
Expand Down Expand Up @@ -505,3 +514,31 @@ func checkSysrootDirs(platformString *bringauto_package.PlatformString) (error)
}
return nil
}

// arePackagesInSysroot
// Returns true if packageName an its dependencies are in sysroot, else returns false.
func isPackageWithDepsInSysroot(packageName string, contextManager *bringauto_context.ContextManager, platformString *bringauto_package.PlatformString) (bool, error) {
packageJsonPaths, err := contextManager.GetPackageWithDepsJsonDefPaths(packageName)
if err != nil {
return false, err
}
configList, err := prepareConfigs(packageJsonPaths)
if err != nil {
return false, err
}

sysroot := bringauto_sysroot.Sysroot{
IsDebug: false,
PlatformString: platformString,
}
err = bringauto_prerequisites.Initialize(&sysroot)

for _, config := range configList {
packName := config.Package.GetShortPackageName()
if !sysroot.IsPackageInSysroot(packName) {
return false, nil
}
}

return true, nil
}
7 changes: 1 addition & 6 deletions modules/bringauto_sysroot/BuiltPackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ type BuiltPackages struct {
}

func (builtPackages *BuiltPackages) AddToBuiltPackages(packageName string) error {
err := builtPackages.updateBuiltPackages()
if err != nil {
return err
}

builtPackages.Packages = append(builtPackages.Packages, packageName)
bytes, err := json.Marshal(builtPackages.Packages)
if err != nil {
Expand All @@ -31,7 +26,7 @@ func (builtPackages *BuiltPackages) AddToBuiltPackages(packageName string) error
return err
}

func (builtPackages *BuiltPackages) updateBuiltPackages() error {
func (builtPackages *BuiltPackages) UpdateBuiltPackages() error {
bytes, err := os.ReadFile(path.Join(sysrootDirectoryName, jsonFileName))
if err != nil {
return nil
Expand Down
14 changes: 14 additions & 0 deletions modules/bringauto_sysroot/Sysroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/fs"
"path/filepath"
"strings"
"slices"
)

const (
Expand Down Expand Up @@ -42,6 +43,10 @@ func (sysroot *Sysroot) CheckPrerequisites(args *bringauto_prerequisites.Args) e
if sysroot.PlatformString == nil {
return fmt.Errorf("sysroot PlatformString cannot be nil")
}
err := sysroot.builtPackages.UpdateBuiltPackages()
if err != nil {
return err
}
return nil
}

Expand All @@ -67,6 +72,15 @@ func (sysroot *Sysroot) CopyToSysroot(source string, packageName string) error {
return nil
}

// ArePackagesInSysroot
// Returns true if all expectedPackages are built in sysroot, else false.
func (sysroot *Sysroot) IsPackageInSysroot(packageName string) bool {
if slices.Contains(sysroot.builtPackages.Packages, packageName) {
return true
}
return false
}

// checkForOverwritingFiles
// Checks if in dirPath directory are not files which are also in sysroot directory. If there are
// some, then prints Error with listing problematic files and returns non nil error. Else returns
Expand Down

0 comments on commit 683cd3e

Please sign in to comment.