Skip to content

Commit c23bb9c

Browse files
authored
Replace ctx.ToolsDirs with ctx.BuiltInToolsDirs (#418)
* Removed ctx.ToolsDirs The ToolsDirs field has been replaced by BuiltInToolsDirs during the big refactoring in the arduino-builder repo. The intention was to remove ToolsDirs once done, but for some reasons I forgot to remove it. This commit completes the transition. * Fixed test for legacy ctx.ToolsDirs -> BuiltInToolsDirs rename
1 parent dd586db commit c23bb9c

9 files changed

+40
-63
lines changed

commands/compile/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
9595
}
9696

9797
if toolsDir, err := config.BundleToolsDirectories(); err == nil {
98-
builderCtx.ToolsDirs = toolsDir
98+
builderCtx.BuiltInToolsDirs = toolsDir
9999
} else {
100100
return nil, fmt.Errorf("cannot get bundled tools directories: %s", err)
101101
}

legacy/builder/grpc/rpc.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type builderServer struct {
5757
}
5858

5959
func (s *builderServer) watch() {
60-
folders := []paths.PathList{s.ctx.HardwareDirs, s.ctx.ToolsDirs, s.ctx.BuiltInLibrariesDirs, s.ctx.OtherLibrariesDirs}
60+
folders := []paths.PathList{s.ctx.HardwareDirs, s.ctx.BuiltInToolsDirs, s.ctx.BuiltInLibrariesDirs, s.ctx.OtherLibrariesDirs}
6161

6262
for _, category := range folders {
6363
for _, folder := range category {
@@ -84,7 +84,7 @@ func (s *builderServer) DropCache(ctx context.Context, args *pb.VerboseParams) (
8484
func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams) (*pb.Response, error) {
8585

8686
s.ctx.HardwareDirs = paths.NewPathList(strings.Split(args.HardwareFolders, ",")...)
87-
s.ctx.ToolsDirs = paths.NewPathList(strings.Split(args.ToolsFolders, ",")...)
87+
s.ctx.BuiltInToolsDirs = paths.NewPathList(strings.Split(args.ToolsFolders, ",")...)
8888
s.ctx.BuiltInLibrariesDirs = paths.NewPathList(strings.Split(args.BuiltInLibrariesFolders, ",")...)
8989
s.ctx.OtherLibrariesDirs = paths.NewPathList(strings.Split(args.OtherLibrariesFolders, ",")...)
9090
s.ctx.SketchLocation = paths.New(args.SketchLocation)
@@ -128,7 +128,7 @@ func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams)
128128
func (s *builderServer) Build(args *pb.BuildParams, stream pb.Builder_BuildServer) error {
129129

130130
s.ctx.HardwareDirs = paths.NewPathList(strings.Split(args.HardwareFolders, ",")...)
131-
s.ctx.ToolsDirs = paths.NewPathList(strings.Split(args.ToolsFolders, ",")...)
131+
s.ctx.BuiltInToolsDirs = paths.NewPathList(strings.Split(args.ToolsFolders, ",")...)
132132
s.ctx.BuiltInLibrariesDirs = paths.NewPathList(strings.Split(args.BuiltInLibrariesFolders, ",")...)
133133
s.ctx.OtherLibrariesDirs = paths.NewPathList(strings.Split(args.OtherLibrariesFolders, ",")...)
134134
s.ctx.SketchLocation = paths.New(args.SketchLocation)

legacy/builder/test/builder_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func TestBuilderBridgeRedBearLab(t *testing.T) {
242242

243243
ctx := prepareBuilderTestContext(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "RedBearLab:avr:blend")
244244
ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff"))
245-
ctx.ToolsDirs = append(ctx.ToolsDirs, paths.New("downloaded_board_manager_stuff"))
245+
ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff"))
246246

247247
buildPath := SetupBuildPath(t, ctx)
248248
defer buildPath.RemoveAll()
@@ -277,7 +277,7 @@ func TestBuilderSketchNoFunctions(t *testing.T) {
277277

278278
ctx := prepareBuilderTestContext(t, paths.New("sketch_no_functions", "main.ino"), "RedBearLab:avr:blend")
279279
ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff"))
280-
ctx.ToolsDirs = append(ctx.ToolsDirs, paths.New("downloaded_board_manager_stuff"))
280+
ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff"))
281281

282282
buildPath := SetupBuildPath(t, ctx)
283283
defer buildPath.RemoveAll()
@@ -293,7 +293,7 @@ func TestBuilderSketchWithBackup(t *testing.T) {
293293

294294
ctx := prepareBuilderTestContext(t, paths.New("sketch_with_backup_files", "sketch.ino"), "arduino:avr:uno")
295295
ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff"))
296-
ctx.ToolsDirs = append(ctx.ToolsDirs, paths.New("downloaded_board_manager_stuff"))
296+
ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff"))
297297

298298
buildPath := SetupBuildPath(t, ctx)
299299
defer buildPath.RemoveAll()

legacy/builder/test/create_build_options_map_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
func TestCreateBuildOptionsMap(t *testing.T) {
4242
ctx := &types.Context{
4343
HardwareDirs: paths.NewPathList("hardware", "hardware2"),
44-
ToolsDirs: paths.NewPathList("tools"),
44+
BuiltInToolsDirs: paths.NewPathList("tools"),
4545
OtherLibrariesDirs: paths.NewPathList("libraries"),
4646
SketchLocation: paths.New("sketchLocation"),
4747
FQBN: parseFQBN(t, "my:nice:fqbn"),
@@ -55,15 +55,15 @@ func TestCreateBuildOptionsMap(t *testing.T) {
5555
err := create.Run(ctx)
5656
NoError(t, err)
5757

58-
require.Equal(t, "{\n"+
59-
" \"additionalFiles\": \"\",\n"+
60-
" \"builtInLibrariesFolders\": \"\",\n"+
61-
" \"customBuildProperties\": \"\",\n"+
62-
" \"fqbn\": \"my:nice:fqbn\",\n"+
63-
" \"hardwareFolders\": \"hardware,hardware2\",\n"+
64-
" \"otherLibrariesFolders\": \"libraries\",\n"+
65-
" \"runtime.ide.version\": \"ideVersion\",\n"+
66-
" \"sketchLocation\": \"sketchLocation\",\n"+
67-
" \"toolsFolders\": \"tools\"\n"+
68-
"}", ctx.BuildOptionsJson)
58+
require.Equal(t, `{
59+
"additionalFiles": "",
60+
"builtInLibrariesFolders": "",
61+
"builtInToolsFolders": "tools",
62+
"customBuildProperties": "",
63+
"fqbn": "my:nice:fqbn",
64+
"hardwareFolders": "hardware,hardware2",
65+
"otherLibrariesFolders": "libraries",
66+
"runtime.ide.version": "ideVersion",
67+
"sketchLocation": "sketchLocation"
68+
}`, ctx.BuildOptionsJson)
6969
}

legacy/builder/test/load_vid_pid_specific_properties_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) {
4444

4545
ctx := &types.Context{
4646
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"),
47-
ToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"),
47+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"),
4848
SketchLocation: paths.New("sketch1", "sketch.ino"),
4949
FQBN: parseFQBN(t, "arduino:avr:micro"),
5050
ArduinoAPIVersion: "10600",
@@ -74,7 +74,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) {
7474

7575
ctx := &types.Context{
7676
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"),
77-
ToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"),
77+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"),
7878
SketchLocation: paths.New("sketch1", "sketch.ino"),
7979
FQBN: parseFQBN(t, "arduino:avr:micro"),
8080
ArduinoAPIVersion: "10600",

legacy/builder/test/merge_sketch_with_bootloader_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestMergeSketchWithBootloader(t *testing.T) {
4646

4747
ctx := &types.Context{
4848
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"),
49-
ToolsDirs: paths.NewPathList("downloaded_tools"),
49+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
5050
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
5151
OtherLibrariesDirs: paths.NewPathList("libraries"),
5252
SketchLocation: paths.New("sketch1", "sketch.ino"),
@@ -88,7 +88,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) {
8888

8989
ctx := &types.Context{
9090
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"),
91-
ToolsDirs: paths.NewPathList("downloaded_tools"),
91+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
9292
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
9393
OtherLibrariesDirs: paths.NewPathList("libraries"),
9494
SketchLocation: paths.New("sketch1", "sketch.ino"),
@@ -130,7 +130,7 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) {
130130

131131
ctx := &types.Context{
132132
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"),
133-
ToolsDirs: paths.NewPathList("downloaded_tools"),
133+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
134134
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
135135
OtherLibrariesDirs: paths.NewPathList("libraries"),
136136
SketchLocation: paths.New("sketch1", "sketch.ino"),
@@ -168,7 +168,7 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) {
168168

169169
ctx := &types.Context{
170170
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"),
171-
ToolsDirs: paths.NewPathList("downloaded_tools"),
171+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
172172
BuiltInLibrariesDirs: paths.NewPathList("downloaded_libraries"),
173173
OtherLibrariesDirs: paths.NewPathList("libraries"),
174174
SketchLocation: paths.New("sketch1", "sketch.ino"),

legacy/builder/test/store_build_options_map_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
func TestStoreBuildOptionsMap(t *testing.T) {
4343
ctx := &types.Context{
4444
HardwareDirs: paths.NewPathList("hardware"),
45-
ToolsDirs: paths.NewPathList("tools"),
45+
BuiltInToolsDirs: paths.NewPathList("tools"),
4646
BuiltInLibrariesDirs: paths.NewPathList("built-in libraries"),
4747
OtherLibrariesDirs: paths.NewPathList("libraries"),
4848
SketchLocation: paths.New("sketchLocation"),
@@ -73,15 +73,15 @@ func TestStoreBuildOptionsMap(t *testing.T) {
7373
bytes, err := buildPath.Join(constants.BUILD_OPTIONS_FILE).ReadFile()
7474
NoError(t, err)
7575

76-
require.Equal(t, "{\n"+
77-
" \"additionalFiles\": \"\",\n"+
78-
" \"builtInLibrariesFolders\": \"built-in libraries\",\n"+
79-
" \"customBuildProperties\": \"custom=prop\",\n"+
80-
" \"fqbn\": \"my:nice:fqbn\",\n"+
81-
" \"hardwareFolders\": \"hardware\",\n"+
82-
" \"otherLibrariesFolders\": \"libraries\",\n"+
83-
" \"runtime.ide.version\": \"ideVersion\",\n"+
84-
" \"sketchLocation\": \"sketchLocation\",\n"+
85-
" \"toolsFolders\": \"tools\"\n"+
86-
"}", string(bytes))
76+
require.Equal(t, `{
77+
"additionalFiles": "",
78+
"builtInLibrariesFolders": "built-in libraries",
79+
"builtInToolsFolders": "tools",
80+
"customBuildProperties": "custom=prop",
81+
"fqbn": "my:nice:fqbn",
82+
"hardwareFolders": "hardware",
83+
"otherLibrariesFolders": "libraries",
84+
"runtime.ide.version": "ideVersion",
85+
"sketchLocation": "sketchLocation"
86+
}`, string(bytes))
8787
}

legacy/builder/tools_loader.go

+1-23
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
package builder
3131

3232
import (
33-
"fmt"
34-
"strings"
35-
3633
"github.com/arduino/arduino-cli/legacy/builder/types"
3734
"github.com/arduino/go-paths-helper"
3835
)
@@ -45,28 +42,9 @@ func (s *ToolsLoader) Run(ctx *types.Context) error {
4542
return nil
4643
}
4744

48-
folders := paths.NewPathList()
4945
builtinFolders := paths.NewPathList()
50-
51-
if ctx.BuiltInToolsDirs != nil || len(ctx.BuiltInLibrariesDirs) == 0 {
52-
folders = ctx.ToolsDirs
46+
if ctx.BuiltInToolsDirs != nil {
5347
builtinFolders = ctx.BuiltInToolsDirs
54-
} else {
55-
// Auto-detect built-in tools folders (for arduino-builder backward compatibility)
56-
// this is a deprecated feature and will be removed in the future
57-
builtinHardwareFolder, err := ctx.BuiltInLibrariesDirs[0].Join("..").Abs()
58-
59-
if err != nil {
60-
fmt.Println("Error detecting ")
61-
}
62-
63-
for _, folder := range ctx.ToolsDirs {
64-
if !strings.Contains(folder.String(), builtinHardwareFolder.String()) { // TODO: make a function to check for subfolders
65-
folders = append(folders, folder)
66-
} else {
67-
builtinFolders = append(builtinFolders, folder)
68-
}
69-
}
7048
}
7149

7250
pm := ctx.PackageManager

legacy/builder/types/context.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type ProgressStruct struct {
2424
type Context struct {
2525
// Build options
2626
HardwareDirs paths.PathList
27-
ToolsDirs paths.PathList
2827
BuiltInToolsDirs paths.PathList
2928
BuiltInLibrariesDirs paths.PathList
3029
OtherLibrariesDirs paths.PathList
@@ -122,7 +121,7 @@ type Context struct {
122121
func (ctx *Context) ExtractBuildOptions() *properties.Map {
123122
opts := properties.NewMap()
124123
opts.Set("hardwareFolders", strings.Join(ctx.HardwareDirs.AsStrings(), ","))
125-
opts.Set("toolsFolders", strings.Join(ctx.ToolsDirs.AsStrings(), ","))
124+
opts.Set("builtInToolsFolders", strings.Join(ctx.BuiltInToolsDirs.AsStrings(), ","))
126125
opts.Set("builtInLibrariesFolders", strings.Join(ctx.BuiltInLibrariesDirs.AsStrings(), ","))
127126
opts.Set("otherLibrariesFolders", strings.Join(ctx.OtherLibrariesDirs.AsStrings(), ","))
128127
opts.SetPath("sketchLocation", ctx.SketchLocation)
@@ -146,7 +145,7 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
146145

147146
func (ctx *Context) InjectBuildOptions(opts *properties.Map) {
148147
ctx.HardwareDirs = paths.NewPathList(strings.Split(opts.Get("hardwareFolders"), ",")...)
149-
ctx.ToolsDirs = paths.NewPathList(strings.Split(opts.Get("toolsFolders"), ",")...)
148+
ctx.BuiltInToolsDirs = paths.NewPathList(strings.Split(opts.Get("builtInToolsFolders"), ",")...)
150149
ctx.BuiltInLibrariesDirs = paths.NewPathList(strings.Split(opts.Get("builtInLibrariesFolders"), ",")...)
151150
ctx.OtherLibrariesDirs = paths.NewPathList(strings.Split(opts.Get("otherLibrariesFolders"), ",")...)
152151
ctx.SketchLocation = opts.GetPath("sketchLocation")

0 commit comments

Comments
 (0)