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

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=bd91c90b0ffaba0923a248a8472e6c6ac4b8e565

commit bd91c90b0ffaba0923a248a8472e6c6ac4b8e565
Author: Guillem Jover <[email protected]>
AuthorDate: Mon Jul 10 02:31:53 2023 +0200

    dpkg-buildtree: New program
    
    This is a new helper program that initially will try to abstract
    operations that deal with internal dpkg implementation details where
    packagers in general should not need to be concerned about.
    
    The first operation introduced is to clean state files generated by
    various dpkg tools, so that we can eventually move their locations
    through a new dpkg-build-api level for example.
---
 debian/README.bug-usertags |   2 +
 debian/dpkg-dev.install    |   1 +
 debian/dpkg-dev.manpages   |   1 +
 man/Makefile.am            |   2 +
 man/dpkg-buildtree.pod     |  98 ++++++++++++++++++++++++++++++++++++++
 man/po/po4a.cfg            |   1 +
 scripts/.gitignore         |   1 +
 scripts/Dpkg/BuildTree.pm  | 115 +++++++++++++++++++++++++++++++++++++++++++++
 scripts/Makefile.am        |   4 ++
 scripts/dpkg-buildtree.pl  |  75 +++++++++++++++++++++++++++++
 scripts/po/POTFILES.in     |   2 +
 scripts/t/Dpkg_BuildTree.t |  64 +++++++++++++++++++++++++
 t/pod-spell.t              |   1 +
 13 files changed, 367 insertions(+)

diff --git a/debian/README.bug-usertags b/debian/README.bug-usertags
index 68ea1efdc..6077c00ea 100644
--- a/debian/README.bug-usertags
+++ b/debian/README.bug-usertags
@@ -52,6 +52,7 @@ dpkg-architecture
 dpkg-buildapi
 dpkg-buildflags
 dpkg-buildpackage
+dpkg-buildtree
 dpkg-checkbuilddeps
 dpkg-db-backup
 dpkg-deb
@@ -119,6 +120,7 @@ usercategory dpkg-program [hidden]
   + dpkg-buildapi [tag=dpkg-buildapi]
   + dpkg-buildflags [tag=dpkg-buildflags]
   + dpkg-buildpackage [tag=dpkg-buildpackage]
+  + dpkg-buildtree [tag=dpkg-buildtree]
   + dpkg-checkbuilddeps [tag=dpkg-checkbuilddeps]
   + dpkg-distaddfile [tag=dpkg-distaddfile]
   + dpkg-genbuildinfo [tag=dpkg-genbuildinfo]
diff --git a/debian/dpkg-dev.install b/debian/dpkg-dev.install
index aa95e5ae5..552352fef 100644
--- a/debian/dpkg-dev.install
+++ b/debian/dpkg-dev.install
@@ -5,6 +5,7 @@ usr/bin/dpkg-architecture
 usr/bin/dpkg-buildapi
 usr/bin/dpkg-buildflags
 usr/bin/dpkg-buildpackage
+usr/bin/dpkg-buildtree
 usr/bin/dpkg-checkbuilddeps
 usr/bin/dpkg-distaddfile
 usr/bin/dpkg-genbuildinfo
diff --git a/debian/dpkg-dev.manpages b/debian/dpkg-dev.manpages
index 2c6241380..0b4e54fd4 100644
--- a/debian/dpkg-dev.manpages
+++ b/debian/dpkg-dev.manpages
@@ -29,6 +29,7 @@ usr/share/man/{*,*/*}/dpkg-build-api.7
 usr/share/man/{*,*/*}/dpkg-buildapi.1
 usr/share/man/{*,*/*}/dpkg-buildflags.1
 usr/share/man/{*,*/*}/dpkg-buildpackage.1
+usr/share/man/{*,*/*}/dpkg-buildtree.1
 usr/share/man/{*,*/*}/dpkg-checkbuilddeps.1
 usr/share/man/{*,*/*}/dpkg-distaddfile.1
 usr/share/man/{*,*/*}/dpkg-genbuildinfo.1
diff --git a/man/Makefile.am b/man/Makefile.am
index 075bef801..5b437a3e2 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -32,6 +32,7 @@ man_MANS = \
        dpkg-buildapi.1 \
        dpkg-buildflags.1 \
        dpkg-buildpackage.1 \
