diff --git a/bin/build-arduino-package b/bin/build-arduino-package index 7fde4f43..858a461b 100644 --- a/bin/build-arduino-package +++ b/bin/build-arduino-package @@ -7,83 +7,145 @@ ################### ################### -my $executed_as = join(' ', @ARGV); +my $executed_as = join( ' ', @ARGV ); use warnings; use strict; use File::Temp qw/tempdir/; use Cwd qw/abs_path cwd/; use JSON::PP; - use Getopt::Long; +use Getopt::Long; + +my $avr_platform_template = { + 'archiveFileName' => $filename, + 'toolsDependencies' => [ + { + "packager" => "arduino", + "name" => "avr-gcc", + "version" => "7.3.0-atmel3.6.1-arduino7" + }, + { + "packager" => "arduino", + "name" => "avrdude", + "version" => "6.3.0-arduino17" + } + ], + 'url' => $build_base_url . '/' . $filename, + 'name' => "Kaleidoscope keyboards", + 'version' => $version, + 'checksum' => 'SHA-256:' . $sha256, + 'size' => $size, + 'boards' => [ + { 'name' => 'Keyboardio Model 01' }, { 'name' => 'Keyboardio Atreus' } + ], + 'architecture' => 'avr', + 'category' => 'Contributed', + 'help' => { + 'online' => 'https://community.keyboard.io' + } +}; + +my $gd32_platform_template = { + 'archiveFileName' => $filename, + 'url' => $build_base_url . '/' . $filename, + 'name' => "Kaleidoscope keyboards (GD32)", + 'version' => $version, + 'checksum' => 'SHA-256:' . $sha256, + 'size' => $size, + 'architecture' => 'gd32', + 'toolsDependencies' => [ + { + 'name' => 'xpack-arm-none-eabi-gcc', + 'packager' => 'GD32Community', + 'version' => '9.3.1-1.3' + }, + { + 'packager' => 'GD32Community', + 'version' => '0.11.0-1', + 'name' => 'xpack-openocd' + }, + { + 'name' => 'dfu-util', + 'version' => '0.10.0-arduino1', + 'packager' => 'GD32Community' + } + ], + 'version' => '0.0.1', + 'name' => 'Kaleidoscope Keyboards (GD32)', + 'boards' => [ + { + 'name' => 'Keyboardio Model 100' + } + ], + 'category' => 'Contributed', + 'help' => { + 'online' => 'https://community.keyboard.io' + } +}; my $sha256 = 0; my $size = 0; -my $version = ''; -my $tag = 'master'; -my $kaleidoscope_tag = 'master'; -my $temp_dir = tempdir( CLEANUP => 0 ); -my $index_filename_slug ='keyboardio'; +my $version = ''; +my $tag = 'master'; +my $kaleidoscope_tag = 'master'; +my $working_dir = tempdir( CLEANUP => 0 ); +my $index_filename_slug = 'keyboardio'; my $only_latest_platform = 0; -my $bundle_repo = 'https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio'; -my $boards_repo = 'https://github.com/keyboardio/boardsmanager'; +my $bundle_repo = + 'https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio'; +my $boards_repo = 'https://github.com/keyboardio/boardsmanager'; my $push_package_repo = 0; +GetOptions( + "bundle-tag=s" => \$tag, + "kaleidoscope-tag=s" => \$kaleidoscope_tag, + "bundle-repo=s" => \$bundle_repo, + "output-repo=s" => \$boards_repo, + "index-filename-slug=s" => \$index_filename_slug, + "version=s" => \$version, + "only-one-platform-revision" => \$only_latest_platform, + "push" => \$push_package_repo +) or die("Error in command line arguments\n"); - - GetOptions ("bundle-tag=s" => \$tag, - "kaleidoscope-tag=s" => \$kaleidoscope_tag, - "bundle-repo=s" => \$bundle_repo, - "output-repo=s" => \$boards_repo, - "index-filename-slug=s" => \$index_filename_slug, - "version=s" => \$version, - "only-one-platform-revision" => \$only_latest_platform, - "push" => \$push_package_repo) - or die("Error in command line arguments\n"); - -my $index_filename = 'package_'.$index_filename_slug.'_index.json'; +my $index_filename = 'package_' . $index_filename_slug . '_index.json'; if ( $version eq '' && $tag =~ /^v(\d.*)$/ ) { $version = $1; } -my $checkout_dir = "Kaleidoscope-$version"; -my $filename = $checkout_dir . ".tar.bz2"; +my $checkout_dir = "Kaleidoscope-$version"; +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|^https?://github.com|https://raw.githubusercontent.com|; -my @bundle_dirs_to_remove = qw|toolchain etc doc avr/build-tools avr/bootloaders/*/lufa avr/libraries/Kaleidoscope/testing avr/libraries/Kaleidoscope/tests avr/libraries/Kaleidoscope/docs|; - -chdir($temp_dir); - -`git clone --depth=1 --quiet --recurse-submodules --branch $tag $bundle_repo $checkout_dir`; -`git clone $boards_repo boardsmanager`; +print "Working directory: $working_dir\n"; +chdir($working_dir); +clone_repos(); print "cd $checkout_dir\n"; chdir($checkout_dir); +my @bundle_dirs_to_remove = + 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"; + print "rm -rf $dir_to_remove\n"; `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 * ../../`; -} +checkout_kaleidoscope($kaleidoscope_tag); +lift_plugins_to_arduino_libs(); set_plugin_versions(); - -chdir($temp_dir); +chdir($working_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`; @@ -96,67 +158,78 @@ 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/*`; + `rm -rf boardsmanager/builds/*`; } `cp $filename boardsmanager/builds/`; -my $platform_template = { - 'archiveFileName' => $filename, - 'toolsDependencies' => [ - { - "packager" => "arduino", - "name" => "avr-gcc", - "version" => "7.3.0-atmel3.6.1-arduino7" - }, - { - "packager" => "arduino", - "name" => "avrdude", - "version" => "6.3.0-arduino17" - } - ], - 'url' => $build_base_url . '/' . $filename, - 'name' => "Kaleidoscope keyboards", - 'version' => $version, - 'checksum' => 'SHA-256:' . $sha256, - 'size' => $size, - 'boards' => [ - { 'name' => 'Keyboardio Model 01' }, { 'name' => 'Keyboardio Atreus' } - ], - 'architecture' => 'avr', - 'category' => 'Contributed', - 'help' => { - 'online' => 'https://community.keyboard.io' - } -}; +update_index_file(); -my $json = JSON::PP->new->allow_nonref; -local $/; -open( my $fh, '<', 'boardsmanager/'.$index_filename) || die "Could not open boardsmanager/$index_filename $!"; -my $json_text = <$fh>; -my $data = decode_json($json_text); -if ($only_latest_platform) { -@{ $data->{'packages'}->[0]->{'platforms'} } = ( $platform_template); -} else { -push @{ $data->{'packages'}->[0]->{'platforms'} }, $platform_template; -} -my $json_out = $json->canonical->pretty->encode($data); -open( my $out_fh, '>', 'boardsmanager/'.$index_filename); -print $out_fh $json_out; -close($out_fh); chdir('boardsmanager'); -`git add $index_filename`; -`git add builds`; -`git commit -a -m 'Built by $executed_as'`; + +commit_results(); + if ($push_package_repo) { - `git push`; -} else { + `git push`; +} +else { -print -"Now, you need to cd to $temp_dir/boardsmanager check the content and push it\n"; + print +"Now, you need to cd to $working_dir/boardsmanager check the content and push it\n"; } +exit 0; sub set_plugin_versions { - chdir("$temp_dir/$checkout_dir/avr/libraries"); - `perl -pi -e's/version=0.0.0/version=$version/' */library.properties` + chdir("$working_dir/$checkout_dir/avr/libraries"); + `perl -pi -e's/version=0.0.0/version=$version/' */library.properties`; +} + +sub clone_repos { + +`git clone --depth=1 --quiet --recurse-submodules --branch $tag $bundle_repo $checkout_dir`; + `git clone $boards_repo boardsmanager`; +} + +sub checkout_kaleidoscope { + my $tag = shift; + `git checkout --quiet $tag`; +} + +sub lift_plugins_to_arduino_libs { + if ( -d 'plugins' ) { + chdir("plugins"); + + # move the plugins to be fullfledged arduino libraries + `mv * ../../`; + } +} + +sub update_index_file { + + my $json = JSON::PP->new->allow_nonref; + local $/; + open( my $fh, '<', 'boardsmanager/' . $index_filename ) + || die "Could not open boardsmanager/$index_filename $!"; + my $json_text = <$fh>; + my $data = decode_json($json_text); + if ($only_latest_platform) { + @{ $data->{'packages'}->[0]->{'platforms'} } = + ( $avr_platform_template, $gd32_platform_template ); + } + else { + push @{ $data->{'packages'}->[0]->{'platforms'} }, + $avr_platform_template, + $gd32_platform_template; + } + my $json_out = $json->canonical->pretty->encode($data); + open( my $out_fh, '>', 'boardsmanager/' . $index_filename ); + print $out_fh $json_out; + close($out_fh); +} + +sub commit_results { + + `git add $index_filename`; + `git add builds`; + `git commit -a -m 'Built by $executed_as'`; }