Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run cbuild2cmake per context & build summary #235

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions pkg/builder/cbuildidx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -208,19 +206,15 @@ 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 {
for _, context := range b.BuildContexts {
args = append(args, "--target", context)
}
} else if b.BuildContext != "" {
args = append(args, "--target", b.BuildContext)
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/cbuildidx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
73 changes: 38 additions & 35 deletions pkg/builder/csolution/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -404,7 +404,13 @@ func (b CSolutionBuilder) buildContexts(selectedContexts []string, projBuilders
operation = "Setting up"
}

buildSuccess := true
printSeparator := func(delimiter string, length int) {
sep := strings.Repeat(delimiter, length)
utils.LogStdMsg(sep)
}

buildPassCnt := 0
buildFailCnt := 0
var totalBuildTime time.Duration
for index := range projBuilders {
var infoMsg string
Expand All @@ -415,31 +421,28 @@ 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)
}

printSeparator("-", len(infoMsg))
utils.LogStdMsg(infoMsg)
b.setBuilderOptions(&projBuilders[index], false)

buildStartTime := time.Now()
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("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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type BuilderParams struct {
InputFile string
InstallConfigs utils.Configurations
Setup bool
BuildContexts []string
BuildContext string
}

type Options struct {
Expand Down
24 changes: 23 additions & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}