+       dpkg-buildtree.1 \
        dpkg-checkbuilddeps.1 \
        dpkg-deb.1 \
        dpkg-distaddfile.1 \
@@ -121,6 +122,7 @@ EXTRA_DIST += \
        dpkg-buildapi.pod \
        dpkg-buildflags.pod \
        dpkg-buildpackage.pod \
+       dpkg-buildtree.pod \
        dpkg-checkbuilddeps.pod \
        dpkg-deb.pod \
        dpkg-distaddfile.pod \
diff --git a/man/dpkg-buildtree.pod b/man/dpkg-buildtree.pod
new file mode 100644
index 000000000..660ebb0f1
--- /dev/null
+++ b/man/dpkg-buildtree.pod
@@ -0,0 +1,98 @@
+# dpkg manual page - dpkg-buildtree(1)
+#
+# Copyright © 2023 Guillem Jover <[email protected]>
+#
+# This 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 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/>.
+
+=encoding utf8
+
+=head1 NAME
+
+dpkg-buildtree - helper for build tree operations during package builds
+
+=head1 SYNOPSIS
+
+B<dpkg-buildtree> [I<option>...] [I<command>]
+
+=head1 DESCRIPTION
+
+B<dpkg-buildtree> is a tool to perform common operations on the build tree
+for a source package.
+
+This program was introduced in dpkg 1.22.3.
+
+=head1 COMMANDS
+
+=over
+
+=item B<clean>
+
+Removes all artifacts generated during a build by the various dpkg tools,
+and pathnames used or controlled by dpkg tools that are safe to clean.
+These files are used to track state between package build runs,
+and are in many cases internal implementation details the packager should
+not be concerned about,
+or are staging directories containing build artifacts.
+
+=item B<--help>
+
+Show the usage message and exit.
+
+=item B<--version>
+
+Show the version and exit.
+
+=back
+
+=head1 FILES
+
+=head2 Cleaned files
+
+=over
+
+=item F<debian/files>
+
+=item F<debian/files.new>
+
+Files generated by L<dpkg-distaddfile(1)>.
+
+=item F<debian/substvars>
+
+=item F<debian/substvars.new>
+
+Files generated by L<dpkg-shlibdeps(1)>.
+
+=item F<debian/tmp>
+
+Staging directory containing the contents to be used when creating a package.
+Both L<dpkg-gencontrol(1)> and L<dpkg-gensymbols(1)> generate files within.
+
+=back
+
+=head1 EXAMPLES
+
+=head2 Usage in debian/rules
+
+You can call B<dpkg-buildtree clean> from the F<debian/rules> B<clean> target,
+after having performed other necessary cleanups.
+
+For example for an autoconf-like build system:
+
+=over
+
+  clean:
+       [ ! -f Makefile ] || $(MAKE) distclean
+       dpkg-buildtree clean
+
+=back
diff --git a/man/po/po4a.cfg b/man/po/po4a.cfg
index 97c073b9c..8be949633 100644
--- a/man/po/po4a.cfg
+++ b/man/po/po4a.cfg
@@ -35,6 +35,7 @@
 [type:pod] dpkg-buildapi.pod $lang:$lang/dpkg-buildapi.pod
 [type:pod] dpkg-buildflags.pod $lang:$lang/dpkg-buildflags.pod
 [type:pod] dpkg-buildpackage.pod $lang:$lang/dpkg-buildpackage.pod
+[type:pod] dpkg-buildtree.pod $lang:$lang/dpkg-buildtree.pod
 [type:pod] dpkg-checkbuilddeps.pod $lang:$lang/dpkg-checkbuilddeps.pod
 [type:pod] dpkg-deb.pod $lang:$lang/dpkg-deb.pod
 [type:pod] dpkg-distaddfile.pod $lang:$lang/dpkg-distaddfile.pod
diff --git a/scripts/.gitignore b/scripts/.gitignore
index b1c8335aa..feea933e6 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -4,6 +4,7 @@ dpkg-architecture
 dpkg-buildapi
 dpkg-buildflags
 dpkg-buildpackage
+dpkg-buildtree
 dpkg-checkbuilddeps
 dpkg-distaddfile
 dpkg-fsys-usrunmess
