Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for 'Provides' and 'Conflicts' sections for debian packaging #803

Merged
merged 1 commit into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ case class PackageMetaData(
priority: String = "optional",
architecture: String = "all",
section: String = "java",
conflicts: Seq[String] = Seq.empty,
depends: Seq[String] = Seq.empty,
provides: Seq[String] = Seq.empty,
recommends: Seq[String] = Seq.empty
) {
def makeContent(installSizeEstimate: Long = 0L): String = {
Expand All @@ -29,10 +31,14 @@ case class PackageMetaData(
sb append ("Priority: %s\n" format priority)
sb append ("Architecture: %s\n" format architecture)
sb append ("Installed-Size: %d\n" format installSizeEstimate)
if (!depends.isEmpty)
if (depends.nonEmpty)
sb append ("Depends: %s\n" format (depends mkString ", "))
if (!recommends.isEmpty)
if (recommends.nonEmpty)
sb append ("Recommends: %s\n" format (recommends mkString ", "))
if (provides.nonEmpty)
sb append ("Provides: %s\n" format (provides mkString ", "))
if (conflicts.nonEmpty)
sb append ("Conflicts: %s\n" format (conflicts mkString ", "))
sb append ("Maintainer: %s\n" format info.maintainer)
sb append ("Description: %s\n %s\n" format (info.summary, info.description))
sb toString
Expand All @@ -49,10 +55,14 @@ case class PackageMetaData(
sb append ("Architecture: %s\n" format architecture)
sb append ("Section: %s\n" format section)
sb append ("Priority: %s\n" format priority)
if (!depends.isEmpty)
if (depends.nonEmpty)
sb append ("Depends: %s\n" format (depends mkString ", "))
if (!recommends.isEmpty)
if (recommends.nonEmpty)
sb append ("Recommends: %s\n" format (recommends mkString ", "))
if (provides.nonEmpty)
sb append ("Provides: %s\n" format (provides mkString ", "))
if (conflicts.nonEmpty)
sb append ("Conflicts: %s\n" format (conflicts mkString ", "))
sb append ("Description: %s\n %s\n" format (info.summary, info.description))
sb toString
}
Expand All @@ -79,4 +89,4 @@ case class DebianControlScriptReplacements(
"name" -> name,
"version" -> version
)
}
}
18 changes: 10 additions & 8 deletions src/main/scala/com/typesafe/sbt/packager/debian/DebianPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
/* ==== Debian default settings ==== */
debianPriority := "optional",
debianSection := "java",
debianPackageConflicts := Seq.empty,
debianPackageDependencies := Seq.empty,
debianPackageProvides := Seq.empty,
debianPackageRecommends := Seq.empty,
debianSignRole := "builder",
target in Debian <<= (target, name in Debian, version in Debian) apply ((t, n, v) => t / (n + "-" + v)),
Expand Down Expand Up @@ -118,8 +120,8 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
Names.Postrm -> defaultMaintainerScript(Names.Postrm).toSeq.flatten
)

// this is for legacy purposes to keep old behaviour
// --- legacy starts
// this is for legacy purposes to keep old behaviour
// --- legacy starts
def readContent(scriptFiles: Seq[(File, String)]): Map[String, Seq[String]] = scriptFiles.map {
case (scriptFile, scriptName) => scriptName -> IO.readLines(scriptFile)
}.toMap
Expand All @@ -131,24 +133,24 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
debianMakePostrmScript.value.map(script => script -> Names.Postrm)
).flatten)

// these things get appended. Don't check for nonexisting keys as they are already in the default scripts map
// these things get appended. Don't check for nonexisting keys as they are already in the default scripts map
val appendedScripts = scripts.map {
case (scriptName, content) => scriptName -> (content ++ userProvided.getOrElse(scriptName, Nil))
}
// override and merge with the user defined scripts. Will change in the future
// override and merge with the user defined scripts. Will change in the future
val controlScriptsDir = debianControlScriptsDirectory.value
val overridenScripts = scripts ++ readContent(Seq(
scriptMapping(Names.Prerm, debianMakePrermScript.value, controlScriptsDir),
scriptMapping(Names.Preinst, debianMakePreinstScript.value, controlScriptsDir),
scriptMapping(Names.Postinst, debianMakePostinstScript.value, controlScriptsDir),
scriptMapping(Names.Postrm, debianMakePostrmScript.value, controlScriptsDir)
).flatten)
// --- legacy ends
// --- legacy ends

// TODO remove the overridenScripts
// TODO remove the overridenScripts
val content = appendedScripts ++ overridenScripts

