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

Sign up
Appearance settings

Commit 5edfa98

Browse files
committed
Fixed missing ARDUINO_USER_AGENT env var setting. (#2501)
* Added integration test * Fixed missing ARDUINO_USER_AGENT env var
1 parent ebab482 commit 5edfa98

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

‎arduino/builder/builder.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ type Builder struct {
9090
buildOptions *buildOptions
9191

9292
libsDetector *detector.SketchLibrariesDetector
93+
94+
toolEnv []string
9395
}
9496

9597
// buildArtifacts contains the result of various build
@@ -126,6 +128,7 @@ func NewBuilder(
126128
libraryDirs paths.PathList,
127129
stdout, stderr io.Writer, verbose bool, warningsLevel string,
128130
progresCB rpc.TaskProgressCB,
131+
toolEnv []string,
129132
) (*Builder, error) {
130133
buildProperties := properties.NewMap()
131134
if boardBuildProperties != nil {
@@ -209,6 +212,7 @@ func NewBuilder(
209212
buildArtifacts: &buildArtifacts{},
210213
targetPlatform: targetPlatform,
211214
actualPlatform: actualPlatform,
215+
toolEnv: toolEnv,
212216
libsDetector: detector.NewSketchLibrariesDetector(
213217
libsManager, libsResolver,
214218
useCachedLibrariesResolution,
@@ -493,7 +497,7 @@ func (b *Builder) prepareCommandForRecipe(buildProperties *properties.Map, recip
493497
}
494498
}
495499

496-
command, err := executils.NewProcess(nil, parts...)
500+
command, err := executils.NewProcess(b.toolEnv, parts...)
497501
if err != nil {
498502
return nil, err
499503
}

‎commands/compile/compile.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
199199
paths.NewPathList(req.Library...),
200200
outStream, errStream, req.GetVerbose(), req.GetWarnings(),
201201
progressCB,
202+
pme.GetEnvVarsForSpawnedProcess(),
202203
)
203204
if err != nil {
204205
if strings.Contains(err.Error(), "invalid build properties") {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 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 compile_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/internal/integrationtest"
22+
"github.com/arduino/go-paths-helper"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestCompileEnvVarOnNewProcess(t *testing.T) {
27+
// See: https://github.com/arduino/arduino-cli/issues/2499
28+
29+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
30+
defer env.CleanUp()
31+
32+
// Run update-index with our test index
33+
_, _, err := cli.Run("core", "install", "arduino:avr@1.8.6")
34+
require.NoError(t, err)
35+
36+
// Prepare sketchbook and sketch
37+
sketch, err := paths.New("testdata", "bare_minimum").Abs()
38+
require.NoError(t, err)
39+
40+
// Build "printenv" helper insider testdata/printenv
41+
printenvDir, err := paths.New("testdata", "printenv").Abs()
42+
require.NoError(t, err)
43+
builder, err := paths.NewProcess(nil, "go", "build")
44+
require.NoError(t, err)
45+
builder.SetDir(printenvDir.String())
46+
require.NoError(t, builder.Run())
47+
printenv := printenvDir.Join("printenv")
48+
49+
// Patch avr core to run printenv instead of size
50+
plTxt, err := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6", "platform.txt").Append()
51+
require.NoError(t, err)
52+
_, err = plTxt.WriteString("recipe.size.pattern=" + printenv.String() + "\n")
53+
require.NoError(t, err)
54+
require.NoError(t, plTxt.Close())
55+
56+
// Run compile and get ENV
57+
_, stderr, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", sketch.String())
58+
require.NoError(t, err)
59+
require.Contains(t, string(stderr), "ENV> ARDUINO_USER_AGENT=")
60+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
printenv
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
for _, env := range os.Environ() {
10+
fmt.Fprintln(os.Stderr, "ENV>", env)
11+
}
12+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /