Skip to content

Remove Sketchbook concept, introduce User data folder #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core
foundTools := map[string]*cores.ToolRelease{}

// a Platform may not specify required tools (because it's a platform that comes from a
// sketchbook/hardware dir without a package_index.json) then add all available tools
// user/hardware dir without a package_index.json) then add all available tools
for _, targetPackage := range pm.Packages {
for _, tool := range targetPackage.Tools {
rel := tool.GetLatestInstalled()
Expand Down
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
fmt.Println(viper.AllSettings())
pm := packagemanager.NewPackageManager(
dataDir1,
paths.New(viper.GetString("directories.Packages")),
configuration.PackagesDir(),
paths.New(viper.GetString("directories.Downloads")),
dataDir1,
)
Expand Down
2 changes: 1 addition & 1 deletion arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (library *Library) PriorityForArchitecture(arch string) uint8 {
return bonus + 0x01
case PlatformBuiltIn:
return bonus + 0x02
case Sketchbook:
case User:
return bonus + 0x03
}
panic(fmt.Sprintf("Invalid library location: %d", library.Location))
Expand Down
16 changes: 8 additions & 8 deletions arduino/libraries/libraries_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const (
PlatformBuiltIn
// ReferencedPlatformBuiltIn are libraries bundled in a PlatformRelease referenced for build
ReferencedPlatformBuiltIn
// Sketchbook are user installed libraries
Sketchbook
// User are user installed libraries
User
)

func (d *LibraryLocation) String() string {
Expand All @@ -45,8 +45,8 @@ func (d *LibraryLocation) String() string {
return "platform"
case ReferencedPlatformBuiltIn:
return "ref-platform"
case Sketchbook:
return "sketchbook"
case User:
return "user"
}
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
}
Expand All @@ -60,8 +60,8 @@ func (d *LibraryLocation) MarshalJSON() ([]byte, error) {
return json.Marshal("platform")
case ReferencedPlatformBuiltIn:
return json.Marshal("ref-platform")
case Sketchbook:
return json.Marshal("sketchbook")
case User:
return json.Marshal("user")
}
return nil, fmt.Errorf("invalid library location value: %d", *d)
}
Expand All @@ -79,8 +79,8 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
*d = PlatformBuiltIn
case "ref-platform":
*d = ReferencedPlatformBuiltIn
case "sketchbook":
*d = Sketchbook
case "user":
*d = User
}
return fmt.Errorf("invalid library location: %s", s)
}
10 changes: 5 additions & 5 deletions arduino/libraries/librariesmanager/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
var replaced *libraries.Library
if installedLibs, have := lm.Libraries[saneName]; have {
for _, installedLib := range installedLibs.Alternatives {
if installedLib.Location != libraries.Sketchbook {
if installedLib.Location != libraries.User {
continue
}
if installedLib.Version.Equal(indexLibrary.Version) {
Expand All @@ -52,9 +52,9 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
}
}

libsDir := lm.getSketchbookLibrariesDir()
libsDir := lm.getUserLibrariesDir()
if libsDir == nil {
return nil, nil, fmt.Errorf("sketchbook directory not set")
return nil, nil, fmt.Errorf("User directory not set")
}

libPath := libsDir.Join(saneName)
Expand All @@ -68,9 +68,9 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde

// Install installs a library on the specified path.
func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path) error {
libsDir := lm.getSketchbookLibrariesDir()
libsDir := lm.getUserLibrariesDir()
if libsDir == nil {
return fmt.Errorf("sketchbook directory not set")
return fmt.Errorf("User directory not set")
}
return indexLibrary.Resource.Install(lm.DownloadsDir, libsDir, libPath)
}
Expand Down
10 changes: 5 additions & 5 deletions arduino/libraries/librariesmanager/librariesmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ func (sc *LibrariesManager) RescanLibraries() error {
return nil
}

func (sc *LibrariesManager) getSketchbookLibrariesDir() *paths.Path {
func (sc *LibrariesManager) getUserLibrariesDir() *paths.Path {
for _, dir := range sc.LibrariesDir {
if dir.Location == libraries.Sketchbook {
if dir.Location == libraries.User {
return dir.Path
}
}
Expand Down Expand Up @@ -208,17 +208,17 @@ func (sc *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) err

// FindByReference return the installed library matching the Reference
// name and version or, if the version is nil, the library installed
// in the sketchbook.
// in the User folder.
func (sc *LibrariesManager) FindByReference(libRef *librariesindex.Reference) *libraries.Library {
saneName := utils.SanitizeName(libRef.Name)
alternatives, have := sc.Libraries[saneName]
if !have {
return nil
}
// TODO: Move "search into sketchbook" into another method...
// TODO: Move "search into user" into another method...
if libRef.Version == nil {
for _, candidate := range alternatives.Alternatives {
if candidate.Location == libraries.Sketchbook {
if candidate.Location == libraries.User {
return candidate
}
}
Expand Down
14 changes: 7 additions & 7 deletions arduino/libraries/librariesresolver/cpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
"github.com/stretchr/testify/require"
)

var l1 = &libraries.Library{Name: "Calculus Lib", Location: libraries.Sketchbook}
var l2 = &libraries.Library{Name: "Calculus Lib-master", Location: libraries.Sketchbook}
var l3 = &libraries.Library{Name: "Calculus Lib Improved", Location: libraries.Sketchbook}
var l4 = &libraries.Library{Name: "Another Calculus Lib", Location: libraries.Sketchbook}
var l5 = &libraries.Library{Name: "Yet Another Calculus Lib Improved", Location: libraries.Sketchbook}
var l6 = &libraries.Library{Name: "Calculus Unified Lib", Location: libraries.Sketchbook}
var l7 = &libraries.Library{Name: "AnotherLib", Location: libraries.Sketchbook}
var l1 = &libraries.Library{Name: "Calculus Lib", Location: libraries.User}
var l2 = &libraries.Library{Name: "Calculus Lib-master", Location: libraries.User}
var l3 = &libraries.Library{Name: "Calculus Lib Improved", Location: libraries.User}
var l4 = &libraries.Library{Name: "Another Calculus Lib", Location: libraries.User}
var l5 = &libraries.Library{Name: "Yet Another Calculus Lib Improved", Location: libraries.User}
var l6 = &libraries.Library{Name: "Calculus Unified Lib", Location: libraries.User}
var l7 = &libraries.Library{Name: "AnotherLib", Location: libraries.User}

func TestClosestMatchWithTotallyDifferentNames(t *testing.T) {
libraryList := libraries.List{}
Expand Down
22 changes: 0 additions & 22 deletions arduino/sketches/sketches.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ import (
"github.com/arduino/go-paths-helper"
)

// SketchBook is a sketchbook
type SketchBook struct {
Path *paths.Path
}

// Sketch is a sketch for Arduino
type Sketch struct {
Name string
Expand All @@ -47,23 +42,6 @@ type BoardMetadata struct {
Name string `json:"name,omitempty"`
}

// NewSketchBook returns a new SketchBook object
func NewSketchBook(path *paths.Path) *SketchBook {
return &SketchBook{
Path: path,
}
}

// NewSketch loads a sketch from the sketchbook
func (sketchbook *SketchBook) NewSketch(name string) (*Sketch, error) {
sketch := &Sketch{
FullPath: sketchbook.Path.Join(name),
Name: name,
}
sketch.ImportMetadata()
return sketch, nil
}

// NewSketchFromPath loads a sketch from the specified path
func NewSketchFromPath(path *paths.Path) (*Sketch, error) {
sketch := &Sketch{
Expand Down
Loading