[dh-r] 01/02: Add dh-update-R

Gordon Ball chronitis-guest at moszumanska.debian.org
Thu Nov 30 16:23:02 UTC 2017


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

chronitis-guest pushed a commit to branch master
in repository dh-r.

commit 12a0753cd6160e2e493954a49f02900567e7cc2f
Author: Gordon Ball <gordon at chronitis.net>
Date:   Thu Nov 30 16:19:16 2017 +0000

    Add dh-update-R
---
 README.md           |   1 +
 debian/changelog    |   6 ++-
 debian/dh-r.install |   1 +
 scripts/dh-update-R | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 806d6fc..e5cfe8d 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,7 @@ In addition:
 
  * R packages already available in the archive are automatically detected and included in the `${R:Depends}`, `${R:Recommends}` and `${R:Suggests}` substvars
  * Script `dh-make-R` generates a `debian/` skeleton from an extracted R package tarball
+ * Script `dh-update-R` updates `debian/control` (particularly `Build-Depends`) after importing a new R tarball
 
 ### Notes
 
diff --git a/debian/changelog b/debian/changelog
index d795ef1..55066bd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-dh-r (20170929) UNRELEASED; urgency=medium
+dh-r (20171130) UNRELEASED; urgency=medium
 
   [ Andreas Tille ]
   * dh-make-R: Vcs-Git != Vcs-Browser
@@ -10,8 +10,10 @@ dh-r (20170929) UNRELEASED; urgency=medium
     Testsuite: autopkgtest-pkg-r, which should enable an autodep8
     namespace-can-be-imported test. This will be ignored if
     d/tests/control is present defining some other test(s).
+  * Add script dh-update-R, which updates some fields in d/control
+    after a new R tarball has been imported
 
- -- Andreas Tille <tille at debian.org>  Mon, 16 Jan 2017 16:48:10 +0100
+ -- Gordon Ball <gordon at chronitis.net>  Thu, 30 Nov 2017 16:01:47 +0000
 
 dh-r (20161219) unstable; urgency=medium
 
diff --git a/debian/dh-r.install b/debian/dh-r.install
index 43d11b8..1754aab 100644
--- a/debian/dh-r.install
+++ b/debian/dh-r.install
@@ -4,3 +4,4 @@ dh/vignette.pm usr/share/perl5/Debian/Debhelper/Sequence
 scripts/convert-to-dh-r usr/share/dh-r
 scripts/dh-make-R usr/bin
 scripts/dh_vignette usr/bin
+scripts/dh-update-R usr/bin
diff --git a/scripts/dh-update-R b/scripts/dh-update-R
new file mode 100755
index 0000000..b3d391a
--- /dev/null
+++ b/scripts/dh-update-R
@@ -0,0 +1,115 @@
+#!/usr/bin/env perl
+
+use feature say;
+use strict;
+use Debian::Debhelper::Buildsystem::R qw(parse_deps);
+use Dpkg::Control;
+use Dpkg::Deps qw(deps_parse);
+use Getopt::Long;
+use Pod::Usage;
+
+my $opt_desc = 0;
+my $opt_help = 0;
+
+GetOptions('help|?' => \$opt_help, 'desc|d' => \$opt_desc);
+pod2usage(1) if $opt_help;
+
+( -d "debian") or die "No debian/ directory, this tool updates existing R packaging";
+( -e "DESCRIPTION") or die "No DESCRIPTION file, is this an R package?";
+
+my $desc = Dpkg::Control->new(type => Dpkg::Control::CTRL_UNKNOWN);
+$desc->load("DESCRIPTION");
+
+my $dctrl = Dpkg::Control::Info->new();
+$dctrl->load("debian/control");
+
+my $dsrc = $dctrl->get_source();
+my $dbin = $dctrl->get_pkg_by_idx(1);
+
+my @aptavail = qx/grep-aptavail -P -s Package -n -e ^r-/;
+my %apthash;
+ at apthash{@aptavail} = ();
+
+sub deps_concat {
+    # Dpkg::Deps::deps_concat generates "dep, , , " if some arguments are empty strings
+    my (@dep_list) = @_;
+    @dep_list = grep { /[a-z]/ } @dep_list;
+    return join ', ', @dep_list;
+}
+
+sub unmanaged {
+    my $rawtext = shift;
+    # deps_parse errors on substvars like ${R:Depends}, so split it manually
+    my @deps = split(/\s*,\s*/m, $rawtext);
+    my @keep;
+    foreach my $d (@deps) {
+        if ($d !~ /^(r-|debhelper|dh-r|\$)/) {
+            say "I: keeping unmanaged dependency: $d";
+            push(@keep, $d);
+        }
+    }
+    return deps_concat(@keep);
+}
+
+my $unmanaged_builddeps = unmanaged($dsrc->{'Build-Depends'});
+my $unmanaged_depends = unmanaged($dbin->{Depends});
+my $unmanaged_recommends = unmanaged($dbin->{Recommends});
+my $unmanaged_suggests = unmanaged($dbin->{Suggests});
+
+my $rdepends = deps_concat(Debian::Debhelper::Buildsystem::R::parse_depends("Depends", $desc->{Depends}, \%apthash));
+my $rimports = deps_concat(Debian::Debhelper::Buildsystem::R::parse_depends("Imports", $desc->{Imports}, \%apthash));
+
+my $compiled = lc $desc->{NeedsCompilation} eq "yes";
+say "I: Updating Build-Depends";
+$dsrc->{'Build-Depends'} = deps_concat("debhelper (>= 10)", "dh-r", "r-base-dev", $rdepends, $rimports, $unmanaged_builddeps);
+say "I: Updating binary Depends, Recommends, Suggests";
+$dbin->{Depends} = deps_concat("\${R:Depends}", $compiled ? "\${shlibs:Depends}" : "", "\${misc:Depends}", $unmanaged_depends);
+$dbin->{Recommends} = deps_concat("\${R:Recommends}", $unmanaged_recommends);
+$dbin->{Suggests} = deps_concat("\${R:Suggests}", $unmanaged_suggests);
+
+if ( ! -e 'debian/tests/control' & ! exists $dsrc->{Testsuite} ) {
+    say "W: No debian/tests/control and no Testsuite field, adding Testsuite: autopkgtest-pkg-r";
+    $dsrc->{Testsuite} = "autopkgtest-pkg-r";
+}
+
+if ($opt_desc) {
+    say "I: Updating package description";
+    my $longdesc = $desc->{Description};
+    $longdesc =~ s/^\s*/ /gm;
+    $dbin->{Description} = "$desc->{Title}\n$longdesc";
+}
+
+open(my $fh, ">", "debian/control") or die "Can't write to debian/control";
+$dctrl->output($fh);
+close($fh);
+
+__END__
+
+=head1 NAME
+
+dh-update-R - Updates d/control for a debian R package
+
+=head1 SYNOPSIS
+
+dh-update-R [options]
+
+ Options:
+    --help
+    --desc Update the package description
+
+=head1 OPTIONS
+
+=over 8
+
+=item B<--help>
+
+Print this help message.
+
+=back
+
+=head1 DESCRIPTION
+
+B<dh-update-R> should be run from the root of an unpacked R tarball (ie, the
+directory containing DESCRIPTION), where there is already a debian/ directory.
+This tools attempts to update files in debian/ after a new upstream version has
+been imported.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/dh-r.git



More information about the debian-science-commits mailing list