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{
......
......@@ -45,7 +45,7 @@ var (
currDownloadDir string
currDataDir string
currSketchbookDir string
currUserDir string
)
type stdOutRedirect struct {
......@@ -95,21 +95,23 @@ func TestMain(m *testing.M) {
// SetUp
currDataDir = tmpDirOrDie()
os.MkdirAll(filepath.Join(currDataDir, "packages"), 0755)
os.Setenv("ARDUINO_DATA_DIR", currDataDir)
os.Setenv("ARDUINO_DIRECTORIES_DATA", currDataDir)
currDownloadDir = tmpDirOrDie()
os.Setenv("ARDUINO_DOWNLOADS_DIR", currDownloadDir)
currSketchbookDir = filepath.Join("testdata", "sketchbook_with_custom_hardware")
os.Setenv("ARDUINO_SKETCHBOOK_DIR", currSketchbookDir)
os.Setenv("ARDUINO_DIRECTORIES_DOWNLOADS", currDownloadDir)
currUserDir = filepath.Join("testdata", "custom_hardware")
// use ARDUINO_SKETCHBOOK_DIR instead of ARDUINO_DIRECTORIES_USER to
// ensure the backward compat code is working
os.Setenv("ARDUINO_SKETCHBOOK_DIR", currUserDir)
// Run
res := m.Run()
// TearDown
os.RemoveAll(currDataDir)
os.Unsetenv("ARDUINO_DATA_DIR")
os.Unsetenv("ARDUINO_DIRECTORIES_DATA")
currDataDir = ""
os.RemoveAll(currDownloadDir)
os.Unsetenv("ARDUINO_DOWNLOADS_DIR")
os.Unsetenv("ARDUINO_DIRECTORIES_DOWNLOADS")
currDownloadDir = ""
os.Unsetenv("ARDUINO_SKETCHBOOK_DIR")
......@@ -222,66 +224,66 @@ func TestUploadIntegration(t *testing.T) {
require.Zero(t, exitCode)
// -i flag
exitCode, d := executeWithArgs("upload", "-i", filepath.Join(currSketchbookDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, d := executeWithArgs("upload", "-i", filepath.Join(currUserDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode)
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
require.Contains(t, string(d), "testdata/custom_hardware/test.hex")
// -i flag with implicit extension
exitCode, d = executeWithArgs("upload", "-i", filepath.Join(currSketchbookDir, "test"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, d = executeWithArgs("upload", "-i", filepath.Join(currUserDir, "test"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode)
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
require.Contains(t, string(d), "testdata/custom_hardware/test.hex")
// -i with absolute path
fullPath, err := filepath.Abs(filepath.Join(currSketchbookDir, "test.hex"))
fullPath, err := filepath.Abs(filepath.Join(currUserDir, "test.hex"))
require.NoError(t, err)
exitCode, d = executeWithArgs("upload", "-i", fullPath, "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode)
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
require.Contains(t, string(d), "testdata/custom_hardware/test.hex")
// -v verbose
exitCode, d = executeWithArgs("upload", "-v", "-t", "-i", filepath.Join(currSketchbookDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, d = executeWithArgs("upload", "-v", "-t", "-i", filepath.Join(currUserDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode)
require.Contains(t, string(d), "VERBOSE")
require.Contains(t, string(d), "VERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
require.Contains(t, string(d), "testdata/custom_hardware/test.hex")
// -t verify
exitCode, d = executeWithArgs("upload", "-i", filepath.Join(currSketchbookDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, d = executeWithArgs("upload", "-i", filepath.Join(currUserDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode)
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
require.Contains(t, string(d), "testdata/custom_hardware/test.hex")
// -v -t verbose verify
exitCode, d = executeWithArgs("upload", "-v", "-t", "-i", filepath.Join(currSketchbookDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, d = executeWithArgs("upload", "-v", "-t", "-i", filepath.Join(currUserDir, "test.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode)
require.Contains(t, string(d), "VERBOSE")
require.Contains(t, string(d), "VERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
require.Contains(t, string(d), "testdata/custom_hardware/test.hex")
// non-existent file
exitCode, _ = executeWithArgs("upload", "-i", filepath.Join(currSketchbookDir, "test123.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, _ = executeWithArgs("upload", "-i", filepath.Join(currUserDir, "test123.hex"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.NotZero(t, exitCode)
// sketch
exitCode, d = executeWithArgs("upload", filepath.Join(currSketchbookDir, "TestSketch"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, d = executeWithArgs("upload", filepath.Join(currUserDir, "TestSketch"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode)
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex")
require.Contains(t, string(d), "testdata/custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex")
// sketch without build
exitCode, _ = executeWithArgs("upload", filepath.Join(currSketchbookDir, "TestSketch2"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, _ = executeWithArgs("upload", filepath.Join(currUserDir, "TestSketch2"), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.NotZero(t, exitCode)
// platform without 'recipe.output.tmp_file' property
exitCode, _ = executeWithArgs("upload", "-i", filepath.Join(currSketchbookDir, "test.hex"), "-b", "test2:avr:testboard", "-p", "/dev/ttyACM0")
exitCode, _ = executeWithArgs("upload", "-i", filepath.Join(currUserDir, "test.hex"), "-b", "test2:avr:testboard", "-p", "/dev/ttyACM0")
require.NotZero(t, exitCode)
}
......@@ -290,10 +292,6 @@ func TestCompileCommandsIntegration(t *testing.T) {
tmp := tmpDirOrDie()
defer os.RemoveAll(tmp)
// override SetUp dirs
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp)
currSketchbookDir = tmp
exitCode, _ := executeWithArgs("core", "update-index")
require.Zero(t, exitCode)
......@@ -302,26 +300,26 @@ func TestCompileCommandsIntegration(t *testing.T) {
require.Zero(t, exitCode)
// Create a test sketch
test1 := filepath.Join(currSketchbookDir, "Test1")
exitCode, d := executeWithArgs("sketch", "new", test1)
sketchPath := filepath.Join(tmp, "Test1")
exitCode, d := executeWithArgs("sketch", "new", sketchPath)
require.Zero(t, exitCode)
// Build sketch without FQBN
exitCode, d = executeWithArgs("compile", test1)
exitCode, d = executeWithArgs("compile", sketchPath)
require.NotZero(t, exitCode)
require.Contains(t, string(d), "no FQBN provided")
// Build sketch for arduino:avr:uno
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", test1)
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", sketchPath)
require.Zero(t, exitCode)
require.Contains(t, string(d), "Sketch uses")
require.True(t, paths.New(test1).Join("Test1.arduino.avr.uno.hex").Exist())
require.True(t, paths.New(sketchPath).Join("Test1.arduino.avr.uno.hex").Exist())
// Build sketch for arduino:avr:nano (without options)
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", test1)
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", sketchPath)
require.Zero(t, exitCode)
require.Contains(t, string(d), "Sketch uses")
require.True(t, paths.New(test1).Join("Test1.arduino.avr.nano.hex").Exist())
require.True(t, paths.New(sketchPath).Join("Test1.arduino.avr.nano.hex").Exist())
// Build sketch with --output path
pwd, err := os.Getwd()
......@@ -329,23 +327,23 @@ func TestCompileCommandsIntegration(t *testing.T) {
defer func() { require.NoError(t, os.Chdir(pwd)) }()
require.NoError(t, os.Chdir(tmp))
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", "test", test1)
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", "test", sketchPath)
require.Zero(t, exitCode)
require.Contains(t, string(d), "Sketch uses")
require.True(t, paths.New("test.hex").Exist())
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", "test2.hex", test1)
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", "test2.hex", sketchPath)
require.Zero(t, exitCode)
require.Contains(t, string(d), "Sketch uses")
require.True(t, paths.New("test2.hex").Exist())
require.NoError(t, paths.New(tmp, "anothertest").MkdirAll())
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", "anothertest/test", test1)
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", "anothertest/test", sketchPath)
require.Zero(t, exitCode)
require.Contains(t, string(d), "Sketch uses")
require.True(t, paths.New("anothertest", "test.hex").Exist())
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", tmp+"/anothertest/test2", test1)
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:nano", "-o", tmp+"/anothertest/test2", sketchPath)
require.Zero(t, exitCode)
require.Contains(t, string(d), "Sketch uses")
require.True(t, paths.New("anothertest", "test2.hex").Exist())
......@@ -375,7 +373,9 @@ func Test3rdPartyCoreIntegration(t *testing.T) {
require.Contains(t, string(d), "installed")
// Build a simple sketch and check if all artifacts are copied
tmpSketch := paths.New(currSketchbookDir).Join("Blink")
tmp := tmpDirOrDie()
defer os.RemoveAll(tmp)
tmpSketch := paths.New(tmp).Join("Blink")
err := paths.New("testdata/Blink").CopyDirTo(tmpSketch)
require.NoError(t, err, "copying test sketch into temp dir")
exitCode, d = executeWithArgs("--config-file", configFile, "compile", "-b", "esp32:esp32:esp32", tmpSketch.String())
......@@ -386,12 +386,6 @@ func Test3rdPartyCoreIntegration(t *testing.T) {
}
func TestCoreCommandsIntegration(t *testing.T) {
// override SetUp dirs
tmp := tmpDirOrDie()
defer os.RemoveAll(tmp)
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp)
currSketchbookDir = tmp
exitCode, _ := executeWithArgs("core", "update-index")
require.Zero(t, exitCode)
......
......@@ -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