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,59 +7,101 @@
################### ###################
################### ###################
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 $temp_dir = tempdir( CLEANUP => 0 );
my $checkout_dir = "Kaleidoscope-$tag"; my $checkout_dir = "Kaleidoscope-$tag";
my $filename = $checkout_dir . ".tar.bz2"; my $filename = $checkout_dir . ".tar.bz2";
my $checkout_path = "$dir/$checkout_dir"; my $index_filename_slug ='keyboardio';
chdir($dir);
my $only_latest_platform = 0;
`git clone --depth=1 https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio $checkout_path`;
chdir($checkout_path); my $bundle_repo = 'https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio';
`git checkout $tag`; my $boards_repo = 'https://github.com/keyboardio/boardsmanager';
`make update-submodules`;
`rm -rf $checkout_path/toolchain`;
`rm -rf $checkout_path/etc`;
`rm -rf $checkout_path/doc`;
chdir("$checkout_path/avr/libraries/Kaleidoscope"); GetOptions ("bundle-tag=s" => \$tag,
`git checkout $kaleidoscope_tag`; "kaleidoscope-tag=s" => \$kaleidoscope_tag,
"bundle-repo=s" => \$bundle_repo,
print "In $checkout_path/avr/libraries/Kaleidoscope\n"; "output-repo=s" => \$boards_repo,
chdir("$checkout_path/avr/libraries"); "index-filename-slug=s" => \$index_filename_slug,
"version=s" => \$version,
`mv Kaleidoscope/plugins/* .`; "only-one-platform-revision" => \$only_latest_platform
chdir($dir); )
`rm -rf $checkout_path/avr/build-tools`; or die("Error in command line arguments\n");
`mv $checkout_path/avr $checkout_path/$checkout_dir`; # A hack to get consistent naming with the old setup
`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",
@ -67,15 +109,13 @@ my $platform_template = {
"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 Model 01' }, { 'name' => 'Keyboardio Atreus' }
{ '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