Make bootstrap safe for arguments including spaces (#882)

This commit is contained in:
Ryo Fukumuro 2018-07-16 21:05:22 +09:00 committed by Alexandre Archambault
parent 13582d6ee6
commit c5b43d8d35
2 changed files with 28 additions and 20 deletions

View File

@ -69,32 +69,35 @@ object Bootstrap extends CaseApp[BootstrapOptions] {
private def createJarBootstrapWithPreamble(javaOpts: Seq[String], output: File, content: Array[Byte]): Unit = {
val argsPartitioner =
"""|sys_args=""
|app_args=""
|i=1; while [ "$i" -le $# ]; do
| eval arg=\${$i}
| case $arg in
| -J-*)
| sys_args="$sys_args ${arg#-J}"
| ;;
| *)
| app_args="$app_args $arg"
| ;;
| esac
| i=$((i + 1))
|done
"""|nargs=$#
|
|i=1; while [ "$i" -le $nargs ]; do
| eval arg=\${$i}
| case $arg in
| -J-*) set -- "$@" "${arg#-J}" ;;
| esac
| i=$((i + 1))
| done
|
|set -- "$@" -jar "$0"
|
|i=1; while [ "$i" -le $nargs ]; do
| eval arg=\${$i}
| case $arg in
| -J-*) ;;
| *) set -- "$@" "$arg" ;;
| esac
| i=$((i + 1))
| done
|
|shift "$nargs"
|""".stripMargin
val javaCmd = Seq("java") ++
javaOpts
// escaping possibly a bit loose :-|
.map(s => "'" + s.replace("'", "\\'") + "'") ++
Seq(
"$sys_args",
"-jar",
"\"$0\"",
"$app_args"
)
Seq("\"$@\"")
val shellPreamble = Seq(
"#!/usr/bin/env sh",

View File

@ -141,6 +141,11 @@ testBootstrap() {
exit 1
fi
if [ "$(./cs-echo-launcher "-n foo")" != "-n foo" ]; then
echo "Error: unexpected output from bootstrapped echo command (generated by proguarded launcher)." 1>&2
exit 1
fi
# run via the launcher rather than via the sbt-pack scripts, because the latter interprets -Dfoo=baz itself
# rather than passing it to coursier since https://github.com/xerial/sbt-pack/pull/118
./coursier-test bootstrap -o cs-props -D other=thing -J -Dfoo=baz io.get-coursier:props:1.0.2