Skip to content
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

Added 'source override' feature to compile command. #1099

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Dec 3, 2020

This feature allows to selectively "override" the content of a sketch. Overridden files will not be read from disk as usual but fetched directly from gRPC parameters (if the CLI is running as a daemon) or from a .json file containing the new source code (if the CLI us running from the command line).

This feature is useful for IDE that may have unsaved changes: in this case, the "dirty" content of the text editor may be verified/compiled anyway without the need to save the sketch on disk.

The same feature from the command line is achieved by storing the overridden files in a temporary json file and by using the --source-override path/to/json option for compile.

here an example transcript:

:~/Arduino/TestTemps$ ls -l
totale 12
-rw-r--r-- 1 cmaglie cmaglie 70 dic  3 17:25 overrides.json
-rw-r--r-- 1 cmaglie cmaglie 13 dic  3 17:23 Second.ino
-rw-r--r-- 1 cmaglie cmaglie 40 dic  3 17:23 TestTemps.ino

:~/Arduino/TestTemps$ cat TestTemps.ino 
void setup() {
}
void loop() {
  a();
}

:~/Arduino/TestTemps$ cat Second.ino 
void b() { }

:~/Arduino/TestTemps$ arduino-cli compile -b arduino:avr:uno 
/home/cmaglie/Arduino/TestTemps/TestTemps.ino: In function 'void loop()':
/home/cmaglie/Arduino/TestTemps/TestTemps.ino:4:3: error: 'a' was not declared in this scope
   a();
   ^

Error during build: exit status 1

:~/Arduino/TestTemps$ cat overrides.json
{ "overrides": {
  "Second.ino": "void b() { }\nvoid a() { }\n"
  }
}

:~/Arduino/TestTemps$ arduino-cli compile -b arduino:avr:uno --source-override overrides.json 
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

:~/Arduino/TestTemps$ arduino-cli compile -b arduino:avr:uno --source-override overrides.json --format json
{
  "compiler_out": "Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.\nGlobal variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.\n",
  "compiler_err": "",
  "builder_result": {
    "build_path": "/tmp/arduino-sketch-A54D0E2639DDA6E3481AB05BD0D564A6",
    "executable_sections_size": [
      {
        "name": "text",
        "size": 444,
        "maxSize": 32256
      },
      {
        "name": "data",
        "size": 9,
        "maxSize": 2048
      }
    ]
  },
  "success": true
}

:~/Arduino/TestTemps$ cat /tmp/arduino-sketch-A54D0E2639DDA6E3481AB05BD0D564A6/sketch/TestTemps.ino.cpp
#include <Arduino.h>
#line 1 "/home/cmaglie/Arduino/TestTemps/TestTemps.ino"
#line 1 "/home/cmaglie/Arduino/TestTemps/TestTemps.ino"
void setup();
#line 3 "/home/cmaglie/Arduino/TestTemps/TestTemps.ino"
void loop();
#line 1 "/home/cmaglie/Arduino/TestTemps/Second.ino"
void b();
#line 2 "/home/cmaglie/Arduino/TestTemps/Second.ino"
void a();
#line 1 "/home/cmaglie/Arduino/TestTemps/TestTemps.ino"
void setup() {
}
void loop() {
  a();
}

#line 1 "/home/cmaglie/Arduino/TestTemps/Second.ino"
void b() { }
void a() { }

Copy link
Collaborator

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked over the code, looks good to me. Haven't looked in much detail or done testing, though.

This feature allows to selectively "override" the content of a sketch.
Overridden files will not be read from disk as usual but fetched directly
from gRPC paramaters (if the cli is running as daemon) or from a .json
file containing the new source code (if running from command line).
@cmaglie cmaglie merged commit 5a2a707 into arduino:master Dec 15, 2020
@cmaglie cmaglie deleted the source-override-command branch December 15, 2020 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants