refactor the builder tool to be able to build multi-arch support

pull/1086/head
Jesse Vincent 3 years ago
parent 6b9b6c388a
commit 262622a54a
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -16,8 +16,11 @@ use Cwd qw/abs_path cwd/;
use JSON::PP; use JSON::PP;
use Getopt::Long; use Getopt::Long;
my $avr_platform_template = { my $sha256 = 0;
'archiveFileName' => $filename, my $size = 0;
my $platforms_template = {
avr => {
'toolsDependencies' => [ 'toolsDependencies' => [
{ {
"packager" => "arduino", "packager" => "arduino",
@ -30,28 +33,19 @@ my $avr_platform_template = {
"version" => "6.3.0-arduino17" "version" => "6.3.0-arduino17"
} }
], ],
'url' => $build_base_url . '/' . $filename,
'name' => "Kaleidoscope keyboards", 'name' => "Kaleidoscope keyboards",
'version' => $version,
'checksum' => 'SHA-256:' . $sha256,
'size' => $size,
'boards' => [ 'boards' => [
{ 'name' => 'Keyboardio Model 01' }, { 'name' => 'Keyboardio Atreus' } { 'name' => 'Keyboardio Model 01' },
{ 'name' => 'Keyboardio Atreus' }
], ],
'architecture' => 'avr', 'architecture' => 'avr',
'category' => 'Contributed', 'category' => 'Contributed',
'help' => { 'help' => {
'online' => 'https://community.keyboard.io' 'online' => 'https://community.keyboard.io'
} }
}; },
gd32 => {
my $gd32_platform_template = {
'archiveFileName' => $filename,
'url' => $build_base_url . '/' . $filename,
'name' => "Kaleidoscope keyboards (GD32)", 'name' => "Kaleidoscope keyboards (GD32)",
'version' => $version,
'checksum' => 'SHA-256:' . $sha256,
'size' => $size,
'architecture' => 'gd32', 'architecture' => 'gd32',
'toolsDependencies' => [ 'toolsDependencies' => [
{ {
@ -81,16 +75,15 @@ my $gd32_platform_template = {
'help' => { 'help' => {
'online' => 'https://community.keyboard.io' 'online' => 'https://community.keyboard.io'
} }
}
}; };
my $sha256 = 0;
my $size = 0;
my $version = ''; my $version = '';
my $tag = 'master'; my $tag = 'master';
my $kaleidoscope_tag = 'master'; my $kaleidoscope_tag = 'master';
my $working_dir = tempdir( CLEANUP => 0 ); my $working_dir = tempdir( CLEANUP => 0 );
my $index_filename_slug = 'keyboardio'; my $index_filename_slug = 'keyboardio';
my $output_dir = $working_dir . '/boards_manager_repo';
my $builds_dir = $output_dir . '/builds';
my $only_latest_platform = 0; my $only_latest_platform = 0;
@ -116,8 +109,7 @@ if ( $version eq '' && $tag =~ /^v(\d.*)$/ ) {
$version = $1; $version = $1;
} }
my $checkout_dir = "Kaleidoscope-$version"; my $checkout_dir = 'kaleidoscope-checkout';
my $filename = $checkout_dir . ".tar.bz2";
my $build_base_url = $boards_repo . "/master/builds/"; my $build_base_url = $boards_repo . "/master/builds/";
$build_base_url =~ s|^ssh://git\@github.com|https://raw.githubusercontent.com|; $build_base_url =~ s|^ssh://git\@github.com|https://raw.githubusercontent.com|;
@ -126,68 +118,58 @@ $build_base_url =~ s|^https?://github.com|https://raw.githubusercontent.com|;
print "Working directory: $working_dir\n"; print "Working directory: $working_dir\n";
chdir($working_dir); chdir($working_dir);
clone_repos(); clone_repos( $tag, $bundle_repo, $checkout_dir, $boards_repo );
print "cd $checkout_dir\n"; chdir( $working_dir . "/" . $checkout_dir );
chdir($checkout_dir); if ($only_latest_platform) {
my @bundle_dirs_to_remove = `rm -rf $builds_dir/*`;
qw|toolchain etc doc avr/build-tools avr/bootloaders/*/lufa avr/libraries/Kaleidoscope/testing avr/libraries/Kaleidoscope/tests avr/libraries/Kaleidoscope/docs|;
foreach my $dir_to_remove (@bundle_dirs_to_remove) {
print "rm -rf $dir_to_remove\n";
`rm -rf $dir_to_remove`;
} }
chdir("avr/libraries/Kaleidoscope"); foreach my $arch (qw(avr gd32)) {
checkout_kaleidoscope($kaleidoscope_tag);
lift_plugins_to_arduino_libs(); remove_unneeded_files($arch);
set_plugin_versions();
chdir($working_dir); # Get the specified Kaleidoscope build and all its plugins as libraries
`mv $checkout_dir/avr $checkout_dir/$checkout_dir` # into the checkout
; # A hack to get consistent naming with the old setup chdir("$working_dir/$checkout_dir/$arch/libraries/Kaleidoscope");
`find $checkout_dir -name .git |xargs rm -rf`; checkout_kaleidoscope($kaleidoscope_tag);
`tar cjvf $filename -C $checkout_dir/ $checkout_dir `;
$sha256 = `sha256sum $filename | cut -d' ' -f 1 `; lift_plugins_to_arduino_libs();
chomp($sha256); set_plugin_versions( $working_dir, $checkout_dir, $arch, $version );
die "There was a problem generating the sha256" unless ($sha256);
$size = -s $filename;
`mkdir -p boardsmanager/builds`;
if ($only_latest_platform) {
`rm -rf boardsmanager/builds/*`;
}
`cp $filename boardsmanager/builds/`;
update_index_file(); chdir($working_dir);
chdir('boardsmanager'); my $release_dir = "Kaleidoscope-$arch-$version";
my $filename = $release_dir . ".tar.bz2";
commit_results(); build_archive( $arch, $checkout_dir, $release_dir, $filename );
deploy_build( $builds_dir, $filename );
if ($push_package_repo) {
`git push`;
} }
else {
print update_index_file( $output_dir, $index_filename );
"Now, you need to cd to $working_dir/boardsmanager check the content and push it\n"; chdir("$output_dir");
} commit_results($index_filename);
finalize_action($push_package_repo);
exit 0; exit 0;
sub set_plugin_versions { sub set_plugin_versions {
chdir("$working_dir/$checkout_dir/avr/libraries"); my $working_dir = shift;
my $checkout_dir = shift;
my $arch = shift;
my $version = shift;
chdir("$working_dir/$checkout_dir/$arch/libraries");
`perl -pi -e's/version=0.0.0/version=$version/' */library.properties`; `perl -pi -e's/version=0.0.0/version=$version/' */library.properties`;
} }
sub clone_repos { sub clone_repos {
my $tag = shift;
my $bundle_repo = shift;
my $checkout_dir = shift;
my $boards_repo = shift;
`git clone --depth=1 --quiet --recurse-submodules --branch $tag $bundle_repo $checkout_dir`; `git clone --depth=1 --quiet --recurse-submodules --branch $tag $bundle_repo $checkout_dir`;
`git clone $boards_repo boardsmanager`; `git clone $boards_repo $output_dir`;
} }
sub checkout_kaleidoscope { sub checkout_kaleidoscope {
@ -205,31 +187,99 @@ sub lift_plugins_to_arduino_libs {
} }
sub update_index_file { sub update_index_file {
my $output_dir = shift;
my $index_filename = shift;
my $json = JSON::PP->new->allow_nonref; my $json = JSON::PP->new->allow_nonref;
local $/; local $/;
open( my $fh, '<', 'boardsmanager/' . $index_filename )
|| die "Could not open boardsmanager/$index_filename $!"; my $index_path = $output_dir . '/' . $index_filename;
open( my $fh, '<', $index_path )
|| die "Could not open $index_path $!";
my $json_text = <$fh>; my $json_text = <$fh>;
my $data = decode_json($json_text); my $data = decode_json($json_text);
if ($only_latest_platform) { if ($only_latest_platform) {
@{ $data->{'packages'}->[0]->{'platforms'} } = @{ $data->{'packages'}->[0]->{'platforms'} } =
( $avr_platform_template, $gd32_platform_template ); ( $platforms_template->{'avr'}, $platforms_template->{'gd32'} );
} }
else { else {
push @{ $data->{'packages'}->[0]->{'platforms'} }, push @{ $data->{'packages'}->[0]->{'platforms'} },
$avr_platform_template, $platforms_template->{'avr'},
$gd32_platform_template; $platforms_template->{'gd32'};
} }
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, '>', $index_path );
print $out_fh $json_out; print $out_fh $json_out;
close($out_fh); close($out_fh);
} }
sub commit_results { sub commit_results {
my $index_filename = shift;
`git add $index_filename`; `git add $index_filename`;
`git add builds`; `git add builds`;
`git commit -a -m 'Built by $executed_as'`; `git commit -a -m 'Built by $executed_as'`;
} }
sub remove_unneeded_files {
my $arch = shift;
my @bundle_dirs_to_remove = (
"etc",
"doc",
$arch . '/bootloaders/*/lufa',
"$arch/libraries/Kaleidoscope/testing",
"$arch/libraries/Kaleidoscope/tests",
"$arch/libraries/Kaleidoscope/docs"
);
foreach my $dir_to_remove (@bundle_dirs_to_remove) {
print "rm -rf $dir_to_remove\n";
`rm -rf $dir_to_remove`;
}
}
sub deploy_build {
my $builds_dir = shift;
my $filename = shift;
`mkdir -p $builds_dir`;
`cp $filename $builds_dir/`;
}
sub build_archive {
my $arch = shift;
my $checkout_dir = shift;
my $release_dir = shift;
my $filename = shift;
`mv $checkout_dir/$arch $checkout_dir/$release_dir`;
; # A hack to get consistent naming with the old setup
`find $checkout_dir/$release_dir -name .git |xargs rm -rf`;
`tar cjvf $filename -C $checkout_dir/ $release_dir `;
$sha256 = `sha256sum $filename | cut -d' ' -f 1 `;
chomp($sha256);
die "There was a problem generating the sha256" unless ($sha256);
$size = -s $filename;
$platforms_template->{$arch}->{'archiveFileName'} = $filename;
$platforms_template->{$arch}->{'url'} = $build_base_url . '/' . $filename;
$platforms_template->{$arch}->{'version'} = $version;
$platforms_template->{$arch}->{'checksum'} = 'SHA-256:' . $sha256;
$platforms_template->{$arch}->{'size'} = $size;
}
sub finalize_action {
my $do_push = shift;
if ($do_push) {
`git push`;
}
else {
print
"Now, you need to cd to $output_dir check the content and push it\n";
}
}

Loading…
Cancel
Save