Skip to content

Commit

Permalink
Refactor, add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mikusaq committed Nov 30, 2024
1 parent 683cd3e commit a9941c5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
67 changes: 39 additions & 28 deletions bap-builder/PackageMode.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ func prepareConfigs(packageJsonPaths []string) ([]*bringauto_config.Config, erro
return configList, nil
}

// prepareConfigsSinglePackageNoBuildDeps
// prepareConfigsNoBuildDeps
// Returns Config structures only for given package.
func prepareConfigsSinglePackageNoBuildDeps(packageName string, contextManager bringauto_context.ContextManager) ([]*bringauto_config.Config, error) {
func prepareConfigsNoBuildDeps(packageName string, contextManager *bringauto_context.ContextManager) ([]*bringauto_config.Config, error) {
var configList []*bringauto_config.Config
packageJsonPaths, err := contextManager.GetPackageJsonDefPaths(packageName)
if err != nil {
Expand All @@ -340,6 +340,41 @@ func prepareConfigsSinglePackageNoBuildDeps(packageName string, contextManager b
return configList, nil
}

// prepareConfigsBuildDepsOrBuildDepsOn
// Returns Config structures based on --build-deps and --build-deps-on flags.
func prepareConfigsBuildDepsOrBuildDepsOn(
cmdLine *BuildPackageCmdLineArgs,
packageName string,
contextManager *bringauto_context.ContextManager,
platformString *bringauto_package.PlatformString,
) ([]*bringauto_config.Config, error) {
var packageJsonPaths []string
if *cmdLine.BuildDeps {
paths, err := contextManager.GetPackageWithDepsJsonDefPaths(packageName)
if err != nil {
return []*bringauto_config.Config{}, err
}
packageJsonPaths = append(packageJsonPaths, paths...)
} else if *cmdLine.BuildDepsOn {
value, err := isPackageWithDepsInSysroot(packageName, contextManager, platformString)
if err != nil {
return []*bringauto_config.Config{}, err
}
if !value {
err = fmt.Errorf("--build-deps-on set but base package or its dependencies are not in sysroot")
return []*bringauto_config.Config{}, err
}
}
if *cmdLine.BuildDepsOn {
paths, err := contextManager.GetDepsOnJsonDefPaths(packageName)
if err != nil {
return []*bringauto_config.Config{}, err
}
packageJsonPaths = append(packageJsonPaths, paths...)
}
return prepareConfigs(packageJsonPaths)
}

// buildSinglePackage
// Builds single package specified by name in cmdLine. Also takes care of building all deps for
// given package in correct order. It returns nil if everything is ok, or not nil in case of error.
Expand All @@ -357,33 +392,9 @@ func buildSinglePackage(
var configList []*bringauto_config.Config

if *cmdLine.BuildDeps || *cmdLine.BuildDepsOn {
var packageJsonPaths []string
if *cmdLine.BuildDeps {
paths, err := contextManager.GetPackageWithDepsJsonDefPaths(packageName)
if err != nil {
return err
}
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
}
packageJsonPaths = append(packageJsonPaths, paths...)
}
configList, err = prepareConfigs(packageJsonPaths)
configList, err = prepareConfigsBuildDepsOrBuildDepsOn(cmdLine, packageName, &contextManager, platformString)
} else {
configList, err = prepareConfigsSinglePackageNoBuildDeps(packageName, contextManager)
configList, err = prepareConfigsNoBuildDeps(packageName, &contextManager)
}
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions modules/bringauto_context/ContextManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,17 @@ func (context *ContextManager) GetDepsOnJsonDefPaths(packageName string) ([]stri
return packsToBuild, nil
}

// removeStrings
// Removes strList2 strings from strList1
func removeStrings(strList1 []string, strList2 []string) []string {
for _, str2 := range strList2 {
strList1 = removeString(strList1, str2)
}
return strList1
}

// removeString
// Removes str string from strList1
func removeString(strList1 []string, str string) []string {
i := 0
for _, str1 := range strList1 {
Expand Down

0 comments on commit a9941c5

Please sign in to comment.