Skip to content

Commit 9510d61

Browse files
authored
Fixed loading of Library given a non-absolute path (#2265)
* Fixed loading of Library given a non-absolute path Givin a relative path is not ideal, but at least allows the CLI to compile the sketch correctly. * Added test
1 parent 459fe76 commit 9510d61

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: arduino/libraries/libraries_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ func TestLibLayoutAndLocationJSONUnMarshaler(t *testing.T) {
5454

5555
func TestLibrariesLoader(t *testing.T) {
5656
{
57-
lib, err := Load(paths.New("testdata", "TestLib"), User)
57+
libPath := paths.New("testdata", "TestLib")
58+
lib, err := Load(libPath, User)
5859
require.NoError(t, err)
5960
require.Equal(t, "TestLib", lib.Name)
6061
require.Equal(t, "1.0.3", lib.Version.String())
6162
require.False(t, lib.IsLegacy)
6263
require.False(t, lib.InDevelopment)
64+
absPath, err := libPath.Abs()
65+
require.NoError(t, err)
66+
require.Equal(t, lib.InstallDir.String(), absPath.String())
6367
}
6468
{
6569
lib, err := Load(paths.New("testdata", "TestLibInDev"), User)

Diff for: arduino/libraries/loader.go

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ import (
2828

2929
// Load loads a library from the given LibraryLocation
3030
func Load(libDir *paths.Path, location LibraryLocation) (*Library, error) {
31+
if !libDir.IsAbs() {
32+
if abs, err := libDir.Abs(); err == nil {
33+
libDir = abs
34+
} else {
35+
return nil, err
36+
}
37+
}
3138
if libDir.Join("library.properties").Exist() {
3239
return makeNewLibrary(libDir, location)
3340
}

0 commit comments

Comments
 (0)