Skip to content

Commit

Permalink
Fixed loading of Library given a non-absolute path (#2265)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cmaglie authored Aug 17, 2023
1 parent 459fe76 commit 9510d61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion arduino/libraries/libraries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ func TestLibLayoutAndLocationJSONUnMarshaler(t *testing.T) {

func TestLibrariesLoader(t *testing.T) {
{
lib, err := Load(paths.New("testdata", "TestLib"), User)
libPath := paths.New("testdata", "TestLib")
lib, err := Load(libPath, User)
require.NoError(t, err)
require.Equal(t, "TestLib", lib.Name)
require.Equal(t, "1.0.3", lib.Version.String())
require.False(t, lib.IsLegacy)
require.False(t, lib.InDevelopment)
absPath, err := libPath.Abs()
require.NoError(t, err)
require.Equal(t, lib.InstallDir.String(), absPath.String())
}
{
lib, err := Load(paths.New("testdata", "TestLibInDev"), User)
Expand Down
7 changes: 7 additions & 0 deletions arduino/libraries/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import (

// Load loads a library from the given LibraryLocation
func Load(libDir *paths.Path, location LibraryLocation) (*Library, error) {
if !libDir.IsAbs() {
if abs, err := libDir.Abs(); err == nil {
libDir = abs
} else {
return nil, err
}
}
if libDir.Join("library.properties").Exist() {
return makeNewLibrary(libDir, location)
}
Expand Down

0 comments on commit 9510d61

Please sign in to comment.