Upgrade to in-progress sbt-native-packager plugin, including new support for universal->debian/rpm packages.

This commit is contained in:
Josh Suereth 2013-06-27 16:43:31 -04:00
parent 360428a2eb
commit a99f6fffbf
6 changed files with 114 additions and 134 deletions

View File

@ -1,7 +1,7 @@
import sbt._
import com.typesafe.packager.Keys._
import com.typesafe.sbt.packager.Keys._
import sbt.Keys._
import com.typesafe.packager.PackagerPlugin._
import com.typesafe.sbt.SbtNativePackager._
object Packaging {
@ -9,12 +9,6 @@ object Packaging {
val sbtLaunchJarLocation = SettingKey[File]("sbt-launch-jar-location")
val sbtLaunchJar = TaskKey[File]("sbt-launch-jar", "Resolves SBT launch jar")
val fixedScriptDir = SettingKey[File]("fixed-script-dir")
val fixedLinuxScriptDir = SettingKey[File]("fixed-linux-script-dir")
val fixedUniversalScriptDir = SettingKey[File]("fixed-universal-script-dir")
val linuxFixedScripts = TaskKey[File]("linux-fixed-scripts")
val universalFixedScripts = TaskKey[File]("universal-fixed-scripts")
val stagingDirectory = SettingKey[File]("staging-directory")
val stage = TaskKey[File]("stage")
@ -29,26 +23,7 @@ object Packaging {
case _ => "http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/"+v+"/sbt-launch.jar"
}
def fixScripts(launchJar: String, bashLib: String)(scriptDir: File, target: File): File = {
if(!target.exists) target.mkdirs()
for(file <- (scriptDir.*** --- scriptDir).get) {
val tfile = target / file.getName
// TODO - Speedier version
val lines =
for {
line <- IO.readLines(file).view
} yield line.replaceAll("@@BASH-LIB-LOCATION@@", bashLib).replaceAll("@@LAUNCH-JAR-LOCATION@@", launchJar)
IO.writeLines(tfile, lines)
}
target
}
val settings: Seq[Setting[_]] = packagerSettings ++ deploymentSettings ++ Seq(
fixedScriptDir <<= sourceDirectory / "scripts",
fixedLinuxScriptDir <<= target / "linux-scripts",
fixedUniversalScriptDir <<= target / "universal-scripts",
linuxFixedScripts <<= (fixedScriptDir, fixedLinuxScriptDir) map fixScripts("/usr/lib/sbt/sbt-launch.jar", "/usr/share/sbt/sbt-launch-lib.bash"),
universalFixedScripts <<= (fixedScriptDir, fixedUniversalScriptDir) map fixScripts("\\$(dirname \\$(realpath \\$0))/sbt-launch.jar", "\\$(dirname \\$(realpath \\$0))/sbt-launch-lib.bash"),
val settings: Seq[Setting[_]] = packagerSettings ++ deploymentSettings ++ mapGenericFilesToLinux ++ Seq(
sbtLaunchJarUrl <<= sbtVersion apply downloadUrlForVersion,
sbtLaunchJarLocation <<= target apply (_ / "sbt-launch.jar"),
sbtLaunchJar <<= (sbtLaunchJarUrl, sbtLaunchJarLocation) map { (uri, file) =>
@ -68,40 +43,13 @@ object Packaging {
packageSummary := "Simple Build Tool for Scala-driven builds",
packageDescription := """This script provides a native way to run the Simple Build Tool,
a build tool for Scala software, also called SBT.""",
linuxPackageMappings <+= (linuxFixedScripts) map { bd =>
(packageMapping((bd / "sbt") -> "/usr/bin/sbt",
bd -> "/usr/share/sbt",
(bd / "sbt-launch-lib.bash") -> "/usr/share/sbt/sbt-launch-lib.bash")
withUser "root" withGroup "root" withPerms "0755")
},
linuxPackageMappings <+= (sourceDirectory) map { bd =>
(packageMapping(
(bd / "linux" / "usr/share/man/man1/sbt.1") -> "/usr/share/man/man1/sbt.1.gz"
) withPerms "0644" gzipped) asDocs()
},
linuxPackageMappings <+= (sourceDirectory in Linux) map { bd =>
packageMapping(
(bd / "usr/share/doc/sbt/copyright") -> "/usr/share/doc/sbt/copyright"
) withPerms "0644" asDocs()
},
linuxPackageMappings <+= (sourceDirectory in Linux) map { bd =>
packageMapping(
(bd / "usr/share/doc/sbt") -> "/usr/share/doc/sbt"
) asDocs()
},
linuxPackageMappings <+= (sourceDirectory in Linux) map { bd =>
packageMapping(
(bd / "etc/sbt") -> "/etc/sbt"
) withConfig()
},
linuxPackageMappings <+= (sourceDirectory in Linux) map { bd =>
packageMapping(
(bd / "etc/sbt/sbtopts") -> "/etc/sbt/sbtopts"
) withPerms "0644" withConfig("noreplace")
},
linuxPackageMappings <+= (sbtLaunchJar, sourceDirectory in Linux, sbtVersion) map { (jar, dir, v) =>
packageMapping(dir -> "/usr/lib/sbt",
jar -> ("/usr/lib/sbt/sbt-launch.jar")) withPerms "0755"
// Here we remove the jar file and launch lib from the symlinks:
linuxPackageSymlinks <<= linuxPackageSymlinks map { links =>
for {
link <- links
if !(link.destination endsWith "sbt-launch-lib.bash")
if !(link.destination endsWith "sbt-launch.jar")
} yield link
},
// DEBIAN SPECIFIC
name in Debian <<= (sbtVersion) apply { (sv) => "sbt" /* + "-" + (sv split "[^\\d]" take 3 mkString ".")*/ },
@ -137,7 +85,6 @@ object Packaging {
mappings in packageMsi in Windows <+= sbtLaunchJar map { f => f -> "sbt-launch.jar" },
mappings in packageMsi in Windows <++= sourceDirectory in Windows map { d => Seq(
(d / "sbt.bat") -> "sbt.bat",
(d / "sbt") -> "sbt",
(d / "sbtconfig.txt") -> "sbtconfig.txt"
)},
javacOptions := Seq("-source", "1.5", "-target", "1.5"),
@ -145,16 +92,9 @@ object Packaging {
// Universal ZIP download install. TODO - Share the above windows code, here....
name in Universal := "sbt",
mappings in Universal <+= sbtLaunchJar map { _ -> "bin/sbt-launch.jar" },
mappings in Universal <++= universalFixedScripts map { d =>
Seq(
(d / "sbt") -> "bin/sbt",
(d / "sbt-launch-lib.bash") -> "bin/sbt-launch-lib.bash"
)
mappings in Universal <+= sourceDirectory in Windows map { d =>
(d / "sbt.bat") -> "bin/sbt.bat"
},
mappings in Universal <++= sourceDirectory in Windows map { d => Seq(
(d / "sbt.bat") -> "bin/sbt.bat",
(d / "sbt") -> "bin/win-sbt"
)},
// TODO - Adapt global `sbt`/`sbt-launch-lib` scripts for universal install...
// Misccelaneous publishing stuff...

View File

@ -6,7 +6,10 @@ object PluginBuild extends Build {
val root = Project("root", file(".")) settings(
resolvers += Resolver.url("scalasbt", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns),
addSbtPlugin("com.typesafe" % "sbt-native-packager" % "0.4.4"),
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.6.0-symlink-2"),
libraryDependencies += "net.databinder" % "dispatch-http_2.9.1" % "0.8.6"
)
) /*dependsOn(nativePackager)*/
/*lazy val nativePackager = uri("file:///home/jsuereth/projects/sbt/sbt-native-packager")*/
}

View File

@ -1,49 +0,0 @@
# ------------------------------------------------ #
# The SBT Configuration file. #
# ------------------------------------------------ #
# Disable ANSI color codes
#
#-no-colors
# Starts sbt even if the current directory contains no sbt project.
#
-sbt-create
# Path to global settings/plugins directory (default: ~/.sbt)
#
#-sbt-dir /etc/sbt
# Path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
#
#-sbt-boot ~/.sbt/boot
# Path to local Ivy repository (default: ~/.ivy2)
#
#-ivy ~/.ivy2
# set memory options
#
#-mem <integer>
# Use local caches for projects, no sharing.
#
#-no-share
# Put SBT in offline mode.
#
#-offline
# Sets the SBT version to use.
#-sbt-version 0.11.3
# Scala version (default: latest release)
#
#-scala-home <path>
#-scala-version <version>
# java version (default: java from PATH, currently $(java -version |& grep version))
#
#-java-home <path>

View File

@ -1,31 +1,63 @@
#!/usr/bin/env bash
### ------------------------------- ###
### Helper methods for BASH scripts ###
### ------------------------------- ###
realpath () {
(
TARGET_FILE=$1
TARGET_FILE="$1"
cd $(dirname $TARGET_FILE)
TARGET_FILE=$(basename $TARGET_FILE)
cd $(dirname "$TARGET_FILE")
TARGET_FILE=$(basename "$TARGET_FILE")
COUNT=0
while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
do
TARGET_FILE=$(readlink $TARGET_FILE)
cd $(dirname $TARGET_FILE)
TARGET_FILE=$(basename $TARGET_FILE)
TARGET_FILE=$(readlink "$TARGET_FILE")
cd $(dirname "$TARGET_FILE")
TARGET_FILE=$(basename "$TARGET_FILE")
COUNT=$(($COUNT + 1))
done
echo $(pwd -P)/$TARGET_FILE
# make sure we grab the actual windows path, instead of cygwin's path.
echo $(cygwinpath "$(pwd -P)/$TARGET_FILE")
)
}
. @@BASH-LIB-LOCATION@@
# Uses uname to detect if we're in the odd cygwin environment.
is_cygwin() {
local os=$(uname -s)
case "$os" in
CYGWIN*) return 0 ;;
*) return 1 ;;
esac
}
# TODO - Use nicer bash-isms here.
CYGWIN_FLAG=$(if is_cygwin; then echo true; else echo false; fi)
# This can fix cygwin style /cygdrive paths so we get the
# windows style paths.
cygwinpath() {
local file="$1"
if [[ "$CYGWIN_FLAG" == "true" ]]; then
echo $(cygpath -w $file)
else
echo $file
fi
}
. $(dirname "$(realpath "$0")")/sbt-launch-lib.bash
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
declare -r sbt_opts_file=".sbtopts"
declare -r etc_sbt_opts_file="/etc/sbt/sbtopts"
declare -r etc_sbt_opts_file="${sbt_home}/conf/sbtopts"
declare -r win_sbt_opts_file="${sbt_home}/conf/sbtconfig.txt"
usage() {
cat <<EOM
@ -97,8 +129,31 @@ loadConfigFile() {
cat "$1" | sed '/^\#/d'
}
# if sbtopts files exist, prepend their contents to $@ so it can be processed by this runner
#If we're in cygwin, we should use the windows config, and terminal hacks
if [[ "$CYGWIN_FLAG" == "true" ]]; then
stty -icanon min 1 -echo > /dev/null 2>&1
addJava "-Djline.terminal=jline.UnixTerminal"
addJava "-Dsbt.cygwin=true"
fi
# TODO - Pull in config based on operating system... (MSYS + cygwin should pull in txt file).
# Here we pull in the global settings configuration.
[[ -f "$etc_sbt_opts_file" ]] && set -- $(loadConfigFile "$etc_sbt_opts_file") "$@"
# -- Windows behavior stub'd
# JAVA_OPTS=$(cat "$WDIR/sbtconfig.txt" | sed -e 's/\r//g' -e 's/^#.*$//g' | sed ':a;N;$!ba;s/\n/ /g')
# Pull in the project-level config file, if it exists.
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"
run "$@"
exit_code=$?
# Clean up the terminal from cygwin hacks.
if [[ "$IS_CYGWIN" == "true" ]] then
stty icanon echo > /dev/null 2>&1
fi
exit $exit_code

View File

@ -17,6 +17,8 @@ declare -a java_args
declare -a scalac_args
declare -a sbt_commands
declare java_cmd=java
declare -r sbt_bin_dir="$(dirname "$(realpath "$0")")"
declare -r sbt_home="$(dirname "$sbt_bin_dir")"
echoerr () {
echo 1>&2 "$@"
@ -29,7 +31,8 @@ dlog () {
}
jar_file () {
echo "@@LAUNCH-JAR-LOCATION@@"
# TODO - Is this where we want the launch jar?
echo "${sbt_home}/bin/sbt-launch.jar"
}
acquire_sbt_jar () {
@ -128,6 +131,31 @@ process_args () {
}
}
# Detect that we have java installed.
checkJava() {
local required_version="$1"
# Now check to see if it's a good enough version
declare -r java_version=$("$java_cmd" -version 2>&1 | awk -F '"' '/version/ {print $2}')
if [[ "$java_version" == "" ]]; then
echo
echo No java installations was detected.
echo Please go to http://www.java.com/getjava/ and download
echo
exit 1
elif [[ ! "$java_version" > "$required_version" ]]; then
echo
echo The java installation you have is not up to date
echo $script_name requires at least version $required_version+, you have
echo version $java_version
echo
echo Please go to http://www.java.com/getjava/ and download
echo a valid Java Runtime and install before running $script_name.
echo
exit 1
fi
}
run() {
# no jar? download it.
[[ -f "$sbt_jar" ]] || acquire_sbt_jar "$sbt_version" || {
@ -141,6 +169,9 @@ run() {
set -- "${residual_args[@]}"
argumentCount=$#
# TODO - java check should be configurable...
checkJava "1.6"
# run sbt
execRunner "$java_cmd" \
${SBT_OPTS:-$default_sbt_opts} \

View File