Skip to content

Commit

Permalink
#1178 attempt at adding in rpm epochs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ophirr33 authored and Ty Coghlan committed Dec 11, 2018
1 parent 596eb92 commit 83bac3c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1917,4 +1917,4 @@
## [0.1.0](https://github.com/sbt/sbt-native-packager/tree/0.1.0) (2012-01-16)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
2 changes: 2 additions & 0 deletions integration-tests-ansible/test-project-play-rpm/packaging.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ rpmRelease := "1"
rpmVendor := "DemoVendor"

rpmLicense := Some("Apache-2.0")

rpmEpoch := Some(1)
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trait RpmKeys {
// DESCRIPTION KEYS
// TODO - Summary and license are required.
val rpmLicense = SettingKey[Option[String]]("rpm-license", "License of the code within the RPM.")
val rpmEpoch = SettingKey[Option[Int]]("rpm-epoch", "Epoch of the generated RPM.")
val rpmDistribution = SettingKey[Option[String]]("rpm-distribution")
val rpmUrl =
SettingKey[Option[String]]("rpm-url", "Url to include in the RPM.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ case class RpmMetadata(name: String,
summary: String,
description: String,
autoprov: String,
autoreq: String)
autoreq: String,
epoch: Option[Int])

/**
* The Description used to generate an RPM
Expand Down Expand Up @@ -222,6 +223,11 @@ case class RpmSpec(meta: RpmMetadata,
sb append ("Version: %s\n" format meta.version)
sb append ("Release: %s\n" format meta.release)
sb append ("Summary: %s\n" format meta.summary)

meta.epoch filter (_ >= 0) foreach { epoch =>
sb append ("Epoch: %d\n" format epoch)
}

meta.prefix foreach { v =>
sb append ("prefix: %s\n" format v)
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ object RpmPlugin extends AutoPlugin {
rpmPrefix := None,
rpmVendor := "", // TODO - Maybe pull in organization?
rpmLicense := None,
rpmEpoch := None,
rpmDistribution := None,
rpmUrl := None,
rpmGroup := None,
Expand Down Expand Up @@ -105,7 +106,8 @@ object RpmPlugin extends AutoPlugin {
validatePackageValidators in Rpm := Seq(
nonEmptyMappings((linuxPackageMappings in Rpm).value.flatMap(_.mappings)),
filesExist((linuxPackageMappings in Rpm).value.flatMap(_.mappings)),
checkMaintainer((maintainer in Rpm).value, asWarning = false)
checkMaintainer((maintainer in Rpm).value, asWarning = false),
epochIsNaturalNumber((rpmEpoch in Rpm).value.getOrElse(0))
),
// override the linux sourceDirectory setting
sourceDirectory in Rpm := sourceDirectory.value,
Expand All @@ -121,7 +123,8 @@ object RpmPlugin extends AutoPlugin {
(packageSummary in Rpm).value,
(packageDescription in Rpm).value,
rpmAutoprov.value,
rpmAutoreq.value
rpmAutoreq.value,
rpmEpoch.value
),
rpmDescription := RpmDescription(
rpmLicense.value,
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/validation/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ package object validation {
}
}

def epochIsNaturalNumber(epoch: Int): Validation.Validator = () => {
sys.error(s"Passed: $epoch")
if (epoch < 0) {
ValidationError(
description = s"The Epoch cannot be a negative number (found $epoch)",
howToFix = "Change rpmEpoch to Some(n), where n >= 0"
) :: Nil
} else {
Nil
}
}

}
3 changes: 3 additions & 0 deletions src/sbt-test/rpm/simple-rpm/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ rpmUrl := Some("http://github.com/sbt/sbt-native-packager")

rpmLicense := Some("BSD")

rpmEpoch := Some(1)

packageArchitecture in Rpm := "x86_64"

linuxPackageMappings in Rpm := {
Expand All @@ -38,6 +40,7 @@ TaskKey[Unit]("checkSpecFile") := {
assert(spec contains "Release: 1", "Contains project release")
assert(spec contains "Summary: Test rpm package", "Contains project summary")
assert(spec contains "License: BSD", "Contains project license")
assert(spec contains "Epoch: 1", "Contains epoch of 1")
assert(spec contains "Vendor: typesafe", "Contains project vendor")
assert(spec contains "URL: http://github.com/sbt/sbt-native-packager", "Contains project url")
assert(spec contains "BuildArch: x86_64", "Contains project package architecture")
Expand Down
6 changes: 6 additions & 0 deletions src/sphinx/formats/rpm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ Informational Settings
``rpmLicense``
The license associated with software in the RPM.

``rpmEpoch``
The epoch is the most significant number used when resolving different versions
for the same RPM. For a given package, packages with the highest epoch will be
used, and in the event of a tie it will fall back to comparing the version and
release.

Dependency Settings
~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 83bac3c

Please sign in to comment.