Skip to content

Commit 817b8fa

Browse files
committed
Deprecate --build-properties flag in favor of --build-property
1 parent 17fe9a1 commit 817b8fa

File tree

6 files changed

+119
-28
lines changed

6 files changed

+119
-28
lines changed

Diff for: cli/compile/compile.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ var (
5757
// NewCommand created a new `compile` command
5858
func NewCommand() *cobra.Command {
5959
command := &cobra.Command{
60-
Use: "compile",
61-
Short: "Compiles Arduino sketches.",
62-
Long: "Compiles Arduino sketches.",
63-
Example: " " + os.Args[0] + " compile -b arduino:avr:uno /home/user/Arduino/MySketch",
64-
Args: cobra.MaximumNArgs(1),
65-
Run: run,
60+
Use: "compile",
61+
Short: "Compiles Arduino sketches.",
62+
Long: "Compiles Arduino sketches.",
63+
Example: "" +
64+
" " + os.Args[0] + " compile -b arduino:avr:uno /home/user/Arduino/MySketch\n" +
65+
" " + os.Args[0] + " compile -b arduino:avr:uno --build-property='build.extra_flags=\"-DMY_DEFINE=\"hello world\"\"' /home/user/Arduino/MySketch\n" +
66+
" " + os.Args[0] + " compile -b arduino:avr:uno --build-property='build.extra_flags=-DPIN=2 \"-DMY_DEFINE=\"hello world\"\"' /home/user/Arduino/MySketch\n" +
67+
" " + os.Args[0] + " compile -b arduino:avr:uno --build-property=build.extra_flags=-DPIN=2 --build-property='compiler.cpp.extra_flags=\"-DSSID=\"hello world\"\"'-DMY_DEFINE=\"hello world\"' /home/user/Arduino/MySketch\n",
68+
Args: cobra.MaximumNArgs(1),
69+
Run: run,
6670
}
6771

6872
command.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno")
@@ -73,8 +77,10 @@ func NewCommand() *cobra.Command {
7377
command.Flags().BoolVarP(&dryRun, "dry-run", "n", false, "Perform the build but do not copy the compile output file.")
7478
command.Flags().StringVar(&buildPath, "build-path", "",
7579
"Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.")
76-
command.Flags().StringArrayVar(&buildProperties, "build-properties", []string{},
77-
"List of custom build properties separated by spaces. Or can be used multiple times for multiple properties.")
80+
command.Flags().StringSliceVar(&buildProperties, "build-properties", []string{},
81+
"List of custom build properties separated by commas. Or can be used multiple times for multiple properties.")
82+
command.Flags().StringArrayVar(&buildProperties, "build-property", []string{},
83+
"Override a build property with a custom value. Can be used multiple times for multiple properties.")
7884
command.Flags().StringVar(&warnings, "warnings", "none",
7985
`Optional, can be "none", "default", "more" and "all". Defaults to "none". Used to tell gcc which warning level to use (-W flag).`)
8086
command.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
@@ -89,6 +95,8 @@ func NewCommand() *cobra.Command {
8995
command.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload.")
9096
command.Flags().BoolVar(&clean, "clean", false, "Optional, cleanup the build folder and do not use any cached build.")
9197

98+
command.Flags().MarkDeprecated("build-properties", "please use --build-property instead.")
99+
92100
return command
93101
}
94102

Diff for: test/test_compile.py

+76-20
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,78 @@ def test_compile_without_precompiled_libraries(run_command, data_dir):
235235
assert result.ok
236236

237237

238-
def test_compile_with_build_property_containing_quotes(run_command, data_dir, copy_sketch):
238+
def test_compile_with_build_properties_flag(run_command, data_dir, copy_sketch):
239239
# Init the environment explicitly
240240
assert run_command("core update-index")
241241

242242
# Install Arduino AVR Boards
243243
assert run_command("core install arduino:[email protected]")
244244

245-
sketch_path = copy_sketch("sketch_with_single_define")
245+
sketch_path = copy_sketch("sketch_with_single_string_define")
246246
fqbn = "arduino:avr:uno"
247247

248-
# Compile using a build property with an equal
248+
# Compile using a build property with quotes
249249
res = run_command(
250250
f"compile -b {fqbn} "
251251
+ '--build-properties="build.extra_flags=\\"-DMY_DEFINE=\\"hello world\\"\\"" '
252+
+ f"{sketch_path} --verbose --clean"
253+
)
254+
assert res.failed
255+
assert "Flag --build-properties has been deprecated, please use --build-property instead." not in res.stderr
256+
257+
# Try again with quotes
258+
res = run_command(
259+
f"compile -b {fqbn} "
260+
+ '--build-properties="build.extra_flags=-DMY_DEFINE=\\"hello\\"" '
261+
+ f"{sketch_path} --verbose --clean"
262+
)
263+
assert res.failed
264+
assert "Flag --build-properties has been deprecated, please use --build-property instead." not in res.stderr
265+
266+
# Try without quotes
267+
sketch_path = copy_sketch("sketch_with_single_int_define")
268+
res = run_command(
269+
f"compile -b {fqbn} "
270+
+ '--build-properties="build.extra_flags=-DMY_DEFINE=1" '
271+
+ f"{sketch_path} --verbose --clean"
272+
)
273+
assert res.ok
274+
assert "Flag --build-properties has been deprecated, please use --build-property instead." in res.stderr
275+
assert "-DMY_DEFINE=1" in res.stdout
276+
277+
sketch_path = copy_sketch("sketch_with_multiple_int_defines")
278+
res = run_command(
279+
f"compile -b {fqbn} "
280+
+ '--build-properties="build.extra_flags=-DFIRST_PIN=1,compiler.cpp.extra_flags=-DSECOND_PIN=2" '
281+
+ f"{sketch_path} --verbose --clean"
282+
)
283+
assert res.ok
284+
assert "Flag --build-properties has been deprecated, please use --build-property instead." in res.stderr
285+
assert "-DFIRST_PIN=1" in res.stdout
286+
assert "-DSECOND_PIN=2" in res.stdout
287+
288+
289+
def test_compile_with_build_property_containing_quotes(run_command, data_dir, copy_sketch):
290+
# Init the environment explicitly
291+
assert run_command("core update-index")
292+
293+
# Install Arduino AVR Boards
294+
assert run_command("core install arduino:[email protected]")
295+
296+
sketch_path = copy_sketch("sketch_with_single_string_define")
297+
fqbn = "arduino:avr:uno"
298+
299+
# Compile using a build property with quotes
300+
res = run_command(
301+
f"compile -b {fqbn} "
302+
+ '--build-property="build.extra_flags=\\"-DMY_DEFINE=\\"hello world\\"\\"" '
252303
+ f"{sketch_path} --verbose"
253304
)
254305
assert res.ok
255306
assert '-DMY_DEFINE=\\"hello world\\"' in res.stdout
256307

257308

258-
def test_compile_with_multiple_build_properties(run_command, data_dir, copy_sketch):
309+
def test_compile_with_multiple_build_property_flags(run_command, data_dir, copy_sketch, working_dir):
259310
# Init the environment explicitly
260311
assert run_command("core update-index")
261312

@@ -265,42 +316,47 @@ def test_compile_with_multiple_build_properties(run_command, data_dir, copy_sket
265316
sketch_path = copy_sketch("sketch_with_multiple_defines")
266317
fqbn = "arduino:avr:uno"
267318

268-
# Create a test sketch
269-
assert run_command(f"sketch new {sketch_path}")
270-
271319
# Compile using multiple build properties separated by a space
272320
res = run_command(
273321
f"compile -b {fqbn} "
274-
+ '--build-properties="compiler.cpp.extra_flags=\\"-DPIN=2 -DSSID=\\"This is a String\\"\\"" '
275-
+ f"{sketch_path} --verbose"
322+
+ '--build-property=\'compiler.cpp.extra_flags=\\"-DPIN=2 -DSSID=\\"This is a String\\"\\"\' '
323+
+ f"{sketch_path} --verbose --clean"
324+
)
325+
assert res.failed
326+
327+
# Compile using multiple build properties separated by a space and properly quoted
328+
res = run_command(
329+
f"compile -b {fqbn} "
330+
+ '--build-property=\'compiler.cpp.extra_flags=-DPIN=2 "-DSSID="This is a String""\' '
331+
+ f"{sketch_path} --verbose --clean"
276332
)
277333
assert res.ok
278-
assert '-DPIN=2 -DSSID=\\"This is a String\\"' in res.stdout
334+
assert '-DPIN=2 "-DSSID=\\"This is a String\\""' in res.stdout
279335

280336
# Tries compilation using multiple build properties separated by a comma
281337
res = run_command(
282338
f"compile -b {fqbn} "
283-
+ '--build-properties="compiler.cpp.extra_flags=\\"-DPIN=2,-DSSID=\\"This is a String\\"\\"\\" '
284-
+ f"{sketch_path} --verbose"
339+
+ '--build-property="compiler.cpp.extra_flags=\\"-DPIN=2,-DSSID=\\"This is a String\\"\\"\\" '
340+
+ f"{sketch_path} --verbose --clean"
285341
)
286342
assert res.failed
287343

288344
res = run_command(
289345
f"compile -b {fqbn} "
290-
+ '--build-properties="compiler.cpp.extra_flags=\\"-DPIN=2\\"" '
291-
+ '--build-properties="compiler.cpp.extra_flags=\\"-DSSID=\\"This is a String\\"\\"" '
292-
+ f"{sketch_path} --verbose"
346+
+ '--build-property="compiler.cpp.extra_flags=\\"-DPIN=2\\"" '
347+
+ '--build-property="compiler.cpp.extra_flags=\\"-DSSID=\\"This is a String\\"\\"" '
348+
+ f"{sketch_path} --verbose --clean"
293349
)
294-
assert res.ok
350+
assert res.failed
295351
assert "-DPIN=2" not in res.stdout
296352
assert '-DSSID=\\"This is a String\\"' in res.stdout
297353

298354
res = run_command(
299355
f"compile -b {fqbn} "
300-
+ '--build-properties="compiler.cpp.extra_flags=\\"-DPIN=2\\"" '
301-
+ '--build-properties="build.extra_flags=\\"-DMY_DEFINE=\\"hello world\\"\\"" '
302-
+ f"{sketch_path} --verbose"
356+
+ '--build-property="compiler.cpp.extra_flags=\\"-DPIN=2\\"" '
357+
+ '--build-property="build.extra_flags=\\"-DSSID=\\"hello world\\"\\"" '
358+
+ f"{sketch_path} --verbose --clean"
303359
)
304360
assert res.ok
305361
assert "-DPIN=2" in res.stdout
306-
assert '-DMY_DEFINE=\\"hello world\\"' in res.stdout
362+
assert '-DSSID=\\"hello world\\"' in res.stdout

Diff for: test/testdata/sketch_with_multiple_defines/sketch_with_multiple_defines.ino

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const int DEFAULT_PIN = PIN;
33
const String DEFAULT_SSID = SSID;
44

55
void setup() {
6+
Serial.begin(9600);
7+
Serial.println(DEFAULT_PIN);
8+
Serial.println(DEFAULT_SSID);
69
}
710

811
void loop() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
const int MY_FIRST_PIN = FIRST_PIN;
3+
const int MY_SECOND_PIN = SECOND_PIN;
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
Serial.println(MY_FIRST_PIN);
8+
Serial.println(MY_SECOND_PIN);
9+
}
10+
11+
void loop() {
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
const int FOO = MY_DEFINE;
3+
4+
void setup() {
5+
Serial.begin(9600);
6+
Serial.println(FOO);
7+
}
8+
9+
void loop() {
10+
}

Diff for: test/testdata/sketch_with_single_define/sketch_with_single_define.ino renamed to test/testdata/sketch_with_single_string_define/sketch_with_single_string_define.ino

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const String FOO = MY_DEFINE;
33

44
void setup() {
5+
Serial.begin(9600);
6+
Serial.println(FOO);
57
}
68

79
void loop() {

0 commit comments

Comments
 (0)