A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/arduino/arduino-cli/commit/3dca438dd803ec67f277e12611d8af7cdf0b0281 below:

Allow locally installed libraries in sketch profiles. (#2930) · arduino/arduino-cli@3dca438 · GitHub

1 +

// This file is part of arduino-cli.

2 +

//

3 +

// Copyright 2022-2025 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 sketch_test

17 + 18 +

import (

19 +

"encoding/json"

20 +

"strings"

21 +

"testing"

22 + 23 +

"github.com/arduino/arduino-cli/internal/integrationtest"

24 +

"github.com/arduino/go-paths-helper"

25 +

"github.com/stretchr/testify/require"

26 +

"go.bug.st/testifyjson/requirejson"

27 +

)

28 + 29 +

func TestSketchProfileDump(t *testing.T) {

30 +

env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)

31 +

t.Cleanup(env.CleanUp)

32 + 33 +

// Prepare the sketch with libraries

34 +

tmpDir, err := paths.MkTempDir("", "")

35 +

require.NoError(t, err)

36 +

t.Cleanup(func() { _ = tmpDir.RemoveAll })

37 + 38 +

sketchTemplate, err := paths.New("testdata", "SketchWithLibrary").Abs()

39 +

require.NoError(t, err)

40 + 41 +

sketch := tmpDir.Join("SketchWithLibrary")

42 +

libInside := sketch.Join("libraries", "MyLib")

43 +

err = sketchTemplate.CopyDirTo(sketch)

44 +

require.NoError(t, err)

45 + 46 +

libOutsideTemplate := sketchTemplate.Join("..", "MyLibOutside")

47 +

libOutside := sketch.Join("..", "MyLibOutside")

48 +

err = libOutsideTemplate.CopyDirTo(libOutside)

49 +

require.NoError(t, err)

50 + 51 +

// Install the required core and libraries

52 +

_, _, err = cli.Run("core", "install", "arduino:avr@1.8.6")

53 +

require.NoError(t, err)

54 +

_, _, err = cli.Run("lib", "install", "Adafruit BusIO@1.17.1", "--no-overwrite")

55 +

require.NoError(t, err)

56 +

_, _, err = cli.Run("lib", "install", "Adafruit GFX Library@1.12.1", "--no-overwrite")

57 +

require.NoError(t, err)

58 +

_, _, err = cli.Run("lib", "install", "Adafruit SSD1306@2.5.14", "--no-overwrite")

59 +

require.NoError(t, err)

60 + 61 +

// Check if the profile dump:

62 +

// - keeps libraries in the sketch with a relative path

63 +

// - keeps libraries outside the sketch with an absolute path

64 +

// - keeps libraries installed in the system with just the name and version

65 +

out, _, err := cli.Run("compile", "-b", "arduino:avr:uno",

66 +

"--library", libInside.String(),

67 +

"--library", libOutside.String(),

68 +

"--dump-profile",

69 +

sketch.String())

70 +

require.NoError(t, err)

71 +

require.Equal(t, strings.TrimSpace(`

72 +

profiles:

73 +

uno:

74 +

fqbn: arduino:avr:uno

75 +

platforms:

76 +

- platform: arduino:avr (1.8.6)

77 +

libraries:

78 +

- dir: libraries/MyLib

79 +

- dir: `+libOutside.String()+`

80 +

- Adafruit SSD1306 (2.5.14)

81 +

- Adafruit GFX Library (1.12.1)

82 +

- Adafruit BusIO (1.17.1)

83 +

`), strings.TrimSpace(string(out)))

84 + 85 +

// Dump the profile in the sketch directory and compile with it again

86 +

err = sketch.Join("sketch.yaml").WriteFile(out)

87 +

require.NoError(t, err)

88 +

out, _, err = cli.Run("compile", "-m", "uno", "--json", sketch.String())

89 +

require.NoError(t, err)

90 +

// Check if local libraries are picked up correctly

91 +

libInsideJson, _ := json.Marshal(libInside.String())

92 +

libOutsideJson, _ := json.Marshal(libOutside.String())

93 +

j := requirejson.Parse(t, out).Query(".builder_result.used_libraries")

94 +

j.MustContain(`

95 +

[

96 +

{"name": "MyLib", "install_dir": ` + string(libInsideJson) + `},

97 +

{"name": "MyLibOutside", "install_dir": ` + string(libOutsideJson) + `}

98 +

]`)

99 +

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4