Skip to content

Commit f0245bc

Browse files
cmaglieper1234
andauthored
[skip-changelog] Fixed initialization of profile libraries (#1739)
* Fixed initializaion of profile libraries * Apply suggestions from code review The library must be installed globally in order to provide coverage of the bug. Co-authored-by: per1234 <[email protected]> Co-authored-by: per1234 <[email protected]>
1 parent 7e9e4ca commit f0245bc

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

Diff for: commands/compile/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
124124
builderCtx.OtherLibrariesDirs = paths.NewPathList(req.GetLibraries()...)
125125
builderCtx.OtherLibrariesDirs.Add(configuration.LibrariesDir(configuration.Settings))
126126
builderCtx.LibraryDirs = paths.NewPathList(req.Library...)
127-
if len(builderCtx.OtherLibrariesDirs) > 0 || len(builderCtx.LibraryDirs) > 0 {
127+
if len(req.GetLibraries()) > 0 || len(req.GetLibrary()) > 0 {
128128
builderCtx.LibrariesManager = nil // let the builder rebuild the library manager
129129
}
130130
if req.GetBuildPath() == "" {

Diff for: test/test_profiles.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is part of arduino-cli.
2+
#
3+
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
#
5+
# This software is released under the GNU General Public License version 3,
6+
# which covers the main part of arduino-cli.
7+
# The terms of this license can be found at:
8+
# https://www.gnu.org/licenses/gpl-3.0.en.html
9+
#
10+
# You can be released from the requirements of the above licenses by purchasing
11+
# a commercial license. Buying such a license is mandatory if you want to modify or
12+
# otherwise use the software for commercial activities involving the Arduino
13+
# software without disclosing the source code of your own applications. To purchase
14+
# a commercial license, send an email to [email protected].
15+
16+
17+
def test_compile_with_profiles(run_command, copy_sketch):
18+
# Init the environment explicitly
19+
run_command(["core", "update-index"])
20+
21+
sketch_path = copy_sketch("sketch_with_profile")
22+
23+
# use profile without a required library -> should fail
24+
assert run_command(["lib", "install", "Arduino_JSON"])
25+
result = run_command(["compile", "-m", "avr1", sketch_path])
26+
assert result.failed
27+
28+
# use profile with the required library -> should succeed
29+
result = run_command(["compile", "-m", "avr2", sketch_path])
30+
assert result.ok

Diff for: test/testdata/sketch_with_profile/sketch.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
profiles:
2+
avr1:
3+
fqbn: arduino:avr:uno
4+
platforms:
5+
- platform: arduino:avr (1.8.5)
6+
7+
avr2:
8+
fqbn: arduino:avr:uno
9+
platforms:
10+
- platform: arduino:avr (1.8.5)
11+
libraries:
12+
- Arduino_JSON (0.1.0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <Arduino_JSON.h>
2+
3+
void setup() {}
4+
void loop() {}

0 commit comments

Comments
 (0)