Skip to content

Commit

Permalink
Introduce RPM / packageBin / artifactPath setting. Closes sbt#1287
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasering committed Jan 26, 2020
1 parent 6039c2e commit 1fdaba0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.typesafe.sbt.packager.rpm
import sbt._
import com.typesafe.sbt.packager.Compat._
import com.typesafe.sbt.packager.linux.LinuxSymlink
import sbt.Keys.{artifactPath, packageBin}

object RpmHelper {

Expand All @@ -26,6 +27,9 @@ object RpmHelper {
workArea
}

private[rpm] def defaultRpmArtifactPath(stagingArea: File, meta: RpmMetadata): File =
stagingArea / "RPMS" / meta.arch / s"${meta.name}-${meta.version}-${meta.release}.${meta.arch}.rpm"

/**
* Build the rpm package
*
Expand All @@ -36,9 +40,12 @@ object RpmHelper {
*/
def buildRpm(spec: RpmSpec, stagingArea: File, log: sbt.Logger): File = {
buildPackage(stagingArea, spec, log)
// We should probably return the File that was created.
val rpmname = "%s-%s-%s.%s.rpm" format (spec.meta.name, spec.meta.version, spec.meta.release, spec.meta.arch)
stagingArea / "RPMS" / spec.meta.arch / rpmname
// buildPackage uses rpmbuild command which always generates the file at defaultRpmArtifactPath
// If the artifactPath is not the default value then we need to copy the file.
val defaultPath = defaultRpmArtifactPath(stagingArea, spec.meta)
val path = (artifactPath in (RpmPlugin.autoImport.Rpm, packageBin)).value
if (path.getCanonicalFile != defaultPath.getCanonicalFile) IO.copyFile(defaultPath, path)
path
}

private[this] def copyFiles(spec: RpmSpec, workArea: File, log: sbt.Logger): Unit = {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ object RpmPlugin extends AutoPlugin {
(defaultLinuxInstallLocation in Rpm).value
),
stage in Rpm := RpmHelper.stage(rpmSpecConfig.value, (target in Rpm).value, streams.value.log),
artifactPath in (Rpm, packageBin) := RpmHelper
.defaultRpmArtifactPath((stage in Rpm).value, rpmSpecConfig.value.meta),
packageBin in Rpm := RpmHelper.buildRpm(rpmSpecConfig.value, (stage in Rpm).value, streams.value.log),
rpmLint := {
sys.process.Process(Seq("rpmlint", "-v", (packageBin in Rpm).value.getAbsolutePath)) ! streams.value.log match {
Expand Down

0 comments on commit 1fdaba0

Please sign in to comment.