-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cbuild] Add list environment command
Related to Open-CMSIS-Pack/devtools#783 Extended `cbuild` with `list environment` command for e.g ``` $ cbuild list environment CMSIS_PACK_ROOT=C:/Users/Test/AppData/Local/Arm/Packs CMSIS_COMPILER_ROOT=C:/Test/cmsis-toolbox/etc cmake=C:/tools/bin/cmake.exe, version 3.26.0 ninja=C:/Users/Test/AppData/Local/Programs/Python/Python310/Scripts/ninja.exe, version 1.10.2 ``` or ``` $ cbuild list environment CMSIS_PACK_ROOT=C:/Users/Test/AppData/Local/Arm/Packs CMSIS_COMPILER_ROOT=C:/Test/cmsis-toolbox/etc cmake=<Not Found> ninja=<Not Found> ``` or ``` $ cbuild list environment -h Print list of environment configurations Usage: cbuild list environment [flags] Flags: -h, --help help for environment Global Flags: -l, --log string Save output messages in a log file ```
- Loading branch information
Showing
8 changed files
with
208 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2023 Arm Limited. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package list | ||
|
||
import ( | ||
"cbuild/pkg/builder" | ||
"cbuild/pkg/builder/csolution" | ||
"cbuild/pkg/utils" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ListEnvironmentCmd = &cobra.Command{ | ||
Use: "environment", | ||
Short: "Print list of environment configurations", | ||
Args: cobra.MaximumNArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
configs, err := utils.GetInstallConfigs() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
p := csolution.CSolutionBuilder{ | ||
BuilderParams: builder.BuilderParams{ | ||
Runner: utils.Runner{}, | ||
InstallConfigs: configs, | ||
}, | ||
} | ||
return p.ListEnvironment() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2023 Arm Limited. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package list_test | ||
|
||
import ( | ||
"cbuild/cmd/cbuild/commands" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestListEnvironmentCommand(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
t.Run("invalid args", func(t *testing.T) { | ||
cmd := commands.NewRootCmd() | ||
cmd.SetArgs([]string{"list", "environment", "--invalid"}) | ||
err := cmd.Execute() | ||
assert.Error(err) | ||
}) | ||
|
||
t.Run("test list environment", func(t *testing.T) { | ||
cmd := commands.NewRootCmd() | ||
cmd.SetArgs([]string{"list", "environment"}) | ||
err := cmd.Execute() | ||
assert.Error(err) | ||
}) | ||
|
||
t.Run("test help", func(t *testing.T) { | ||
cmd := commands.NewRootCmd() | ||
cmd.SetArgs([]string{"list", "environment", "-h"}) | ||
err := cmd.Execute() | ||
assert.Nil(err) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ func (r RunnerMock) ExecuteCommand(program string, quiet bool, args ...string) ( | |
return "[email protected]\n[email protected]\n[email protected]\n[email protected]\n", nil | ||
} else if args[1] == "packs" { | ||
return "ARM::test:0.0.1\r\nARM::test2:0.0.2", nil | ||
} else if args[1] == "environment" { | ||
return "CMSIS_PACK_ROOT=C:/Path/Packs\nCMSIS_COMPILER_ROOT=C:/Test/etc\n", nil | ||
} | ||
} else if args[0] == "convert" { | ||
return "", nil | ||
|
@@ -271,6 +273,45 @@ func TestListToolchians(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestListEnvironment(t *testing.T) { | ||
assert := assert.New(t) | ||
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin") | ||
configs, err := utils.GetInstallConfigs() | ||
assert.Nil(err) | ||
b := CSolutionBuilder{ | ||
BuilderParams: builder.BuilderParams{ | ||
Runner: RunnerMock{}, | ||
InstallConfigs: configs, | ||
}, | ||
} | ||
|
||
t.Run("test list environment", func(t *testing.T) { | ||
envConfigs, err := b.listEnvironment(true) | ||
assert.Nil(err) | ||
assert.Equal(len(envConfigs), 4) | ||
assert.Equal("CMSIS_PACK_ROOT=C:/Path/Packs", envConfigs[0]) | ||
assert.Equal("CMSIS_COMPILER_ROOT=C:/Test/etc", envConfigs[1]) | ||
assert.Regexp(`^cmake=([^\s]+)`, envConfigs[2]) | ||
assert.Regexp(`^ninja=([^\s]+)`, envConfigs[3]) | ||
}) | ||
|
||
t.Run("test list environment fails to detect", func(t *testing.T) { | ||
// set empty install config, when cbuild is run standalone (without installation env) | ||
b.InstallConfigs = utils.Configurations{} | ||
envConfigs, err := b.listEnvironment(true) | ||
assert.Error(err) | ||
assert.Equal(len(envConfigs), 0) | ||
// restore install config | ||
b.InstallConfigs = configs | ||
}) | ||
|
||
t.Run("test list environment", func(t *testing.T) { | ||
err := b.ListEnvironment() | ||
assert.Nil(err) | ||
}) | ||
|
||
} | ||
|
||
func TestBuild(t *testing.T) { | ||
assert := assert.New(t) | ||
os.Setenv("CMSIS_BUILD_ROOT", testRoot+"/run/bin") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters