- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 432
Allow locally installed libraries in sketch profiles. #2930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b35a0d2
              
                Allow directories in profile libraries
              
              
                cmaglie 9dcc9b7
              
                Updated docs
              
              
                cmaglie 65d1029
              
                Dump custom libraries in profiles with --dump-profile command
              
              
                cmaglie a0a53ed
              
                Added integration tests
              
              
                cmaglie 9483f8d
              
                Fix integration test in Windows
              
              
                cmaglie 1589119
              
                Improved integration tests
              
              
                cmaglie 1a933cb
              
                Fixed flaky intergration test.
              
              
                cmaglie File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // This file is part of arduino-cli. | ||
| // | ||
| // Copyright 2022-2025 ARDUINO SA (http://www.arduino.cc/) | ||
| // | ||
| // This software is released under the GNU General Public License version 3, | ||
| // which covers the main part of arduino-cli. | ||
| // The terms of this license can be found at: | ||
| // https://www.gnu.org/licenses/gpl-3.0.en.html | ||
| // | ||
| // You can be released from the requirements of the above licenses by purchasing | ||
| // a commercial license. Buying such a license is mandatory if you want to | ||
| // modify or otherwise use the software for commercial activities involving the | ||
| // Arduino software without disclosing the source code of your own applications. | ||
| // To purchase a commercial license, send an email to [email protected]. | ||
|  | ||
| package sketch_test | ||
|  | ||
| import ( | ||
| "encoding/json" | ||
| "strings" | ||
| "testing" | ||
|  | ||
| "github.com/arduino/arduino-cli/internal/integrationtest" | ||
| "github.com/arduino/go-paths-helper" | ||
| "github.com/stretchr/testify/require" | ||
| "go.bug.st/testifyjson/requirejson" | ||
| ) | ||
|  | ||
| func TestSketchProfileDump(t *testing.T) { | ||
| env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) | ||
| t.Cleanup(env.CleanUp) | ||
|  | ||
| // Prepare the sketch with libraries | ||
| tmpDir, err := paths.MkTempDir("", "") | ||
| require.NoError(t, err) | ||
| t.Cleanup(func() { _ = tmpDir.RemoveAll }) | ||
|  | ||
| sketchTemplate, err := paths.New("testdata", "SketchWithLibrary").Abs() | ||
| require.NoError(t, err) | ||
|  | ||
| sketch := tmpDir.Join("SketchWithLibrary") | ||
| libInside := sketch.Join("libraries", "MyLib") | ||
| err = sketchTemplate.CopyDirTo(sketch) | ||
| require.NoError(t, err) | ||
|  | ||
| libOutsideTemplate := sketchTemplate.Join("..", "MyLibOutside") | ||
| libOutside := sketch.Join("..", "MyLibOutside") | ||
| err = libOutsideTemplate.CopyDirTo(libOutside) | ||
| require.NoError(t, err) | ||
|  | ||
| // Install the required core and libraries | ||
| _, _, err = cli.Run("core", "install", "arduino:[email protected]") | ||
| require.NoError(t, err) | ||
| _, _, err = cli.Run("lib", "install", "Adafruit [email protected]", "--no-overwrite") | ||
| require.NoError(t, err) | ||
| _, _, err = cli.Run("lib", "install", "Adafruit GFX [email protected]", "--no-overwrite") | ||
| require.NoError(t, err) | ||
| _, _, err = cli.Run("lib", "install", "Adafruit [email protected]", "--no-overwrite") | ||
| require.NoError(t, err) | ||
|  | ||
| // Check if the profile dump: | ||
| // - keeps libraries in the sketch with a relative path | ||
| // - keeps libraries outside the sketch with an absolute path | ||
| // - keeps libraries installed in the system with just the name and version | ||
| out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", | ||
| "--library", libInside.String(), | ||
| "--library", libOutside.String(), | ||
| "--dump-profile", | ||
| sketch.String()) | ||
| require.NoError(t, err) | ||
| require.Equal(t, strings.TrimSpace(` | ||
| profiles: | ||
| uno: | ||
| fqbn: arduino:avr:uno | ||
| platforms: | ||
| - platform: arduino:avr (1.8.6) | ||
| libraries: | ||
| - dir: libraries/MyLib | ||
| - dir: `+libOutside.String()+` | ||
| - Adafruit SSD1306 (2.5.14) | ||
| - Adafruit GFX Library (1.12.1) | ||
| - Adafruit BusIO (1.17.1) | ||
| `), strings.TrimSpace(string(out))) | ||
|  | ||
| // Dump the profile in the sketch directory and compile with it again | ||
| err = sketch.Join("sketch.yaml").WriteFile(out) | ||
| require.NoError(t, err) | ||
| out, _, err = cli.Run("compile", "-m", "uno", "--json", sketch.String()) | ||
| require.NoError(t, err) | ||
| // Check if local libraries are picked up correctly | ||
| libInsideJson, _ := json.Marshal(libInside.String()) | ||
| libOutsideJson, _ := json.Marshal(libOutside.String()) | ||
| j := requirejson.Parse(t, out).Query(".builder_result.used_libraries") | ||
| j.MustContain(` | ||
| [ | ||
| {"name": "MyLib", "install_dir": ` + string(libInsideJson) + `}, | ||
| {"name": "MyLibOutside", "install_dir": ` + string(libOutsideJson) + `} | ||
| ]`) | ||
| } | ||
              Empty file.
          
    
        
          
          
            10 changes: 10 additions & 0 deletions
          
          10 
        
  internal/integrationtest/sketch/testdata/MyLibOutside/library.properties
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| name=MyLibOutside | ||
| version=1.3.7 | ||
| author=Arduino | ||
| maintainer=Arduino <[email protected]> | ||
| sentence= | ||
| paragraph= | ||
| category=Communication | ||
| url= | ||
| architectures=* | ||
| includes=MyLibOutside.h | 
        
          
          
            6 changes: 6 additions & 0 deletions
          
          6 
        
  internal/integrationtest/sketch/testdata/SketchWithLibrary/SketchWithLibrary.ino
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #include <MyLib.h> | ||
| #include <MyLibOutside.h> | ||
| #include <Adafruit_SSD1306.h> | ||
|  | ||
| void setup() {} | ||
| void loop() {} | 
              Empty file.
          
    
        
          
          
            10 changes: 10 additions & 0 deletions
          
          10 
        
  ...rnal/integrationtest/sketch/testdata/SketchWithLibrary/libraries/MyLib/library.properties
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| name=MyLib | ||
| version=1.3.7 | ||
| author=Arduino | ||
| maintainer=Arduino <[email protected]> | ||
| sentence= | ||
| paragraph= | ||
| category=Communication | ||
| url= | ||
| architectures=* | ||
| includes=MyLib.h | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.