diff --git a/scripts/Dpkg/BuildTree.pm b/scripts/Dpkg/BuildTree.pm
new file mode 100644
index 000000000..7943eb41d
--- /dev/null
+++ b/scripts/Dpkg/BuildTree.pm
@@ -0,0 +1,115 @@
+# Copyright © 2023 Guillem Jover <[email protected]>
+#
+# 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/>.
+
+=encoding utf8
+
+=head1 NAME
+
+Dpkg::BuildTree - handle build tree actions
+
+=head1 DESCRIPTION
+
+The Dpkg::BuildTree module provides functions to handle build tree actions.
+
+B<Note>: This is a private module, its API can change at any time.
+
+=cut
+
+package Dpkg::BuildTree 0.01;
+
+use strict;
+use warnings;
+
+use Cwd;
+
+use Dpkg::Source::Functions qw(erasedir);
+
+=head1 METHODS
+
+=over 4
+
+=item $bt = Dpkg::BuildTree->new(%opts)
+
+Create a new Dpkg::BuildTree object.
+Supported options are:
+
+=over 8
+
+=item dir
+
+The build tree directory.
+If not specified, it assumes the current working directory.
+
+=back
+
+=cut
+
+sub new {
+    my ($this, %opts) = @_;
+    my $class = ref($this) || $this;
+
+    my $self = {
+        buildtree => $opts{dir} || getcwd(),
+    };
+    bless $self, $class;
+
+    return $self;
+}
+
+=item $bt->clean()
+
+Clean the build tree, by removing any dpkg generated artifacts.
+
+=cut
+
+sub clean {
+    my $self = shift;
+
+    my $buildtree = $self->{buildtree};
+
+    # If this does not look like a build tree, do nothing.
+    return unless -f "$buildtree/debian/control";
+
+    my @files = qw(
+        debian/files
+        debian/files.new
+        debian/substvars
+        debian/substvars.new
+    );
+    my @dirs = qw(
+        debian/tmp
+    );
+
+    foreach my $file (@files) {
+        unlink "$buildtree/$file";
+    }
+    foreach my $dir (@dirs) {
+        erasedir("$buildtree/$dir");
+    }
+
+    return;
+}
+
+=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 1132a1d88..1cec2052b 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -11,6 +11,7 @@ bin_SCRIPTS = \
        dpkg-buildflags \
        dpkg-buildapi \
        dpkg-buildpackage \
+       dpkg-buildtree \
        dpkg-checkbuilddeps \
        dpkg-distaddfile \
        dpkg-genbuildinfo \
@@ -32,6 +33,7 @@ EXTRA_DIST = \
        dpkg-buildapi.pl \
        dpkg-buildflags.pl \
        dpkg-buildpackage.pl \
+       dpkg-buildtree.pl \
        dpkg-checkbuilddeps.pl \
        dpkg-distaddfile.pl \
        dpkg-fsys-usrunmess.pl \
@@ -70,6 +72,7 @@ nobase_dist_perllib_DATA = \
        Dpkg/BuildInfo.pm \
        Dpkg/BuildOptions.pm \
        Dpkg/BuildProfiles.pm \
+       Dpkg/BuildTree.pm \
        Dpkg/BuildTypes.pm \
        Dpkg/Build/Info.pm \
        Dpkg/Changelog.pm \
@@ -235,6 +238,7 @@ test_scripts = \
        t/Dpkg_BuildInfo.t \
        t/Dpkg_BuildOptions.t \
        t/Dpkg_BuildProfiles.t \
+       t/Dpkg_BuildTree.t \
        t/Dpkg_BuildTypes.t \
        t/Dpkg_Checksums.t \
        t/Dpkg_ErrorHandling.t \
