-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprocess_build_artefacts.pl
79 lines (62 loc) · 2.14 KB
/
process_build_artefacts.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!perl
#
#
# Re-use build artefacts from previous runs.
#
# To force a rebuild of all packages set an env var called REBUILD_ALL to a true value.
#
# To override and force a rebuild for an individual package,
# append "rebuild" to the entry in the source list.
# e.g. to rebuild readline you might use this (without the leading # on each line):
#
# ###### termcap + readline vybuildit co nejdrive
# termcap-1.3.1
# readline-8.2 rebuild
use strict;
use warnings;
use 5.010;
use Archive::Zip qw /:ERROR_CODES/;
my $sources_file = shift @ARGV or die "Need sources file";
my $suffix = shift @ARGV || '__';
my $bitness = $suffix eq '_' ? '32' : '64';
die "bitness argument $bitness is invalid, can only be 64 or 32"
if not $bitness eq '64' and $bitness eq '32';
my $build_dir = "_${sources_file}" . ($bitness eq 64 ? "__" : "_");
my $zip_dir = '_out';
my $zip_pfx = "${bitness}bit_";
open my $sources_fh, '<', $sources_file
or die "Cannot open $sources_file, $!";
my @to_build;
my @packaged;
foreach my $line (<$sources_fh>) {
chomp $line;
$line =~ s/\s+$//;
next if !length $line;
next if $line =~ /^#/;
my ($package, $rebuild) = split /\s+/, $line;
# only need those flagged as rebuilds
if (!$rebuild) {
push @packaged, $package;
}
push @to_build, $package; # we refilter lower down as there might not be a zip
}
#say 'To build: ' . join " ", @to_build;
#say 'Packaged: ' . join " ", @packaged;
if (@packaged and !$ENV{REBUILD_ALL}) {
my @package_zips = sort glob "$zip_dir/*.zip";
foreach my $pkg (@packaged) {
#say STDERR "PACKAGE IS $pkg";
#say STDERR "$zip_dir/$zip_pfx$pkg";
my @targets = grep {m|^$zip_dir/$zip_pfx$pkg|} @package_zips;
next if !@targets; # we found no zipped package
@to_build = grep {!m/^$pkg$/} @to_build; # retain the file order
my $target = pop @targets;
say STDERR "Will extract $target to $build_dir";
my $zip = Archive::Zip->new();
my $status = $zip->read($target);
die "Read of $target failed" if $status != AZ_OK;
$zip->extractTree( 'c', $build_dir );
}
}
# This gets ingested by the build script
say join "\n", @to_build;