// apply all replacements
// apply all replacements
content.mapValues { lines =>
TemplateWriter.generateScriptFromLines(lines, replacements)
}
Expand All @@ -171,7 +173,7 @@ object DebianPlugin extends AutoPlugin with DebianNativePackaging {
packageArchitecture := "all",
debianPackageInfo <<= (packageName, version, maintainer, packageSummary, packageDescription) apply PackageInfo,
debianPackageMetadata <<= (debianPackageInfo, debianPriority, packageArchitecture, debianSection,
debianPackageDependencies, debianPackageRecommends) apply PackageMetaData,
debianPackageConflicts, debianPackageDependencies, debianPackageProvides, debianPackageRecommends) apply PackageMetaData,
debianPackageInstallSize <<= linuxPackageMappings map { mappings =>
(for {
LinuxPackageMapping(files, _, zipped) <- mappings
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ trait DebianKeys {
// Metadata keys
val debianSection = SettingKey[String]("debian-section", "The section category for this deb file.")
val debianPriority = SettingKey[String]("debian-priority")
val debianPackageConflicts = SettingKey[Seq[String]]("debian-package-conflicts", "Packages that conflict with the currently packaged one.")
val debianPackageDependencies = SettingKey[Seq[String]]("debian-package-dependencies", "Packages that this debian package depends on.")
val debianPackageProvides = SettingKey[Seq[String]]("debian-package-provides", "Packages that are provided by the currently packaged one.")
val debianPackageRecommends = SettingKey[Seq[String]]("debian-package-recommends", "Packages recommended to use with the currently packaged one.")
val debianPackageInfo = SettingKey[PackageInfo]("debian-package-info", "Information (name, version, etc.) about a debian package.")
val debianPackageMetadata = SettingKey[PackageMetaData]("debian-package-metadata", "Meta data used when constructing a debian package.")
Expand Down Expand Up @@ -51,4 +53,4 @@ trait DebianKeys {
val debianPackageInstallSize = TaskKey[Long]("debian-installed-size")

val debianNativeBuildOptions = SettingKey[Seq[String]]("debian-native-build-options", "Options passed to dpkg-deb, e.g. compression level")
}
}
25 changes: 25 additions & 0 deletions src/sbt-test/debian/jdeb-conflicts/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
enablePlugins(JavaServerAppPackaging, JDebPackaging)

name := "debian-test"

version := "0.1.0"

maintainer := "Josh Suereth <[email protected]>"

packageSummary := "Test debian package"

packageDescription := """A fun package description of our software,
with multiple lines."""

debianPackageConflicts in Debian := Seq("debian-test-package")

TaskKey[Unit]("check-conflicts") <<= (target, streams) map { (target, out) =>
val extracted = target / "extracted"
Seq("dpkg-deb", "-R", (target / "debian-test_0.1.0_all.deb").absolutePath, extracted.absolutePath).!

val control = IO.read(extracted / "DEBIAN" / "control")
assert(control.contains("Conflicts:"))

out.log.success("Successfully tested systemV control files")
()
}
3 changes: 3 additions & 0 deletions src/sbt-test/debian/jdeb-conflicts/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))

libraryDependencies += "org.vafer" % "jdeb" % "1.3" artifacts (Artifact("jdeb", "jar", "jar"))
5 changes: 5 additions & 0 deletions src/sbt-test/debian/jdeb-conflicts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Run the debian packaging.
$ mkdir src/resources/empty
> debian:package-bin
$ exists target/debian-test_0.1.0_all.deb
> check-conflicts
25 changes: 25 additions & 0 deletions src/sbt-test/debian/jdeb-provides/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
enablePlugins(JavaServerAppPackaging, JDebPackaging)

name := "debian-test"

version := "0.1.0"

maintainer := "Josh Suereth <[email protected]>"

packageSummary := "Test debian package"

packageDescription := """A fun package description of our software,
with multiple lines."""

debianPackageProvides in Debian := Seq("debian-test-package")

TaskKey[Unit]("check-provides") <<= (target, streams) map { (target, out) =>
val extracted = target / "extracted"
Seq("dpkg-deb", "-R", (target / "debian-test_0.1.0_all.deb").absolutePath, extracted.absolutePath).!

val control = IO.read(extracted / "DEBIAN" / "control")
assert(control.contains("Provides:"))

out.log.success("Successfully tested systemV control files")
()
}
3 changes: 3 additions & 0 deletions src/sbt-test/debian/jdeb-provides/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))

libraryDependencies += "org.vafer" % "jdeb" % "1.3" artifacts (Artifact("jdeb", "jar", "jar"))
5 changes: 5 additions & 0 deletions src/sbt-test/debian/jdeb-provides/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Run the debian packaging.
$ mkdir src/resources/empty
> debian:package-bin
$ exists target/debian-test_0.1.0_all.deb
> check-provides
4 changes: 4 additions & 0 deletions src/sbt-test/debian/simple-deb/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ packageSummary := "Test debian package"
packageDescription := """A fun package description of our software,
with multiple lines."""

debianPackageConflicts in Debian += "debian-other-test-package"

debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11)")

debianPackageProvides in Debian += "debian-test-package"

debianPackageRecommends in Debian += "git"
4 changes: 4 additions & 0 deletions src/sbt-test/debian/simple-jdeb/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ packageSummary := "Test debian package"
packageDescription := """A fun package description of our software,
with multiple lines."""

debianPackageConflicts in Debian += "debian-other-test-package"

debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11)")

debianPackageProvides in Debian += "debian-test-package"

debianPackageRecommends in Debian += "git"
6 changes: 6 additions & 0 deletions src/sphinx/formats/debian.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ Debian requires the following specific settings:
``version in Debian``
The debian-friendly version of the package. Should be of the form ``x.y.z-build-aa``.

``debianPackageConflicts in Debian``
The list of debian packages that this package conflicts with.

``debianPackageDependencies in Debian``
The list of debian packages that this package depends on.

``debianPackageProvides in Debian``
The list of debian packages that are provided by this package.

``debianPackageRecommends in Debian``
The list of debian packages that are recommended to be installed with this package.

Expand Down