Skip to content

Instantly share code, notes, and snippets.

@paulp
Created June 27, 2017 22:11
Show Gist options
  • Save paulp/8c0d472de9cb95d3dab98de965ea8ef3 to your computer and use it in GitHub Desktop.
Save paulp/8c0d472de9cb95d3dab98de965ea8ef3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Dependencies:
# coursier ( on OSX: brew install --HEAD paulp/extras/coursier )
# zinc ( on OSX: brew install zinc )
#
set -euo pipefail
# You can compile code in different projects by overriding these, e.g.
#
# PROJECT=foundation SCOPE=test <qscalac> ./foundation/src/test/**/*.scala
#
: ${PROJECT=connector}
: ${SCOPE=compile}
run () { echo >&2 "$@" && "$@"; }
scalacArgs () { cat <<EOM
-language:_
-target:jvm-1.8
-Ybackend:GenBCode
-Ydelambdafy:method
-Yno-imports
-Ypartial-unification
-Yliteral-types
-Ywarn-dead-code
-Ywarn-numeric-widen
-Ywarn-value-discard
-Ywarn-unused-import
EOM
}
scalacPlugins () { cat <<EOM
org.spire-math:kind-projector_2.11:0.9.0
com.github.mpilquist:simulacrum_2.11:0.7.0
org.scalamacros:paradise_2.11.8:2.1.0
EOM
}
# org.wartremover:wartremover_2.11:1.1.1
# wartArgs () { cat <<EOM
# -S-P:wartremover:only-warn-traverser:org.wartremover.warts.All
# EOM
# }
expandPlugins () {
for plugin in $(scalacPlugins); do
marker="$(echo "$plugin" | sed 's/:.*//' | sed 's/.*[.]//')"
coursier fetch $plugin | egrep "$marker"
done
}
cpfile="$PROJECT/.classpath-$SCOPE"
[[ -s "$cpfile" ]] || {
./sbt "export $PROJECT/$SCOPE:fullClasspath" | tail -n1 | tr : "\n" > "$cpfile"
}
run zinc \
-scala-path $(coursier fetch org.typelevel:scala-compiler:2.11.8 | paste -sd: -) \
-classpath "$(cat "$cpfile" | paste -sd: -)" \
$(printf -- " -S-Xplugin:%s" $(expandPlugins)) \
$(printf -- " -S%s" $(scalacArgs)) \
"$@"
# -nailed \
# $(wartArgs) \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment