From 7446d8f8f21d2955735be9f745865a42e4444185 Mon Sep 17 00:00:00 2001 From: Pierre Kisters Date: Sat, 31 Mar 2018 23:50:58 +0200 Subject: [PATCH] Updated universal script and removed shebang line by default (#789) * changed the method used to skip the script for the other platform to be in sync with lihaoyi/mill#264 * set shebang parameter to be false by default * updated docs on how to prepend the shebang line on linux and added info on how to download on windows --- build.sbt | 39 ++++++++++++++++++++++----------------- readme/Footer.scalatex | 6 ++++++ readme/Sample.scala | 6 +++++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/build.sbt b/build.sbt index 5cfcc6c3a..3c96db9eb 100644 --- a/build.sbt +++ b/build.sbt @@ -153,28 +153,33 @@ lazy val amm = project assemblyOption in assembly := (assemblyOption in assembly).value.copy( prependShellScript = { - def universalScript(shellCommands: Seq[String], - cmdCommands: Seq[String], - shebang: Boolean = true): Seq[String] = { + def universalScript(shellCommands: String, + cmdCommands: String, + shebang: Boolean = false): String = { Seq( - Seq("#!/usr/bin/env sh") - .filter(_ => shebang), - Seq("shopt -s expand_aliases", "alias ::=''") - .map(line => s":; $line"), - (shellCommands :+ "exit") - .map(line => s":: $line"), - "@echo off" +: cmdCommands :+ "exit /B", - Seq("\r\n") - ).flatten + if (shebang) "#!/usr/bin/env sh" else "", + "@ 2>/dev/null # 2>nul & echo off & goto BOF\r", + ":", + shellCommands.replaceAll("\r\n|\n", "\n"), + "exit", + Seq( + "", + ":BOF", + "@echo off", + cmdCommands.replaceAll("\r\n|\n", "\r\n"), + "exit /B %errorlevel%", + "" + ).mkString("\r\n") + ).filterNot(_.isEmpty).mkString("\n") } - def defaultUniversalScript(javaOpts: Seq[String] = Seq.empty, shebang: Boolean = true): Seq[String] = { + def defaultUniversalScript(javaOpts: Seq[String] = Seq.empty, shebang: Boolean = false): Seq[String] = { val javaOptsString = javaOpts.map(_ + " ").mkString - universalScript( - shellCommands = Seq(s"exec java -jar $javaOptsString" + """$JAVA_OPTS "$0" "$@""""), - cmdCommands = Seq(s"java -jar $javaOptsString" + """%JAVA_OPTS% "%~dpnx0" %*"""), + Seq(universalScript( + shellCommands = s"""exec java -jar $javaOptsString$$JAVA_OPTS "$$0" "$$@"""", + cmdCommands = s"""java -jar $javaOptsString%JAVA_OPTS% "%~dpnx0" %*""", shebang = shebang - ) + )) } // G1 Garbage Collector is awesome https://github.com/lihaoyi/Ammonite/issues/216 diff --git a/readme/Footer.scalatex b/readme/Footer.scalatex index a1a9cf93d..0c5106cd8 100644 --- a/readme/Footer.scalatex +++ b/readme/Footer.scalatex @@ -1433,6 +1433,12 @@ @hl.sh @readme.Sample.unstableCurl + @p + The latest build can also be run on windows. Just save it as amm.bat: + + @p + @lnk(ammonite.Constants.unstableCurlUrl) + @p Or usage in an SBT project diff --git a/readme/Sample.scala b/readme/Sample.scala index 22b18fbc3..f5bb48d0b 100644 --- a/readme/Sample.scala +++ b/readme/Sample.scala @@ -17,8 +17,12 @@ object Sample{ s"$$ sudo curl -L -o /usr/local/bin/amm " + curlUrl + " && sudo chmod +x /usr/local/bin/amm && amm" + def unstableCurlCommand(curlUrl: String) = + s"""$$ sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L """ + + curlUrl + + ") > /usr/local/bin/amm && chmod +x /usr/local/bin/amm' && amm" val replCurl = curlCommand(ammonite.Constants.curlUrl) - val unstableCurl = curlCommand(ammonite.Constants.unstableCurlUrl) + val unstableCurl = unstableCurlCommand(ammonite.Constants.unstableCurlUrl) val filesystemCurl = "$ mkdir -p ~/.ammonite && curl -L -o ~/.ammonite/predef.sc https://git.io/vHaKQ" val cacheVersion = 6