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 #662 and make universal archive options customizable #666

Merged
merged 1 commit into from
Sep 9, 2015
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
18 changes: 12 additions & 6 deletions src/main/scala/com/typesafe/sbt/packager/universal/Archives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ object Archives {
* @param name of output (without extension)
* @param mappings included in the output
* @param top level directory
* @param options NOT USED
* @return zip file
*/
def makeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
def makeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
val zip = target / (name + ".zip")

// add top level directory if defined
Expand All @@ -35,9 +36,10 @@ object Archives {
* @param name of output (without extension)
* @param mappings included in the output
* @param top level directory
* @param options NOT USED
* @return zip file
*/
def makeNativeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
def makeNativeZip(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
val zip = target / (name + ".zip")

// add top level directory if defined
Expand All @@ -58,9 +60,10 @@ object Archives {
* @param name of output (without extension)
* @param mappings included in the output
* @param top level directory : NOT USED
* @param options NOT USED
* @return dmg file
*/
def makeDmg(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
def makeDmg(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val t = target / "dmg"
val dmg = target / (name + ".dmg")
if (!t.isDirectory) IO.createDirectory(t)
Expand Down Expand Up @@ -139,20 +142,21 @@ object Archives {
}
file(f.getAbsolutePath + ".xz")
}

val makeTxz = makeTarball(xz, ".txz") _
val makeTgz = makeTarball(gzip, ".tgz") _
val makeTar = makeTarball(identity, ".tar") _

/**
* Helper method used to construct tar-related compression functions.
* @param target folder to build package in
* @param name of output (without extension)
* @param mappings included in the output
* @param top level directory
* @param options for tar command
* @return tar file
*
*/
def makeTarball(compressor: File => File, ext: String)(target: File, name: String, mappings: Seq[(File, String)], top: Option[String]): File = {
def makeTarball(compressor: File => File, ext: String)(target: File, name: String, mappings: Seq[(File, String)], top: Option[String], options: Seq[String]): File = {
val relname = name
val tarball = target / (name + ext)
IO.withTemporaryDirectory { f =>
Expand All @@ -179,7 +183,9 @@ object Archives {

val tmptar = f / (relname + ".tar")

Process(Seq("tar", "--force-local", "-pcvf", tmptar.getAbsolutePath) ++ distdirs, Some(rdir)).! match {
val cmd = Seq("tar") ++ options ++ Seq(tmptar.getAbsolutePath) ++ distdirs
println("Running with " + cmd.mkString(" "))
Process(cmd, Some(rdir)).! match {
case 0 => ()
case n => sys.error("Error tarballing " + tarball + ". Exit code: " + n)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ trait UniversalKeys {
val dist = TaskKey[File]("dist", "Creates the distribution packages.")
val stagingDirectory = SettingKey[File]("stagingDirectory", "Directory where we stage distributions/releases.")
val topLevelDirectory = SettingKey[Option[String]]("topLevelDirectory", "Top level dir in compressed output file.")
val universalArchiveOptions = SettingKey[Seq[String]]("universal-archive-options", "Options passed to the tar/zip command. Scope by task")
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ object UniversalPlugin extends AutoPlugin {
) ++
makePackageSettingsForConfig(Universal) ++
makePackageSettingsForConfig(UniversalDocs) ++
makePackageSettingsForConfig(UniversalSrc)
makePackageSettingsForConfig(UniversalSrc) ++
defaultUniversalArchiveOptions

/** Creates all package types for a given configuration */
private[this] def makePackageSettingsForConfig(config: Configuration): Seq[Setting[_]] =
Expand All @@ -89,19 +90,25 @@ object UniversalPlugin extends AutoPlugin {
target in config <<= target apply (_ / config.name)
)

private[this] def defaultUniversalArchiveOptions: Seq[Setting[_]] = Seq(
universalArchiveOptions in (Universal, packageZipTarball) := Seq("-pcvf"),
universalArchiveOptions in (Universal, packageXzTarball) := Seq("-pcvf")
)

private[this] def printDist(dist: File, streams: TaskStreams): File = {
streams.log.info("")
streams.log.info("Your package is ready in " + dist.getCanonicalPath)
streams.log.info("")
dist
}

private type Packager = (File, String, Seq[(File, String)], Option[String]) => File
private type Packager = (File, String, Seq[(File, String)], Option[String], Seq[String]) => File
/** Creates packaging settings for a given package key, configuration + archive type. */
private[this] def makePackageSettings(packageKey: TaskKey[File], config: Configuration)(packager: Packager): Seq[Setting[_]] =
inConfig(config)(Seq(
universalArchiveOptions in packageKey := Nil,
mappings in packageKey <<= mappings map checkMappings,
packageKey <<= (target, packageName, mappings in packageKey, topLevelDirectory) map packager
packageKey <<= (target, packageName, mappings in packageKey, topLevelDirectory, universalArchiveOptions in packageKey) map packager
))

/** check that all mapped files actually exist */
Expand Down
19 changes: 19 additions & 0 deletions src/sphinx/formats/universal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ Tasks
Customize
---------

Universal Archive Options
~~~~~~~~~~~~~~~~~~~~~~~~~

You can customize the commandline options (if used) for the different zip formats.
If you want to force local for the `tgz` output add this line:

.. code-block:: scala

universalArchiveOptions in (Universal, packageZipTarball) := Seq("--force-local", "-pcvf")

This will set the cli options for the `packageZipTarball` task in the `Universal` plugin to the following sequence.
Currently these task can be customized

``universal:package-zip-tarball``
`universalArchiveOptions in (Universal, packageZipTarball)`

``universal:package-xz-tarball``
`universalArchiveOptions in (Universal, packageXzTarball)`

Getting Started with Universal Packaging
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default, all files found in the ``src/universal`` directory are included in the distribution. So, the first step
Expand Down