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

Fix scoping in RPM plugin for #789 #826

Merged
merged 3 commits into from
Aug 5, 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
63 changes: 31 additions & 32 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,38 @@ object RpmPlugin extends AutoPlugin {
rpmDaemonLogFile := s"${(packageName in Linux).value}.log",
daemonStdoutLogFile in Rpm := Some((rpmDaemonLogFile).value),
// override the linux sourceDirectory setting
sourceDirectory in Rpm <<= sourceDirectory
) ++ inConfig(Rpm)(Seq(
packageArchitecture := "noarch",
rpmMetadata <<=
(packageName, version, rpmRelease, rpmPrefix, packageArchitecture, rpmVendor, rpmOs, packageSummary, packageDescription, rpmAutoprov, rpmAutoreq) apply RpmMetadata,
rpmDescription <<=
(rpmLicense, rpmDistribution, rpmUrl, rpmGroup, rpmPackager, rpmIcon, rpmChangelogFile) apply RpmDescription,
rpmDependencies <<=
(rpmProvides, rpmRequirements, rpmPrerequisites, rpmObsoletes, rpmConflicts) apply RpmDependencies,
maintainerScripts := {
val scripts = maintainerScripts.value
if (rpmBrpJavaRepackJars.value) {
val pre = scripts.getOrElse(Names.Pre, Nil)
val scriptBits = IO.readStream(RpmPlugin.osPostInstallMacro.openStream, Charset forName "UTF-8")
scripts + (Names.Pre -> (pre :+ scriptBits))
} else {
scripts
}
},
rpmScripts := RpmScripts.fromMaintainerScripts(maintainerScripts.value, linuxScriptReplacements.value),
rpmSpecConfig <<=
(rpmMetadata, rpmDescription, rpmDependencies, rpmSetarch, rpmScripts, linuxPackageMappings, linuxPackageSymlinks, defaultLinuxInstallLocation) map RpmSpec,
packageBin <<= (rpmSpecConfig, target, streams) map { (spec, dir, s) =>
spec.validate(s.log)
RpmHelper.buildRpm(spec, dir, s.log)
},
rpmLint <<= (packageBin, streams) map { (rpm, s) =>
(Process(Seq("rpmlint", "-v", rpm.getAbsolutePath)) ! s.log) match {
case 0 => ()
case x => sys.error("Failed to run rpmlint, exit status: " + x)
}
sourceDirectory in Rpm <<= sourceDirectory,
packageArchitecture in Rpm := "noarch",
rpmMetadata <<=
(packageName in Rpm, version in Rpm, rpmRelease, rpmPrefix, packageArchitecture in Rpm, rpmVendor, rpmOs, packageSummary in Rpm, packageDescription in Rpm, rpmAutoprov, rpmAutoreq) apply RpmMetadata,
rpmDescription <<=
(rpmLicense, rpmDistribution, rpmUrl, rpmGroup, rpmPackager, rpmIcon, rpmChangelogFile) apply RpmDescription,
rpmDependencies <<=
(rpmProvides, rpmRequirements, rpmPrerequisites, rpmObsoletes, rpmConflicts) apply RpmDependencies,
maintainerScripts in Rpm := {
val scripts = (maintainerScripts in Rpm).value
if (rpmBrpJavaRepackJars.value) {
val pre = scripts.getOrElse(Names.Pre, Nil)
val scriptBits = IO.readStream(RpmPlugin.osPostInstallMacro.openStream, Charset forName "UTF-8")
scripts + (Names.Pre -> (pre :+ scriptBits))
} else {
scripts
}
))
},
rpmScripts := RpmScripts.fromMaintainerScripts((maintainerScripts in Rpm).value, (linuxScriptReplacements in Rpm).value),
rpmSpecConfig <<=
(rpmMetadata, rpmDescription, rpmDependencies, rpmSetarch, rpmScripts, linuxPackageMappings in Rpm, linuxPackageSymlinks in Rpm, defaultLinuxInstallLocation in Rpm) map RpmSpec,
packageBin in Rpm <<= (rpmSpecConfig, target in Rpm, streams) map { (spec, dir, s) =>
spec.validate(s.log)
RpmHelper.buildRpm(spec, dir, s.log)
},
rpmLint <<= (packageBin in Rpm, streams) map { (rpm, s) =>
(Process(Seq("rpmlint", "-v", rpm.getAbsolutePath)) ! s.log) match {
case 0 => ()
case x => sys.error("Failed to run rpmlint, exit status: " + x)
}
}
)
}

object RpmDeployPlugin extends AutoPlugin {
Expand Down
55 changes: 55 additions & 0 deletions src/sbt-test/rpm/simple-rpm/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.typesafe.sbt.packager.linux._

enablePlugins(RpmPlugin)

name := "rpm-test"
Expand All @@ -19,4 +21,57 @@ rpmUrl := Some("http://github.com/sbt/sbt-native-packager")

rpmLicense := Some("BSD")

packageArchitecture in Rpm := "x86_64"

linuxPackageMappings in Rpm := {
val mapping1 = ((baseDirectory.value / "test"), "tmp/test")
val mapping2 = ((baseDirectory.value / "build.sbt"), "/tmp/build.sbt")
Seq(LinuxPackageMapping(Seq(mapping1, mapping2)))
}

linuxPackageSymlinks in Rpm := Seq(
LinuxSymlink("/etc/link1", "destination1"),
LinuxSymlink("link2", "destination2")
)

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")
assert(spec contains "Version: 0.1.0", "Contains project version")
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 "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")

assert(spec contains
"%description\nA fun package description of our software,\n with multiple lines.",
"Contains project description"
)

assert(spec contains
"%files\n%attr(755,root,root) /tmp/test\n%attr(755,root,root) /tmp/build.sbt",
"Contains package mappings"
)

assert(spec contains
"ln -s $(relocateLink destination1 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX) $(relocateLink /etc/link1 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX)",
"Contains package symlink link (1)"
)

assert(spec contains
"ln -s $(relocateLink destination2 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX) $(relocateLink link2 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX)",
"Contains package symlink link (2)"
)

out.log.success("Successfully tested rpm test file")
()
}
6 changes: 5 additions & 1 deletion src/sbt-test/rpm/simple-rpm/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Run the debian packaging.
> rpm:package-bin
$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm
$ exists target/rpm/RPMS/x86_64/rpm-test-0.1.0-1.x86_64.rpm

> unzip

> checkSpecFile