diff options
author | Lauri Aarnio <Lauri.Aarnio@iki.fi> | 2009-02-14 22:23:35 +0200 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2009-02-16 11:50:39 +0200 |
commit | 5dece7403940041ff0b01de809618ac7765d5528 (patch) | |
tree | 48d0663f7d2c3ea8ccc08ee3d722ea6bc6078548 | |
parent | 695d40b976b79460e31ec5f85eb9f092ba9ad98e (diff) |
dpkg-checkbuilddeps: Fixes + output format change
- output format is now not entirely unlike what the real dpkg-checkbuilddeps
prints, more verbose output can be enabled by setting
SBOX_CHECKBUILDDEPS_VERBOSE='y'
-rwxr-xr-x | utils/sb2-cmp-checkbuilddeps-output.pl | 116 | ||||
-rwxr-xr-x | wrappers/dpkg-checkbuilddeps | 95 |
2 files changed, 143 insertions, 68 deletions
diff --git a/utils/sb2-cmp-checkbuilddeps-output.pl b/utils/sb2-cmp-checkbuilddeps-output.pl index 8748928..4f4ecf9 100755 --- a/utils/sb2-cmp-checkbuilddeps-output.pl +++ b/utils/sb2-cmp-checkbuilddeps-output.pl @@ -25,6 +25,12 @@ my $both_required=$ARGV[2]; my $accepted_from_tools=$ARGV[3]; my $ignored_from_tools=$ARGV[4]; +my $verbose_messages_env_var=$ENV{'SBOX_CHECKBUILDDEPS_VERBOSE'}; +my $verbose_messages = 0; +if (defined $verbose_messages_env_var && $verbose_messages_env_var ne '') { + $verbose_messages = 1; +} + my @both_required = split(/\s/,$both_required); my @accepted_from_tools = split(/\s/,$accepted_from_tools); @@ -56,16 +62,16 @@ sub is_accepted_from_tools { if ($accepted_from_tools{$name}) { if (defined $r_host_missing->{$name}) { - return 0, "$name $vers can be used from tools, but is is not installed there"; + return(0, "$name $vers can be used from tools, but is is not installed there"); } - return 1, "$name $vers found from tools"; + return(1, "$name $vers found from tools"); } # not allowed from tools if (defined $r_host_missing->{$name}) { - return 0, "$name $vers can not be used from tools (not found and not allowed)"; + return(0, "$name $vers can not be used from tools (not found and not allowed)"); } - return 0, "$name $vers can not be used from tools (installed, but not allowed)"; + return(0, "$name $vers can not be used from tools (installed, but not allowed)"); } # Parse one required package name from output of "dpkg-checkbuilddeps" @@ -90,7 +96,7 @@ sub parse_requirement { } # else failed to recognize enything from $list - print "Parse error in '$list'\n"; + print "dpkg-checkbuilddeps: Parse error in '$list'\n"; return(undef, undef, undef); } @@ -110,7 +116,7 @@ sub parse_list_of_missing_packages { ($pkg_name, $version, $leftovers) = parse_requirement($a, "\t"); if (!defined $pkg_name) { - print "FAILED to parse '$a'\n"; + print "dpkg-checkbuilddeps: FAILED to parse '$a'\n"; exit(1); } @@ -142,7 +148,7 @@ sub parse_list_of_missing_packages { ($alt_pkg_name, $alt_version, $leftovers) = parse_requirement($leftovers, "\t\t"); if (!defined $alt_pkg_name) { - print "FAILED to process alternatives ($leftovers)\n"; + print "dpkg-checkbuilddeps: FAILED to process alternatives ($leftovers)\n"; exit(1); } $alternatives .= " ".$alt_pkg_name; @@ -155,7 +161,7 @@ sub parse_list_of_missing_packages { } if ($debug) { if ($alternatives ne "") { - print "\talternatives=[". + print "\talternatives for $pkg_name=[". join(", ", @{$pkgs{$pkg_name}->{'alternatives'}}). "] == $alternatives\n"; } @@ -166,6 +172,7 @@ sub parse_list_of_missing_packages { return(\%pkgs); } +# a debugging routine: sub show_missing { my $r_missing = shift; @@ -193,8 +200,9 @@ my $r_host_missing = parse_list_of_missing_packages($host_missing_deps); my @host_listed = sort(keys(%$r_host_missing)); if ($debug) { - print "Host is missing: ".join("; ", @host_listed)."\n"; + print "\n\nHost is missing: ".join("; ", @host_listed)."\n"; show_missing($r_host_missing); + print "\n\n"; } my $r_target_missing = parse_list_of_missing_packages($target_missing_deps); @@ -202,13 +210,15 @@ my $r_target_missing = parse_list_of_missing_packages($target_missing_deps); my @target_listed = sort(keys(%$r_target_missing)); if ($debug) { - print "Target is missing: ".join("; ", @target_listed)."\n"; + print "\n\nTarget is missing: ".join("; ", @target_listed)."\n"; show_missing($r_target_missing); + print "\n\n"; } my $build_deps_ok = 1; # assume everything is ok. +my $std_missing_pkg_msg = ""; # list of missing packages in "standard" format. -# See if the packages that target is missing can be found from host: +# See if the packages that target is missing can be found from tools: my $n; foreach $n (@target_listed) { if (defined $r_target_missing->{$n}->{'primary'}) { @@ -216,55 +226,86 @@ foreach $n (@target_listed) { print "(skipping alternative $n)\n"; } } elsif ($ignored_from_tools{$n}) { - print "\t$n: Missing from tools, but dependency has been ignored by configuration\n"; + if ($verbose_messages) { + print "\t$n: Missing from tools, but dependency has been ignored by configuration\n"; + } } elsif (defined $r_host_missing->{$n}) { my $target_vers_req = $r_target_missing->{$n}->{'version'}; my $tools_vers_req = $r_host_missing->{$n}->{'version'}; - print "\t$n: Missing from tools $tools_vers_req and target $target_vers_req\n"; + if ($verbose_messages) { + print "\t$n: Missing from tools $tools_vers_req and target $target_vers_req\n"; + } my $alt = $r_target_missing->{$n}->{'alternatives'}; - if (defined $alt && @$alt > 0) { + if (defined $alt && (@$alt > 0)) { # there are alternatives: see if any of those exists on the host - print "\t There are alternatives: ".join(", ", @$alt)."\n"; + if ($verbose_messages) { + print "\t There are alternatives: ".join(", ", @$alt)."\n"; + } my $no_alternatives_found = 1; my $k; foreach $k (@$alt) { if (defined $r_host_missing->{$k}) { - print "\t ($k not found from tools)\n"; + if ($verbose_messages) { + print "\t ($k not found from tools)\n"; + } } elsif ($ignored_from_tools{$k}) { - print "\t $k: Missing from tools, ignored by configuration, good..\n"; + if ($verbose_messages) { + print "\t $k: Missing from tools, ignored by configuration, good..\n"; + } $no_alternatives_found = 0; } else { my ($found, $message); - $found, $message = is_accepted_from_tools( + ($found, $message) = is_accepted_from_tools( $r_host_missing, $n, $target_vers_req); if ($found) { - print "\t $n: found from tools, good..\n"; + if ($verbose_messages) { + print "\t $n: found from tools, good..\n"; + } $no_alternatives_found = 0; } else { - print "\t $n: $message\n"; + if ($verbose_messages) { + print "\t $n: $message\n"; + } } } } if ($no_alternatives_found) { - print "\t$n: none of the alternatives exist, requirement failed.\n"; + if ($verbose_messages) { + print "\t$n: none of the alternatives exist, requirement failed.\n"; + } $build_deps_ok = 0; + $std_missing_pkg_msg .= + " ".$n." | ".join(" | ", @$alt); } } else { - print "\t$n: not found, requirement failed.\n"; + if ($verbose_messages) { + print "\t$n: not found, requirement failed.\n"; + } $build_deps_ok = 0; + $std_missing_pkg_msg .= " ".$n; } } else { my ($found, $message); - $found, $message = is_accepted_from_tools($n); - if ($found) { - print "\t$n: found from tools, good..\n"; - } else { - print "\t$n: $message\n"; + ($found, $message) = is_accepted_from_tools($n); + if ($verbose_messages) { + if ($found) { + print "\t$n: found from tools, good..\n"; + } else { + print "\t$n: $message\n"; + } + } + if ($found == 0) { + $build_deps_ok = 0; + $std_missing_pkg_msg .= " ".$n; + my $alt = $r_target_missing->{$n}->{'alternatives'}; + if (defined $alt && (@$alt > 0)) { + $std_missing_pkg_msg .= " | ".join(" | ", @$alt); + } } } } @@ -273,6 +314,7 @@ foreach $n (@target_listed) { # but the host does not have: my $n; my @failures_in_dual_requirements; +my @failed_pkgs_in_dual_requirements; foreach $n (@both_required) { if (defined $r_host_missing->{$n}) { # Host does not have this... @@ -297,10 +339,12 @@ foreach $n (@both_required) { } push(@failures_in_dual_requirements, $msg); + push(@failed_pkgs_in_dual_requirements, $n); } elsif (defined $r_target_missing->{$n}) { my $target_vers_req = $r_target_missing->{$n}->{'version'}; my $msg = "$n: only tools has it $target_vers_req\n"; push(@failures_in_dual_requirements, $msg); + push(@failed_pkgs_in_dual_requirements, $n); } else { if ($debug) { print "B: $n, both have it\n"; @@ -308,16 +352,26 @@ foreach $n (@both_required) { } } if (@failures_in_dual_requirements > 0) { - print "Some packages must exist in target and tools:\n"; - print "\t".join("\n\t", @failures_in_dual_requirements)."\n"; + if ($verbose_messages) { + print "Some packages must exist in target and tools:\n"; + print "\t".join("\n\t", @failures_in_dual_requirements)."\n"; + } else { + print "dpkg-checkbuilddeps: Some packages must exist in target and tools.\n"; + } $build_deps_ok = 0; + $std_missing_pkg_msg .= " ".join(" ", @failed_pkgs_in_dual_requirements); } if ($build_deps_ok) { - print "Dependency checks ok\n"; + if ($verbose_messages) { + print "Dependency checks ok\n"; + } exit(0); } -print "Dependency checks failed\n"; +if ($verbose_messages) { + print "Dependency checks failed\n"; +} +print "dpkg-checkbuilddeps: Unmet build dependencies:$std_missing_pkg_msg\n"; exit(1); diff --git a/wrappers/dpkg-checkbuilddeps b/wrappers/dpkg-checkbuilddeps index 1f729e0..c998f25 100755 --- a/wrappers/dpkg-checkbuilddeps +++ b/wrappers/dpkg-checkbuilddeps @@ -12,6 +12,11 @@ # # dpkg-checkbuilddeps wrapper for SB2. # +# ENVIRONMENT VARIABLES: +# - set SBOX_CHECKBUILDDEPS_VERBOSE to non-empty value to get +# verbose description about what is missing. +# - SBOX_DOUBLECHECK_DEPS; see the text below: +# # Currently there are two algorithms for this: Old and new. # # The old one, implemented completely as a shell script, @@ -22,7 +27,7 @@ # the perl script (the old algorithm is off by default). # # Alternatively, the old and new algorithms can both be -# enable by setting environment variable SBOX_DOUBLECHECK_DEPS +# enabled by setting environment variable SBOX_DOUBLECHECK_DEPS # to any non-empty value. I haven't seen any cases where the # old algorithm would be better that the new one, but I'm # interested to hear if there are any...before this old @@ -61,6 +66,13 @@ function error_not_inside_sb2() exit 1 } +function verbose_message() +{ + if [ -n "$SBOX_CHECKBUILDDEPS_VERBOSE" ]; then + echo "$*" 1>&2 + fi +} + if [ -z "$SBOX_SESSION_DIR" ] then error_not_inside_sb2 @@ -175,7 +187,7 @@ function check_gcc_dependency() if [ "$required_gcc" = "gcc" ] then # requires GCC, but does not depend on gcc version - echo "$prefix""SB2 provides gcc" + verbose_message "$prefix""SB2 provides gcc" return 0 fi # @@ -190,7 +202,7 @@ function check_gcc_dependency() full_vrs="gcc-$SBOX_CROSS_GCC_VERSION" if [ "$required_gcc" = "$short_vrs" -o \ "$required_gcc" = "$full_vrs" ]; then - echo "$prefix""SB2 provides $required_gcc" + verbose_message "$prefix""SB2 provides $required_gcc" return 0 fi fi @@ -244,7 +256,7 @@ function check_host_builddeps() ret=0 # do the magic here - echo "$prefix""SB2 Checking host build deps.." + verbose_message "$prefix""SB2 Checking host build deps.." list_ok=1 # default to ok # $m will be the package to test, or pkg/pkg[/...] if there are @@ -259,31 +271,31 @@ function check_host_builddeps() has_one_alternative=0 for mmm in $(echo $m | sed -e 's:/: :') do - echo "$prefix"" ...$mmm" + verbose_message "$prefix"" ...$mmm" check_host_pkg $mmm if [ "$installed_to_host" = "yes" ] then - echo "$prefix"" $mmm = ok" + verbose_message "$prefix"" $mmm = ok" has_one_alternative=1 else - echo "$prefix"" no $mmm.." + verbose_message "$prefix"" no $mmm.." fi done if [ $has_one_alternative == 0 ] then - echo "$prefix"" Requirement $m failed; none of the alternatives were found." + verbose_message "$prefix"" Requirement $m failed; none of the alternatives were found." list_ok=0 else - echo "$prefix"" '$m': At least one alternative found, ok." + verbose_message "$prefix"" '$m': At least one alternative found, ok." fi ;; *) # No alternatives. check_host_pkg $m - echo "$prefix"" $check_result_msg" + verbose_message "$prefix"" $check_result_msg" if [ -n "$check_result_msg2" ] then - echo "$prefix"" $check_result_msg2" + verbose_message "$prefix"" $check_result_msg2" fi if [ "$installed_to_host" = "no" ] then @@ -304,7 +316,7 @@ function check_host_builddeps() function check_host_builddeps_by_real_tool() { ret=0 - echo "SB2 Checking tools build deps..." + verbose_message "SB2 Checking tools build deps..." x_missing_dep_file=`mktemp -p $SBOX_SESSION_DIR/tmp tools_missing_deps.XXXXXXXXXX` # Run dpkg-checkbuilddeps in the "tools" mode @@ -335,7 +347,7 @@ function check_host_builddeps_by_real_tool() else # failing target deps, but $tools_missing_deps is empty. Something # is fatally wrong. - echo "FATAL: Failed to check dependencies from tools_root DB" + echo "dpkg-checkbuilddeps: FATAL: Failed to check dependencies from tools_root DB" exit 1 fi } @@ -343,7 +355,7 @@ function check_host_builddeps_by_real_tool() function check_target_builddeps() { ret=0 - echo "SB2 Checking target build deps..." + verbose_message "SB2 Checking target build deps..." missing_dep_file=`mktemp -p $SBOX_SESSION_DIR/tmp missing_deps.XXXXXXXXXX` # dpkg-checkbuilddeps with another package db.. @@ -361,7 +373,9 @@ function check_target_builddeps() fi # else real dpkg-checkbuilddeps failed. - sed -e 's/^/ /' < $missing_dep_file + if [ -n "$SBOX_CHECKBUILDDEPS_VERBOSE" ]; then + sed -e 's/^/ /' < $missing_dep_file + fi missing_deps=$(egrep \ "^dpkg-checkbuilddeps: Unmet build dependencies:" \ $missing_dep_file | \ @@ -376,7 +390,7 @@ function check_target_builddeps() else # failing target deps, but $missing_deps is empty. Something # is fatally wrong. - echo "FATAL: Failed to check dependencies from target_root DB" + echo "dpkg-checkbuilddeps: FATAL: Failed to check dependencies from target_root DB" exit 1 fi } @@ -396,7 +410,7 @@ function compare_target_and_host_results_with_new_tool() host_ignored=`grep -v "#" $cfgfile_host_ignored_pkgs` fi - echo "SB2 Combining results from target and tools..." + verbose_message "SB2 Combining results from target and tools..." $sbox_dir/share/scratchbox2/lib/sb2-cmp-checkbuilddeps-output.pl \ "$t_missing" "$h_missing" "$both_required" "$host_accepted" "$host_ignored" @@ -412,7 +426,7 @@ function compare_target_and_host_results_with_new_tool() # First, make sure we are in a correct directory: if [ ! -f debian/control ] then - echo "Error: Can't find file debian/control" + echo "dpkg-checkbuilddeps: failure: cannot read debian/control: No such file or directory" 1>&2 exit 1 fi @@ -429,18 +443,18 @@ function old_deps_checker() { if [ $check_target_builddeps_result == 0 ]; then # nothing is missing = nothing needed from the host side - echo "OLD_CHK: Target rootstrap => all dependencies OK" + verbose_message "OLD_CHK: Target rootstrap => all dependencies OK" return 0 fi - echo "OLD_CHK: Build dependencies missing from the target environment:" - echo "OLD_CHK: $missing_deps" + verbose_message "OLD_CHK: Build dependencies missing from the target environment:" + verbose_message "OLD_CHK: $missing_deps" # Something is missing. Check if SB2 can fulfill the requirements: check_sb2_builddeps "$missing_deps" "OLD_CHK: " if [ $? == 0 ]; then # OK now, nothing needed from the host side - echo "OLD_CHK: SB2 tools check => all dependencies OK" + verbose_message "OLD_CHK: SB2 tools check => all dependencies OK" return 0 fi @@ -449,21 +463,21 @@ function old_deps_checker() # if [ ! -f $cfgfile_host_accepted_pkgs ] then - echo "OLD_CHK:" - echo "OLD_CHK: Configuration file $cfgfile_host_accepted_pkgs" - echo "OLD_CHK: does not exist. This means that no packages have been approved to be used" - echo "OLD_CHK: from the host environment in this mapping mode ($sbox_mapmode)." + verbose_message "OLD_CHK:" + verbose_message "OLD_CHK: Configuration file $cfgfile_host_accepted_pkgs" + verbose_message "OLD_CHK: does not exist. This means that no packages have been approved to be used" + verbose_message "OLD_CHK: from the host environment in this mapping mode ($sbox_mapmode)." return 1 fi check_host_builddeps "$missing_deps" "OLD_CHK: " if [ $? != 0 ]; then - echo "OLD_CHK: Failed. Host environment did not meet all requirements." + verbose_message "OLD_CHK: Failed. Host environment did not meet all requirements." return 1 fi # since we're here, everything is more or less ok - echo "OLD_CHK: All OK." + verbose_message "OLD_CHK: All OK." return 0 } @@ -480,6 +494,15 @@ function new_deps_checker() new_deps_checker_result=$? } +function deps_check_failed_exit_1() +{ + verbose_message "Failed." + if [ -z "$SBOX_CHECKBUILDDEPS_VERBOSE" ]; then + echo "dpkg-checkbuilddeps: (Set env.var. SBOX_CHECKBUILDDEPS_VERBOSE='y' and run this command again to get more details)" 1>&2 + fi + exit 1 +} + if [ -n "$SBOX_DOUBLECHECK_DEPS" ]; then old_deps_checker old_deps_checker_result=$? @@ -490,25 +513,23 @@ new_deps_checker if [ -n "$SBOX_DOUBLECHECK_DEPS" ]; then if [ "$new_deps_checker_result" != "$old_deps_checker_result" ]; then - echo "INCONSISTENT: new and old methods do not agree:" + verbose_message "INCONSISTENT: new and old methods do not agree:" if [ "$new_deps_checker_result" = 0 ]; then - echo " : new => dependency checks OK" + verbose_message " : new => dependency checks OK" else - echo " : new => dependency checks FAILED" + verbose_message " : new => dependency checks FAILED" fi if [ "$old_deps_checker_result" = 0 ]; then - echo " : old => dependency checks OK" + verbose_message " : old => dependency checks OK" else - echo " : old => dependency checks FAILED" + verbose_message " : old => dependency checks FAILED" fi - echo "Failed." - exit 1 + deps_check_failed_exit_1 fi fi if [ "$new_deps_checker_result" != "0" ]; then - echo "Failed." - exit 1 + deps_check_failed_exit_1 fi # since we're here, everything is more or less ok |