-
-
Notifications
You must be signed in to change notification settings - Fork 409
Allow locally installed libraries in sketch profiles. #2930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cmaglie
wants to merge
6
commits into
arduino:master
Choose a base branch
from
cmaglie:allow_paths_in_profile_libs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ebafc23
Allow directories in profile libraries
cmaglie a9cabb3
Updated docs
cmaglie a37057c
Dump custom libraries in profiles with --dump-profile command
cmaglie 211a7ea
Added integration tests
cmaglie cdd7f4e
Fix integration test in Windows
cmaglie 0bd806e
Improved integration tests
cmaglie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,99 @@ | ||
// This file is part of arduino-cli. | ||
// | ||
// Copyright 2022-2025 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This software is released under the GNU General Public License version 3, | ||
// which covers the main part of arduino-cli. | ||
// The terms of this license can be found at: | ||
// https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to license@arduino.cc. | ||
|
||
package sketch_test | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/arduino/arduino-cli/internal/integrationtest" | ||
"github.com/arduino/go-paths-helper" | ||
"github.com/stretchr/testify/require" | ||
"go.bug.st/testifyjson/requirejson" | ||
) | ||
|
||
func TestSketchProfileDump(t *testing.T) { | ||
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) | ||
t.Cleanup(env.CleanUp) | ||
|
||
// Prepare the sketch with libraries | ||
tmpDir, err := paths.MkTempDir("", "") | ||
require.NoError(t, err) | ||
t.Cleanup(func() { _ = tmpDir.RemoveAll }) | ||
|
||
sketchTemplate, err := paths.New("testdata", "SketchWithLibrary").Abs() | ||
require.NoError(t, err) | ||
|
||
sketch := tmpDir.Join("SketchWithLibrary") | ||
libInside := sketch.Join("libraries", "MyLib") | ||
err = sketchTemplate.CopyDirTo(sketch) | ||
require.NoError(t, err) | ||
|
||
libOutsideTemplate := sketchTemplate.Join("..", "MyLibOutside") | ||
libOutside := sketch.Join("..", "MyLibOutside") | ||
err = libOutsideTemplate.CopyDirTo(libOutside) | ||
require.NoError(t, err) | ||
|
||
// Install the required core and libraries | ||
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.6") | ||
require.NoError(t, err) | ||
_, _, err = cli.Run("lib", "install", "Adafruit BusIO@1.17.1") | ||
require.NoError(t, err) | ||
_, _, err = cli.Run("lib", "install", "Adafruit GFX Library@1.12.1") | ||
require.NoError(t, err) | ||
_, _, err = cli.Run("lib", "install", "Adafruit SSD1306@2.5.14") | ||
require.NoError(t, err) | ||
|
||
// Check if the profile dump: | ||
// - keeps libraries in the sketch with a relative path | ||
// - keeps libraries outside the sketch with an absolute path | ||
// - keeps libraries installed in the system with just the name and version | ||
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", | ||
"--library", libInside.String(), | ||
"--library", libOutside.String(), | ||
"--dump-profile", | ||
sketch.String()) | ||
require.NoError(t, err) | ||
require.Equal(t, strings.TrimSpace(` | ||
profiles: | ||
uno: | ||
fqbn: arduino:avr:uno | ||
platforms: | ||
- platform: arduino:avr (1.8.6) | ||
libraries: | ||
- dir: libraries/MyLib | ||
- dir: `+libOutside.String()+` | ||
- Adafruit SSD1306 (2.5.14) | ||
- Adafruit GFX Library (1.12.1) | ||
- Adafruit BusIO (1.17.1) | ||
`), strings.TrimSpace(string(out))) | ||
|
||
// Dump the profile in the sketch directory and compile with it again | ||
err = sketch.Join("sketch.yaml").WriteFile(out) | ||
require.NoError(t, err) | ||
out, _, err = cli.Run("compile", "-m", "uno", "--json", sketch.String()) | ||
require.NoError(t, err) | ||
// Check if local libraries are picked up correctly | ||
libInsideJson, _ := json.Marshal(libInside.String()) | ||
libOutsideJson, _ := json.Marshal(libOutside.String()) | ||
j := requirejson.Parse(t, out).Query(".builder_result.used_libraries") | ||
j.MustContain(` | ||
[ | ||
{"name": "MyLib", "install_dir": ` + string(libInsideJson) + `}, | ||
{"name": "MyLibOutside", "install_dir": ` + string(libOutsideJson) + `} | ||
]`) | ||
} |
Empty file.
10 changes: 10 additions & 0 deletions
10
internal/integrationtest/sketch/testdata/MyLibOutside/library.properties
This file contains hidden or 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 @@ | ||
name=MyLibOutside | ||
version=1.3.7 | ||
author=Arduino | ||
maintainer=Arduino <info@arduino.cc> | ||
sentence= | ||
paragraph= | ||
category=Communication | ||
url= | ||
architectures=* | ||
includes=MyLibOutside.h |
6 changes: 6 additions & 0 deletions
6
internal/integrationtest/sketch/testdata/SketchWithLibrary/SketchWithLibrary.ino
This file contains hidden or 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,6 @@ | ||
#include <MyLib.h> | ||
#include <MyLibOutside.h> | ||
#include <Adafruit_SSD1306.h> | ||
|
||
void setup() {} | ||
void loop() {} |
Empty file.
10 changes: 10 additions & 0 deletions
10
...rnal/integrationtest/sketch/testdata/SketchWithLibrary/libraries/MyLib/library.properties
This file contains hidden or 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 @@ | ||
name=MyLib | ||
version=1.3.7 | ||
author=Arduino | ||
maintainer=Arduino <info@arduino.cc> | ||
sentence= | ||
paragraph= | ||
category=Communication | ||
url= | ||
architectures=* | ||
includes=MyLib.h |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.