[Reproducible-commits] [dpkg] 85/105: scripts: Add support for new --build option to define build type

Niko Tyni ntyni at moszumanska.debian.org
Mon May 2 13:49:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

ntyni pushed a commit to branch ntyni/reproducible_builds
in repository dpkg.

commit bc2068676fe68ff4080ddee254622ee689ad28ac
Author: Guillem Jover <guillem at debian.org>
Date:   Sun Apr 3 19:45:14 2016 +0200

    scripts: Add support for new --build option to define build type
    
    This simplifies the way to select what to build, and makes it both
    easier to remember, and easier to deal with in the code. The current
    set of split single options are really a mess.
---
 debian/changelog             |  3 ++
 man/dpkg-buildpackage.1      | 76 ++++++++++++++++++++++++++++----------------
 man/dpkg-genchanges.1        | 56 +++++++++++++++++++++-----------
 scripts/Dpkg/Build/Types.pm  | 54 ++++++++++++++++++++++++++++++-
 scripts/dpkg-buildpackage.pl | 13 ++++----
 scripts/dpkg-genchanges.pl   |  6 +++-
 scripts/t/Dpkg_Build_Types.t | 15 +++++++--
 7 files changed, 168 insertions(+), 55 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index cc44104..d855667 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -74,6 +74,9 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
   * Add very basic color support to all dpkg namespaced programs, enabled by
     setting the environment variable DPKG_COLORS to “auto”, “always” or
     “never”, the latter being the default.
+  * Add support for a new --build option to define build type by a
+    comma-separated list of components (“source”, “any”, “all”, “binary” or
+    “full”) in dpkg-genchanges and dpkg-buildpackage.
   * Portability:
     - Move DPKG_ADMINDIR environment variable name out from update-alternatives
       code, to make life easier for non-dpkg-based systems.
diff --git a/man/dpkg-buildpackage.1 b/man/dpkg-buildpackage.1
index b96b753..aaf5c1e 100644
--- a/man/dpkg-buildpackage.1
+++ b/man/dpkg-buildpackage.1
@@ -46,17 +46,20 @@ option, it calls that target and stops here. Otherwise it runs the
 clean the build-tree (unless \fB\-nc\fP is specified).
 .IP \fB4.\fP 3
 It runs the \fBsource\fP hook and calls \fBdpkg\-source \-b\fP to generate
-the source package (unless a binary\-only build has been requested with
-\fB\-b\fP, \fB\-B\fP or \fB\-A\fP).
+the source package (if a \fBsource\fP build has been requested with
+\fB\-\-build\fP or equivalent options).
 .IP \fB5.\fP 3
 It runs the \fBbuild\fP hook and calls \fBdebian/rules\fP \fIbuild-target\fP,
 then runs the \fBbinary\fP hook followed by \fBfakeroot debian/rules\fP
 \fIbinary-target\fP (unless a source-only build has been requested with
-\fB\-S\fP). Note that \fIbuild-target\fR and \fIbinary-target\fP are either
-\fBbuild\fP and \fBbinary\fP (default case, or if \fB\-b\fP is specified),
-or \fBbuild\-arch\fP and \fBbinary\-arch\fP (if \fB\-B\fP or \fB\-G\fP are
-specified), or \fBbuild\-indep\fP and \fBbinary\-indep\fP (if \fB\-A\fP
-or \fB\-g\fP are specified).
+\fB\-\-build=source\fP or equivalent options).
+Note that \fIbuild-target\fR and \fIbinary-target\fP are either \fBbuild\fP
+and \fBbinary\fP (default case, or if an \fBany\fP and \fBall\fP build
+has been requested with \fB\-\-build\fP or equivalent options), or
+\fBbuild\-arch\fP and \fBbinary\-arch\fP (if an \fBany\fP and not \fBall\fP
+build has been requested with \fB\-\-build\fP or equivalent options), or
+\fBbuild\-indep\fP and \fBbinary\-indep\fP (if an \fBall\fP and not \fBany\fP
+build has been requested with \fB\-\-build\fP or equivalent options).
 .IP \fB6.\fP 3
 It runs the \fBchanges\fP hook and calls \fBdpkg\-genchanges\fP to
 generate a \fB.changes\fP file.