diff --git a/scripts/dpkg-buildtree.pl b/scripts/dpkg-buildtree.pl
new file mode 100755
index 000000000..f25059813
--- /dev/null
+++ b/scripts/dpkg-buildtree.pl
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+#
+# dpkg-buildtree
+#
+# Copyright © 2023 Guillem Jover <[email protected]>
+#
+# 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 Dpkg ();
+use Dpkg::Gettext;
+use Dpkg::ErrorHandling;
+use Dpkg::BuildTree;
+
+textdomain('dpkg-dev');
+
+sub version {
+    printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
+
+    printf g_('
+This is free software; see the GNU General Public License version 2 or
+later for copying conditions. There is NO warranty.
+');
+}
+
+sub usage {
+    printf g_(
+'Usage: %s [<command>]')
+    . "\n\n" . g_(
+'Commands:
+  clean              clean dpkg generated artifacts from the build tree.
+  --help             show this help message.
+  --version          show the version.
+'), $Dpkg::PROGNAME;
+}
+
+my $action;
+
+while (@ARGV) {
+    my $arg = shift @ARGV;
+    if ($arg eq 'clean') {
+        usageerr(g_('two commands specified: %s and %s'), $1, $action)
+            if defined $action;
+        $action = $arg;
+    } elsif ($arg eq '-?' or $arg eq '--help') {
+        usage();
+        exit 0;
+    } elsif ($arg eq '--version') {
+        version();
+        exit 0;
+    } else {
+        usageerr(g_("unknown option '%s'"), $arg);
+    }
+}
+
+usageerr(g_('missing action')) unless $action;
+
+my $bt = Dpkg::BuildTree->new();
+
+if ($action eq 'clean') {
+    $bt->clean();
+}
diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in
index f382a3af8..125792b6c 100644
--- a/scripts/po/POTFILES.in
+++ b/scripts/po/POTFILES.in
@@ -4,6 +4,7 @@ scripts/dpkg-architecture.pl
 scripts/dpkg-buildapi.pl
 scripts/dpkg-buildflags.pl
 scripts/dpkg-buildpackage.pl
+scripts/dpkg-buildtree.pl
 scripts/dpkg-checkbuilddeps.pl
 scripts/dpkg-distaddfile.pl
 scripts/dpkg-genbuildinfo.pl
@@ -26,6 +27,7 @@ scripts/Dpkg/BuildFlags.pm
 scripts/Dpkg/BuildInfo.pm
 scripts/Dpkg/BuildOptions.pm
 scripts/Dpkg/BuildProfiles.pm
+scripts/Dpkg/BuildTree.pm
 scripts/Dpkg/BuildTypes.pm
 scripts/Dpkg/Build/Info.pm
 scripts/Dpkg/Changelog.pm
diff --git a/scripts/t/Dpkg_BuildTree.t b/scripts/t/Dpkg_BuildTree.t
new file mode 100644
index 000000000..baef2aa5e
--- /dev/null
+++ b/scripts/t/Dpkg_BuildTree.t
@@ -0,0 +1,64 @@
+#!/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 => 11;
+use Test::Dpkg qw(:paths);
+
+use Cwd qw(realpath);
+use File::Path qw(make_path rmtree);
+use File::Spec::Functions qw(abs2rel);
+
+use Dpkg::File;
+
+use_ok('Dpkg::BuildTree');
+
+my $tmpdir = test_get_temp_path();
+
+make_path("$tmpdir/debian/tmp");
+
+my @srcfiles = qw(
+    changelog
+    control
+    copyright
+    shlibs.local
+);
+
+my @genfiles = qw(
+    files
+    files.new
+    substvars
+    substvars.new
+    tmp/build-object
+    tmp/generated
+);
+
+foreach my $file (@srcfiles, @genfiles) {
+    file_touch("$tmpdir/debian/$file");
+}
+
+my $bt = Dpkg::BuildTree->new(dir => $tmpdir);
+
+$bt->clean();
+
+foreach my $srcfile (@srcfiles) {
+    ok(-e "$tmpdir/debian/$srcfile", "source file $tmpdir/$srcfile exists");
+}
+
+foreach my $genfile (@genfiles) {
+    ok(! -e "$tmpdir/debian/$genfile", "generated file $tmpdir/$genfile does 
not exist");
+}
diff --git a/t/pod-spell.t b/t/pod-spell.t
index dfb2102c0..5edaa6419 100644
--- a/t/pod-spell.t
+++ b/t/pod-spell.t
@@ -64,6 +64,7 @@ debian
 decompressor
 dep
 deps
+dir
 dpkg
 dpkg-buildapi
 dpkg-buildflags

-- 
Dpkg.Org's dpkg

Reply via email to