Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b3264a

Browse filesBrowse files
committed
Fixed nil pointer exception in build options extraction
1 parent baf246a commit 1b3264a
Copy full SHA for 1b3264a

File tree

Expand file treeCollapse file tree

4 files changed

+69
-5
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+69
-5
lines changed

‎legacy/builder/libraries_loader.go

Copy file name to clipboardExpand all lines: legacy/builder/libraries_loader.go
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
3636
ctx.LibrariesManager = lm
3737

3838
builtInLibrariesFolders := ctx.BuiltInLibrariesDirs
39-
if err := builtInLibrariesFolders.ToAbs(); err != nil {
40-
return errors.WithStack(err)
39+
if builtInLibrariesFolders != nil {
40+
if err := builtInLibrariesFolders.ToAbs(); err != nil {
41+
return errors.WithStack(err)
42+
}
43+
lm.AddLibrariesDir(builtInLibrariesFolders, libraries.IDEBuiltIn)
4144
}
42-
lm.AddLibrariesDir(builtInLibrariesFolders, libraries.IDEBuiltIn)
4345

4446
if ctx.ActualPlatform != ctx.TargetPlatform {
4547
lm.AddPlatformReleaseLibrariesDir(ctx.ActualPlatform, libraries.ReferencedPlatformBuiltIn)

‎legacy/builder/test/create_build_options_map_test.go

Copy file name to clipboardExpand all lines: legacy/builder/test/create_build_options_map_test.go
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func TestCreateBuildOptionsMap(t *testing.T) {
4343

4444
require.Equal(t, `{
4545
"additionalFiles": "",
46-
"builtInLibrariesFolders": "",
4746
"builtInToolsFolders": "tools",
4847
"compiler.optimization_flags": "-Os",
4948
"customBuildProperties": "",

‎legacy/builder/types/context.go

Copy file name to clipboardExpand all lines: legacy/builder/types/context.go
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
208208
opts := properties.NewMap()
209209
opts.Set("hardwareFolders", strings.Join(ctx.HardwareDirs.AsStrings(), ","))
210210
opts.Set("builtInToolsFolders", strings.Join(ctx.BuiltInToolsDirs.AsStrings(), ","))
211-
opts.Set("builtInLibrariesFolders", ctx.BuiltInLibrariesDirs.String())
211+
if ctx.BuiltInLibrariesDirs != nil {
212+
opts.Set("builtInLibrariesFolders", ctx.BuiltInLibrariesDirs.String())
213+
}
212214
opts.Set("otherLibrariesFolders", strings.Join(ctx.OtherLibrariesDirs.AsStrings(), ","))
213215
opts.SetPath("sketchLocation", ctx.SketchLocation)
214216
var additionalFilesRelative []string

‎legacy/builder/types/context_test.go

Copy file name to clipboard
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package types
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/arduino/cores"
22+
paths "github.com/arduino/go-paths-helper"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestInjectBuildOption(t *testing.T) {
27+
fqbn, err := cores.ParseFQBN("aaa:bbb:ccc")
28+
require.NoError(t, err)
29+
30+
{
31+
ctx := &Context{
32+
HardwareDirs: paths.NewPathList("aaa", "bbb"),
33+
BuiltInToolsDirs: paths.NewPathList("ccc", "ddd"),
34+
BuiltInLibrariesDirs: paths.New("eee"),
35+
OtherLibrariesDirs: paths.NewPathList("fff", "ggg"),
36+
SketchLocation: paths.New("hhh"),
37+
FQBN: fqbn,
38+
ArduinoAPIVersion: "iii",
39+
CustomBuildProperties: []string{"jjj", "kkk"},
40+
OptimizationFlags: "lll",
41+
}
42+
newCtx := &Context{}
43+
newCtx.InjectBuildOptions(ctx.ExtractBuildOptions())
44+
require.Equal(t, ctx, newCtx)
45+
}
46+
{
47+
ctx := &Context{
48+
HardwareDirs: paths.NewPathList("aaa", "bbb"),
49+
BuiltInToolsDirs: paths.NewPathList("ccc", "ddd"),
50+
OtherLibrariesDirs: paths.NewPathList("fff", "ggg"),
51+
SketchLocation: paths.New("hhh"),
52+
FQBN: fqbn,
53+
ArduinoAPIVersion: "iii",
54+
CustomBuildProperties: []string{"jjj", "kkk"},
55+
OptimizationFlags: "lll",
56+
}
57+
newCtx := &Context{}
58+
newCtx.InjectBuildOptions(ctx.ExtractBuildOptions())
59+
require.Equal(t, ctx, newCtx)
60+
}
61+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.