Skip to content

Commit

Permalink
Merge pull request #29 from bringauto/BAF-997/fix-any-machine
Browse files Browse the repository at this point in the history
Revert "Refactor using PlatformString"
  • Loading branch information
mikusaq authored Nov 19, 2024
2 parents ffa9988 + d0e0ba9 commit 9494381
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
45 changes: 36 additions & 9 deletions bap-builder/PackageMode.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ func BuildPackage(cmdLine *BuildPackageCmdLineArgs, contextPath string) error {
}
buildAll := cmdLine.All
if *buildAll {
return buildAllPackages(cmdLine, contextPath, platformString)
return buildAllPackages(cmdLine, contextPath)
}
return buildSinglePackage(cmdLine, contextPath, platformString)
return buildSinglePackage(cmdLine, contextPath)
}

// buildAllPackages
// Builds all packages specified in contextPath. Also takes care of building all deps for all
// packages in correct order. It returns nil if everything is ok, or not nil in case of error.
func buildAllPackages(cmdLine *BuildPackageCmdLineArgs, contextPath string, platformString *bringauto_package.PlatformString) error {
func buildAllPackages(cmdLine *BuildPackageCmdLineArgs, contextPath string) error {
contextManager := ContextManager{
ContextPath: contextPath,
}
Expand All @@ -246,12 +246,12 @@ func buildAllPackages(cmdLine *BuildPackageCmdLineArgs, contextPath string, plat

count := int32(0)
for _, config := range configList {
buildConfigs := config.GetBuildStructure(*cmdLine.DockerImageName, platformString)
buildConfigs := config.GetBuildStructure(*cmdLine.DockerImageName)
if len(buildConfigs) == 0 {
continue
}
count++
err = buildAndCopyPackage(cmdLine, &buildConfigs, platformString)
err = buildAndCopyPackage(cmdLine, &buildConfigs)
if err != nil {
logger.Fatal("cannot build package '%s' - %s", config.Package.Name, err)
}
Expand All @@ -266,7 +266,7 @@ func buildAllPackages(cmdLine *BuildPackageCmdLineArgs, contextPath string, plat
// 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.
func buildSinglePackage(cmdLine *BuildPackageCmdLineArgs, contextPath string, platformString *bringauto_package.PlatformString) error {
func buildSinglePackage(cmdLine *BuildPackageCmdLineArgs, contextPath string) error {
contextManager := ContextManager{
ContextPath: contextPath,
}
Expand Down Expand Up @@ -305,8 +305,8 @@ func buildSinglePackage(cmdLine *BuildPackageCmdLineArgs, contextPath string, pl
}

for _, config := range configList {
buildConfigs := config.GetBuildStructure(*cmdLine.DockerImageName, platformString)
err = buildAndCopyPackage(cmdLine, &buildConfigs, platformString)
buildConfigs := config.GetBuildStructure(*cmdLine.DockerImageName)
err = buildAndCopyPackage(cmdLine, &buildConfigs)
if err != nil {
logger.Fatal("cannot build package '%s' - %s", packageName, err)
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func addConfigsToDefsMap(defsMap *ConfigMapType, packageJsonPathList []string) {

// buildAndCopyPackage
// Builds single package, takes care of every step of build for single package.
func buildAndCopyPackage(cmdLine *BuildPackageCmdLineArgs, build *[]bringauto_build.Build, platformString *bringauto_package.PlatformString) error {
func buildAndCopyPackage(cmdLine *BuildPackageCmdLineArgs, build *[]bringauto_build.Build) error {
if *cmdLine.OutputDirMode != OutputDirModeGitLFS {
return fmt.Errorf("invalid OutputDirmode. Only GitLFS is supported")
}
Expand All @@ -355,6 +355,11 @@ func buildAndCopyPackage(cmdLine *BuildPackageCmdLineArgs, build *[]bringauto_bu
logger := bringauto_log.GetLogger()

for _, buildConfig := range *build {
platformString, err := determinePlatformStringFromBuild(&buildConfig)
if err != nil {
return err
}

logger.Info("Build %s", buildConfig.Package.GetFullPackageName())

sysroot := bringauto_sysroot.Sysroot{
Expand Down Expand Up @@ -397,6 +402,28 @@ func buildAndCopyPackage(cmdLine *BuildPackageCmdLineArgs, build *[]bringauto_bu
return err
}

// determinePlatformString will construct platform string suitable
// for sysroot.
// For example: the any_machine platformString must be copied to all machine-specific sysroot for
// a given image.
func determinePlatformStringFromBuild(build *bringauto_build.Build) (*bringauto_package.PlatformString, error) {
platformStringSpecialized := build.Package.PlatformString
if build.Package.PlatformString.Mode == bringauto_package.ModeAnyMachine {
platformStringStruct := bringauto_package.PlatformString{
Mode: bringauto_package.ModeAuto,
}
platformStringStruct.Mode = bringauto_package.ModeAuto
err := bringauto_prerequisites.Initialize[bringauto_package.PlatformString](&platformStringStruct,
build.SSHCredentials, build.Docker,
)
if err != nil {
return nil, err
}
platformStringSpecialized.String.Machine = platformStringStruct.String.Machine
}
return &platformStringSpecialized, nil
}

// determinePlatformString
// Will construct platform string suitable for sysroot.
func determinePlatformString(dockerImageName string) (*bringauto_package.PlatformString, error) {
Expand Down
14 changes: 7 additions & 7 deletions modules/bringauto_config/Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bringauto/modules/bringauto_git"
"bringauto/modules/bringauto_package"
"bringauto/modules/bringauto_prerequisites"
"bringauto/modules/bringauto_ssh"
"encoding/json"
"fmt"
"os"
Expand Down Expand Up @@ -82,13 +83,13 @@ func (config *Config) SaveToJSONConfig(configPath string) error {

// Returns array of builds structs for specific image name. The returned array will contain max one build.
// It is an array for simple handling of result using for loop.
func (config *Config) GetBuildStructure(imageName string, platformString *bringauto_package.PlatformString) []bringauto_build.Build {
func (config *Config) GetBuildStructure(imageName string) []bringauto_build.Build {
var buildConfigs []bringauto_build.Build
for _, value := range config.DockerMatrix.ImageNames {
if imageName != "" && imageName != value {
continue
}
build := config.fillBuildStructure(imageName, platformString)
build := config.fillBuildStructure(value)
defaultBuild := bringauto_prerequisites.CreateAndInitialize[bringauto_build.Build]()
err := copier.CopyWithOption(defaultBuild, build, copier.Option{DeepCopy: true, IgnoreEmpty: true})
if err != nil {
Expand All @@ -100,7 +101,7 @@ func (config *Config) GetBuildStructure(imageName string, platformString *bringa
return buildConfigs
}

func (config *Config) fillBuildStructure(dockerImageName string, platformString *bringauto_package.PlatformString) bringauto_build.Build {
func (config *Config) fillBuildStructure(dockerImageName string) bringauto_build.Build {
var err error
defaultDocker := bringauto_prerequisites.CreateAndInitialize[bringauto_docker.Docker]()
defaultDocker.ImageName = dockerImageName
Expand All @@ -121,11 +122,10 @@ func (config *Config) fillBuildStructure(dockerImageName string, platformString
panic(err)
}

sshCreds := bringauto_prerequisites.CreateAndInitialize[bringauto_ssh.SSHCredentials]()
tmpPackage := config.Package
err = bringauto_prerequisites.Initialize(&tmpPackage)
if platformString != nil {
tmpPackage.PlatformString = *platformString
}

err = bringauto_prerequisites.Initialize(&tmpPackage, sshCreds, defaultDocker)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 9494381

Please sign in to comment.