diff options
author | Guillem Jover <guillem@debian.org> | 2016-01-29 19:44:40 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2016-02-15 02:10:45 +0100 |
commit | d122537d6df899dc1d0599e0a24ee3b27f0d9e18 (patch) | |
tree | 2fa353e5c5684dedd7bf4451a4ae52f7aeb3a55b | |
parent | 6e28595c2dd54f38b7e005355692996179e2c557 (diff) | |
download | dpkg-d122537d6df899dc1d0599e0a24ee3b27f0d9e18.tar.gz |
scripts: Use new Dpkg::Build::Types module instead of ad-hoc code
-rwxr-xr-x | scripts/dpkg-buildpackage.pl | 73 | ||||
-rwxr-xr-x | scripts/dpkg-genchanges.pl | 67 |
2 files changed, 31 insertions, 109 deletions
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl index 17ada97e0..5a3b6348e 100755 --- a/scripts/dpkg-buildpackage.pl +++ b/scripts/dpkg-buildpackage.pl @@ -23,7 +23,6 @@ use strict; use warnings; -use Carp; use Cwd; use File::Temp qw(tempdir); use File::Basename; @@ -33,6 +32,7 @@ use POSIX qw(:sys_wait_h); use Dpkg (); use Dpkg::Gettext; use Dpkg::ErrorHandling; +use Dpkg::Build::Types; use Dpkg::BuildOptions; use Dpkg::BuildProfiles qw(set_build_profiles); use Dpkg::Compression; @@ -168,47 +168,6 @@ my @hook_names = qw( my %hook; $hook{$_} = undef foreach @hook_names; -use constant BUILD_DEFAULT => 1; -use constant BUILD_SOURCE => 2; -use constant BUILD_ARCH_DEP => 4; -use constant BUILD_ARCH_INDEP => 8; -use constant BUILD_BINARY => BUILD_ARCH_DEP | BUILD_ARCH_INDEP; -use constant BUILD_SOURCE_DEP => BUILD_SOURCE | BUILD_ARCH_DEP; -use constant BUILD_SOURCE_INDEP => BUILD_SOURCE | BUILD_ARCH_INDEP; -use constant BUILD_ALL => BUILD_BINARY | BUILD_SOURCE; -my $include = BUILD_ALL | BUILD_DEFAULT; - -sub build_is_default() { return $include & BUILD_DEFAULT; } -sub build_sourceonly() { return $include == BUILD_SOURCE; } -sub build_binaryonly() { return !($include & BUILD_SOURCE); } -sub build_binaryindep() { return ($include == BUILD_ARCH_INDEP); } -sub build_opt { - if ($include == BUILD_BINARY) { - return '-b'; - } elsif ($include == BUILD_ARCH_DEP) { - return '-B'; - } elsif ($include == BUILD_ARCH_INDEP) { - return '-A'; - } elsif ($include == BUILD_SOURCE) { - return '-S'; - } elsif ($include == BUILD_SOURCE_DEP) { - return '-G'; - } elsif ($include == BUILD_SOURCE_INDEP) { - return '-g'; - } else { - croak "build_opt called with include=$include"; - } -} - -sub set_build_type -{ - my ($build_type, $build_option) = @_; - - usageerr(g_('cannot combine %s and %s'), build_opt(), $build_option) - if not build_is_default and $include != $build_type; - $include = $build_type; -} - my $build_opts = Dpkg::BuildOptions->new(); if ($build_opts->has('nocheck')) { @@ -325,7 +284,7 @@ while (@ARGV) { set_build_type(BUILD_SOURCE_INDEP, $_); push @changes_opts, '-g'; } elsif (/^-F$/) { - set_build_type(BUILD_ALL, $_); + set_build_type(BUILD_FULL, $_); } elsif (/^-v(.*)$/) { $since = $1; } elsif (/^-m(.*)$/) { @@ -345,22 +304,22 @@ while (@ARGV) { } } -if (($include & BUILD_BINARY) == BUILD_BINARY) { +if (build_has(BUILD_BINARY)) { $buildtarget = 'build'; $binarytarget = 'binary'; -} elsif ($include & BUILD_ARCH_DEP) { +} elsif (build_has(BUILD_ARCH_DEP)) { $buildtarget = 'build-arch'; $binarytarget = 'binary-arch'; -} elsif ($include & BUILD_ARCH_INDEP) { +} elsif (build_has(BUILD_ARCH_INDEP)) { $buildtarget = 'build-indep'; $binarytarget = 'binary-indep'; } if ($noclean) { # -nc without -b/-B/-A/-S/-F implies -b - $include = BUILD_BINARY if build_is_default; + set_build_type(BUILD_BINARY) if build_has(BUILD_DEFAULT); # -nc with -S implies no dependency checks - $checkbuilddep = 0 if build_sourceonly; + $checkbuilddep = 0 if build_is(BUILD_SOURCE); } if ($< == 0) { @@ -456,9 +415,9 @@ while (<$arch_env>) { close $arch_env or subprocerr('dpkg-architecture'); my $arch; -if (build_sourceonly) { +if (build_is(BUILD_SOURCE)) { $arch = 'source'; -} elsif (build_binaryindep) { +} elsif (build_is(BUILD_ARCH_INDEP)) { $arch = 'all'; } else { $arch = mustsetvar($ENV{DEB_HOST_ARCH}, g_('host architecture')); @@ -479,7 +438,7 @@ if (not $signcommand) { $signchanges = 0; } -if ($signsource && build_binaryonly) { +if ($signsource && build_has_not(BUILD_SOURCE)) { $signsource = 0; } @@ -503,8 +462,8 @@ unless ($call_target) { if ($checkbuilddep) { my @checkbuilddep_opts; - push @checkbuilddep_opts, '-A' if ($include & BUILD_ARCH_DEP) == 0; - push @checkbuilddep_opts, '-B' if ($include & BUILD_ARCH_INDEP) == 0; + push @checkbuilddep_opts, '-A' if build_has_not(BUILD_ARCH_DEP); + push @checkbuilddep_opts, '-B' if build_has_not(BUILD_ARCH_INDEP); push @checkbuilddep_opts, '-I' if not $check_builtin_builddep; push @checkbuilddep_opts, "--admindir=$admindir" if $admindir; @@ -535,9 +494,9 @@ unless ($noclean) { withecho(@rootcommand, @debian_rules, 'clean'); } -run_hook('source', $include & BUILD_SOURCE); +run_hook('source', build_has(BUILD_SOURCE)); -if ($include & BUILD_SOURCE) { +if (build_has(BUILD_SOURCE)) { warning(g_('building a source package without cleaning up as you asked; ' . 'it might contain undesired files')) if $noclean; chdir('..') or syserr('chdir ..'); @@ -545,7 +504,7 @@ if ($include & BUILD_SOURCE) { chdir($dir) or syserr("chdir $dir"); } -run_hook('build', $include & BUILD_BINARY); +run_hook('build', build_has(BUILD_BINARY)); if ($buildtarget ne 'build' and scalar(@debian_rules) == 1) { # Verify that build-{arch,indep} are supported. If not, fallback to build. @@ -565,7 +524,7 @@ if ($buildtarget ne 'build' and scalar(@debian_rules) == 1) { } } -if ($include & BUILD_BINARY) { +if (build_has(BUILD_BINARY)) { withecho(@debian_rules, $buildtarget); run_hook('binary', 1); withecho(@rootcommand, @debian_rules, $binarytarget); diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index 30c7abd0a..e23e52a9e 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -22,7 +22,6 @@ use strict; use warnings; -use Carp; use Encode; use POSIX qw(:errno_h :locale_h); @@ -32,6 +31,7 @@ use Dpkg::Util qw(:list); use Dpkg::File; use Dpkg::Checksums; use Dpkg::ErrorHandling; +use Dpkg::Build::Types; use Dpkg::BuildProfiles qw(get_build_profiles parse_build_profiles evaluate_restriction_formula); use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is); @@ -80,43 +80,6 @@ my $substvars_loaded = 0; my $substvars = Dpkg::Substvars->new(); $substvars->set_as_auto('Format', $changes_format); -use constant BUILD_SOURCE => 1; -use constant BUILD_ARCH_DEP => 2; -use constant BUILD_ARCH_INDEP => 4; -use constant BUILD_BINARY => BUILD_ARCH_DEP | BUILD_ARCH_INDEP; -use constant BUILD_SOURCE_DEP => BUILD_SOURCE | BUILD_ARCH_DEP; -use constant BUILD_SOURCE_INDEP => BUILD_SOURCE | BUILD_ARCH_INDEP; -use constant BUILD_ALL => BUILD_BINARY | BUILD_SOURCE; -my $include = BUILD_ALL; - -sub build_is_default() { return ($include & BUILD_ALL) == BUILD_ALL; } -sub build_opt { - if ($include == BUILD_BINARY) { - return '-b'; - } elsif ($include == BUILD_ARCH_DEP) { - return '-B'; - } elsif ($include == BUILD_ARCH_INDEP) { - return '-A'; - } elsif ($include == BUILD_SOURCE) { - return '-S'; - } elsif ($include == BUILD_SOURCE_DEP) { - return '-G'; - } elsif ($include == BUILD_SOURCE_INDEP) { - return '-g'; - } else { - croak "build_opt called with include=$include"; - } -} - -sub set_build_type -{ - my ($build_type, $build_option) = @_; - - usageerr(g_('cannot combine %s and %s'), build_opt(), $build_option) - if not build_is_default and $include != $build_type; - $include = $build_type; -} - sub version { printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION; @@ -264,7 +227,7 @@ foreach (keys %{$src_fields}) { my $dist = Dpkg::Dist::Files->new(); my $origsrcmsg; -if ($include & BUILD_SOURCE) { +if (build_has(BUILD_SOURCE)) { my $sec = $sourcedefault{'Section'} // '-'; my $pri = $sourcedefault{'Priority'} // '-'; warning(g_('missing Section for source files')) if $sec eq '-'; @@ -313,17 +276,17 @@ if ($include & BUILD_SOURCE) { for my $f ($checksums->get_files()) { $dist->add_file($f, $sec, $pri); } -} elsif ($include == BUILD_ARCH_DEP) { +} elsif (build_is(BUILD_ARCH_DEP)) { $origsrcmsg = g_('binary-only arch-specific upload ' . '(source code and arch-indep packages not included)'); -} elsif ($include == BUILD_ARCH_INDEP) { +} elsif (build_is(BUILD_ARCH_INDEP)) { $origsrcmsg = g_('binary-only arch-indep upload ' . '(source code and arch-specific packages not included)'); } else { $origsrcmsg = g_('binary-only upload (no source code included)'); } -if ($include & BUILD_BINARY) { +if (build_has(BUILD_BINARY)) { my $dist_count = 0; $dist_count = $dist->load($fileslistfile) if -e $fileslistfile; @@ -367,9 +330,9 @@ foreach my $pkg ($control->get_packages()) { if (not defined($p2f{$p})) { # No files for this package... warn if it's unexpected - if (((debarch_eq('all', $a) and ($include & BUILD_ARCH_INDEP)) || - ((any { debarch_is($host_arch, $_) } split /\s+/, $a) - and ($include & BUILD_ARCH_DEP))) and + if (((debarch_eq('all', $a) and build_has(BUILD_ARCH_INDEP)) || + ((any { debarch_is($host_arch, $_) } split /\s+/, $a) + and build_has(BUILD_ARCH_DEP))) and (@restrictions == 0 or evaluate_restriction_formula(\@restrictions, \@profiles))) { @@ -388,7 +351,7 @@ foreach my $pkg ($control->get_packages()) { $f2pricf{$_} = $v foreach (@f); } elsif (m/^Architecture$/) { if ((any { debarch_is($host_arch, $_) } split /\s+/, $v) - and ($include & BUILD_ARCH_DEP)) { + and build_has(BUILD_ARCH_DEP)) { $v = $host_arch; } elsif (!debarch_eq('all', $v)) { $v = ''; @@ -467,12 +430,12 @@ if (length($fields->{'Binary'}) > 980) { $fields->{'Binary'} =~ s/(.{0,980}) /$1\n/g; } -unshift @archvalues, 'source' if $include & BUILD_SOURCE; -@archvalues = ('all') if $include == BUILD_ARCH_INDEP; +unshift @archvalues, 'source' if build_has(BUILD_SOURCE); +@archvalues = ('all') if build_is(BUILD_ARCH_INDEP); @archvalues = grep { !debarch_eq('all', $_) } @archvalues - unless $include & BUILD_ARCH_INDEP; + if build_has_not(BUILD_ARCH_INDEP); @archvalues = grep { !debarch_eq($host_arch, $_) } @archvalues - unless $include & BUILD_ARCH_DEP; + if build_has_not(BUILD_ARCH_DEP); $fields->{'Architecture'} = join ' ', @archvalues; $fields->{'Built-For-Profiles'} = join ' ', get_build_profiles(); @@ -487,8 +450,8 @@ for my $file ($dist->get_files()) { if (defined $file->{package} && $file->{package_type} =~ m/^u?deb$/) { my $arch_all = debarch_eq('all', $file->{arch}); - next if (not ($include & BUILD_ARCH_INDEP) and $arch_all); - next if (not ($include & BUILD_ARCH_DEP) and not $arch_all); + next if build_has_not(BUILD_ARCH_INDEP) and $arch_all; + next if build_has_not(BUILD_ARCH_DEP) and not $arch_all; } $checksums->add_from_file("$uploadfilesdir/$f", key => $f); } |