From cd9e0334fc917e635cc4c4f83d7d74f60546095a Mon Sep 17 00:00:00 2001 From: Sourabh Mehta Date: Fri, 14 Jun 2024 08:24:03 +0200 Subject: [PATCH 1/4] Run cbuild2cmake per context --- pkg/builder/cbuildidx/builder.go | 30 ++++++------- pkg/builder/cbuildidx/builder_test.go | 2 +- pkg/builder/csolution/builder.go | 65 +++++++++++++-------------- pkg/builder/interface.go | 2 +- 4 files changed, 47 insertions(+), 52 deletions(-) diff --git a/pkg/builder/cbuildidx/builder.go b/pkg/builder/cbuildidx/builder.go index 88429ab0..97dec078 100644 --- a/pkg/builder/cbuildidx/builder.go +++ b/pkg/builder/cbuildidx/builder.go @@ -134,7 +134,7 @@ func (b CbuildIdxBuilder) Build() error { _ = utils.UpdateEnvVars(vars.BinPath, vars.EtcPath) - if len(b.Options.Contexts) == 0 && len(b.BuildContexts) == 0 { + if len(b.Options.Contexts) == 0 && b.BuildContext == "" { err = errors.New("error no context(s) to process") return err } @@ -144,16 +144,14 @@ func (b CbuildIdxBuilder) Build() error { } if b.Options.Clean { - for _, context := range b.BuildContexts { - dirs, err := b.getDirs(context) - if err != nil { - return err - } + dirs, err := b.getDirs(b.BuildContext) + if err != nil { + return err + } - log.Info("Cleaning context: \"" + context + "\"") - if err := b.clean(dirs, vars); err != nil { - return err - } + log.Info("Cleaning context: \"" + b.BuildContext + "\"") + if err := b.clean(dirs, vars); err != nil { + return err } return nil } @@ -208,19 +206,19 @@ func (b CbuildIdxBuilder) Build() error { // CMake build target(s) command args = []string{"--build", dirs.IntDir, "-j", fmt.Sprintf("%d", b.GetJobs())} + if b.Options.Target != "" { args = append(args, "--target", b.Options.Target) - } else if len(b.Options.Contexts) == 0 { - args = append(args, "--target", "all") + } else if b.BuildContext != "" { + args = append(args, "--target", b.BuildContext) } else { - for _, context := range b.BuildContexts { + for _, context := range b.Options.Contexts { args = append(args, "--target", context) } } + if b.Setup { - for _, context := range b.BuildContexts { - args = append(args, "--target", context+"-database") - } + args = append(args, "--target", b.BuildContext+"-database") } if b.Options.Debug { diff --git a/pkg/builder/cbuildidx/builder_test.go b/pkg/builder/cbuildidx/builder_test.go index 866628cd..e32c4dbc 100644 --- a/pkg/builder/cbuildidx/builder_test.go +++ b/pkg/builder/cbuildidx/builder_test.go @@ -240,7 +240,7 @@ func TestBuildAllContexts(t *testing.T) { BinExtn: configs.BinExtn, EtcPath: configs.EtcPath, }, - BuildContexts: []string{"Hello.Debug+AVH"}, + BuildContext: "Hello.Debug+AVH", }, } t.Run("test build cbuild-idx", func(t *testing.T) { diff --git a/pkg/builder/csolution/builder.go b/pkg/builder/csolution/builder.go index 27959718..ef64e857 100644 --- a/pkg/builder/csolution/builder.go +++ b/pkg/builder/csolution/builder.go @@ -315,30 +315,30 @@ func (b CSolutionBuilder) getProjsBuilders(selectedContexts []string) (projBuild } var projBuilder builder.IBuilderInterface - if b.Options.UseCbuild2CMake { - // get idx builder - projBuilder = cbuildidx.CbuildIdxBuilder{ - BuilderParams: builder.BuilderParams{ - Runner: b.Runner, - Options: buildOptions, - InputFile: idxFile, - InstallConfigs: b.InstallConfigs, - Setup: b.Setup, - BuildContexts: selectedContexts, - }, + for _, context := range selectedContexts { + infoMsg := "Retrieve build information for context: \"" + context + "\"" + log.Info(infoMsg) + + // if --output is used, ignore provided --outdir and --intdir + if b.Options.Output != "" && (b.Options.OutDir != "" || b.Options.IntDir != "") { + log.Warn("output files are generated under: \"" + + b.Options.Output + "\". Options --outdir and --intdir shall be ignored.") } - projBuilders = append(projBuilders, projBuilder) - } else { - for _, context := range selectedContexts { - infoMsg := "Retrieve build information for context: \"" + context + "\"" - log.Info(infoMsg) - - // if --output is used, ignore provided --outdir and --intdir - if b.Options.Output != "" && (b.Options.OutDir != "" || b.Options.IntDir != "") { - log.Warn("output files are generated under: \"" + - b.Options.Output + "\". Options --outdir and --intdir shall be ignored.") - } + if b.Options.UseCbuild2CMake { + // get idx builder + projBuilder = cbuildidx.CbuildIdxBuilder{ + BuilderParams: builder.BuilderParams{ + Runner: b.Runner, + Options: buildOptions, + InputFile: idxFile, + InstallConfigs: b.InstallConfigs, + Setup: b.Setup, + BuildContext: context, + }, + } + projBuilders = append(projBuilders, projBuilder) + } else { cprjFile, err := b.getCprjFilePath(idxFile, context) if err != nil { log.Error("error getting cprj file: " + err.Error()) @@ -404,7 +404,8 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders operation = "Setting up" } - buildSuccess := true + buildPassCnt := 0 + buildFailCnt := 0 var totalBuildTime time.Duration for index := range projBuilders { var infoMsg string @@ -415,11 +416,9 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders infoMsg = progress + " " + operation + " context: \"" + selectedContexts[index] + "\"" } - if !b.Options.UseCbuild2CMake { - sep := strings.Repeat("=", len(infoMsg)+13) - utils.LogStdMsg(sep) - utils.LogStdMsg(infoMsg) - } + sep := strings.Repeat("=", len(infoMsg)+13) + utils.LogStdMsg(sep) + utils.LogStdMsg(infoMsg) b.setBuilderOptions(&projBuilders[index], false) @@ -427,18 +426,16 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders err = projBuilders[index].Build() if err != nil { log.Error("error " + strings.ToLower(operation) + " '" + b.getBuilderInputFile(projBuilders[index]) + "'") - buildSuccess = false + buildFailCnt += 1 + } else { + buildPassCnt += 1 } buildEndTime := time.Now() elapsedTime := buildEndTime.Sub(buildStartTime) totalBuildTime += elapsedTime } if !b.Setup { - buildStatus := "Build completed successfully" - if !buildSuccess { - buildStatus = "Build failed" - } - buildSummary := fmt.Sprintf("\nBuild summary: %s - Time Elapsed: %s", buildStatus, utils.FormatTime(totalBuildTime)) + buildSummary := fmt.Sprintf("\nBuild summary: %d succeeded, %d failed - Time Elapsed: %s", buildPassCnt, buildFailCnt, utils.FormatTime(totalBuildTime)) utils.LogStdMsg(buildSummary) } return diff --git a/pkg/builder/interface.go b/pkg/builder/interface.go index 7e548c28..4604cb60 100644 --- a/pkg/builder/interface.go +++ b/pkg/builder/interface.go @@ -22,7 +22,7 @@ type BuilderParams struct { InputFile string InstallConfigs utils.Configurations Setup bool - BuildContexts []string + BuildContext string } type Options struct { From 26c4c7236ad85616d721352c7ec3de8ddc65c0b5 Mon Sep 17 00:00:00 2001 From: Sourabh Mehta Date: Fri, 14 Jun 2024 10:57:20 +0200 Subject: [PATCH 2/4] Remove duplicate contexts if requested in cmdline --- pkg/builder/cbuildidx/builder.go | 4 ---- pkg/utils/utils.go | 24 +++++++++++++++++++++++- pkg/utils/utils_test.go | 13 +++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/pkg/builder/cbuildidx/builder.go b/pkg/builder/cbuildidx/builder.go index 97dec078..e5f762c7 100644 --- a/pkg/builder/cbuildidx/builder.go +++ b/pkg/builder/cbuildidx/builder.go @@ -211,10 +211,6 @@ func (b CbuildIdxBuilder) Build() error { args = append(args, "--target", b.Options.Target) } else if b.BuildContext != "" { args = append(args, "--target", b.BuildContext) - } else { - for _, context := range b.Options.Contexts { - args = append(args, "--target", context) - } } if b.Setup { diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 44f0c570..b0329780 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -278,7 +278,10 @@ func GetProjectName(csolutionFile string) (projectName string, err error) { func ResolveContexts(allContext []string, contextFilters []string) ([]string, error) { var selectedContexts []string - for _, filter := range contextFilters { + // remove duplicates (if any) + filters := RemoveDuplicates(contextFilters) + + for _, filter := range filters { filterContextItem, err := ParseContext(filter) if err != nil { return nil, err @@ -351,3 +354,22 @@ func FormatTime(time time.Duration) string { // Format time in "hh:mm:ss" return fmt.Sprintf("%02d:%02d:%02d", int(time.Hours()), int(time.Minutes())%60, int(time.Seconds())%60) } + +func RemoveDuplicates(input []string) []string { + // Create a map to track seen strings + seen := make(map[string]bool) + // Create a slice to store the unique strings + var result []string + + // Iterate over the input slice + for _, str := range input { + // If the string is not in the map, + // add it to the result and mark it as seen + if !seen[str] { + result = append(result, str) + seen[str] = true + } + } + + return result +} diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index ba799f02..6f4cf82e 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -372,3 +372,16 @@ func TestRemoveVersionRange(t *testing.T) { assert.Equal(test.expectedOutput, outString) } } + +func TestRemoveDuplicates(t *testing.T) { + assert := assert.New(t) + + inputList := []string{"apple", "banana", "apple", "orange", "banana", "grape"} + UniqueList := []string{"apple", "banana", "orange", "grape"} + + outUniqueList := RemoveDuplicates(inputList) + assert.Equal(UniqueList, outUniqueList) + + outUniqueList = RemoveDuplicates(UniqueList) + assert.Equal(UniqueList, outUniqueList) +} From 520c1be30c33703c8d424fe410d6fbba314644f9 Mon Sep 17 00:00:00 2001 From: Sourabh Mehta Date: Fri, 14 Jun 2024 14:06:20 +0200 Subject: [PATCH 3/4] Changed seperators in the output logs --- pkg/builder/csolution/builder.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/builder/csolution/builder.go b/pkg/builder/csolution/builder.go index ef64e857..a58fe7fb 100644 --- a/pkg/builder/csolution/builder.go +++ b/pkg/builder/csolution/builder.go @@ -404,6 +404,11 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders operation = "Setting up" } + printSeparator := func(delimiter string, length int) { + sep := strings.Repeat(delimiter, length) + utils.LogStdMsg(sep) + } + buildPassCnt := 0 buildFailCnt := 0 var totalBuildTime time.Duration @@ -416,10 +421,8 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders infoMsg = progress + " " + operation + " context: \"" + selectedContexts[index] + "\"" } - sep := strings.Repeat("=", len(infoMsg)+13) - utils.LogStdMsg(sep) + printSeparator("-", len(infoMsg)) utils.LogStdMsg(infoMsg) - b.setBuilderOptions(&projBuilders[index], false) buildStartTime := time.Now() @@ -435,8 +438,11 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders totalBuildTime += elapsedTime } if !b.Setup { - buildSummary := fmt.Sprintf("\nBuild summary: %d succeeded, %d failed - Time Elapsed: %s", buildPassCnt, buildFailCnt, utils.FormatTime(totalBuildTime)) + buildSummary := fmt.Sprintf("Build summary: %d succeeded, %d failed - Time Elapsed: %s", buildPassCnt, buildFailCnt, utils.FormatTime(totalBuildTime)) + sepLen := len(buildSummary) + printSeparator("-", sepLen) utils.LogStdMsg(buildSummary) + printSeparator("=", sepLen) } return } From bf39f0ccf92b161d1b4ac659434799febbc0cb01 Mon Sep 17 00:00:00 2001 From: Sourabh Mehta Date: Fri, 14 Jun 2024 15:28:40 +0200 Subject: [PATCH 4/4] Cleanup cbuild errors --- pkg/builder/cbuildidx/builder.go | 6 ------ pkg/builder/cproject/builder.go | 8 -------- pkg/builder/csolution/builder.go | 10 ++-------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/pkg/builder/cbuildidx/builder.go b/pkg/builder/cbuildidx/builder.go index e5f762c7..659062c3 100644 --- a/pkg/builder/cbuildidx/builder.go +++ b/pkg/builder/cbuildidx/builder.go @@ -43,9 +43,6 @@ func (b CbuildIdxBuilder) clean(dirs builder.BuildDirs, vars builder.InternalVar } args := []string{"-E", "remove_directory", dir} _, err = b.Runner.ExecuteCommand(vars.CmakeBin, false, args...) - if err != nil { - log.Error("error executing 'cmake' clean for " + dir) - } return err } @@ -167,7 +164,6 @@ func (b CbuildIdxBuilder) Build() error { _, err = b.Runner.ExecuteCommand(vars.Cbuild2cmakeBin, false, args...) if err != nil { - log.Error("error executing 'cbuild2cmake " + b.InputFile + "'") return err } if _, err := os.Stat(dirs.IntDir + "/CMakeLists.txt"); errors.Is(err, os.ErrNotExist) { @@ -200,7 +196,6 @@ func (b CbuildIdxBuilder) Build() error { _, err = b.Runner.ExecuteCommand(vars.CmakeBin, b.Options.Quiet, args...) if err != nil { - log.Error("error executing 'cmake' configuration") return err } @@ -223,7 +218,6 @@ func (b CbuildIdxBuilder) Build() error { _, err = b.Runner.ExecuteCommand(vars.CmakeBin, false, args...) if err != nil { - log.Error("error executing 'cmake' build") return err } diff --git a/pkg/builder/cproject/builder.go b/pkg/builder/cproject/builder.go index 208b39a6..6407e629 100644 --- a/pkg/builder/cproject/builder.go +++ b/pkg/builder/cproject/builder.go @@ -43,14 +43,12 @@ func (b CprjBuilder) clean(dirs builder.BuildDirs, vars builder.InternalVars) (e if _, err := os.Stat(dirs.IntDir); !os.IsNotExist(err) { _, err = b.Runner.ExecuteCommand(vars.CbuildgenBin, false, "rmdir", dirs.IntDir) if err != nil { - log.Error("error executing 'cbuildgen rmdir'") return err } } if _, err := os.Stat(dirs.OutDir); !os.IsNotExist(err) { _, err = b.Runner.ExecuteCommand(vars.CbuildgenBin, false, "rmdir", dirs.OutDir) if err != nil { - log.Error("error executing 'cbuildgen rmdir'") return err } } @@ -140,7 +138,6 @@ func (b CprjBuilder) Build() error { } else { _, err = b.Runner.ExecuteCommand(vars.XmllintBin, b.Options.Quiet, "--schema", filepath.Join(vars.EtcPath, "CPRJ.xsd"), b.InputFile, "--noout") if err != nil { - log.Error("error executing 'xmllint'") return err } } @@ -163,7 +160,6 @@ func (b CprjBuilder) Build() error { } _, err = b.Runner.ExecuteCommand(vars.CbuildgenBin, false, args...) if err != nil { - log.Error("error executing 'cbuildgen packlist'") return err } @@ -181,7 +177,6 @@ func (b CprjBuilder) Build() error { } _, err = b.Runner.ExecuteCommand(vars.CpackgetBin, b.Options.Quiet, args...) if err != nil { - log.Error("error executing 'cpackget add'") return err } } else { @@ -206,7 +201,6 @@ func (b CprjBuilder) Build() error { _, err = b.Runner.ExecuteCommand(vars.CbuildgenBin, false, args...) if err != nil { - log.Error("error executing 'cbuildgen cmake'") return err } @@ -240,7 +234,6 @@ func (b CprjBuilder) Build() error { _, err = b.Runner.ExecuteCommand(vars.CmakeBin, b.Options.Quiet, args...) if err != nil { - log.Error("error executing 'cmake' configuration") return err } @@ -263,7 +256,6 @@ func (b CprjBuilder) Build() error { _, err = b.Runner.ExecuteCommand(vars.CmakeBin, false, args...) if err != nil { - log.Error("error executing 'cmake' build") return err } diff --git a/pkg/builder/csolution/builder.go b/pkg/builder/csolution/builder.go index a58fe7fb..a1631807 100644 --- a/pkg/builder/csolution/builder.go +++ b/pkg/builder/csolution/builder.go @@ -95,7 +95,6 @@ func (b CSolutionBuilder) installMissingPacks() (err error) { // Get list of missing packs output, err := b.runCSolution(args, false) if err != nil { - log.Error("error in getting list of missing packs") return err } @@ -120,7 +119,6 @@ func (b CSolutionBuilder) installMissingPacks() (err error) { _, err = b.Runner.ExecuteCommand(cpackgetBin, false, args...) if err != nil { - log.Error("error installing pack : " + pack) return err } } @@ -175,7 +173,6 @@ func (b CSolutionBuilder) generateBuildFiles() (err error) { // Retrieve all available contexts in yml-order allContexts, err := b.listContexts(true, true) if err != nil { - log.Error("error getting list of contexts: \"" + err.Error() + "\"") return err } @@ -405,8 +402,8 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders } printSeparator := func(delimiter string, length int) { - sep := strings.Repeat(delimiter, length) - utils.LogStdMsg(sep) + sep := strings.Repeat(delimiter, length-1) + utils.LogStdMsg("+" + sep) } buildPassCnt := 0 @@ -428,7 +425,6 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders buildStartTime := time.Now() err = projBuilders[index].Build() if err != nil { - log.Error("error " + strings.ToLower(operation) + " '" + b.getBuilderInputFile(projBuilders[index]) + "'") buildFailCnt += 1 } else { buildPassCnt += 1 @@ -559,7 +555,6 @@ func (b CSolutionBuilder) build() (err error) { if len(b.Options.Contexts) != 0 && !b.Options.UseContextSet { allContexts, err = b.listContexts(true, true) if err != nil { - log.Error("error getting list of contexts: \"" + err.Error() + "\"") return err } selectedContexts, err = utils.ResolveContexts(allContexts, b.Options.Contexts) @@ -606,7 +601,6 @@ func (b CSolutionBuilder) Build() (err error) { // STEP 1: Install missing pack(s) if err = b.installMissingPacks(); err != nil { - log.Error("error installing missing packs") // Continue with build files generation upon setup command if !b.Setup { return err