diff options
author | Niels Thykier <niels@thykier.net> | 2019-08-16 20:52:04 +0000 |
---|---|---|
committer | Niels Thykier <niels@thykier.net> | 2019-08-16 20:52:04 +0000 |
commit | aa3bf822ff200d6cf47e60ad348f6b745828f7a2 (patch) | |
tree | af42f6962d7040b707e9ded587349ec9f27d0b24 | |
parent | edf64efa348c91d631d090f36007fc1b872d02b3 (diff) | |
download | debhelper-aa3bf822ff200d6cf47e60ad348f6b745828f7a2.tar.gz |
Fix logic for arch-only commands to make it testable again
Signed-off-by: Niels Thykier <niels@thykier.net>
-rwxr-xr-x | dh | 11 | ||||
-rw-r--r-- | lib/Debian/Debhelper/Sequence.pm | 12 | ||||
-rw-r--r-- | lib/Debian/Debhelper/SequencerUtil.pm | 26 | ||||
-rwxr-xr-x | t/dh-sequencer.t | 18 |
4 files changed, 47 insertions, 20 deletions
@@ -749,7 +749,7 @@ my %completed_sequences; # Get the options to pass to commands in the sequence. # Filter out options intended only for this program. my (@options, %seen_options); -my ($unoptimizable_user_option, $unoptimizable_option_bundle) = (0, 0); +my ($unoptimizable_user_option, $unoptimizable_option_bundle, $sequence_unpack_flags) = (0, 0, 0); if ($sequence eq 'build-arch' || $sequence eq 'install-arch' || @@ -767,6 +767,12 @@ elsif ($sequence eq 'build-indep' || @packages = @{$sequence2packages{$sequence}}; } +if (not @arch_packages) { + $sequence_unpack_flags = FLAG_OPT_SOURCE_BUILDS_NO_ARCH_PACKAGES; +} elsif (not @indep_packages) { + $sequence_unpack_flags = FLAG_OPT_SOURCE_BUILDS_NO_INDEP_PACKAGES; +} + @addons = _compute_addons($sequence, @addon_requests); # Load addons, which can modify sequences. @@ -886,7 +892,8 @@ if ( -f $build_stamp_file and not compat(9)) { my ($rules_targets, $full_sequence) = unpack_sequence(\%sequences, $sequence, (!compat(8) ? 0 : 1), - \%completed_sequences + \%completed_sequences, + $sequence_unpack_flags, ); my $stoppoint = $#{$full_sequence}; diff --git a/lib/Debian/Debhelper/Sequence.pm b/lib/Debian/Debhelper/Sequence.pm index 4fd599b8..6911c826 100644 --- a/lib/Debian/Debhelper/Sequence.pm +++ b/lib/Debian/Debhelper/Sequence.pm @@ -8,9 +8,9 @@ use warnings; use Exporter qw(import); -use Debian::Debhelper::Dh_Lib qw(getpackages); use Debian::Debhelper::SequencerUtil qw(extract_rules_target_name sequence_type SEQUENCE_NO_SUBSEQUENCES - SEQUENCE_ARCH_INDEP_SUBSEQUENCES SEQUENCE_TYPE_ARCH_ONLY SEQUENCE_TYPE_INDEP_ONLY SEQUENCE_TYPE_BOTH); + SEQUENCE_ARCH_INDEP_SUBSEQUENCES SEQUENCE_TYPE_ARCH_ONLY SEQUENCE_TYPE_INDEP_ONLY SEQUENCE_TYPE_BOTH + FLAG_OPT_SOURCE_BUILDS_NO_ARCH_PACKAGES FLAG_OPT_SOURCE_BUILDS_NO_INDEP_PACKAGES); sub _as_command { @@ -110,15 +110,13 @@ sub as_rules_target_command { } sub flatten_sequence { - my ($this, $sequence_type) = @_; + my ($this, $sequence_type, $flags) = @_; die("Invalid sequence type $sequence_type") if $sequence_type eq SEQUENCE_NO_SUBSEQUENCES; my @cmds; - my $has_arch_pkgs = getpackages("arch") ? 1 : 0; - my $has_indep_pkgs = getpackages("indep") ? 1 : 0; for my $cmd_desc (@{$this->{'_cmds'}}) { my $seq_limitation = $cmd_desc->{'sequence-limitation'}; - next if ($seq_limitation eq SEQUENCE_TYPE_ARCH_ONLY and not $has_arch_pkgs); - next if ($seq_limitation eq SEQUENCE_TYPE_INDEP_ONLY and not $has_indep_pkgs); + next if ($seq_limitation eq SEQUENCE_TYPE_ARCH_ONLY and ($flags & FLAG_OPT_SOURCE_BUILDS_NO_ARCH_PACKAGES)); + next if ($seq_limitation eq SEQUENCE_TYPE_INDEP_ONLY and ($flags & FLAG_OPT_SOURCE_BUILDS_NO_INDEP_PACKAGES)); if ($seq_limitation eq $sequence_type or $sequence_type eq SEQUENCE_TYPE_BOTH or $seq_limitation eq SEQUENCE_TYPE_BOTH) { my $cmd = $cmd_desc->{'command'}; my @cmd_options = $cmd_desc->{'command-options'}; diff --git a/lib/Debian/Debhelper/SequencerUtil.pm b/lib/Debian/Debhelper/SequencerUtil.pm index a943357d..6dd3eb5d 100644 --- a/lib/Debian/Debhelper/SequencerUtil.pm +++ b/lib/Debian/Debhelper/SequencerUtil.pm @@ -6,12 +6,14 @@ package Debian::Debhelper::SequencerUtil; use strict; use warnings; use constant { - 'DUMMY_TARGET' => 'debhelper-fail-me', - 'SEQUENCE_NO_SUBSEQUENCES' => 'none', - 'SEQUENCE_ARCH_INDEP_SUBSEQUENCES' => 'both', - 'SEQUENCE_TYPE_ARCH_ONLY' => 'arch', - 'SEQUENCE_TYPE_INDEP_ONLY' => 'indep', - 'SEQUENCE_TYPE_BOTH' => 'both', + 'DUMMY_TARGET' => 'debhelper-fail-me', + 'SEQUENCE_NO_SUBSEQUENCES' => 'none', + 'SEQUENCE_ARCH_INDEP_SUBSEQUENCES' => 'both', + 'SEQUENCE_TYPE_ARCH_ONLY' => 'arch', + 'SEQUENCE_TYPE_INDEP_ONLY' => 'indep', + 'SEQUENCE_TYPE_BOTH' => 'both', + 'FLAG_OPT_SOURCE_BUILDS_NO_ARCH_PACKAGES' => 0x1, + 'FLAG_OPT_SOURCE_BUILDS_NO_INDEP_PACKAGES' => 0x2, }; use Exporter qw(import); @@ -29,6 +31,8 @@ our @EXPORT = qw( SEQUENCE_TYPE_ARCH_ONLY SEQUENCE_TYPE_INDEP_ONLY SEQUENCE_TYPE_BOTH + FLAG_OPT_SOURCE_BUILDS_NO_ARCH_PACKAGES + FLAG_OPT_SOURCE_BUILDS_NO_INDEP_PACKAGES ); our (%EXPLICIT_TARGETS, $RULES_PARSED); @@ -67,13 +71,15 @@ sub _agg_subseq { } sub unpack_sequence { - my ($sequences, $sequence_name, $always_inline, $completed_sequences) = @_; + my ($sequences, $sequence_name, $always_inline, $completed_sequences, $flags) = @_; my (@sequence, @targets, %seen, %non_inlineable_targets, @stack); my $sequence_type = sequence_type($sequence_name); # Walk through the sequence effectively doing a DFS of the rules targets # (when we are allowed to inline them). my $seq = $sequences->{$sequence_name}; - push(@stack, [$seq->flatten_sequence($sequence_type)]); + $flags //= 0; + + push(@stack, [$seq->flatten_sequence($sequence_type, $flags)]); while (@stack) { my $current_sequence = pop(@stack); COMMAND: @@ -88,7 +94,7 @@ sub unpack_sequence { my $subsequence = $sequences->{$rules_target}; my $subseq_type = _agg_subseq(sequence_type($rules_target), $sequence_type); push(@stack, $current_sequence); - $current_sequence = [$subsequence->flatten_sequence($subseq_type)]; + $current_sequence = [$subsequence->flatten_sequence($subseq_type, $flags)]; } elsif (defined($rules_target)) { my $subsequence = $sequences->{$rules_target}; my $subseq_type = _agg_subseq(sequence_type($rules_target), $sequence_type); @@ -168,7 +174,7 @@ sub unpack_sequence { } if ($transparent_subseq) { push(@stack, $current_sequence); - $current_sequence = [$subsequence->flatten_sequence($transparent_subseq)]; + $current_sequence = [$subsequence->flatten_sequence($transparent_subseq, $flags)]; } next COMMAND; } else { diff --git a/t/dh-sequencer.t b/t/dh-sequencer.t index 6c38eae2..f8643866 100755 --- a/t/dh-sequencer.t +++ b/t/dh-sequencer.t @@ -100,7 +100,7 @@ my %sequences_unpacked = ( 'clean' => _cmd_names(@c), ); -plan tests => 18 + 3 * scalar(keys(%sequences)); +plan tests => 21 + 3 * scalar(keys(%sequences)); # We will horse around with %EXPLICIT_TARGETS in this test; it should # definitely not attempt to read d/rules or the test will be break. @@ -144,6 +144,22 @@ is_deeply( [[], _cmd_names(@i, @ba, @b)], 'Inlined binary sequence with build-* done has @i, @ba and @b'); +is_deeply( + [unpack_sequence(\%sequences, 'binary', 0, {}, 0)], + [[], _cmd_names(@bd, @i, @ba, @b)], + 'Inlined binary sequence and arch:all + arch:any is reduced to @bd, @i, @ba and @b'); + +is_deeply( + [unpack_sequence(\%sequences, 'binary', 0, {}, FLAG_OPT_SOURCE_BUILDS_NO_ARCH_PACKAGES)], + [[], _cmd_names(@bd, @i, @b)], + 'Inlined binary sequence and not arch:any is reduced to @bd, @i and @b'); + +is_deeply( + [unpack_sequence(\%sequences, 'binary', 0, {}, FLAG_OPT_SOURCE_BUILDS_NO_INDEP_PACKAGES)], + [[], _cmd_names(@bd, @i, @ba, @b)], + 'Inlined binary sequence and not arch:all is reduced to @bd, @i, @ba and @b'); + + { local $Debian::Debhelper::SequencerUtil::EXPLICIT_TARGETS{'build-arch'} = 1; local $Debian::Debhelper::SequencerUtil::EXPLICIT_TARGETS{'build-indep'} = 1; |