From 2ccd77d81176f96b9620bfc60c27f2dda855500e Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Thu, 12 Dec 2019 16:43:07 +0100 Subject: [PATCH 1/2] rename Sketchbook folder to User --- .../cores/packagemanager/package_manager.go | 2 +- .../packagemanager/package_manager_test.go | 2 +- arduino/libraries/libraries.go | 2 +- arduino/libraries/libraries_location.go | 16 ++-- arduino/libraries/librariesmanager/install.go | 10 +-- .../librariesmanager/librariesmanager.go | 10 +-- .../libraries/librariesresolver/cpp_test.go | 14 +-- arduino/sketches/sketches.go | 22 ----- cli/cli_test.go | 90 +++++++++---------- cli/instance/instance.go | 2 +- .../TestSketch/TestSketch.ino | 0 .../TestSketch.test.avr.testboard.hex | 0 .../TestSketch2/TestSketch2.ino | 0 .../hardware/test/avr/boards.txt | 0 .../hardware/test/avr/platform.txt | 0 .../hardware/test2/avr/boards.txt | 0 .../hardware/test2/avr/platform.txt | 0 .../test.hex | 0 commands/compile/compile.go | 2 +- commands/instances.go | 8 +- commands/lib/list.go | 2 +- configuration/configuration.go | 16 ++-- configuration/defaults.go | 6 +- configuration/directories.go | 19 +++- go.sum | 1 + legacy/builder/libraries_loader.go | 2 +- 26 files changed, 104 insertions(+), 122 deletions(-) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/TestSketch/TestSketch.ino (100%) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/TestSketch/TestSketch.test.avr.testboard.hex (100%) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/TestSketch2/TestSketch2.ino (100%) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/hardware/test/avr/boards.txt (100%) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/hardware/test/avr/platform.txt (100%) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/hardware/test2/avr/boards.txt (100%) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/hardware/test2/avr/platform.txt (100%) rename cli/testdata/{sketchbook_with_custom_hardware => custom_hardware}/test.hex (100%) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 66b3616dabb..e666d5c6249 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -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() diff --git a/arduino/cores/packagemanager/package_manager_test.go b/arduino/cores/packagemanager/package_manager_test.go index 428bc50cb32..03fcd8cd9c2 100644 --- a/arduino/cores/packagemanager/package_manager_test.go +++ b/arduino/cores/packagemanager/package_manager_test.go @@ -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, ) diff --git a/arduino/libraries/libraries.go b/arduino/libraries/libraries.go index b3b4ec7980c..66c5cab02ca 100644 --- a/arduino/libraries/libraries.go +++ b/arduino/libraries/libraries.go @@ -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)) diff --git a/arduino/libraries/libraries_location.go b/arduino/libraries/libraries_location.go index b37cb73dbd0..6f7dab746f7 100644 --- a/arduino/libraries/libraries_location.go +++ b/arduino/libraries/libraries_location.go @@ -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) } diff --git a/arduino/libraries/librariesmanager/install.go b/arduino/libraries/librariesmanager/install.go index 393623c56ea..1ba53da5976 100644 --- a/arduino/libraries/librariesmanager/install.go +++ b/arduino/libraries/librariesmanager/install.go @@ -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) } diff --git a/arduino/libraries/librariesmanager/librariesmanager.go b/arduino/libraries/librariesmanager/librariesmanager.go index 08339066005..ec9d09f66c7 100644 --- a/arduino/libraries/librariesmanager/librariesmanager.go +++ b/arduino/libraries/librariesmanager/librariesmanager.go @@ -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 } } diff --git a/arduino/libraries/librariesresolver/cpp_test.go b/arduino/libraries/librariesresolver/cpp_test.go index 2d89634a08a..fd12ec6429c 100644 --- a/arduino/libraries/librariesresolver/cpp_test.go +++ b/arduino/libraries/librariesresolver/cpp_test.go @@ -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{} diff --git a/arduino/sketches/sketches.go b/arduino/sketches/sketches.go index 7bbb926b891..c56db436bbc 100644 --- a/arduino/sketches/sketches.go +++ b/arduino/sketches/sketches.go @@ -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{ diff --git a/cli/cli_test.go b/cli/cli_test.go index 779c12616af..9998162ae9b 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -43,9 +43,9 @@ var ( // line and check with what we want. stdOut = os.Stdout - currDownloadDir string - currDataDir string - currSketchbookDir string + currDownloadDir string + currDataDir 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) diff --git a/cli/instance/instance.go b/cli/instance/instance.go index bd4b68b7c02..422d8bd1e24 100644 --- a/cli/instance/instance.go +++ b/cli/instance/instance.go @@ -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} } diff --git a/cli/testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.ino b/cli/testdata/custom_hardware/TestSketch/TestSketch.ino similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.ino rename to cli/testdata/custom_hardware/TestSketch/TestSketch.ino diff --git a/cli/testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex b/cli/testdata/custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex rename to cli/testdata/custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex diff --git a/cli/testdata/sketchbook_with_custom_hardware/TestSketch2/TestSketch2.ino b/cli/testdata/custom_hardware/TestSketch2/TestSketch2.ino similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/TestSketch2/TestSketch2.ino rename to cli/testdata/custom_hardware/TestSketch2/TestSketch2.ino diff --git a/cli/testdata/sketchbook_with_custom_hardware/hardware/test/avr/boards.txt b/cli/testdata/custom_hardware/hardware/test/avr/boards.txt similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/hardware/test/avr/boards.txt rename to cli/testdata/custom_hardware/hardware/test/avr/boards.txt diff --git a/cli/testdata/sketchbook_with_custom_hardware/hardware/test/avr/platform.txt b/cli/testdata/custom_hardware/hardware/test/avr/platform.txt similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/hardware/test/avr/platform.txt rename to cli/testdata/custom_hardware/hardware/test/avr/platform.txt diff --git a/cli/testdata/sketchbook_with_custom_hardware/hardware/test2/avr/boards.txt b/cli/testdata/custom_hardware/hardware/test2/avr/boards.txt similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/hardware/test2/avr/boards.txt rename to cli/testdata/custom_hardware/hardware/test2/avr/boards.txt diff --git a/cli/testdata/sketchbook_with_custom_hardware/hardware/test2/avr/platform.txt b/cli/testdata/custom_hardware/hardware/test2/avr/platform.txt similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/hardware/test2/avr/platform.txt rename to cli/testdata/custom_hardware/hardware/test2/avr/platform.txt diff --git a/cli/testdata/sketchbook_with_custom_hardware/test.hex b/cli/testdata/custom_hardware/test.hex similarity index 100% rename from cli/testdata/sketchbook_with_custom_hardware/test.hex rename to cli/testdata/custom_hardware/test.hex diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 9d5cda7fc55..b3ea4fe9318 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -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()) diff --git a/commands/instances.go b/commands/instances.go index 0ce25a15dd8..1ffb035f145 100644 --- a/commands/instances.go +++ b/commands/instances.go @@ -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 { diff --git a/commands/lib/list.go b/commands/lib/list.go index 14da1dba910..3a0302c3cf6 100644 --- a/commands/lib/list.go +++ b/commands/lib/list.go @@ -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 } } diff --git a/configuration/configuration.go b/configuration/configuration.go index 23b1bb4c139..9d51ae26312 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -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) diff --git a/configuration/defaults.go b/configuration/defaults.go index edb89ef670b..1f3b18a7797 100644 --- a/configuration/defaults.go +++ b/configuration/defaults.go @@ -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") diff --git a/configuration/directories.go b/configuration/directories.go index 72c6bec5fdc..7b25e55fcd8 100644 --- a/configuration/directories.go +++ b/configuration/directories.go @@ -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")) +} + +// PackagesDir returns the full path to the packages folder +func PackagesDir() *paths.Path { + return paths.New(viper.GetString("directories.Data")).Join("packages") +} diff --git a/go.sum b/go.sum index 01ded9ff60e..973ca95cfc5 100644 --- a/go.sum +++ b/go.sum @@ -124,6 +124,7 @@ github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= diff --git a/legacy/builder/libraries_loader.go b/legacy/builder/libraries_loader.go index a09bddd061e..0e45e6a3c4b 100644 --- a/legacy/builder/libraries_loader.go +++ b/legacy/builder/libraries_loader.go @@ -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 { From 4169b2a629521017692eba22c4b34d9230310753 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Fri, 13 Dec 2019 16:26:22 +0100 Subject: [PATCH 2/2] missing join on path --- configuration/directories.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configuration/directories.go b/configuration/directories.go index 7b25e55fcd8..a6f723344a5 100644 --- a/configuration/directories.go +++ b/configuration/directories.go @@ -80,7 +80,7 @@ func IDEBundledLibrariesDir() *paths.Path { // LibrariesDir returns the full path to the user directory containing // custom libraries func LibrariesDir() *paths.Path { - return paths.New(viper.GetString("directories.User")) + return paths.New(viper.GetString("directories.User")).Join("libraries") } // PackagesDir returns the full path to the packages folder