Skip to content

Commit d474fd7

Browse files
thetristanmuuki88
authored andcommitted
Fix scoping in RPM plugin for #789 (#826)
* Fix scoping in RPM plugin for #789 * Update simple-rpm test to check contents of spec file * Add checks for additional fields used to build rpmspec
1 parent a125a60 commit d474fd7

File tree

3 files changed

+91
-33
lines changed

3 files changed

+91
-33
lines changed

src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala

+31-32
Original file line numberDiff line numberDiff line change
@@ -96,39 +96,38 @@ object RpmPlugin extends AutoPlugin {
9696
rpmDaemonLogFile := s"${(packageName in Linux).value}.log",
9797
daemonStdoutLogFile in Rpm := Some((rpmDaemonLogFile).value),
9898
// override the linux sourceDirectory setting
99-
sourceDirectory in Rpm <<= sourceDirectory
100-
) ++ inConfig(Rpm)(Seq(
101-
packageArchitecture := "noarch",
102-
rpmMetadata <<=
103-
(packageName, version, rpmRelease, rpmPrefix, packageArchitecture, rpmVendor, rpmOs, packageSummary, packageDescription, rpmAutoprov, rpmAutoreq) apply RpmMetadata,
104-
rpmDescription <<=
105-
(rpmLicense, rpmDistribution, rpmUrl, rpmGroup, rpmPackager, rpmIcon, rpmChangelogFile) apply RpmDescription,
106-
rpmDependencies <<=
107-
(rpmProvides, rpmRequirements, rpmPrerequisites, rpmObsoletes, rpmConflicts) apply RpmDependencies,
108-
maintainerScripts := {
109-
val scripts = maintainerScripts.value
110-
if (rpmBrpJavaRepackJars.value) {
111-
val pre = scripts.getOrElse(Names.Pre, Nil)
112-
val scriptBits = IO.readStream(RpmPlugin.osPostInstallMacro.openStream, Charset forName "UTF-8")
113-
scripts + (Names.Pre -> (pre :+ scriptBits))
114-
} else {
115-
scripts
116-
}
117-
},
118-
rpmScripts := RpmScripts.fromMaintainerScripts(maintainerScripts.value, linuxScriptReplacements.value),
119-
rpmSpecConfig <<=
120-
(rpmMetadata, rpmDescription, rpmDependencies, rpmSetarch, rpmScripts, linuxPackageMappings, linuxPackageSymlinks, defaultLinuxInstallLocation) map RpmSpec,
121-
packageBin <<= (rpmSpecConfig, target, streams) map { (spec, dir, s) =>
122-
spec.validate(s.log)
123-
RpmHelper.buildRpm(spec, dir, s.log)
124-
},
125-
rpmLint <<= (packageBin, streams) map { (rpm, s) =>
126-
(Process(Seq("rpmlint", "-v", rpm.getAbsolutePath)) ! s.log) match {
127-
case 0 => ()
128-
case x => sys.error("Failed to run rpmlint, exit status: " + x)
129-
}
99+
sourceDirectory in Rpm <<= sourceDirectory,
100+
packageArchitecture in Rpm := "noarch",
101+
rpmMetadata <<=
102+
(packageName in Rpm, version in Rpm, rpmRelease, rpmPrefix, packageArchitecture in Rpm, rpmVendor, rpmOs, packageSummary in Rpm, packageDescription in Rpm, rpmAutoprov, rpmAutoreq) apply RpmMetadata,
103+
rpmDescription <<=
104+
(rpmLicense, rpmDistribution, rpmUrl, rpmGroup, rpmPackager, rpmIcon, rpmChangelogFile) apply RpmDescription,
105+
rpmDependencies <<=
106+
(rpmProvides, rpmRequirements, rpmPrerequisites, rpmObsoletes, rpmConflicts) apply RpmDependencies,
107+
maintainerScripts in Rpm := {
108+
val scripts = (maintainerScripts in Rpm).value
109+
if (rpmBrpJavaRepackJars.value) {
110+
val pre = scripts.getOrElse(Names.Pre, Nil)
111+
val scriptBits = IO.readStream(RpmPlugin.osPostInstallMacro.openStream, Charset forName "UTF-8")
112+
scripts + (Names.Pre -> (pre :+ scriptBits))
113+
} else {
114+
scripts
130115
}
131-
))
116+
},
117+
rpmScripts := RpmScripts.fromMaintainerScripts((maintainerScripts in Rpm).value, (linuxScriptReplacements in Rpm).value),
118+
rpmSpecConfig <<=
119+
(rpmMetadata, rpmDescription, rpmDependencies, rpmSetarch, rpmScripts, linuxPackageMappings in Rpm, linuxPackageSymlinks in Rpm, defaultLinuxInstallLocation in Rpm) map RpmSpec,
120+
packageBin in Rpm <<= (rpmSpecConfig, target in Rpm, streams) map { (spec, dir, s) =>
121+
spec.validate(s.log)
122+
RpmHelper.buildRpm(spec, dir, s.log)
123+
},
124+
rpmLint <<= (packageBin in Rpm, streams) map { (rpm, s) =>
125+
(Process(Seq("rpmlint", "-v", rpm.getAbsolutePath)) ! s.log) match {
126+
case 0 => ()
127+
case x => sys.error("Failed to run rpmlint, exit status: " + x)
128+
}
129+
}
130+
)
132131
}
133132

134133
object RpmDeployPlugin extends AutoPlugin {

src/sbt-test/rpm/simple-rpm/build.sbt

+55
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.typesafe.sbt.packager.linux._
2+
13
enablePlugins(RpmPlugin)
24

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

2022
rpmLicense := Some("BSD")
2123

24+
packageArchitecture in Rpm := "x86_64"
25+
26+
linuxPackageMappings in Rpm := {
27+
val mapping1 = ((baseDirectory.value / "test"), "tmp/test")
28+
val mapping2 = ((baseDirectory.value / "build.sbt"), "/tmp/build.sbt")
29+
Seq(LinuxPackageMapping(Seq(mapping1, mapping2)))
30+
}
31+
32+
linuxPackageSymlinks in Rpm := Seq(
33+
LinuxSymlink("/etc/link1", "destination1"),
34+
LinuxSymlink("link2", "destination2")
35+
)
36+
37+
defaultLinuxInstallLocation in Rpm := "/opt/foo"
38+
39+
TaskKey[Unit]("unzip") <<= (packageBin in Rpm, streams) map { (rpmFile, streams) =>
40+
val rpmPath = Seq(rpmFile.getAbsolutePath)
41+
Process("rpm2cpio" , rpmPath) #| Process("cpio -i --make-directories") ! streams.log
42+
}
43+
44+
TaskKey[Unit]("checkSpecFile") <<= (target, streams) map { (target, out) =>
45+
val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec")
46+
assert(spec contains "Name: rpm-test", "Contains project name")
47+
assert(spec contains "Version: 0.1.0", "Contains project version")
48+
assert(spec contains "Release: 1", "Contains project release")
49+
assert(spec contains "Summary: Test rpm package", "Contains project summary")
50+
assert(spec contains "License: BSD", "Contains project license")
51+
assert(spec contains "Vendor: typesafe", "Contains project vendor")
52+
assert(spec contains "URL: http://github.com/sbt/sbt-native-packager", "Contains project url")
53+
assert(spec contains "BuildArch: x86_64", "Contains project package architecture")
54+
55+
assert(spec contains
56+
"%description\nA fun package description of our software,\n with multiple lines.",
57+
"Contains project description"
58+
)
59+
60+
assert(spec contains
61+
"%files\n%attr(755,root,root) /tmp/test\n%attr(755,root,root) /tmp/build.sbt",
62+
"Contains package mappings"
63+
)
64+
65+
assert(spec contains
66+
"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)",
67+
"Contains package symlink link (1)"
68+
)
69+
70+
assert(spec contains
71+
"ln -s $(relocateLink destination2 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX) $(relocateLink link2 /opt/foo/rpm-test rpm-test $RPM_INSTALL_PREFIX)",
72+
"Contains package symlink link (2)"
73+
)
2274

75+
out.log.success("Successfully tested rpm test file")
76+
()
77+
}

src/sbt-test/rpm/simple-rpm/test

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Run the debian packaging.
22
> rpm:package-bin
3-
$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm
3+
$ exists target/rpm/RPMS/x86_64/rpm-test-0.1.0-1.x86_64.rpm
4+
5+
> unzip
6+
7+
> checkSpecFile

0 commit comments

Comments
 (0)