Further generalize the arduino platform bundle builder tool.

pull/1000/head
Jesse Vincent 4 years ago
parent e71cacc918
commit 301ccf92fc
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -7,75 +7,115 @@
################### ###################
################### ###################
my $executed_as = join(' ', @ARGV);
use warnings; use warnings;
use strict; use strict;
use File::Temp qw/tempdir/; use File::Temp qw/tempdir/;
use Cwd qw/abs_path cwd/; use Cwd qw/abs_path cwd/;
use JSON; use JSON;
use Getopt::Long;
my $sha256 = 0; my $sha256 = 0;
my $size = 0; my $size = 0;
my $tag = shift || 'master'; my $version = '';
my $kaleidoscope_tag = shift || 'master'; my $tag = 'master';
my $dir = tempdir( CLEANUP => 0 ); my $kaleidoscope_tag = 'master';
my $checkout_dir = "Kaleidoscope-$tag"; my $temp_dir = tempdir( CLEANUP => 0 );
my $filename = $checkout_dir . ".tar.bz2"; my $checkout_dir = "Kaleidoscope-$tag";
my $checkout_path = "$dir/$checkout_dir"; my $filename = $checkout_dir . ".tar.bz2";
chdir($dir); my $index_filename_slug ='keyboardio';
`git clone --depth=1 https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio $checkout_path`; my $only_latest_platform = 0;
chdir($checkout_path);
`git checkout $tag`; my $bundle_repo = 'https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio';
`make update-submodules`; my $boards_repo = 'https://github.com/keyboardio/boardsmanager';
`rm -rf $checkout_path/toolchain`;
`rm -rf $checkout_path/etc`;
`rm -rf $checkout_path/doc`;
chdir("$checkout_path/avr/libraries/Kaleidoscope");
`git checkout $kaleidoscope_tag`; GetOptions ("bundle-tag=s" => \$tag,
"kaleidoscope-tag=s" => \$kaleidoscope_tag,
print "In $checkout_path/avr/libraries/Kaleidoscope\n"; "bundle-repo=s" => \$bundle_repo,
chdir("$checkout_path/avr/libraries"); "output-repo=s" => \$boards_repo,
"index-filename-slug=s" => \$index_filename_slug,
`mv Kaleidoscope/plugins/* .`; "version=s" => \$version,
chdir($dir); "only-one-platform-revision" => \$only_latest_platform
`rm -rf $checkout_path/avr/build-tools`; )
`mv $checkout_path/avr $checkout_path/$checkout_dir`; # A hack to get consistent naming with the old setup or die("Error in command line arguments\n");
`find $checkout_path -name .git |xargs rm -rf`;
my $index_filename = 'package_'.$index_filename_slug.'_index.json';
if ( $version eq '' && $tag =~ /^v(\d.*)$/ ) {
$version = $1;
}
my $build_base_url = $boards_repo."/master/builds/";
$build_base_url =~ s/github.com/raw.githubusercontent.com/;
my @bundle_dirs_to_remove = qw|toolchain etc doc avr/build-tools|;
chdir($temp_dir);
`git clone --depth=1 --quiet --recurse-submodules --branch $tag $bundle_repo $checkout_dir`;
`git clone $boards_repo boardsmanager`;
chdir($checkout_dir);
foreach my $dir_to_remove (@bundle_dirs_to_remove) {
`rm -rf $dir_to_remove`;
}
chdir("avr/libraries/Kaleidoscope");
`git checkout --quiet $kaleidoscope_tag`;
if ( -d 'plugins') {
chdir("plugins");
# move the plugins to where they should live
`mv * ../../`;
}
chdir($temp_dir);
`mv $checkout_dir/avr $checkout_dir/$checkout_dir`
; # A hack to get consistent naming with the old setup
`find $checkout_dir -name .git |xargs rm -rf`;
`tar cjvf $filename -C $checkout_dir/ $checkout_dir `; `tar cjvf $filename -C $checkout_dir/ $checkout_dir `;
$sha256 = `sha256sum $filename | cut -d' ' -f 1 `; $sha256 = `sha256sum $filename | cut -d' ' -f 1 `;
chomp($sha256); chomp($sha256);
die "There was a problem generating the sha256" unless ($sha256); die "There was a problem generating the sha256" unless ($sha256);
$size = -s $filename;
`git clone https://github.com/keyboardio/boardsmanager`; $size = -s $filename;
`mkdir -p boardsmanager/builds`; `mkdir -p boardsmanager/builds`;
if ($only_latest_platform) {
`rm -rf boardsmanager/builds/*`;
}
`cp $filename boardsmanager/builds/`; `cp $filename boardsmanager/builds/`;
my $platform_template = { my $platform_template = {
'archiveFileName' => 'Arduino-Boards-v1.14.zip', 'archiveFileName' => $filename,
'toolsDependencies' => [ 'toolsDependencies' => [
{ {
"packager" => "arduino", "packager" => "arduino",
"name" => "avr-gcc", "name" => "avr-gcc",
"version" => "7.3.0-atmel3.6.1-arduino5" "version" => "7.3.0-atmel3.6.1-arduino7"
}, },
{ {
"packager" => "arduino", "packager" => "arduino",
"name" => "avrdude", "name" => "avrdude",
"version" => "6.3.0-arduino17" "version" => "6.3.0-arduino17"
} }
], ],
'url' => 'https://github.com/keyboardio/Arduino-Boards/archive/v1.14.zip', 'url' => $build_base_url . '/' . $filename,
'name' => 'keyboardio', 'name' => 'keyboardio',
'version' => '1.1.4', 'version' => $version,
'checksum' => 'checksum' => 'SHA-256:' . $sha256,
'SHA-256:fd0017ea2950f6fb3afb46a503f0193c75111d68dfc95fa2775fbd63f0cf4528', 'size' => $size,
'size' => '1008405', 'boards' => [
'boards' => [ { 'name' => 'Keyboardio Model 01' }, { 'name' => 'Keyboardio Atreus' }
{ 'name' => 'Keyboardio Model 01' },
{ 'name' => 'Keyboardio Atreus' }
], ],
'architecture' => 'avr', 'architecture' => 'avr',
'category' => 'Contributed', 'category' => 'Contributed',
@ -84,35 +124,23 @@ my $platform_template = {
} }
}; };
my $version = $tag;
if ($version =~ /^v(\d.*)$/) {
$version = $1
};
$platform_template->{archiveFileName} = $filename;
$platform_template->{version} = $version;
$platform_template->{url} =
'https://raw.githubusercontent.com/keyboardio/boardsmanager/master/builds/'
. $filename;
$platform_template->{checksum} = 'SHA-256:' . $sha256;
$platform_template->{size} = $size;
my $json = JSON->new->allow_nonref; my $json = JSON->new->allow_nonref;
local $/; local $/;
open( my $fh, '<', 'boardsmanager/package_keyboardio_index.json' ); open( my $fh, '<', 'boardsmanager/'.$index_filename) || die "Could not open boardsmanager/$index_filename $!";
my $json_text = <$fh>; my $json_text = <$fh>;
my $data = from_json($json_text); my $data = from_json($json_text);
if ($only_latest_platform) {
@{ $data->{'packages'}->[0]->{'platforms'} } = ( $platform_template);
} else {
push @{ $data->{'packages'}->[0]->{'platforms'} }, $platform_template; push @{ $data->{'packages'}->[0]->{'platforms'} }, $platform_template;
}
my $json_out = $json->canonical->pretty->encode($data); my $json_out = $json->canonical->pretty->encode($data);
open( my $out_fh, '>', 'boardsmanager/'.$index_filename);
open( my $out_fh, '>', 'boardsmanager/package_keyboardio_index.json' );
print $out_fh $json_out; print $out_fh $json_out;
close($out_fh); close($out_fh);
chdir('boardsmanager');
# rm -rf /tmp/boardsmanager `git add $index_filename`;
`git add builds`;
`git commit -a -m 'Built by $executed_as'`;
print print
"Now, you need to cd to $dir/boardsmanager check the content and commit it\n"; "Now, you need to cd to $temp_dir/boardsmanager check the content and push it\n";

Loading…
Cancel
Save