Skip to content

Commit

Permalink
Added libraries .development flag detection (arduino#1962)
Browse files Browse the repository at this point in the history
* Added in_development flag in Library gRPC message

* Small cosmetic fix in docs

* Implemented 'in_development' flag in libraries loader

* Added unit-test
  • Loading branch information
cmaglie authored Nov 4, 2022
1 parent 4dcf0da commit ec3e71c
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 76 deletions.
2 changes: 2 additions & 0 deletions arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Library struct {
PrecompiledWithSources bool
LDflags string
IsLegacy bool
InDevelopment bool
Version *semver.Version
License string
Properties *properties.Map
Expand Down Expand Up @@ -136,6 +137,7 @@ func (library *Library) ToRPCLibrary() (*rpc.Library, error) {
Precompiled: library.Precompiled,
LdFlags: library.LDflags,
IsLegacy: library.IsLegacy,
InDevelopment: library.InDevelopment,
Version: library.Version.String(),
License: library.License,
Examples: library.Examples.AsStrings(),
Expand Down
20 changes: 20 additions & 0 deletions arduino/libraries/libraries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"testing"

paths "github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -48,3 +49,22 @@ func TestLibLayoutAndLocationJSONUnMarshaler(t *testing.T) {
testLocation(User)
testLocation(Unmanaged)
}

func TestLibrariesLoader(t *testing.T) {
{
lib, err := Load(paths.New("testdata", "TestLib"), 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)
}
{
lib, err := Load(paths.New("testdata", "TestLibInDev"), User)
require.NoError(t, err)
require.Equal(t, "TestLibInDev", lib.Name)
require.Equal(t, "1.0.3", lib.Version.String())
require.False(t, lib.IsLegacy)
require.True(t, lib.InDevelopment)
}
}
3 changes: 2 additions & 1 deletion arduino/libraries/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
library.Precompiled = libProperties.Get("precompiled") == "true" || library.PrecompiledWithSources
library.LDflags = strings.TrimSpace(libProperties.Get("ldflags"))
library.Properties = libProperties

library.InDevelopment = libraryDir.Join(".development").Exist()
return library, nil
}

Expand All @@ -136,6 +136,7 @@ func makeLegacyLibrary(path *paths.Path, location LibraryLocation) (*Library, er
Architectures: []string{"*"},
IsLegacy: true,
Version: semver.MustParse(""),
InDevelopment: path.Join(".development").Exist(),
}
if err := addExamples(library); err != nil {
return nil, errors.Errorf(tr("scanning examples: %s"), err)
Expand Down
9 changes: 9 additions & 0 deletions arduino/libraries/testdata/TestLib/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=TestLib
version=1.0.3
author=Arduino
maintainer=Arduino <info@arduino.cc>
sentence=A test lib
paragraph=very powerful!
category=Device Control
url=http://www.arduino.cc/en/Reference/TestLib
architectures=avr
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions arduino/libraries/testdata/TestLibInDev/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=TestLibInDev
version=1.0.3
author=Arduino
maintainer=Arduino <info@arduino.cc>
sentence=A test lib
paragraph=very powerful!
category=Device Control
url=http://www.arduino.cc/en/Reference/TestLib
architectures=avr
Empty file.
4 changes: 2 additions & 2 deletions docs/library-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ In Arduino IDE 1.6.5 and newer this field overrides `KEYWORD_TOKENTYPE`. In prev
Normally the Arduino IDE treats the contents of the library folder as read-only. This is to prevent users from
accidentally modifying example sketches. During the library development process you may want to edit example sketches in
place using the Arduino IDE. With Arduino IDE 1.6.6 and newer, the read-only behavior can be disabled by adding a file
named .development to the root of the library folder. A [library.properties](#libraryproperties-file-format) file must
named `.development` to the root of the library folder. A [library.properties](#libraryproperties-file-format) file must
also be present. The [Library Manager indexer](https://github.com/arduino/library-registry/blob/main/FAQ.md#readme) will
not pick up releases that contain a .development file so be sure not to push this file to your remote repository.
not pick up releases that contain a `.development` file so be sure not to push this file to your remote repository.

### A complete example

Expand Down
159 changes: 86 additions & 73 deletions rpc/cc/arduino/cli/commands/v1/lib.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions rpc/cc/arduino/cli/commands/v1/lib.proto
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ message Library {
repeated string provides_includes = 27;
// Map of FQBNs that specifies if library is compatible with this library
map<string, bool> compatible_with = 28;
// This value is set to true if the library is in development and should not
// be treated as read-only. This status is determined by the presence of a
// `.development` file in the library root directory.
bool in_development = 29;
}

enum LibraryLayout {
Expand Down

0 comments on commit ec3e71c

Please sign in to comment.