Skip to content

Use the correct library when a relative path is passed as --library value #2126

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion internal/cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
stdOut, stdErr, stdIORes = feedback.OutputStreams()
}

var libraryAbs []string
for _, libPath := range paths.NewPathList(library...) {
if libPath, err = libPath.Abs(); err != nil {
feedback.Fatal(tr("Error converting path to absolute: %v", err), feedback.ErrGeneric)
}
libraryAbs = append(libraryAbs, libPath.String())
}

compileRequest := &rpc.CompileRequest{
Instance: inst,
Fqbn: fqbn,
Expand All @@ -244,7 +252,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
Clean: clean,
CreateCompilationDatabaseOnly: compilationDatabaseOnly,
SourceOverride: overrides,
Library: library,
Library: libraryAbs,
KeysKeychain: keysKeychain,
SignKey: signKey,
EncryptKey: encryptKey,
Expand Down
38 changes: 38 additions & 0 deletions internal/integrationtest/compile_3/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,41 @@ func TestCompilerErrOutput(t *testing.T) {
compilerErr := requirejson.Parse(t, out).Query(".compiler_err")
compilerErr.MustContain(`"error"`)
}

func TestCompileRelativeLibraryPath(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

// Initialize configs to enable --zip-path flag
_, _, err := cli.Run("config", "init", "--dest-dir", ".")
require.NoError(t, err)
_, _, err = cli.Run("config", "set", "library.enable_unsafe_install", "true", "--config-file", "arduino-cli.yaml")
require.NoError(t, err)
configFile := cli.WorkingDir().Join("arduino-cli.yaml")

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

// Install library and its dependencies
zipPath, err := paths.New("..", "testdata", "FooLib.zip").Abs()
require.NoError(t, err)
// Manually install the library and move into one of the example's directories
FooLib := cli.WorkingDir().Join("FooLib")
err = paths.New("..", "testdata", "FooLib").CopyDirTo(FooLib)
require.NoError(t, err)
cli.SetWorkingDir(FooLib.Join("examples", "FooSketch"))

// Compile using a relative path to the library
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--library", "../../")
require.NoError(t, err)

// Install the same library using lib install and compile again using the relative path.
// The manually installed library should be chosen
_, _, err = cli.Run("lib", "install", "--zip-path", zipPath.String(), "--config-file", configFile.String())
require.NoError(t, err)
stdout, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "--library", "../../", "-v")
require.NoError(t, err)
require.Contains(t, string(stdout), "Multiple libraries were found for \"FooLib.h\"")
require.Contains(t, string(stdout), "Used: "+FooLib.String())
require.Contains(t, string(stdout), "Not used: "+cli.SketchbookDir().Join("libraries", "FooLib").String())
}
Binary file added internal/integrationtest/testdata/FooLib.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file intentionally left empty.
1 change: 1 addition & 0 deletions internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file intentionally left empty.
1 change: 1 addition & 0 deletions internal/integrationtest/testdata/FooLib/FooLib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file intentionally left empty.
1 change: 1 addition & 0 deletions internal/integrationtest/testdata/FooLib/FooLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file intentionally left empty.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <FooLib.h>
void setup() {}
void loop() {}