Skip to content

Commit cee091c

Browse files
pauldrapermuuki88
authored andcommitted
Don't compress debian packages (#787)
Also allow custom options to dpkg-deb --build
1 parent ae04b90 commit cee091c

File tree

10 files changed

+55
-4
lines changed

10 files changed

+55
-4
lines changed

src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
158158
(maintainerScripts in Debian).value,
159159
(linuxScriptReplacements in Debian).value,
160160
(target in Universal).value
161-
)
161+
),
162+
debianNativeBuildOptions := Nil
162163
)
163164

164165
/**

src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala

+2
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ trait DebianKeys {
4949
val debianMakeChownReplacements = TaskKey[(String, String)]("debianMakeChownReplacements", "Creates the chown commands for correct own files and directories")
5050

5151
val debianPackageInstallSize = TaskKey[Long]("debian-installed-size")
52+
53+
val debianNativeBuildOptions = SettingKey[Seq[String]]("debian-native-build-options", "Options passed to dpkg-deb, e.g. compression level")
5254
}

src/main/scala/com/typesafe/sbt/packager/debian/NativePackaging.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ trait DebianNativePackaging extends DebianPluginLike {
4343
* package.
4444
*/
4545
private[debian] def debianNativeSettings: Seq[Setting[_]] = inConfig(Debian)(Seq(
46+
debianNativeBuildOptions += "-Znone", // packages are largely JARs, which are already compressed
4647
genChanges <<= (packageBin, target, debianChangelog, name, version, debianPackageMetadata) map {
4748
(pkg, tdir, changelog, name, version, data) =>
4849
changelog match {
@@ -81,12 +82,12 @@ trait DebianNativePackaging extends DebianPluginLike {
8182
},
8283

8384
/** Implementation of the actual packaging */
84-
packageBin <<= (debianExplodedPackage, debianMD5sumsFile, debianSection, debianPriority, name, version, packageArchitecture, target, streams) map {
85-
(pkgdir, _, section, priority, name, version, arch, tdir, s) =>
85+
packageBin <<= (debianExplodedPackage, debianMD5sumsFile, debianSection, debianPriority, name, version, packageArchitecture, debianNativeBuildOptions, target, streams) map {
86+
(pkgdir, _, section, priority, name, version, arch, options, tdir, s) =>
8687
s.log.info("Building debian package with native implementation")
8788
// Make the package. We put this in fakeroot, so we can build the package with root owning files.
8889
val archive = archiveFilename(name, version, arch)
89-
Process(Seq("fakeroot", "--", "dpkg-deb", "--build", pkgdir.getAbsolutePath, "../" + archive), Some(tdir)) ! s.log match {
90+
Process(Seq("fakeroot", "--", "dpkg-deb", "--build") ++ options ++ Seq(pkgdir.getAbsolutePath, "../" + archive), Some(tdir)) ! s.log match {
9091
case 0 => ()
9192
case x => sys.error("Failure packaging debian file. Exit code: " + x)
9293
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enablePlugins(DebianPlugin)
2+
3+
debianNativeBuildOptions in Debian := Nil
4+
5+
maintainer := "Maintainer <[email protected]>"
6+
7+
packageDescription := "Description"
8+
9+
packageSummary := "Summary"
10+
11+
TaskKey[Unit]("check-deb-compression") := {
12+
val deb = target.value / s"${(name in Debian).value}_${(version in Debian).value}_all.deb"
13+
assert(Seq("ar", "-t", deb.toString).lines.exists(_.startsWith("data.tar."))) // exact extension varies by dpkg-deb version
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> debian:packageBin
2+
> check-deb-compression
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
enablePlugins(DebianPlugin)
2+
3+
maintainer := "Maintainer <[email protected]>"
4+
5+
packageDescription := "Description"
6+
7+
packageSummary := "Summary"
8+
9+
TaskKey[Unit]("check-deb-compression") := {
10+
val deb = target.value / s"${(name in Debian).value}_${(version in Debian).value}_all.deb"
11+
assert(Seq("ar", "-t", deb.toString).lines.contains("data.tar"))
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> debian:packageBin
2+
> check-deb-compression

src/sphinx/formats/debian.rst

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ Enable the debian plugin to activate the native package implementation.
5656
5757
enablePlugins(DebianPlugin)
5858
59+
Native packaging
60+
~~~~~~~~~~~~~~~~
61+
62+
Since JARs are by default already compressed, `DebianPlugin` disables additional compression of the debian package
63+
contents.
64+
65+
To compress the debian package, override `debianNativeBuildOptions` with
66+
`options <http://man7.org/linux/man-pages/man1/dpkg-deb.1.html>`_ for `dpkg-deb`.
67+
68+
.. code-block:: scala
69+
70+
debianNativeBuildOptions in Debian := Nil // dpkg-deb's default compression (currently xz)
71+
72+
debianNativeBuildOptions in Debian := Seq("-Zgzip", "-z3") // gzip compression at level 3
73+
5974
Java based packaging
6075
~~~~~~~~~~~~~~~~~~~~
6176

0 commit comments

Comments
 (0)