@@ -81,39 +84,58 @@ It runs the \fBdone\fP hook.
 .
 .SH OPTIONS
 .TP
-.B \-g
-Specifies a build limited to source and architecture independent packages
-(since dpkg 1.17.11).
+.BI \-\-build= type
+Specifies the build \fItype\fP from a comma-separated list of components
+(since dpkg 1.18.5).
 Passed to \fBdpkg\-genchanges\fP.
+
+The allowed values are:
+.RS
+.TP
+.B source
+Builds the source package.
+Note: when using this value standalone and if what you want is simply to
+(re-)build the source package, using \fBdpkg\-source\fP is always better
+as it does not require any build dependencies to be installed to be able
+to call the \fBclean\fP target.
+.TP
+.B any
+Builds the architecture specific binary packages.
+.TP
+.B all
+Builds the architecture independent binary packages.
+.TP
+.B binary
+Builds the architecture specific and independent binary packages.
+This is an alias for \fBany,all\fP.
+.TP
+.B full
+Builds everything.
+This is an alias for \fBsource,any,all\fP, and the same as the default
+case when no build option is specified.
+.RE
+.TP
+.B \-g
+Equivalent to \fB\-\-build=source,all\fP (since dpkg 1.17.11).
 .TP
 .B \-G
-Specifies a build limited to source and architecture specific packages
-(since dpkg 1.17.11).
-Passed to \fBdpkg\-genchanges\fP.
+Equivalent to \fB\-\-build=source,any\fP (since dpkg 1.17.11).
 .TP
 .B \-b
-Specifies a binary-only build, no source files are to be built and/or
-distributed. Passed to \fBdpkg\-genchanges\fP.
+Equivalent to \fB\-\-build=binary\fP or \fB\-\-build=any,all\fP.
 .TP
 .B \-B
-Specifies a binary-only build, limited to architecture dependent packages.
-Passed to \fBdpkg\-genchanges\fP.
+Equivalent to \fB\-\-build=any\fP.
 .TP
 .B \-A
-Specifies a binary-only build, limited to architecture independent
-packages. Passed to \fBdpkg\-genchanges\fP.
+Equivalent to \fB\-\-build=all\fP.
 .TP
 .B \-S
-Specifies a source-only build, no binary packages need to be made.
-Passed to \fBdpkg\-genchanges\fP.
-Note: if what you want is simply to (re-)build the source package, using
-\fBdpkg\-source\fP is always better as it does not require any build
-dependencies to be installed to be able to call the \fBclean\fP target.
+Equivalent to \fB\-\-build=source\fP.
 .TP
 .B \-F
-Specifies a normal full build, binary and source packages will be built
-(since dpkg 1.15.8).
-This is the same as the default case when no build option is specified.
+Equivalent to \fB\-\-build=full\fP, \fB\-\-build=source,binary\fP or
+\fB\-\-build=source,any,all\fP since dpkg 1.15.8).
 .TP
 .BI \-\-target= target
 .TQ
diff --git a/man/dpkg-genchanges.1 b/man/dpkg-genchanges.1
index 75d82ec..c24630b 100644
--- a/man/dpkg-genchanges.1
+++ b/man/dpkg-genchanges.1
@@ -36,29 +36,49 @@ file
 .
 .SH OPTIONS
 .TP
+.BI \-\-build= type
+Specifies the build \fItype\fP from a comma-separated list of components
+(since dpkg 1.18.5).
+
+The allowed values are:
+.RS
+.TP
+.B source
+Upload the source package.
+.TP
+.B any
+Upload the architecture specific binary packages.
+.TP
+.B all
+Upload the architecture independent binary packages.
+.TP
+.B binary
+Upload the architecture specific and independent binary packages.
+This is an alias for \fBany,all\fP.
+.TP
+.B full
+Upload everything.
+This is alias for \fBsource,any,all\fP, and the same as the default case
+when no build option is specified.
+.RE
+.TP
 .B \-g
-Specifies that only source and architecture independent packages should
-be uploaded, thus no architecture specific packages will be included
-(since dpkg 1.17.11).
+Equivalent to \fB\-\-build=source,all\fP (since dpkg 1.17.11).
 .TP
 .B \-G
-Specifies that only source and architecture specific packages should
-be uploaded, thus no architecture independent packages will be included
-(since dpkg 1.17.11).
-.TP
-.BR \-b ", " \-B ", " \-A
-Specifies that a binary-only build is taking place, thus no source
-files are to be included.
-There's no distinction between \fB\-b\fP, \fB\-B\fP and \fB\-A\fP,
-the produced
-.B .changes
-file will include whatever files were created by the
-.B binary\-*
-target(s) of the package being built.
+Equivalent to \fB\-\-build=source,any\fP (since dpkg 1.17.11).
+.TP
+.B \-b
+Equivalent to \fB\-\-build=binary\fP or \fB\-\-build=any,all\fP.
+.TP
+.B \-B
+Equivalent to \fB\-\-build=any\fP.
+.TP
+.B \-A
+Equivalent to \fB\-\-build=all\fP.
 .TP
 .B \-S
-Specifies that only the source should be uploaded, thus no binary
-packages will be included.
+Equivalent to \fB\-\-build=source\fP.
 .PP
 The \fB\-s\fP\fIx\fP options control whether the original source archive is
 included in the upload if any source is being generated (i.e.
diff --git a/scripts/Dpkg/Build/Types.pm b/scripts/Dpkg/Build/Types.pm
index 7f6f1bc..9a921fa 100644
--- a/scripts/Dpkg/Build/Types.pm
+++ b/scripts/Dpkg/Build/Types.pm
@@ -19,7 +19,7 @@ package Dpkg::Build::Types;
 use strict;
 use warnings;
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 our @EXPORT = qw(
     BUILD_DEFAULT
     BUILD_SOURCE
@@ -32,6 +32,8 @@ our @EXPORT = qw(
     build_has_none
     build_is
     set_build_type
+    set_build_type_from_options
+    get_build_options_from_type
 );
 
 use Exporter qw(import);
@@ -98,6 +100,15 @@ use constant BUILD_FULL   => BUILD_BINARY | BUILD_SOURCE;
 my $current_type = BUILD_FULL | BUILD_DEFAULT;
 my $current_option = undef;
 
+my @build_types = qw(source any all);
+my %build_types = (
+    full => BUILD_FULL,
+    source => BUILD_SOURCE,
+    any => BUILD_ARCH_DEP,
+    all => BUILD_ARCH_INDEP,
+    binary => BUILD_BINARY,
+);
+
 =back
 
 =head1 FUNCTIONS
@@ -182,6 +193,47 @@ sub set_build_type
     $current_option = $build_option;
 }
 
+=item set_build_type_from_options($build_type, $build_option, %opts)
+
+Set the current build type from a list of build type components.
+
+The function will check and abort on incompatible build type assignments,
+this behavior can be disabled by using the boolean option "nocheck".
+
+=cut
+
+sub set_build_type_from_options
+{
+    my ($build_parts, $build_option, %opts) = @_;
+
+    my $build_type = 0;
+    foreach my $type (split /,/, $build_parts) {
+        usageerr(g_('unknown build type %s'), $type)
+            unless exists $build_types{$type};
+        $build_type |= $build_types{$type};
+    }
+
+    set_build_type($build_type, $build_option, %opts);
+}
+
+=item get_build_options_from_type()
+
+Get the current build type as a set of comma-separated string options.
+
+=cut
+
+sub get_build_options_from_type
+{
+    return 'full' if build_has_all(BUILD_FULL);
+
+    my @parts;
+    foreach my $type (@build_types) {
+        push @parts, $type if build_has_all($build_types{$type});
+    }
+
+    return join ',', @parts;
+}
+
 =back
 
 =head1 CHANGES
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index e922e0c..475da41 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -59,6 +59,9 @@ sub usage {
 'Usage: %s [<option>...]')
     . "\n\n" . g_(
 'Options:
+  --build=<type>[,...]
+                 specify the build <type>: full, source, binary, any, all
+                   (default is \'full\').
   -F             normal full build (binaries and sources, default).
   -g             source and arch-indep build.
   -G             source and arch-specific build.
@@ -265,24 +268,20 @@ while (@ARGV) {
         $call_target_as_root = 1;
     } elsif (/^-nc$/) {
 	$noclean = 1;
+    } elsif (/^--build=(.*)$/) {
+        set_build_type_from_options($1, $_);
     } elsif (/^-b$/) {
 	set_build_type(BUILD_BINARY, $_);
-	push @changes_opts, '-b';
     } elsif (/^-B$/) {
 	set_build_type(BUILD_ARCH_DEP, $_);
-	push @changes_opts, '-B';
     } elsif (/^-A$/) {
 	set_build_type(BUILD_ARCH_INDEP, $_);
-	push @changes_opts, '-A';
     } elsif (/^-S$/) {
 	set_build_type(BUILD_SOURCE, $_);
-	push @changes_opts, '-S';
     } elsif (/^-G$/) {
 	set_build_type(BUILD_SOURCE | BUILD_ARCH_DEP, $_);
-	push @changes_opts, '-G';
     } elsif (/^-g$/) {
 	set_build_type(BUILD_SOURCE | BUILD_ARCH_INDEP, $_);
-	push @changes_opts, '-g';
     } elsif (/^-F$/) {
 	set_build_type(BUILD_FULL, $_);
     } elsif (/^-v(.*)$/) {
@@ -532,6 +531,8 @@ if (build_has_any(BUILD_BINARY)) {
 
 run_hook('changes', 1);
 
+my $build_types = get_build_options_from_type();
+push @changes_opts, "--build=$build_types" if build_has_none(BUILD_DEFAULT);
 push @changes_opts, "-m$maint" if defined $maint;
 push @changes_opts, "-e$changedby" if defined $changedby;
 push @changes_opts, "-v$since" if defined $since;
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index 016cc5e..0c47bd5 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -94,6 +94,8 @@ sub usage {
 'Usage: %s [<option>...]')
     . "\n\n" . g_(
 "Options:
+  --build=<type>[,...]     specify the build <type>: full, source, binary,
+                             any, all (default is \'full\').
   -g                       source and arch-indep build.
   -G                       source and arch-specific build.
   -b                       binary-only, no source files.
@@ -125,7 +127,9 @@ sub usage {
 
 while (@ARGV) {
     $_=shift(@ARGV);
-    if (m/^-b$/) {
+    if (m/^--build=(.*)$/) {
+        set_build_type_from_options($1, $_);
+    } elsif (m/^-b$/) {
 	set_build_type(BUILD_BINARY, $_);
     } elsif (m/^-B$/) {
 	set_build_type(BUILD_ARCH_DEP, $_);
diff --git a/scripts/t/Dpkg_Build_Types.t b/scripts/t/Dpkg_Build_Types.t
index d237c03..857e6e9 100644
--- a/scripts/t/Dpkg_Build_Types.t
+++ b/scripts/t/Dpkg_Build_Types.t
@@ -16,20 +16,31 @@
 use strict;
 use warnings;
 
-use Test::More tests => 19;
+use Test::More tests => 26;
 
 BEGIN {
     use_ok('Dpkg::Build::Types');
 }
 
 ok(build_is(BUILD_DEFAULT | BUILD_FULL), 'build is default full');
+is(get_build_options_from_type(), 'full', 'build is full');
 
 set_build_type(BUILD_DEFAULT | BUILD_BINARY, '--default-binary');
-
+is(get_build_options_from_type(), 'any,all', 'build is any,all');
 ok(build_is(BUILD_DEFAULT | BUILD_BINARY), 'build is default binary');
 
 set_build_type(BUILD_SOURCE | BUILD_ARCH_INDEP, '--build=source,all');
+is(get_build_options_from_type(), 'source,all', 'build is source,all');
+
+set_build_type_from_options('any,all', '--build=any,all', nocheck => 1);
+is(get_build_options_from_type(), 'any,all', 'build is any,all');
+ok(build_is(BUILD_BINARY), 'build is any,all');
+
+set_build_type_from_options('binary', '--build=binary', nocheck => 1);
+is(get_build_options_from_type(), 'any,all', 'build is binary');
+ok(build_is(BUILD_BINARY), 'build is binary');
 
+set_build_type_from_options('source,all', '--build=source,all', nocheck => 1);
 ok(build_is(BUILD_SOURCE | BUILD_ARCH_INDEP), 'build source,all is source,all');
 ok(!build_is(BUILD_SOURCE | BUILD_ARCH_DEP), 'build source,all is not source,any');
 ok(build_has_any(BUILD_SOURCE), 'build source,all has_any source');

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list