Commit 3809fc3f authored by Massimiliano Pippi's avatar Massimiliano Pippi Committed by Roberto Sora

Remove Sketchbook concept, introduce User data folder (#516)

* rename Sketchbook folder to User

* missing join on path
parent 596f4e47
...@@ -402,7 +402,7 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core ...@@ -402,7 +402,7 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core
foundTools := map[string]*cores.ToolRelease{} foundTools := map[string]*cores.ToolRelease{}
// a Platform may not specify required tools (because it's a platform that comes from a // 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 _, targetPackage := range pm.Packages {
for _, tool := range targetPackage.Tools { for _, tool := range targetPackage.Tools {
rel := tool.GetLatestInstalled() rel := tool.GetLatestInstalled()
......
...@@ -219,7 +219,7 @@ func TestFindToolsRequiredForBoard(t *testing.T) { ...@@ -219,7 +219,7 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
fmt.Println(viper.AllSettings()) fmt.Println(viper.AllSettings())
pm := packagemanager.NewPackageManager( pm := packagemanager.NewPackageManager(
dataDir1, dataDir1,
paths.New(viper.GetString("directories.Packages")), configuration.PackagesDir(),
paths.New(viper.GetString("directories.Downloads")), paths.New(viper.GetString("directories.Downloads")),
dataDir1, dataDir1,
) )
......
...@@ -141,7 +141,7 @@ func (library *Library) PriorityForArchitecture(arch string) uint8 { ...@@ -141,7 +141,7 @@ func (library *Library) PriorityForArchitecture(arch string) uint8 {
return bonus + 0x01 return bonus + 0x01
case PlatformBuiltIn: case PlatformBuiltIn:
return bonus + 0x02 return bonus + 0x02
case Sketchbook: case User:
return bonus + 0x03 return bonus + 0x03
} }
panic(fmt.Sprintf("Invalid library location: %d", library.Location)) panic(fmt.Sprintf("Invalid library location: %d", library.Location))
......
...@@ -33,8 +33,8 @@ const ( ...@@ -33,8 +33,8 @@ const (
PlatformBuiltIn PlatformBuiltIn
// ReferencedPlatformBuiltIn are libraries bundled in a PlatformRelease referenced for build // ReferencedPlatformBuiltIn are libraries bundled in a PlatformRelease referenced for build
ReferencedPlatformBuiltIn ReferencedPlatformBuiltIn
// Sketchbook are user installed libraries // User are user installed libraries
Sketchbook User
) )
func (d *LibraryLocation) String() string { func (d *LibraryLocation) String() string {
...@@ -45,8 +45,8 @@ func (d *LibraryLocation) String() string { ...@@ -45,8 +45,8 @@ func (d *LibraryLocation) String() string {
return "platform" return "platform"
case ReferencedPlatformBuiltIn: case ReferencedPlatformBuiltIn:
return "ref-platform" return "ref-platform"
case Sketchbook: case User:
return "sketchbook" return "user"
} }
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d)) panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
} }
...@@ -60,8 +60,8 @@ func (d *LibraryLocation) MarshalJSON() ([]byte, error) { ...@@ -60,8 +60,8 @@ func (d *LibraryLocation) MarshalJSON() ([]byte, error) {
return json.Marshal("platform") return json.Marshal("platform")
case ReferencedPlatformBuiltIn: case ReferencedPlatformBuiltIn:
return json.Marshal("ref-platform") return json.Marshal("ref-platform")
case Sketchbook: case User:
return json.Marshal("sketchbook") return json.Marshal("user")
} }
return nil, fmt.Errorf("invalid library location value: %d", *d) return nil, fmt.Errorf("invalid library location value: %d", *d)
} }
...@@ -79,8 +79,8 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error { ...@@ -79,8 +79,8 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
*d = PlatformBuiltIn *d = PlatformBuiltIn
case "ref-platform": case "ref-platform":
*d = ReferencedPlatformBuiltIn *d = ReferencedPlatformBuiltIn
case "sketchbook": case "user":
*d = Sketchbook *d = User
} }
return fmt.Errorf("invalid library location: %s", s) return fmt.Errorf("invalid library location: %s", s)
} }
...@@ -42,7 +42,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde ...@@ -42,7 +42,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
var replaced *libraries.Library var replaced *libraries.Library
if installedLibs, have := lm.Libraries[saneName]; have { if installedLibs, have := lm.Libraries[saneName]; have {
for _, installedLib := range installedLibs.Alternatives { for _, installedLib := range installedLibs.Alternatives {
if installedLib.Location != libraries.Sketchbook { if installedLib.Location != libraries.User {
continue continue
} }
if installedLib.Version.Equal(indexLibrary.Version) { if installedLib.Version.Equal(indexLibrary.Version) {
...@@ -52,9 +52,9 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde ...@@ -52,9 +52,9 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
} }
} }
libsDir := lm.getSketchbookLibrariesDir() libsDir := lm.getUserLibrariesDir()
if libsDir == nil { 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) libPath := libsDir.Join(saneName)
...@@ -68,9 +68,9 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde ...@@ -68,9 +68,9 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde
// Install installs a library on the specified path. // Install installs a library on the specified path.
func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path) error { func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path) error {
libsDir := lm.getSketchbookLibrariesDir() libsDir := lm.getUserLibrariesDir()
if libsDir == nil { 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) return indexLibrary.Resource.Install(lm.DownloadsDir, libsDir, libPath)
} }
......
...@@ -168,9 +168,9 @@ func (sc *LibrariesManager) RescanLibraries() error { ...@@ -168,9 +168,9 @@ func (sc *LibrariesManager) RescanLibraries() error {
return nil return nil
} }
func (sc *LibrariesManager) getSketchbookLibrariesDir() *paths.Path { func (sc *LibrariesManager) getUserLibrariesDir() *paths.Path {
for _, dir := range sc.LibrariesDir { for _, dir := range sc.LibrariesDir {
if dir.Location == libraries.Sketchbook { if dir.Location == libraries.User {
return dir.Path return dir.Path
} }
} }
...@@ -208,17 +208,17 @@ func (sc *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) err ...@@ -208,17 +208,17 @@ func (sc *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) err
// FindByReference return the installed library matching the Reference // FindByReference return the installed library matching the Reference
// name and version or, if the version is nil, the library installed // 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 { func (sc *LibrariesManager) FindByReference(libRef *librariesindex.Reference) *libraries.Library {
saneName := utils.SanitizeName(libRef.Name) saneName := utils.SanitizeName(libRef.Name)
alternatives, have := sc.Libraries[saneName] alternatives, have := sc.Libraries[saneName]
if !have { if !have {
return nil return nil
} }
// TODO: Move "search into sketchbook" into another method... // TODO: Move "search into user" into another method...
if libRef.Version == nil { if libRef.Version == nil {
for _, candidate := range alternatives.Alternatives { for _, candidate := range alternatives.Alternatives {
if candidate.Location == libraries.Sketchbook { if candidate.Location == libraries.User {
return candidate return candidate
} }
} }
......
...@@ -24,13 +24,13 @@ import ( ...@@ -24,13 +24,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var l1 = &libraries.Library{Name: "Calculus Lib", Location: libraries.Sketchbook} var l1 = &libraries.Library{Name: "Calculus Lib", Location: libraries.User}
var l2 = &libraries.Library{Name: "Calculus Lib-master", Location: libraries.Sketchbook} var l2 = &libraries.Library{Name: "Calculus Lib-master", Location: libraries.User}
var l3 = &libraries.Library{Name: "Calculus Lib Improved", Location: libraries.Sketchbook} var l3 = &libraries.Library{Name: "Calculus Lib Improved", Location: libraries.User}
var l4 = &libraries.Library{Name: "Another Calculus Lib", Location: libraries.Sketchbook} var l4 = &libraries.Library{Name: "Another Calculus Lib", Location: libraries.User}
var l5 = &libraries.Library{Name: "Yet Another Calculus Lib Improved", Location: libraries.Sketchbook} var l5 = &libraries.Library{Name: "Yet Another Calculus Lib Improved", Location: libraries.User}
var l6 = &libraries.Library{Name: "Calculus Unified Lib", Location: libraries.Sketchbook} var l6 = &libraries.Library{Name: "Calculus Unified Lib", Location: libraries.User}
var l7 = &libraries.Library{Name: "AnotherLib", Location: libraries.Sketchbook} var l7 = &libraries.Library{Name: "AnotherLib", Location: libraries.User}
func TestClosestMatchWithTotallyDifferentNames(t *testing.T) { func TestClosestMatchWithTotallyDifferentNames(t *testing.T) {
libraryList := libraries.List{} libraryList := libraries.List{}
......
...@@ -24,11 +24,6 @@ import ( ...@@ -24,11 +24,6 @@ import (
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
) )
// SketchBook is a sketchbook
type SketchBook struct {
Path *paths.Path
}
// Sketch is a sketch for Arduino // Sketch is a sketch for Arduino
type Sketch struct { type Sketch struct {
Name string Name string
...@@ -47,23 +42,6 @@ type BoardMetadata struct { ...@@ -47,23 +42,6 @@ type BoardMetadata struct {
Name string `json:"name,omitempty"` 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 // NewSketchFromPath loads a sketch from the specified path
func NewSketchFromPath(path *paths.Path) (*Sketch, error) { func NewSketchFromPath(path *paths.Path) (*Sketch, error) {
sketch := &Sketch{ sketch := &Sketch{
......
This diff is collapsed.
...@@ -71,7 +71,7 @@ func packageManagerInitReq() *rpc.InitReq { ...@@ -71,7 +71,7 @@ func packageManagerInitReq() *rpc.InitReq {
conf.DataDir = viper.GetString("directories.Data") conf.DataDir = viper.GetString("directories.Data")
conf.DownloadsDir = viper.GetString("directories.Downloads") conf.DownloadsDir = viper.GetString("directories.Downloads")
conf.BoardManagerAdditionalUrls = urls conf.BoardManagerAdditionalUrls = urls
conf.SketchbookDir = viper.GetString("directories.SketchBook") conf.SketchbookDir = viper.GetString("directories.User")
return &rpc.InitReq{Configuration: conf} return &rpc.InitReq{Configuration: conf}
} }
...@@ -93,7 +93,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W ...@@ -93,7 +93,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
builderCtx.BuiltInToolsDirs = configuration.BundleToolsDirectories() builderCtx.BuiltInToolsDirs = configuration.BundleToolsDirectories()
builderCtx.OtherLibrariesDirs = paths.NewPathList() builderCtx.OtherLibrariesDirs = paths.NewPathList()
builderCtx.OtherLibrariesDirs.Add(paths.New(viper.GetString("directories.Libraries"))) builderCtx.OtherLibrariesDirs.Add(configuration.LibrariesDir())
if req.GetBuildPath() != "" { if req.GetBuildPath() != "" {
builderCtx.BuildPath = paths.New(req.GetBuildPath()) builderCtx.BuildPath = paths.New(req.GetBuildPath())
......
...@@ -274,7 +274,7 @@ func createInstance(ctx context.Context, getLibOnly bool) ( ...@@ -274,7 +274,7 @@ func createInstance(ctx context.Context, getLibOnly bool) (
if !getLibOnly { if !getLibOnly {
pm = packagemanager.NewPackageManager( pm = packagemanager.NewPackageManager(
dataDir, dataDir,
paths.New(viper.GetString("directories.Packages")), configuration.PackagesDir(),
downloadsDir, downloadsDir,
dataDir.Join("tmp")) dataDir.Join("tmp"))
...@@ -308,9 +308,9 @@ func createInstance(ctx context.Context, getLibOnly bool) ( ...@@ -308,9 +308,9 @@ func createInstance(ctx context.Context, getLibOnly bool) (
lm.AddLibrariesDir(bundledLibsDir, libraries.IDEBuiltIn) lm.AddLibrariesDir(bundledLibsDir, libraries.IDEBuiltIn)
} }
// Add sketchbook libraries dir // Add user libraries dir
libDir := paths.New(viper.GetString("directories.Libraries")) libDir := configuration.LibrariesDir()
lm.AddLibrariesDir(libDir, libraries.Sketchbook) lm.AddLibrariesDir(libDir, libraries.User)
// Add libraries dirs from installed platforms // Add libraries dirs from installed platforms
if pm != nil { if pm != nil {
......
...@@ -60,7 +60,7 @@ func listLibraries(lm *librariesmanager.LibrariesManager, updatable bool, all bo ...@@ -60,7 +60,7 @@ func listLibraries(lm *librariesmanager.LibrariesManager, updatable bool, all bo
for _, libAlternatives := range lm.Libraries { for _, libAlternatives := range lm.Libraries {
for _, lib := range libAlternatives.Alternatives { for _, lib := range libAlternatives.Alternatives {
if !all { if !all {
if lib.Location != libraries.Sketchbook { if lib.Location != libraries.User {
continue continue
} }
} }
......
...@@ -50,23 +50,23 @@ func Init(configPath string) { ...@@ -50,23 +50,23 @@ func Init(configPath string) {
viper.AutomaticEnv() viper.AutomaticEnv()
// Bind env aliases to keep backward compatibility // Bind env aliases to keep backward compatibility
viper.BindEnv("directories.Sketchbook", "ARDUINO_SKETCHBOOK_DIR") viper.BindEnv("directories.User", "ARDUINO_SKETCHBOOK_DIR")
viper.BindEnv("directories.Downloads", "ARDUINO_DOWNLOADS_DIR") viper.BindEnv("directories.Downloads", "ARDUINO_DOWNLOADS_DIR")
viper.BindEnv("directories.Data", "ARDUINO_DATA_DIR") viper.BindEnv("directories.Data", "ARDUINO_DATA_DIR")
// Early access directories.Data and directories.Sketchbook in case // Early access directories.Data and directories.User in case
// those were set through env vars or cli flags // those were set through env vars or cli flags
dataDir := viper.GetString("directories.Data") dataDir := viper.GetString("directories.Data")
if dataDir == "" { if dataDir == "" {
dataDir = getDefaultArduinoDataDir() dataDir = getDefaultArduinoDataDir()
} }
sketchbookDir := viper.GetString("directories.Sketchbook") userDir := viper.GetString("directories.User")
if sketchbookDir == "" { if userDir == "" {
sketchbookDir = getDefaultSketchbookDir() userDir = getDefaultUserDir()
} }
// Set default values for all the settings // Set default values for all the settings
setDefaults(dataDir, sketchbookDir) setDefaults(dataDir, userDir)
// Attempt to read config file // Attempt to read config file
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
...@@ -103,8 +103,8 @@ func getDefaultArduinoDataDir() string { ...@@ -103,8 +103,8 @@ func getDefaultArduinoDataDir() string {
} }
} }
// getDefaultSketchbookDir returns the full path to the default sketchbook folder // getDefaultUserDir returns the full path to the default user folder
func getDefaultSketchbookDir() string { func getDefaultUserDir() string {
userHomeDir, err := os.UserHomeDir() userHomeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
feedback.Errorf("Unable to get user home dir: %v", err) feedback.Errorf("Unable to get user home dir: %v", err)
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
func setDefaults(dataDir, sketchBookDir string) { func setDefaults(dataDir, userDir string) {
// logging // logging
viper.SetDefault("logging.level", "info") viper.SetDefault("logging.level", "info")
viper.SetDefault("logging.format", "text") viper.SetDefault("logging.format", "text")
...@@ -31,9 +31,7 @@ func setDefaults(dataDir, sketchBookDir string) { ...@@ -31,9 +31,7 @@ func setDefaults(dataDir, sketchBookDir string) {
// arduino directories // arduino directories
viper.SetDefault("directories.Data", dataDir) viper.SetDefault("directories.Data", dataDir)
viper.SetDefault("directories.Downloads", filepath.Join(dataDir, "staging")) viper.SetDefault("directories.Downloads", filepath.Join(dataDir, "staging"))
viper.SetDefault("directories.Packages", filepath.Join(dataDir, "packages")) viper.SetDefault("directories.User", userDir)
viper.SetDefault("directories.SketchBook", sketchBookDir)
viper.SetDefault("directories.Libraries", filepath.Join(sketchBookDir, "libraries"))
// daemon settings // daemon settings
viper.SetDefault("daemon.port", "50051") viper.SetDefault("daemon.port", "50051")
......
...@@ -32,12 +32,12 @@ func HardwareDirectories() paths.PathList { ...@@ -32,12 +32,12 @@ func HardwareDirectories() paths.PathList {
} }
} }
if viper.IsSet("directories.Packages") { if viper.IsSet("directories.Data") {
res.Add(paths.New(viper.GetString("directories.Packages"))) res.Add(PackagesDir())
} }
if viper.IsSet("directories.Sketchbook") { if viper.IsSet("directories.User") {
skDir := paths.New(viper.GetString("directories.Sketchbook")) skDir := paths.New(viper.GetString("directories.User"))
hwDir := skDir.Join("hardware") hwDir := skDir.Join("hardware")
if hwDir.IsDir() { if hwDir.IsDir() {
res.Add(hwDir) res.Add(hwDir)
...@@ -76,3 +76,14 @@ func IDEBundledLibrariesDir() *paths.Path { ...@@ -76,3 +76,14 @@ func IDEBundledLibrariesDir() *paths.Path {
return nil return nil
} }
// LibrariesDir returns the full path to the user directory containing
// custom libraries
func LibrariesDir() *paths.Path {
return paths.New(viper.GetString("directories.User")).Join("libraries")
}
// PackagesDir returns the full path to the packages folder
func PackagesDir() *paths.Path {
return paths.New(viper.GetString("directories.Data")).Join("packages")
}
...@@ -68,7 +68,7 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error { ...@@ -68,7 +68,7 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
return i18n.WrapError(err) return i18n.WrapError(err)
} }
for _, folder := range librariesFolders { for _, folder := range librariesFolders {
lm.AddLibrariesDir(folder, libraries.Sketchbook) lm.AddLibrariesDir(folder, libraries.User)
} }
if err := lm.RescanLibraries(); err != nil { if err := lm.RescanLibraries(); err != nil {
......
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