]> git.proxmox.com Git - dh-cargo.git/commitdiff
Initial version of dh-cargo
authorJosh Triplett <josh@joshtriplett.org>
Mon, 21 Nov 2016 15:16:57 +0000 (07:16 -0800)
committerJosh Triplett <josh@joshtriplett.org>
Mon, 21 Nov 2016 15:16:57 +0000 (07:16 -0800)
cargo.pm [new file with mode: 0644]
config [new file with mode: 0644]
debian/.gitignore [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/dh-cargo.install [new file with mode: 0644]
debian/rules [new file with mode: 0755]
debian/source/format [new file with mode: 0644]

diff --git a/cargo.pm b/cargo.pm
new file mode 100644 (file)
index 0000000..a18aac7
--- /dev/null
+++ b/cargo.pm
@@ -0,0 +1,117 @@
+# debhelper buildsystem for Rust crates using Cargo
+#
+# Josh Triplett <josh@joshtriplett.org>
+
+package Debian::Debhelper::Buildsystem::cargo;
+
+use strict;
+use warnings;
+use Debian::Debhelper::Dh_Lib qw(doit error);
+use Dpkg::Control::Info;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+    "Rust Cargo"
+}
+
+sub check_auto_buildable {
+    my $this = shift;
+    if (-f $this->get_sourcepath("Cargo.toml")) {
+        return 1;
+    }
+    return 0;
+}
+
+sub new {
+    my $class = shift;
+    my $this = $class->SUPER::new(@_);
+    $this->enforce_in_source_building();
+    return $this;
+}
+
+sub pre_building_step {
+    my $this = shift;
+    my $step = shift;
+
+    $this->{cargo_home} = $this->get_buildpath("debian/cargo_home");
+    $ENV{'CARGO_HOME'} = $this->{cargo_home};
+
+    my $control = Dpkg::Control::Info->new();
+    my @packages = $control->get_packages();
+    $this->{libpkg} = 0;
+    $this->{binpkg} = 0;
+    foreach my $package (@packages) {
+        if ($package->{Package} =~ /^librust-.*-dev$/ && $package->{Architecture} eq 'all') {
+            $this->{libpkg} = $package->{Package};
+        } elsif ($package->{Architecture} eq 'any') {
+            $this->{binpkg} = $package->{Package};
+        }
+    }
+    if (!$this->{libpkg} && !$this->{binpkg}) {
+        error("Could not find any Cargo lib or bin packages to build.");
+    }
+
+    my $parallel = $this->get_parallel();
+    $this->{j} = $parallel > 0 ? ["-j$parallel"] : [];
+
+    $this->SUPER::pre_building_step($step);
+}
+
+sub configure {
+    my $this=shift;
+    doit("mkdir", "-p", $this->{cargo_home});
+    doit("cp", "/usr/share/cargo/config", $this->{cargo_home});
+}
+
+sub build {
+    my $this=shift;
+    if ($this->{libpkg}) {
+        # Could skip this and copy the files directly in install if "cargo
+        # package --list0" existed.  See
+        # https://github.com/rust-lang/cargo/issues/3306
+        doit("cargo", "package", "--no-verify");
+    }
+    if ($this->{binpkg}) {
+        doit("cargo", "build", "--release", @{$this->{j}});
+    }
+}
+
+sub install {
+    my $this=shift;
+    if ($this->{libpkg}) {
+        my $target = $this->get_sourcepath("debian/" . $this->{libpkg} . "/usr/share/cargo/registry/");
+        my $pkgdir = $this->get_sourcepath("target/package");
+        opendir(my $dh, $pkgdir);
+        my @crates = grep(/\.crate$/, readdir($dh));
+        closedir($dh);
+        if (@crates != 1) {
+            error("Could not find unique .crate file in $pkgdir");
+        }
+        my $crate_name = $crates[0];
+        my $crate = "$pkgdir/$crate_name";
+        $crate_name =~ s/\.crate$//;
+        doit("mkdir", "-p", $target);
+        doit("tar", "-C", $target, "-x", "--anchored", "--no-wildcards-match-slash", "--exclude=*/debian", "-f", $crate);
+        doit("cp", $this->get_sourcepath("debian/cargo-checksum.json"), "$target/$crate_name/.cargo-checksum.json");
+    }
+    if ($this->{binpkg}) {
+        doit("cargo", "install", "--root", $this->get_sourcepath("debian/" . $this->{binpkg}));
+    }
+}
+
+sub test {
+    my $this=shift;
+    doit("cargo", "test", "--release", @{$this->{j}});
+}
+
+sub clean {
+    my $this=shift;
+    doit("cargo", "clean");
+    doit("rm", "-rf", $this->{cargo_home});
+    # For now, always delete Cargo.lock, since the upstream crates never
+    # include it. This may need to change if future crates start including it.
+    # See https://github.com/rust-lang/cargo/issues/2263
+    doit("rm", "-f", $this->get_sourcepath('Cargo.lock'));
+}
+
+1
diff --git a/config b/config
new file mode 100644 (file)
index 0000000..70dcf1b
--- /dev/null
+++ b/config
@@ -0,0 +1,6 @@
+[source.crates-io]
+replace-with = "debian-registry"
+local-registry = "/nonexistent"
+
+[source.debian-registry]
+directory = "/usr/share/cargo/registry"
diff --git a/debian/.gitignore b/debian/.gitignore
new file mode 100644 (file)
index 0000000..c632272
--- /dev/null
@@ -0,0 +1,4 @@
+debhelper-build-stamp
+dh-cargo
+dh-cargo.substvars
+files
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..bd4bf55
--- /dev/null
@@ -0,0 +1,5 @@
+dh-cargo (1) unstable; urgency=medium
+
+  * Initial Release.
+
+ -- Josh Triplett <josh@joshtriplett.org>  Mon, 21 Nov 2016 06:24:51 -0800
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..f599e28
--- /dev/null
@@ -0,0 +1 @@
+10
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..530e3a0
--- /dev/null
@@ -0,0 +1,16 @@
+Source: dh-cargo
+Section: devel
+Priority: optional
+Maintainer: Rust Maintainers <pkg-rust-maintainers@lists.alioth.debian.org>
+Uploaders: Josh Triplett <josh@joshtriplett.org>
+Build-Depends: debhelper (>= 10)
+Standards-Version: 3.9.8
+Vcs-Git: https://anonscm.debian.org/git/pkg-rust/dh-cargo.git
+Vcs-Browser: https://anonscm.debian.org/cgit/pkg-rust/dh-cargo.git
+
+Package: dh-cargo
+Architecture: all
+Depends: cargo (>= 0.14), debhelper (>= 10), ${misc:Depends}
+Description: debhelper buildsystem for Rust crates using Cargo
+ dh-cargo provides a debhelper buildsystem to build Rust crates using Cargo.
+ Debian packages generated by debcargo use this buildsystem.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..a41f930
--- /dev/null
@@ -0,0 +1,19 @@
+Copyright 2016 Josh Triplett <josh@joshtriplett.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/debian/dh-cargo.install b/debian/dh-cargo.install
new file mode 100644 (file)
index 0000000..63e8bd0
--- /dev/null
@@ -0,0 +1,2 @@
+cargo.pm /usr/share/perl5/Debian/Debhelper/Buildsystem/
+config /usr/share/cargo/
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..cbe925d
--- /dev/null
@@ -0,0 +1,3 @@
+#!/usr/bin/make -f
+%:
+       dh $@
diff --git a/debian/source/format b/debian/source/format
new file mode 100644 (file)
index 0000000..89ae9db
--- /dev/null
@@ -0,0 +1 @@
+3.0 (native)