diff --git a/bap-builder/PackageMode.go b/bap-builder/PackageMode.go index 380f70a..593b307 100644 --- a/bap-builder/PackageMode.go +++ b/bap-builder/PackageMode.go @@ -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, } @@ -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) } @@ -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, } @@ -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) } @@ -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") } @@ -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{ @@ -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) { diff --git a/modules/bringauto_config/Config.go b/modules/bringauto_config/Config.go index 8f44db7..fbd71b3 100644 --- a/modules/bringauto_config/Config.go +++ b/modules/bringauto_config/Config.go @@ -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" @@ -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 { @@ -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 @@ -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) }