[Reproducible-commits] [dpkg] 05/63: Dpkg::Build::Types: Add new module

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Mar 4 17:44:41 UTC 2016


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

lunar pushed a commit to branch pu/buildinfo
in repository dpkg.

commit 6e28595c2dd54f38b7e005355692996179e2c557
Author: Guillem Jover <guillem at debian.org>
Date:   Fri Jan 29 22:46:11 2016 +0100

    Dpkg::Build::Types: Add new module
---
 scripts/Dpkg/Build/Types.pm  | 192 +++++++++++++++++++++++++++++++++++++++++++
 scripts/Makefile.am          |   2 +
 scripts/po/POTFILES.in       |   1 +
 scripts/t/Dpkg_Build_Types.t |  43 ++++++++++
 4 files changed, 238 insertions(+)

diff --git a/scripts/Dpkg/Build/Types.pm b/scripts/Dpkg/Build/Types.pm
new file mode 100644
index 0000000..2dda437
--- /dev/null
+++ b/scripts/Dpkg/Build/Types.pm
@@ -0,0 +1,192 @@
+# Copyright © 2007 Frank Lichtenheld <djpig at debian.org>
+# Copyright © 2010, 2013-2016 Guillem Jover <guillem at debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+package Dpkg::Build::Types;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.01';
+our @EXPORT = qw(
+    BUILD_DEFAULT
+    BUILD_SOURCE
+    BUILD_ARCH_DEP
+    BUILD_ARCH_INDEP
+    BUILD_BINARY
+    BUILD_SOURCE_DEP
+    BUILD_SOURCE_INDEP
+    BUILD_FULL
+    build_has
+    build_has_not
+    build_is
+    set_build_type
+);
+
+use Exporter qw(import);
+
+use Dpkg::Gettext;
+use Dpkg::ErrorHandling;
+
+=encoding utf8
+
+=head1 NAME
+
+Dpkg::Build::Types - track build types
+
+=head1 DESCRIPTION
+
+The Dpkg::Build::Types module is used by various tools to track and decide
+what artifacts need to be built.
+
+The build types are bit constants that are exported by default. Multiple
+types can be ORed.
+
+=head1 CONSTANTS
+
+=over 4
+
+=item BUILD_DEFAULT
+
+This build is the default.
+
+=item BUILD_SOURCE
+
+This build includes source artifacts.
+
+=item BUILD_ARCH_DEP
+
+This build includes architecture dependent binary artifacts.
+
+=item BUILD_ARCH_INDEP
+
+This build includes architecture independent binary artifacts.
+
+=item BUILD_BINARY
+
+This build includes binary artifacts.
+
+=item BUILD_SOURCE_DEP
+
+This build includes source and architecture dependent binary artifacts.
+
+=item BUILD_SOURCE_INDEP
+
+This build includes source and architecture independent binary artifacts.
+
+=item BUILD_FULL
+
+This build includes source and binary artifacts.
+
+=cut
+
+# Simple types.
+use constant {
+    BUILD_DEFAULT      => 1,
+    BUILD_SOURCE       => 2,
+    BUILD_ARCH_DEP     => 4,
+    BUILD_ARCH_INDEP   => 8,
+};
+
+# Composed types.
+use constant {
+    BUILD_BINARY       => BUILD_ARCH_DEP | BUILD_ARCH_INDEP,
+    BUILD_SOURCE_DEP   => BUILD_SOURCE | BUILD_ARCH_DEP,
+    BUILD_SOURCE_INDEP => BUILD_SOURCE | BUILD_ARCH_INDEP,
+};
+use constant {
+    BUILD_FULL         => BUILD_BINARY | BUILD_SOURCE,
+};
+
+my $current_type = BUILD_FULL | BUILD_DEFAULT;
+my $current_option = undef;
+
+=back
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item build_has($bits)
+
+Return a boolean indicating whether the current build type has the specified
+$bits.
+
+=cut
+
+sub build_has
+{
+    my ($bits) = @_;
+
+    return ($current_type & $bits) == $bits;
+}
+
+=item build_has_not($bits)
+
+Return a boolean indicating whether the current build type does not have the
+specified $bits.
+
+=cut
+
+sub build_has_not
+{
+    my ($bits) = @_;
+
+    return ($current_type & $bits) != $bits;
+}
+
+=item build_is($bits)
+
+Return a boolean indicating whether the current build type is the specified
+set of $bits.
+
+=cut
+
+sub build_is
+{
+    my ($bits) = @_;
+
+    return $current_type == $bits;
+}
+
+=item set_build_type($build_type, $build_option)
+
+Set the current build type to $build_type, which was specified via the
+$build_option command-line option.
+
+=cut
+
+sub set_build_type
+{
+    my ($build_type, $build_option) = @_;
+
+    usageerr(g_('cannot combine %s and %s'), $current_option, $build_option)
+        if build_has_not(BUILD_DEFAULT) and $current_type != $build_type;
+
+    $current_type = $build_type;
+    $current_option = $build_option;
+}
+
+=back
+
+=head1 CHANGES
+
+=head2 Version 0.xx
+
+This is a private module.
+
+=cut
+
+1;
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 54cfad9..e00f92e 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -59,6 +59,7 @@ nobase_dist_perllib_DATA = \
 	Dpkg/BuildFlags.pm \
 	Dpkg/BuildOptions.pm \
 	Dpkg/BuildProfiles.pm \
