diff options
author | Charles Baylis <charles.baylis@linaro.org> | 2017-03-08 09:48:26 +0000 |
---|---|---|
committer | Charles Baylis <charles.baylis@linaro.org> | 2017-03-08 13:29:22 +0000 |
commit | 2b409dc8d40197f34156f247c6a6bb77d3beffe9 (patch) | |
tree | 273d4aad4a034fd8a80a1379c7a02289c0b50a7d | |
parent | 67572024e3002537e6c0a4e28733370d75c73935 (diff) |
validate-manifest.pl: Handle multiple manifests.
Accept multiple manifests on a single command line.
Cache md5sums of downloaded files so that files are only
downloaded once when validating multiple files.
Change-Id: I718da2e6c15ac2774e9a3967724da7ff9c3ef8b9
-rwxr-xr-x | validate-manifest.pl | 85 |
1 files changed, 57 insertions, 28 deletions
diff --git a/validate-manifest.pl b/validate-manifest.pl index cc6164f..d6c1dfc 100755 --- a/validate-manifest.pl +++ b/validate-manifest.pl @@ -6,6 +6,7 @@ use warnings; use strict; my ($opt_online, $opt_quiet, $opt_release, $opt_output_normalized); +my (@file_args); # default to online checking of md5sums in .asc files, but don't download # full tarballs to check @@ -20,11 +21,17 @@ while (@ARGV) if ($opt eq "--quiet") { shift; $opt_quiet = 1; next; } if ($opt eq "--release") { shift; $opt_release = 1; next; } if ($opt =~ /^--output-normalized(=(.*))?$/) { shift; $opt_output_normalized = $2 // shift; next; } -# assume unrecognised option is a filename and leave it in @ARGV - last; + if ($opt =~ /^--/) { die "Unrecognised option $opt"; } + # Other arguments are manifest files for validation. + push @file_args, shift; } -my $errors = 0; +die "Syntax..." unless $#file_args > -1; + +if (defined $opt_output_normalized && $#file_args != 0) +{ + die "Must have exactly one input file when using --output-normalized"; +} sub parse_manifest { @@ -42,6 +49,7 @@ sub parse_manifest ### $line == $res->{ctx}{line}; $res->{ctx}{line_no} = 0; $res->{ctx}{errors} = 0; + $res->{ctx}{filename} = $mfile; my $cur_component; my $line; while ($line = <MFILE>) @@ -144,22 +152,28 @@ sub parse_manifest return $res; } +my $exit_status = 0; -my $manifest = parse_manifest(shift); -die ("manifest parsing failed") unless defined $manifest; - -check_manifest_version($manifest); -check_components_list($manifest); -check_all_flags($manifest); -check_all_components($manifest); -check_url_locations($manifest) if $opt_release; -check_gdbserver($manifest); -check_manifestid($manifest); -check_online($manifest) if $opt_online; -output_normalized($manifest, $opt_output_normalized) if $opt_output_normalized; +foreach my $file (@file_args) +{ + my $manifest = parse_manifest($file); + die ("manifest parsing of $file failed") unless defined $manifest; + + check_manifest_version($manifest); + check_components_list($manifest); + check_all_flags($manifest); + check_all_components($manifest); + check_url_locations($manifest) if $opt_release; + check_gdbserver($manifest); + check_manifestid($manifest); + check_online($manifest) if $opt_online; + output_normalized($manifest, $opt_output_normalized) if $opt_output_normalized; + + # indicate success in exit code. + $exit_status=1 if $manifest->{ctx}{errors} > 0; +} -# indicate success in exit code. -exit ($manifest->{ctx}{errors} > 0 ? 1 : 0); +exit $exit_status; sub error { @@ -171,8 +185,9 @@ sub error my $line_no = $m->{ctx}{line_no}; $extra= " at line $line_no: $in\n"; } + my $fn = $m->{ctx}{filename}; $m->{ctx}{errors}++; - print STDERR "ERROR: $msg\n$extra" if !$opt_quiet; + print STDERR "ERROR: $fn: $msg\n$extra" if !$opt_quiet; } sub check_all_components @@ -300,16 +315,23 @@ sub check_all_flags } } +my %asc_md5_lookup=(); + sub check_md5sum_asc_url { my ($m, $component, $exp_md5sum, $url, $filespec) = @_; - my $asc_file = get("$url"); - if (!defined $asc_file) + my $asc_md5 = $asc_md5_lookup{$url}; + if (!defined $asc_md5) { - error ($m, "download of $url failed"); - return; + my $asc_file = get("$url"); + if (!defined $asc_file) + { + error ($m, "download of $url failed"); + return; + } + $asc_md5 = ($asc_file =~ /^([a-f0-9]*) $filespec/)[0]; + $asc_md5_lookup{$url}=$asc_md5; } - my $asc_md5 = ($asc_file =~ /^([a-f0-9]*) $filespec/)[0]; if (!defined $asc_md5) { error ($m, "Component $component asc file $url has invalid format"); @@ -321,16 +343,23 @@ sub check_md5sum_asc_url } } +my %full_md5_lookup; + sub check_md5sum_full_file { my ($m, $component, $exp_md5sum, $url, $filespec) = @_; - my $full_file = get("$url"); - if (!defined $full_file) + my $real_md5sum=$full_md5_lookup{$url}; + if (!defined $real_md5sum) { - error ($m, "download of $url failed"); - return; + my $full_file = get("$url"); + if (!defined $full_file) + { + error ($m, "download of $url failed"); + return; + } + $real_md5sum = md5_hex($full_file); + $full_md5_lookup{$url} = $real_md5sum; } - my $real_md5sum = md5_hex($full_file); if (defined $exp_md5sum && $real_md5sum ne $exp_md5sum) { error ($m, "$component md5sum did not match downloaded file, $exp_md5sum/$real_md5sum"); |