diff --git a/.gitignore b/.gitignore index 402069d..db97f80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target/ /pack/ +/cli-test/ diff --git a/.travis.yml b/.travis.yml index c9a53ed..e35efc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - SCALAJS_VERSION=1.0.0 script: - ./scripts/assemble-cli.sh $SCALAJS_VERSION $TRAVIS_SCALA_VERSION + - ./scripts/test-cli.sh $SCALAJS_VERSION $TRAVIS_SCALA_VERSION cache: directories: - $HOME/.ivy2/cache diff --git a/TESTING.md b/TESTING.md index 150ad95..5fa4bc6 100644 --- a/TESTING.md +++ b/TESTING.md @@ -2,7 +2,7 @@ TODO: We should automate this process -For each major Scala version on a *NIX distro and a Windows distro: +For each major Scala version on a Windows distro: 1. Download packaged Scala from scala-lang.org 2. Build a CLI distribution (see [the release process](./RELEASING.md)) diff --git a/scripts/assemble-cli.sh b/scripts/assemble-cli.sh index 7076a80..663924b 100755 --- a/scripts/assemble-cli.sh +++ b/scripts/assemble-cli.sh @@ -1,31 +1,8 @@ #! /bin/sh -set -e - # Assembles the CLI tools for a given Scala binary version. -if [ $# -lt 2 ]; then - echo "Usage: $(basename $0) " >&2 - exit 1 -fi - -SCALAJS_VER=$1 - -BASEVER=$2 -case $BASEVER in - 2.11.*) - BINVER="2.11" - ;; - 2.12.*) - BINVER="2.12" - ;; - 2.13.*) - BINVER="2.13" - ;; - *) - echo "Invalid Scala version $BINVER" >&2 - exit 2 -esac +. "$(dirname $0)/vars.sh" # Build and lay out the contents of the archives sbt \ @@ -35,21 +12,11 @@ sbt \ "cliPack" \ || exit $? -# Base Scala.js project directory. -BASE="$(dirname $0)/.." - -# Aritfact name (no extension). -NAME=scalajs_$BINVER-$SCALAJS_VER - -# Target directories -TRG_BASE="$BASE/pack" -TRG_VER="$TRG_BASE/$NAME" - # Tar and zip the whole thing up ( cd $TRG_BASE - tar cfz $NAME.tgz $NAME + tar cfz $SJS_ARTIFACT_NAME.tgz $SJS_ARTIFACT_NAME - if [ -f $NAME.zip ]; then rm $NAME.zip; fi - zip -r $NAME.zip -r $NAME + if [ -f $SJS_ARTIFACT_NAME.zip ]; then rm $SJS_ARTIFACT_NAME.zip; fi + zip -r $SJS_ARTIFACT_NAME.zip -r $SJS_ARTIFACT_NAME ) diff --git a/scripts/test-cli.sh b/scripts/test-cli.sh new file mode 100755 index 0000000..c824fb1 --- /dev/null +++ b/scripts/test-cli.sh @@ -0,0 +1,59 @@ +#! /bin/sh + +# Tests the CLI tools. + +. "$(dirname $0)/vars.sh" + +TEST_DIR="$(realpath $(dirname $0)/../cli-test)" + +rm -rf $TEST_DIR +mkdir $TEST_DIR +cd $TEST_DIR + +# Fetch Scala +SCALA_ARTIFACT_NAME=scala-$BASEVER +wget "https://downloads.lightbend.com/scala/$BASEVER/$SCALA_ARTIFACT_NAME.tgz" +tar xf $SCALA_ARTIFACT_NAME.tgz + +# Fetch Scala.js +cp $TRG_BASE/$SJS_ARTIFACT_NAME.tgz . +tar xf $SJS_ARTIFACT_NAME.tgz + +# Setup PATH +PATH=$PATH:$TEST_DIR/$SCALA_ARTIFACT_NAME/bin:$TEST_DIR/$SJS_ARTIFACT_NAME/bin + +fail() { + echo "$1" >&2 + exit 2 +} + +# Actual test. +mkdir bin +cat > foo.scala <<'EOF' +object Foo { + def main(args: Array[String]): Unit = { + println(s"asdf ${1 + 1}") + new A + } + + class A +} +EOF + +scalajsc -d bin foo.scala + +scalajsp bin/Foo$.sjsir > out +test -s out || fail "scalajsp bin/Foo$.sjsir: empty output" + +scalajsp bin/Foo\$A.sjsir > out +test -s out || fail "scalajsp bin/Foo\$A.sjsir: empty output" + +scalajsld -o test.js -mm Foo.main bin +test -s test.js || fail "scalajsld: empty output" + +node test.js > got.run +cat > want.run < " >&2 + exit 1 +fi + +SCALAJS_VER=$1 + +BASEVER=$2 +case $BASEVER in + 2.11.*) + BINVER="2.11" + ;; + 2.12.*) + BINVER="2.12" + ;; + 2.13.*) + BINVER="2.13" + ;; + *) + echo "Invalid Scala version $BINVER" >&2 + exit 2 +esac + +# Base Scala.js project directory. +TRG_BASE="$(realpath $(dirname $0)/../pack)" + +SJS_ARTIFACT_NAME=scalajs_$BINVER-$SCALAJS_VER diff --git a/src/main/resources/scalajsc b/src/main/resources/scalajsc index c9dbe3e..ff6efdf 100755 --- a/src/main/resources/scalajsc +++ b/src/main/resources/scalajsc @@ -2,7 +2,7 @@ SCALA_BIN_VER="@SCALA_BIN_VER@" SCALAJS_VER="@SCALAJS_VER@" -SCALA_VER=$(scalac -version 2>&1 | grep -o '[0-9]\.[0-9]\+\.[0-9]\+') +SCALA_VER=$(scalac -version 2>&1 | grep -i scala | grep -o '[0-9]\.[0-9]\+\.[0-9]\+') if [ "$(echo $SCALA_VER | cut -d '.' -f 1-2)" != "$SCALA_BIN_VER" ]; then echo "This bundle of Scala.js CLI is for $SCALA_BIN_VER. Your scala version is $SCALA_VER!" >&2