[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: dpkg-buildpackage -ucb



On Thu, 2016-04-28 at 19:52:27 +0200, Guillem Jover wrote:
> Sorry, should have qualified with "locally", although I was going to
> push today or so. :) I've now attached the patch sitting in my local
> branch that I'm planning to push.

And of course the patch went for a walk…

Thanks,
Guillem
From 9d17f70407da31758cb8c94781940088525d89b1 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@debian.org>
Date: Sun, 3 Apr 2016 19:45:14 +0200
Subject: [PATCH] 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      | 69 +++++++++++++++++++++++++++-----------------
 man/dpkg-genchanges.1        | 51 ++++++++++++++++++++------------
 scripts/Dpkg/Build/Types.pm  | 50 +++++++++++++++++++++++++++++++-
 scripts/dpkg-buildpackage.pl | 12 ++++----
 scripts/dpkg-genchanges.pl   |  6 +++-
 scripts/t/Dpkg_Build_Types.t | 10 ++++++-
 7 files changed, 148 insertions(+), 53 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 162457d..e521b98 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” 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..7f7375f 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,53 @@ 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 full
+Builds everything, an alias for \fBsource,any,all\fP.
+This is 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=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
+Equivalent to \fB\-\-build=full\fP or \fB\-\-build=source,any,all\fP
 (since dpkg 1.15.8).
-This is the same as the default case when no build option is specified.
 .TP
 .BI \-\-target= target
 .TQ
diff --git a/man/dpkg-genchanges.1 b/man/dpkg-genchanges.1
index 75d82ec..2844aee 100644
--- a/man/dpkg-genchanges.1
+++ b/man/dpkg-genchanges.1
@@ -36,29 +36,44 @@ 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 full
+Upload everything, an alias for \fBsource,any,all\fP.
+This is 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=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 0f45eb7..94f637a 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
@@ -34,6 +34,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);
@@ -114,6 +116,14 @@ use constant {
 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,
+);
+
 =back
 
 =head1 FUNCTIONS
@@ -194,6 +204,44 @@ sub set_build_type
     $current_option = $build_option;
 }
 
+=item set_build_type_from_options($build_type)
+
+Set the current build type from a list of build type components.
+
+=cut
+
+sub set_build_type_from_options
+{
+    my ($build_parts, $build_option) = @_;
+
+    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);
+}
+
+=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 4f229e3..d781c97 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -59,6 +59,8 @@ sub usage {
 'Usage: %s [<option>...]')
     . "\n\n" . g_(
 'Options:
+  --build=<type> specify the build <type>: full, source, any, all
+                   (comma-separated list, 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 +267,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_DEP, $_);
-	push @changes_opts, '-G';
     } elsif (/^-g$/) {
 	set_build_type(BUILD_SOURCE_INDEP, $_);
-	push @changes_opts, '-g';
     } elsif (/^-F$/) {
 	set_build_type(BUILD_FULL, $_);
     } elsif (/^-v(.*)$/) {
@@ -532,6 +530,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 3b27a04..425e310 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, any, all
+                             (comma-separated list, 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 18524e4..a78cb74 100644
--- a/scripts/t/Dpkg_Build_Types.t
+++ b/scripts/t/Dpkg_Build_Types.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 12;
+use Test::More tests => 15;
 
 BEGIN {
     use_ok('Dpkg::Build::Types');
@@ -24,12 +24,20 @@ BEGIN {
 
 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 source arch dep');
+
 ok(build_is(BUILD_DEFAULT | BUILD_BINARY), 'build is default binary');
 
 set_build_type(BUILD_SOURCE_INDEP, '--source-indep');
 
+is(get_build_options_from_type(), 'source,all', 'build is source arch indep');
+
+set_build_type_from_options('source,all', '--build=source,all');
+
 ok(build_is(BUILD_SOURCE_INDEP), 'build is source indep');
 ok(!build_is(BUILD_SOURCE_DEP), 'build is not source dep');
 ok(build_has_any(BUILD_SOURCE), 'build source indep has source');
-- 
2.8.1


Reply to: