Skip to content

Commit

Permalink
[cbuild] Restore cbuild setup --output option (#300)
Browse files Browse the repository at this point in the history
Address Open-CMSIS-Pack/devtools#1747
Fix cbuild-set location when `--output` is specified -
Arm-Debug/devtools-external#1023
  • Loading branch information
brondani authored Sep 10, 2024
1 parent 56da956 commit 40fe18b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/cbuild/commands/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func setUpProject(cmd *cobra.Command, args []string) error {
contexts, _ := cmd.Flags().GetStringSlice("context")
load, _ := cmd.Flags().GetString("load")
jobs, _ := cmd.Flags().GetInt("jobs")
output, _ := cmd.Flags().GetString("output")
quiet, _ := cmd.Flags().GetBool("quiet")
debug, _ := cmd.Flags().GetBool("debug")
verbose, _ := cmd.Flags().GetBool("verbose")
Expand Down Expand Up @@ -94,6 +95,7 @@ func setUpProject(cmd *cobra.Command, args []string) error {
Contexts: contexts,
UseContextSet: useContextSet,
Load: load,
Output: output,
Toolchain: toolchain,
FrozenPacks: frozenPacks,
UseCbuild2CMake: useCbuild2CMake,
Expand Down Expand Up @@ -145,6 +147,7 @@ func init() {
SetUpCmd.Flags().StringP("load", "l", "", "Set policy for packs loading [latest | all | required]")
SetUpCmd.Flags().IntP("jobs", "j", 8, "Number of job slots for parallel execution")
SetUpCmd.Flags().StringP("target", "t", "", "Optional CMake target name")
SetUpCmd.Flags().StringP("output", "O", "", "Add prefix to 'outdir' and 'tmpdir'")
SetUpCmd.Flags().BoolP("schema", "s", true, "Validate project input file(s) against schema")
SetUpCmd.Flags().StringP("log", "", "", "Save output messages in a log file")
SetUpCmd.Flags().StringP("toolchain", "", "", "Input toolchain to be used")
Expand Down
9 changes: 7 additions & 2 deletions pkg/builder/csolution/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,13 @@ func (b CSolutionBuilder) getProjectName(csolutionFile string) (projectName stri
// It is the caller's responsibility to verify if the file exists."
func (b CSolutionBuilder) getCbuildSetFilePath() string {
projName := b.getProjectName(b.InputFile)
setFilePath := utils.NormalizePath(filepath.Join(filepath.Dir(b.InputFile), projName+".cbuild-set.yml"))
return setFilePath
var cbuildSetDir string
if len(b.Options.Output) > 0 {
cbuildSetDir = b.Options.Output
} else {
cbuildSetDir = filepath.Dir(b.InputFile)
}
return utils.NormalizePath(filepath.Join(cbuildSetDir, projName+".cbuild-set.yml"))
}

func (b CSolutionBuilder) getProjsBuilders(selectedContexts []string) (projBuilders []builder.IBuilderInterface, err error) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/builder/csolution/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@ func TestGetCbuildSetFilePath(t *testing.T) {
path := b.getCbuildSetFilePath()
assert.Equal(path, utils.NormalizePath(filepath.Join(testRoot, testDir, "TestSolution/test.cbuild-set.yml")))
})

t.Run("test get cbuild-set file path with output option", func(t *testing.T) {
b.InputFile = filepath.Join(testRoot, testDir, "TestSolution/test.csolution.yml")
b.Options.Output = "OutOfTree"
path := b.getCbuildSetFilePath()
assert.Equal(path, utils.NormalizePath("OutOfTree/test.cbuild-set.yml"))
})
}

func TestHasRebuildNode(t *testing.T) {
Expand Down

0 comments on commit 40fe18b

Please sign in to comment.