From 1fd63544e961e173aeaa37df50a7e0ac37c8dc44 Mon Sep 17 00:00:00 2001 From: Matteo Pologruto Date: Wed, 22 Mar 2023 17:36:42 +0100 Subject: [PATCH 1/2] Use the correct library when a relative path is passed as `--library` value --- internal/cli/compile/compile.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/cli/compile/compile.go b/internal/cli/compile/compile.go index 9695bc19e98..3eb8708ed16 100644 --- a/internal/cli/compile/compile.go +++ b/internal/cli/compile/compile.go @@ -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, @@ -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, From 04f71b073ab89ef89dc5b236cebbd9bba59729a1 Mon Sep 17 00:00:00 2001 From: Matteo Pologruto Date: Wed, 22 Mar 2023 17:40:39 +0100 Subject: [PATCH 2/2] Add test related to the changes --- .../integrationtest/compile_3/compile_test.go | 38 ++++++++++++++++++ internal/integrationtest/testdata/FooLib.zip | Bin 0 -> 1275 bytes .../testdata/FooLib/ArduinoIoTCloud.cpp | 1 + .../testdata/FooLib/ArduinoIoTCloud.h | 1 + .../testdata/FooLib/FooLib.cpp | 1 + .../integrationtest/testdata/FooLib/FooLib.h | 1 + .../FooLib/examples/FooSketch/FooSketch.ino | 3 ++ 7 files changed, 45 insertions(+) create mode 100644 internal/integrationtest/testdata/FooLib.zip create mode 100644 internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.cpp create mode 100644 internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.h create mode 100644 internal/integrationtest/testdata/FooLib/FooLib.cpp create mode 100644 internal/integrationtest/testdata/FooLib/FooLib.h create mode 100644 internal/integrationtest/testdata/FooLib/examples/FooSketch/FooSketch.ino diff --git a/internal/integrationtest/compile_3/compile_test.go b/internal/integrationtest/compile_3/compile_test.go index 2af68d2b03b..11aaeceef5e 100644 --- a/internal/integrationtest/compile_3/compile_test.go +++ b/internal/integrationtest/compile_3/compile_test.go @@ -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()) +} diff --git a/internal/integrationtest/testdata/FooLib.zip b/internal/integrationtest/testdata/FooLib.zip new file mode 100644 index 0000000000000000000000000000000000000000..f12d87aa2979e3095fdfd92477266e268a1b2351 GIT binary patch literal 1275 zcmWIWW@Zs#0D+R#)nQ-;lwfC2U~tRN_sLAs4-MgEVBedglyVS=L3C*aHv=Qf3uXoe zFcAPYgoA;DAs@*Qb)Z4~2ty!d>1BWo+YB@WhS3bWd_A1wMoAO_KB&Vcv|q}yc`Y6MAPF%1~V z!P%)L$r%uH8?p$P3yQN7D-q@z1MN}AYcAXdz0ACPa2U?aR7!ziG{*;@JL7#$)7LX} zL*eQ3-%t8nI=$hs*6H&;ff|0gnz|P*gsfQC`l0yK=Y=ug*ffgylB5lE0mu~r-i%Bl z%(#;#Pzf0Pbp%mFCsc@`u%wEdd_YMR2DUW1A`B%q;lf-DG8~iwkqrl>Kp5E4cpAfS zBGMzwc#tvJ5*Ez(zmCC-@BkqpnIVE3TS7yaz7UJ)@I*mGvO~lGDB&STIVj=5z?R0J dcV@Gl7_a0RU4)LAC$@ literal 0 HcmV?d00001 diff --git a/internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.cpp b/internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.cpp new file mode 100644 index 00000000000..e26b0ab556c --- /dev/null +++ b/internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.cpp @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.h b/internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.h new file mode 100644 index 00000000000..e26b0ab556c --- /dev/null +++ b/internal/integrationtest/testdata/FooLib/ArduinoIoTCloud.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/internal/integrationtest/testdata/FooLib/FooLib.cpp b/internal/integrationtest/testdata/FooLib/FooLib.cpp new file mode 100644 index 00000000000..e26b0ab556c --- /dev/null +++ b/internal/integrationtest/testdata/FooLib/FooLib.cpp @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/internal/integrationtest/testdata/FooLib/FooLib.h b/internal/integrationtest/testdata/FooLib/FooLib.h new file mode 100644 index 00000000000..e26b0ab556c --- /dev/null +++ b/internal/integrationtest/testdata/FooLib/FooLib.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/internal/integrationtest/testdata/FooLib/examples/FooSketch/FooSketch.ino b/internal/integrationtest/testdata/FooLib/examples/FooSketch/FooSketch.ino new file mode 100644 index 00000000000..ea144a785da --- /dev/null +++ b/internal/integrationtest/testdata/FooLib/examples/FooSketch/FooSketch.ino @@ -0,0 +1,3 @@ +#include +void setup() {} +void loop() {}