-
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for default build profile (#2203)
* Add support for default profile to compile command * Add support for default profiles to upload command * Add TestCompileWithDefaultProfile to integration tests * Get the profile's FQBN if it's not already specified in the request * Update documentation regarding sketch projects * Added integration tests for all default_profile cases * Reverted old sketch_with_profile test --------- Co-authored-by: Cristian Maglie <[email protected]>
- Loading branch information
1 parent
048415c
commit b748aec
Showing
10 changed files
with
161 additions
and
13 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
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
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
|
||
"github.com/arduino/arduino-cli/internal/integrationtest" | ||
"github.com/stretchr/testify/require" | ||
"go.bug.st/testifyjson/requirejson" | ||
) | ||
|
||
func TestCompileWithProfiles(t *testing.T) { | ||
|
@@ -69,3 +70,83 @@ func TestBuilderDidNotCatchLibsFromUnusedPlatforms(t *testing.T) { | |
require.NotContains(t, string(stdout), "samd") | ||
require.NotContains(t, string(stderr), "samd") | ||
} | ||
|
||
func TestCompileWithDefaultProfile(t *testing.T) { | ||
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) | ||
defer env.CleanUp() | ||
|
||
// Init the environment explicitly | ||
_, _, err := cli.Run("core", "update-index") | ||
require.NoError(t, err) | ||
|
||
// Installa core/libs globally | ||
_, _, err = cli.Run("core", "install", "arduino:[email protected]") | ||
require.NoError(t, err) | ||
|
||
// copy sketch_with_profile into the working directory | ||
sketchWithoutDefProfilePath := cli.CopySketch("sketch_without_default_profile") | ||
sketchWithDefProfilePath := cli.CopySketch("sketch_with_default_profile") | ||
|
||
{ | ||
// no default profile -> error missing FQBN | ||
_, _, err := cli.Run("compile", sketchWithoutDefProfilePath.String(), "--format", "json") | ||
require.Error(t, err) | ||
} | ||
{ | ||
// specified fbqn -> compile with specified FQBN and use global installation | ||
stdout, _, err := cli.Run("compile", "-b", "arduino:avr:nano", sketchWithoutDefProfilePath.String(), "--format", "json") | ||
require.NoError(t, err) | ||
jsonOut := requirejson.Parse(t, stdout) | ||
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.3"}`) | ||
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`) | ||
} | ||
{ | ||
// specified profile -> use the specified profile | ||
stdout, _, err := cli.Run("compile", "--profile", "avr1", sketchWithoutDefProfilePath.String(), "--format", "json") | ||
require.NoError(t, err) | ||
jsonOut := requirejson.Parse(t, stdout) | ||
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`) | ||
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:uno" ]`) | ||
} | ||
{ | ||
// specified profile and fqbn -> use the specified profile and override fqbn | ||
stdout, _, err := cli.Run("compile", "--profile", "avr1", "-b", "arduino:avr:nano", sketchWithoutDefProfilePath.String(), "--format", "json") | ||
require.NoError(t, err) | ||
jsonOut := requirejson.Parse(t, stdout) | ||
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`) | ||
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`) | ||
} | ||
|
||
{ | ||
// default profile -> use default profile | ||
stdout, _, err := cli.Run("compile", sketchWithDefProfilePath.String(), "--format", "json") | ||
require.NoError(t, err) | ||
jsonOut := requirejson.Parse(t, stdout) | ||
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.5"}`) | ||
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:leonardo" ]`) | ||
} | ||
{ | ||
// default profile, specified fbqn -> use default profile, override fqbn | ||
stdout, _, err := cli.Run("compile", "-b", "arduino:avr:nano", sketchWithDefProfilePath.String(), "--format", "json") | ||
require.NoError(t, err) | ||
jsonOut := requirejson.Parse(t, stdout) | ||
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.5"}`) | ||
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`) | ||
} | ||
{ | ||
// default profile, specified different profile -> use the specified profile | ||
stdout, _, err := cli.Run("compile", "--profile", "avr1", sketchWithDefProfilePath.String(), "--format", "json") | ||
require.NoError(t, err) | ||
jsonOut := requirejson.Parse(t, stdout) | ||
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`) | ||
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:uno" ]`) | ||
} | ||
{ | ||
// default profile, specified different profile and fqbn -> use the specified profile and override fqbn | ||
stdout, _, err := cli.Run("compile", "--profile", "avr1", "-b", "arduino:avr:nano", sketchWithDefProfilePath.String(), "--format", "json") | ||
require.NoError(t, err) | ||
jsonOut := requirejson.Parse(t, stdout) | ||
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`) | ||
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
internal/integrationtest/testdata/sketch_with_default_profile/sketch.yaml
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,12 @@ | ||
profiles: | ||
avr1: | ||
fqbn: arduino:avr:uno | ||
platforms: | ||
- platform: arduino:avr (1.8.4) | ||
|
||
avr2: | ||
fqbn: arduino:avr:leonardo | ||
platforms: | ||
- platform: arduino:avr (1.8.5) | ||
|
||
default_profile: avr2 |
2 changes: 2 additions & 0 deletions
2
...rnal/integrationtest/testdata/sketch_with_default_profile/sketch_with_default_profile.ino
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,2 @@ | ||
void setup() {} | ||
void loop() {} |
10 changes: 10 additions & 0 deletions
10
internal/integrationtest/testdata/sketch_without_default_profile/sketch.yaml
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,10 @@ | ||
profiles: | ||
avr1: | ||
fqbn: arduino:avr:uno | ||
platforms: | ||
- platform: arduino:avr (1.8.4) | ||
|
||
avr2: | ||
fqbn: arduino:avr:leonardo | ||
platforms: | ||
- platform: arduino:avr (1.8.5) |
2 changes: 2 additions & 0 deletions
2
...ntegrationtest/testdata/sketch_without_default_profile/sketch_without_default_profile.ino
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,2 @@ | ||
void setup() {} | ||
void loop() {} |