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

Add rpmSetarch support #786

Merged
merged 2 commits into from
Apr 26, 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
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 @@ -36,6 +36,7 @@ trait RpmKeys {
val rpmObsoletes = SettingKey[Seq[String]]("rpm-obsoletes", "Packages this RPM makes obsolete.")
val rpmConflicts = SettingKey[Seq[String]]("rpm-conflicts", "Packages this RPM conflicts with.")
val rpmDependencies = SettingKey[RpmDependencies]("rpm-dependencies", "Configuration of dependency info for this RPM.")
val rpmSetarch = SettingKey[Option[String]]("rpm-setarch", "run rpmbuild in the context of an architecture.")

// MAINTAINER SCRIPTS
@deprecated("Use maintainerScripts in RPM and RpmConstants.Pretrans instead.", "1.1.x")
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ object RpmHelper {
val gpg = false
// TODO - Full GPG support (with GPG plugin).
IO.withTemporaryDirectory { tmpRpmBuildDir =>
val args: Seq[String] = Seq(
val args: Seq[String] = (spec.setarch match {
case Some(arch) => Seq("setarch", arch)
case None => Seq()
}) ++ Seq(
"rpmbuild",
"-bb",
"--target", spec.meta.arch + '-' + spec.meta.vendor + '-' + spec.meta.os,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ case class RpmSpec(
meta: RpmMetadata,
desc: RpmDescription = RpmDescription(),
deps: RpmDependencies = RpmDependencies(),
setarch: Option[String],
scriptlets: RpmScripts = RpmScripts(),
mappings: Seq[LinuxPackageMapping] = Seq.empty,
symlinks: Seq[LinuxSymlink] = Seq.empty,
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ object RpmPlugin extends AutoPlugin {
rpmPrerequisites := Seq.empty,
rpmObsoletes := Seq.empty,
rpmConflicts := Seq.empty,
rpmSetarch := None,
rpmChangelogFile := None,
rpmBrpJavaRepackJars := false,

Expand Down Expand Up @@ -120,7 +121,7 @@ object RpmPlugin extends AutoPlugin {
},
rpmScripts := RpmScripts.fromMaintainerScripts(maintainerScripts.value),
rpmSpecConfig <<=
(rpmMetadata, rpmDescription, rpmDependencies, rpmScripts, linuxPackageMappings, linuxPackageSymlinks, defaultLinuxInstallLocation) map RpmSpec,
(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)
Expand Down
47 changes: 47 additions & 0 deletions src/sbt-test/rpm/setarch-rpm/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import com.typesafe.sbt.packager.linux.LinuxPackageMapping

enablePlugins(JavaServerAppPackaging)

name := "rpm-test"

version := "0.1.0"

maintainer := "David Pennell <[email protected]>"

packageSummary := "Test rpm package"

packageName in Linux := "rpm-package"

packageDescription := """A fun package description of our software,
with multiple lines."""

rpmRelease := "1"

rpmVendor := "typesafe"

rpmUrl := Some("http://github.com/sbt/sbt-native-packager")

rpmLicense := Some("BSD")

packageArchitecture in Rpm:= "i386"

rpmSetarch := Some("i386")

linuxPackageMappings := {
val helloMapping = LinuxPackageMapping(Seq(((resourceDirectory in Compile).value / "hello-32bit", "/usr/share/rpm-package/libexec/hello-32bit"))) withPerms "0755"
linuxPackageMappings.value :+ helloMapping
}

TaskKey[Unit]("check-spec-file") <<= (target, streams) map { (target, out) =>
val spec = IO.read(target / "rpm" / "SPECS" / "rpm-package.spec")
out.log.success(spec)
assert(spec contains "%attr(0644,root,root) /usr/share/rpm-package/lib/rpm-test.rpm-test-0.1.0.jar", "Wrong installation path\n" + spec)
assert(spec contains "%attr(0755,root,root) /usr/share/rpm-package/libexec/hello-32bit", "Wrong 32-bit exe installation path\n" + spec)
assert(spec contains "%attr(0755,root,root) /etc/init.d/rpm-package", "Wrong /etc/init.d path\n" + spec)
assert(spec contains "%config %attr(644,root,root) /etc/default/rpm-package", "Wrong /etc default file\n" + spec)
assert(spec contains "%dir %attr(755,rpm-package,rpm-package) /var/log/rpm-package", "Wrong logging dir path\n" + spec)
assert(spec contains "%dir %attr(755,rpm-package,rpm-package) /var/run/rpm-package", "Wrong /var/run dir path\n" + spec)
out.log.success("Successfully tested rpm-package file")
()
}

1 change: 1 addition & 0 deletions src/sbt-test/rpm/setarch-rpm/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
6 changes: 6 additions & 0 deletions src/sbt-test/rpm/setarch-rpm/src/main/c/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include<stdio.h>

main()
{
printf("Hello World!\n");
}
Binary file not shown.
7 changes: 7 additions & 0 deletions src/sbt-test/rpm/setarch-rpm/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Run the debian packaging.
> rpm:package-bin
$ exists target/rpm/RPMS/i386/rpm-package-0.1.0-1.i386.rpm
$ exists target/rpm/SPECS/rpm-package.spec

# Check files for defaults
> check-spec-file
3 changes: 3 additions & 0 deletions src/sphinx/formats/rpm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ Dependency Settings
``rpmConflcits``
The packages this RPM conflicts with and cannot be installed with.

``rpmSetarch[SettingKey[Option[String]]]``
Run rpmbuild via Linux ``setarch`` command. Use this for cross-platform builds.

Meta Settings
~~~~~~~~~~~~~

Expand Down