Unverified Commit 51e50e1d authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

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

* Use the correct library when a relative path is passed as `--library` value

* Add test related to the changes
parent 5a67f3b6
...@@ -226,6 +226,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) { ...@@ -226,6 +226,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
stdOut, stdErr, stdIORes = feedback.OutputStreams() 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{ compileRequest := &rpc.CompileRequest{
Instance: inst, Instance: inst,
Fqbn: fqbn, Fqbn: fqbn,
...@@ -244,7 +252,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) { ...@@ -244,7 +252,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
Clean: clean, Clean: clean,
CreateCompilationDatabaseOnly: compilationDatabaseOnly, CreateCompilationDatabaseOnly: compilationDatabaseOnly,
SourceOverride: overrides, SourceOverride: overrides,
Library: library, Library: libraryAbs,
KeysKeychain: keysKeychain, KeysKeychain: keysKeychain,
SignKey: signKey, SignKey: signKey,
EncryptKey: encryptKey, EncryptKey: encryptKey,
......
...@@ -116,3 +116,41 @@ func TestCompilerErrOutput(t *testing.T) { ...@@ -116,3 +116,41 @@ func TestCompilerErrOutput(t *testing.T) {
compilerErr := requirejson.Parse(t, out).Query(".compiler_err") compilerErr := requirejson.Parse(t, out).Query(".compiler_err")
compilerErr.MustContain(`"error"`) 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())
}
// This file intentionally left empty.
// This file intentionally left empty.
#include <FooLib.h>
void setup() {}
void loop() {}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment