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
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()
......
......@@ -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,
)
......
......@@ -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))
......
......@@ -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 {
......@@ -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))
}
......@@ -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)
}
......@@ -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)
}
......@@ -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) {
......@@ -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)
......@@ -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)
}
......
......@@ -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
}
}
......@@ -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
}
}
......
......@@ -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{}
......
......@@ -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
......@@ -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{
......
This diff is collapsed.
......@@ -71,7 +71,7 @@ func packageManagerInitReq() *rpc.InitReq {
conf.DataDir = viper.GetString("directories.Data")
conf.DownloadsDir = viper.GetString("directories.Downloads")
conf.BoardManagerAdditionalUrls = urls
conf.SketchbookDir = viper.GetString("directories.SketchBook")
conf.SketchbookDir = viper.GetString("directories.User")
return &rpc.InitReq{Configuration: conf}
}
......@@ -93,7 +93,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
builderCtx.BuiltInToolsDirs = configuration.BundleToolsDirectories()
builderCtx.OtherLibrariesDirs = paths.NewPathList()
builderCtx.OtherLibrariesDirs.Add(paths.New(viper.GetString("directories.Libraries")))
builderCtx.OtherLibrariesDirs.Add(configuration.LibrariesDir())
if req.GetBuildPath() != "" {
builderCtx.BuildPath = paths.New(req.GetBuildPath())
......
......@@ -274,7 +274,7 @@ func createInstance(ctx context.Context, getLibOnly bool) (
if !getLibOnly {
pm = packagemanager.NewPackageManager(
dataDir,
paths.New(viper.GetString("directories.Packages")),
configuration.PackagesDir(),
downloadsDir,
dataDir.Join("tmp"))
......@@ -308,9 +308,9 @@ func createInstance(ctx context.Context, getLibOnly bool) (
lm.AddLibrariesDir(bundledLibsDir, libraries.IDEBuiltIn)
}
// Add sketchbook libraries dir
libDir := paths.New(viper.GetString("directories.Libraries"))
lm.AddLibrariesDir(libDir, libraries.Sketchbook)
// Add user libraries dir
libDir := configuration.LibrariesDir()
lm.AddLibrariesDir(libDir, libraries.User)
// Add libraries dirs from installed platforms
if pm != nil {
......
......@@ -60,7 +60,7 @@ func listLibraries(lm *librariesmanager.LibrariesManager, updatable bool, all bo
for _, libAlternatives := range lm.Libraries {
for _, lib := range libAlternatives.Alternatives {
if !all {
if lib.Location != libraries.Sketchbook {
if lib.Location != libraries.User {
continue
}
}
......
......@@ -50,23 +50,23 @@ func Init(configPath string) {
viper.AutomaticEnv()
// 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.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
dataDir := viper.GetString("directories.Data")
if dataDir == "" {
dataDir = getDefaultArduinoDataDir()
}
sketchbookDir := viper.GetString("directories.Sketchbook")
if sketchbookDir == "" {
sketchbookDir = getDefaultSketchbookDir()
userDir := viper.GetString("directories.User")
if userDir == "" {
userDir = getDefaultUserDir()
}
// Set default values for all the settings
setDefaults(dataDir, sketchbookDir)
setDefaults(dataDir, userDir)
// Attempt to read config file
if err := viper.ReadInConfig(); err != nil {
......@@ -103,8 +103,8 @@ func getDefaultArduinoDataDir() string {
}
}
// getDefaultSketchbookDir returns the full path to the default sketchbook folder
func getDefaultSketchbookDir() string {
// getDefaultUserDir returns the full path to the default user folder
func getDefaultUserDir() string {
userHomeDir, err := os.UserHomeDir()
if err != nil {
feedback.Errorf("Unable to get user home dir: %v", err)
......
......@@ -21,7 +21,7 @@ import (
"github.com/spf13/viper"
)
func setDefaults(dataDir, sketchBookDir string) {
func setDefaults(dataDir, userDir string) {
// logging
viper.SetDefault("logging.level", "info")
viper.SetDefault("logging.format", "text")
......@@ -31,9 +31,7 @@ func setDefaults(dataDir, sketchBookDir string) {
// arduino directories
viper.SetDefault("directories.Data", dataDir)
viper.SetDefault("directories.Downloads", filepath.Join(dataDir, "staging"))
viper.SetDefault("directories.Packages", filepath.Join(dataDir, "packages"))
viper.SetDefault("directories.SketchBook", sketchBookDir)
viper.SetDefault("directories.Libraries", filepath.Join(sketchBookDir, "libraries"))
viper.SetDefault("directories.User", userDir)
// daemon settings
viper.SetDefault("daemon.port", "50051")
......
......@@ -32,12 +32,12 @@ func HardwareDirectories() paths.PathList {
}
}
if viper.IsSet("directories.Packages") {
res.Add(paths.New(viper.GetString("directories.Packages")))
if viper.IsSet("directories.Data") {
res.Add(PackagesDir())
}
if viper.IsSet("directories.Sketchbook") {
skDir := paths.New(viper.GetString("directories.Sketchbook"))
if viper.IsSet("directories.User") {
skDir := paths.New(viper.GetString("directories.User"))
hwDir := skDir.Join("hardware")
if hwDir.IsDir() {
res.Add(hwDir)
......@@ -76,3 +76,14 @@ func IDEBundledLibrariesDir() *paths.Path {
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 {
return i18n.WrapError(err)
}
for _, folder := range librariesFolders {
lm.AddLibrariesDir(folder, libraries.Sketchbook)
lm.AddLibrariesDir(folder, libraries.User)
}
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