Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mikusaq committed Nov 13, 2024
1 parent 2729470 commit c3293dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 58 deletions.
30 changes: 1 addition & 29 deletions bap-builder/SysrootMode.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bringauto/modules/bringauto_config"
"bringauto/modules/bringauto_context"
"bringauto/modules/bringauto_log"
"bringauto/modules/bringauto_package"
Expand Down Expand Up @@ -56,7 +55,7 @@ func CreateSysroot(cmdLine *CreateSysrootCmdLineArgs, contextPath string) error
if err != nil {
return err
}
packages, err := getPackages(&contextManager, platformString)
packages, err := contextManager.GetAllPackagesConfigs(platformString)

logger.Info("Creating sysroot directory from packages")
err = unzipAllPackagesToDir(packages, &repo, *cmdLine.Sysroot)
Expand Down Expand Up @@ -111,30 +110,3 @@ func isDirEmpty(path string) (bool, error) {

return false, nil
}

func getPackages(contextManager *bringauto_context.ContextManager, platformString *bringauto_package.PlatformString) ([]bringauto_package.Package, error) {
var packConfigs []*bringauto_config.Config
packageJsonPathMap, err := contextManager.GetAllPackagesJsonDefPaths()
if err != nil {
return nil, err
}
logger := bringauto_log.GetLogger()
for _, packageJsonPaths := range packageJsonPathMap {
for _, packageJsonPath := range packageJsonPaths {
var config bringauto_config.Config
err = config.LoadJSONConfig(packageJsonPath)
if err != nil {
logger.Warn("Couldn't load JSON config from %s path - %s", packageJsonPath, err)
continue
}
packConfigs = append(packConfigs, &config)
}
}
var packages []bringauto_package.Package
for _, packConfig := range packConfigs {
packConfig.Package.PlatformString = *platformString
packages = append(packages, packConfig.Package)
}

return packages, nil
}
31 changes: 31 additions & 0 deletions modules/bringauto_context/ContextManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package bringauto_context
import (
"bringauto/modules/bringauto_config"
"bringauto/modules/bringauto_const"
"bringauto/modules/bringauto_log"
"bringauto/modules/bringauto_package"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -37,6 +39,35 @@ func (context *ContextManager) GetAllPackagesJsonDefPaths() (map[string][]string
return packageJsonList, err
}

// GetAllPackagesConfigs
// Returns configs of all packages JSON defintions. Given platformString will be added to all packages.
func (context *ContextManager) GetAllPackagesConfigs(platformString *bringauto_package.PlatformString) ([]bringauto_package.Package, error) {
var packConfigs []*bringauto_config.Config
packageJsonPathMap, err := context.GetAllPackagesJsonDefPaths()
if err != nil {
return nil, err
}
logger := bringauto_log.GetLogger()
for _, packageJsonPaths := range packageJsonPathMap {
for _, packageJsonPath := range packageJsonPaths {
var config bringauto_config.Config
err = config.LoadJSONConfig(packageJsonPath)
if err != nil {
logger.Warn("Couldn't load JSON config from %s path - %s", packageJsonPath, err)
continue
}
packConfigs = append(packConfigs, &config)
}
}
var packages []bringauto_package.Package
for _, packConfig := range packConfigs {
packConfig.Package.PlatformString = *platformString
packages = append(packages, packConfig.Package)
}

return packages, nil
}

// GetAllImagesDockerfilePaths
// returns all dockerfile located in the context directory
func (context *ContextManager) GetAllImagesDockerfilePaths() (map[string][]string, error) {
Expand Down
30 changes: 1 addition & 29 deletions modules/bringauto_repository/GitLFSRepository.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bringauto_repository

import (
"bringauto/modules/bringauto_config"
"bringauto/modules/bringauto_package"
"bringauto/modules/bringauto_prerequisites"
"bringauto/modules/bringauto_log"
Expand Down Expand Up @@ -78,7 +77,7 @@ func (lfs *GitLFSRepository) RestoreAllChanges() error {
}

func (lfs *GitLFSRepository) CheckGitLfsConsistency(contextManager *bringauto_context.ContextManager, platformString *bringauto_package.PlatformString) error {
packages, err := getPackages(contextManager, platformString)
packages, err := contextManager.GetAllPackagesConfigs(platformString)

var expectedPackPaths []string
for _, pack := range packages {
Expand Down Expand Up @@ -113,33 +112,6 @@ func (lfs *GitLFSRepository) CheckGitLfsConsistency(contextManager *bringauto_co
return nil
}

func getPackages(contextManager *bringauto_context.ContextManager, platformString *bringauto_package.PlatformString) ([]bringauto_package.Package, error) {
var packConfigs []*bringauto_config.Config
packageJsonPathMap, err := contextManager.GetAllPackagesJsonDefPaths()
if err != nil {
return nil, err
}
logger := bringauto_log.GetLogger()
for _, packageJsonPaths := range packageJsonPathMap {
for _, packageJsonPath := range packageJsonPaths {
var config bringauto_config.Config
err = config.LoadJSONConfig(packageJsonPath)
if err != nil {
logger.Warn("Couldn't load JSON config from %s path - %s", packageJsonPath, err)
continue
}
packConfigs = append(packConfigs, &config)
}
}
var packages []bringauto_package.Package
for _, packConfig := range packConfigs {
packConfig.Package.PlatformString = *platformString
packages = append(packages, packConfig.Package)
}

return packages, nil
}

func printErrors(errorPackPaths []string, expectedPackPaths []string) error {
logger := bringauto_log.GetLogger()
if len(errorPackPaths) > 0 {
Expand Down

0 comments on commit c3293dc

Please sign in to comment.