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

Implement stage command for rpm #989

Merged
merged 2 commits into from
Jun 6, 2017
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
55 changes: 37 additions & 18 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,35 @@ object RpmHelper {
def hostVendor =
Process(Seq("rpm", "-E", "%{_host_vendor}")) !!

def buildRpm(spec: RpmSpec, workArea: File, log: sbt.Logger): File = {
// TODO - check the spec for errors.
/**
* Prepares the staging directory for the rpm build command.
*
* @param spec The RpmSpec
* @param workArea The target
* @param log Logger
* @return the `workArea`
*/
def stage(spec: RpmSpec, workArea: File, log: sbt.Logger): File = {
buildWorkArea(workArea)
copyFiles(spec, workArea, log)
writeSpecFile(spec, workArea, log)
spec.validate(log)
workArea
}

buildPackage(workArea, spec, log)
/**
* Build the rpm package
*
* @param spec The RpmSpec
* @param stagingArea Prepared staging area
* @param log Logger
* @return The rpm package
*/
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)
workArea / "RPMS" / spec.meta.arch / rpmname
stagingArea / "RPMS" / spec.meta.arch / rpmname
}

private[this] def copyFiles(spec: RpmSpec, workArea: File, log: sbt.Logger): Unit = {
Expand Down Expand Up @@ -70,20 +89,20 @@ object RpmHelper {
case Some(arch) => Seq("setarch", arch)
case None => Seq()
}) ++ Seq(
"rpmbuild",
"-bb",
"--target",
spec.meta.arch + '-' + spec.meta.vendor + '-' + spec.meta.os,
"--buildroot",
buildRoot.getAbsolutePath,
"--define",
"_topdir " + workArea.getAbsolutePath,
"--define",
"_tmppath " + tmpRpmBuildDir.getAbsolutePath
) ++ (
if (gpg) Seq("--define", "_gpg_name " + "<insert keyname>", "--sign")
else Seq.empty
) ++ Seq(spec.meta.name + ".spec")
"rpmbuild",
"-bb",
"--target",
spec.meta.arch + '-' + spec.meta.vendor + '-' + spec.meta.os,
"--buildroot",
buildRoot.getAbsolutePath,
"--define",
"_topdir " + workArea.getAbsolutePath,
"--define",
"_tmppath " + tmpRpmBuildDir.getAbsolutePath
) ++ (
if (gpg) Seq("--define", "_gpg_name " + "<insert keyname>", "--sign")
else Seq.empty
) ++ Seq(spec.meta.name + ".spec")
log.debug("Executing rpmbuild with: " + args.mkString(" "))
(Process(args, Some(specsDir)) ! log) match {
case 0 => ()
Expand Down
8 changes: 2 additions & 6 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ object RpmPlugin extends AutoPlugin {
(linuxPackageSymlinks in Rpm).value,
(defaultLinuxInstallLocation in Rpm).value
),
packageBin in Rpm := {
val log = streams.value.log
val spec = rpmSpecConfig.value
spec.validate(log)
RpmHelper.buildRpm(spec, (target in Rpm).value, log)
},
stage in Rpm := RpmHelper.stage(rpmSpecConfig.value, (target in Rpm).value, streams.value.log),
packageBin in Rpm := RpmHelper.buildRpm(rpmSpecConfig.value, (stage in Rpm).value, streams.value.log),
rpmLint := {
Process(Seq("rpmlint", "-v", (packageBin in Rpm).value.getAbsolutePath)) ! streams.value.log match {
case 0 => ()
Expand Down
5 changes: 0 additions & 5 deletions src/sbt-test/rpm/simple-rpm/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ linuxPackageSymlinks in Rpm := Seq(LinuxSymlink("/etc/link1", "destination1"), L

defaultLinuxInstallLocation in Rpm := "/opt/foo"

TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) =>
val rpmPath = Seq(rpmFile.getAbsolutePath)
Process("rpm2cpio", rpmPath) #| Process("cpio -i --make-directories") ! streams.log
}

TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) =>
val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec")
assert(spec contains "Name: rpm-test", "Contains project name")
Expand Down
9 changes: 4 additions & 5 deletions src/sbt-test/rpm/simple-rpm/test
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Run the debian packaging.
> rpm:stage
$ exists target/rpm
> checkSpecFile
# Run the rpm packaging.
> rpm:package-bin
$ exists target/rpm/RPMS/x86_64/rpm-test-0.1.0-1.x86_64.rpm

> unzip

> checkSpecFile