|
@@ -0,0 +1,87 @@
|
|
|
+#!/usr/bin/perl
|
|
|
+#
|
|
|
+# Wrapper for calling arduino-cli with a bunch of obligatory options...
|
|
|
+#
|
|
|
+
|
|
|
+use File::Spec;
|
|
|
+use Cwd qw(abs_path realpath);
|
|
|
+use strict;
|
|
|
+use integer;
|
|
|
+
|
|
|
+sub dirname($) {
|
|
|
+ my($path) = @_;
|
|
|
+ $path = File::Spec->rel2abs($path);
|
|
|
+ my($vol,$dir,$file) = File::Spec->splitpath($path);
|
|
|
+ return File::Spec->catpath($vol, $dir, '');
|
|
|
+}
|
|
|
+
|
|
|
+my $here = realpath(dirname($0));
|
|
|
+
|
|
|
+my $arduino = File::Spec->catdir($here, 'arduino');
|
|
|
+$ENV{'ARDUINO_DIRECTORIES_DATA'} = $arduino;
|
|
|
+$ENV{'ARDUINO_DIRECTORIES_USER'} = $arduino;
|
|
|
+$ENV{'ARDUINO_LOGGING_FILE'} = File::Spec->catfile($arduino, 'arduino.log');
|
|
|
+$ENV{'ARDUINO_CONFIG_FILE'} = File::Spec->catfile($here, 'arduino_cli.yaml');
|
|
|
+
|
|
|
+my $arduino_cli = $ENV{'ARDUINO_CLI'} || 'arduino-cli';
|
|
|
+
|
|
|
+mkdir($arduino);
|
|
|
+
|
|
|
+my $subcmd = shift(@ARGV);
|
|
|
+my @args = ($subcmd);
|
|
|
+my %props;
|
|
|
+
|
|
|
+if (open(my $prop, '<', 'properties.txt')) {
|
|
|
+ while (defined(my $p = <$prop>)) {
|
|
|
+ chomp $p;
|
|
|
+ next if ($p !~ /^\s*([\w.]+)\s*=\s*(.*)$/);
|
|
|
+ $props{$1} = $2;
|
|
|
+ }
|
|
|
+ close($prop);
|
|
|
+}
|
|
|
+
|
|
|
+if ($subcmd eq 'compile') {
|
|
|
+ my %named_opts = (
|
|
|
+ 'build.fqbn' => '--fqbn',
|
|
|
+ 'build.path' => '--build-path',
|
|
|
+ 'build.output.path' => '--output-dir'
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach my $pn ('build.path', 'build.output.path') {
|
|
|
+ # Make sure directories exist
|
|
|
+ my $pv = $props{$pn};
|
|
|
+ mkdir($pv) if (defined($pv));
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach my $pn (sort(keys(%props))) {
|
|
|
+ my $pv = $props{$pn};
|
|
|
+ my $opt_name = $named_opts{$pn};
|
|
|
+ if ($opt_name) {
|
|
|
+ push(@args, $opt_name, $pv);
|
|
|
+ } elsif ($pn =~ /^build\./) {
|
|
|
+ push(@args, '--build-property', "$pn=$pv");
|
|
|
+ }
|
|
|
+ }
|
|
|
+} elsif ($subcmd eq 'upload') {
|
|
|
+ my %named_opts = (
|
|
|
+ 'build.fqbn' => '--fqbn',
|
|
|
+ 'build.path' => '--build-path',
|
|
|
+ 'build.output.path' => '--input-dir'
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach my $pn (sort(keys(%props))) {
|
|
|
+ my $pv = $props{$pn};
|
|
|
+ my $opt_name = $named_opts{$pn};
|
|
|
+ if ($opt_name) {
|
|
|
+ push(@args, $opt_name, $pv);
|
|
|
+ } elsif ($pn =~ /^upload\./) {
|
|
|
+ push(@args, '--upload-property', "$pn=$pv");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+push(@args, @ARGV);
|
|
|
+
|
|
|
+exec($arduino_cli, @args);
|
|
|
+print STDERR "$0: failed to execute: $arduino_cli ", join(' ', @args), "\n";
|
|
|
+exit 1;
|