8000 Add possibility to embed custom libraries into the sketch by cmaglie · Pull Request #2514 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Add possibility to embed custom libraries into the sketch #2514

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Prev Previous commit
Next Next commit
Added integration test for sketch-vendored libraries
  • Loading branch information
cmaglie committed Nov 12, 2024
commit dcc216ff432da6f62a1c8f25975e3ae1fe1883c3
6 changes: 6 additions & 0 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
return cli.sketchbookDir
}

// SetSketchbookDir sets the sketchbook directory
func (cli *ArduinoCLI) SetSketchbookDir(d *paths.Path) {
cli.sketchbookDir = d
cli.cliEnvVars["ARDUINO_SKETCHBOOK_DIR"] = d.String()
}

// WorkingDir returns the working directory
func (cli *ArduinoCLI) WorkingDir() *paths.Path {
return cli.workingDir
Expand Down
39 changes: 39 additions & 0 deletions internal/integrationtest/compile_2/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 8000 +26,7 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
)

func TestCompilePart4(t *testing.T) {
Expand Down Expand Up @@ -449,3 +450,41 @@ func TestCompileWithKnownPlatformNotInstalled(t *testing.T) {
// Verifies command to fix error is shown to user
require.Contains(t, string(stderr), "Try running `arduino-cli core install arduino:avr`")
}

func TestSketchWithVendoredLibraries(t *testing.T) {
sketchBook, err := paths.New("testdata", "sketchbook_1").Abs()
require.NoError(t, err)

env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

cli.SetSketchbookDir(sketchBook)

_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)

{
sketchWithLibsPath := sketchBook.Join("SketchWithLibraries")
// Sketch should use sketch bundled "MyLib" with and without profiles
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", sketchWithLibsPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"user"`)
out, _, err = cli.Run("compile", "--profile", "uno", sketchWithLibsPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"user"`)
}

{
sketchWithoutLibsPath := sketchBook.Join("SketchWithoutLibraries")
// This sketch should take the user-installed MyLib
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", sketchWithoutLibsPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"upstream"`)
// This sketch should fail to compile since profiles will not see the user-installed MyLib
_, _, err = cli.Run("compile", "--profile", "uno", sketchWithoutLibsPath.String())
require.Error(t, err)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <MyLib.h>

void setup() {}
void loop() {
myFunction();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

void anotherFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name=AnotherLib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

void myFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=MyLib
author=user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
profiles:
uno:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.5)

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <MyLib.h>

void setup() {}
void loop() {
myWrongFunction();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
profiles:
uno:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.5)

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

// This is the wrong library to include (the sketch-bundled one should take priority)

void myWrongFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=MyLib
author=upstream
Loading
0