+	Dpkg/Build/Types.pm \
 	Dpkg/Changelog.pm \
 	Dpkg/Changelog/Debian.pm \
 	Dpkg/Changelog/Entry.pm \
@@ -205,6 +206,7 @@ test_scripts = \
 	t/Dpkg_BuildFlags.t \
 	t/Dpkg_BuildOptions.t \
 	t/Dpkg_BuildProfiles.t \
+	t/Dpkg_Build_Types.t \
 	t/Dpkg_Checksums.t \
 	t/Dpkg_ErrorHandling.t \
 	t/Dpkg_Exit.t \
diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in
index e662514..d601165 100644
--- a/scripts/po/POTFILES.in
+++ b/scripts/po/POTFILES.in
@@ -21,6 +21,7 @@ scripts/Dpkg/Arch.pm
 scripts/Dpkg/BuildEnv.pm
 scripts/Dpkg/BuildFlags.pm
 scripts/Dpkg/BuildOptions.pm
+scripts/Dpkg/Build/Types.pm
 scripts/Dpkg/Changelog.pm
 scripts/Dpkg/Changelog/Debian.pm
 scripts/Dpkg/Changelog/Entry.pm
diff --git a/scripts/t/Dpkg_Build_Types.t b/scripts/t/Dpkg_Build_Types.t
new file mode 100644
index 0000000..ad8bfa5
--- /dev/null
+++ b/scripts/t/Dpkg_Build_Types.t
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+
+use Test::More tests => 12;
+
+BEGIN {
+    use_ok('Dpkg::Build::Types');
+}
+
+ok(build_is(BUILD_DEFAULT | BUILD_FULL), 'build is default full');
+
+set_build_type(BUILD_DEFAULT | BUILD_BINARY, '--default-binary');
+
+ok(build_is(BUILD_DEFAULT | BUILD_BINARY), 'build is default binary');
+
+set_build_type(BUILD_SOURCE_INDEP, '--source-indep');
+
+ok(build_is(BUILD_SOURCE_INDEP), 'build is source indep');
+ok(!build_is(BUILD_SOURCE_DEP), 'build is not source dep');
+ok(build_has(BUILD_SOURCE), 'build source indep has source');
+ok(build_has(BUILD_ARCH_INDEP), 'build source indep has arch indep');
+ok(build_has_not(BUILD_DEFAULT), 'build source indep has not default');
+ok(build_has_not(BUILD_ARCH_DEP), 'build source indep has not arch dep');
+ok(build_has_not(BUILD_BINARY), 'build source indep has not binary');
+ok(build_has_not(BUILD_SOURCE_DEP), 'build source indep has not source dep');
+ok(build_has_not(BUILD_FULL), 'build source indep has not full');
+
+1;

-- 
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