Skip to content

Commit 35320cb

Browse files
Fix #3040: Replace dotc/dotr by wrappers around sbt-pack
1 parent 82dfb6c commit 35320cb

File tree

4 files changed

+18
-417
lines changed

4 files changed

+18
-417
lines changed

bin/common

Lines changed: 13 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,23 @@
11
#!/usr/bin/env bash
22

3-
# Finds in dotty build file a line containing PATTERN
4-
# returns last "" escaped string in this line
5-
function getLastStringOnLineWith {
6-
PATTERN="$1"
7-
grep "$PATTERN" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p
8-
}
3+
# Wrapper for the published dotc/dotr script that check for file changes
4+
# and use sbt to re build the compiler as needed.
95

10-
# Configuration
11-
SCALA_VERSION=$(getLastStringOnLineWith "val scalacVersion")
12-
SCALA_BINARY_VERSION=2.11
13-
SCALA_ASM_VERSION=$(getLastStringOnLineWith "% \"scala-asm\" %")
14-
SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//')
15-
bootcp=true
16-
bootstrapped=false
17-
default_java_opts="-Xmx768m -Xms768m"
18-
programName=$(basename "$0")
19-
# uncomment next line to enable debug output
20-
#debug=true
6+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
217

22-
declare -a java_args scala_args residual_args
23-
unset verbose quiet cygwin toolcp colors saved_stty CDPATH
8+
target="$1"
249

25-
function find_jar {
26-
# Usage:
27-
# find_jar path/to/location file.jar
28-
local artifact="$1/$2"
10+
shift # Mutates $@ by deleting the first element ($1)
2911

30-
if [ ! -f "$artifact" ]; then
31-
artifact=$(find "$HOME/.coursier/cache" -iname "$2" 2> /dev/null)
32-
fi
12+
# Marker file used to obtain the date of latest call to sbt-back
13+
version="$ROOT/dist-bootstrapped/target/pack/VERSION"
3314

34-
echo "$artifact"
35-
}
15+
# Create the target if absent or if file changed in ROOT/compiler
16+
new_files="$(find "$ROOT/compiler" \( -iname "*.scala" -o -iname "*.java" \) -newer "$version" >& /dev/null)"
3617

37-
# Log used to communicate errors from a command substitution, for example:
38-
# $(sbt package || (echo msg >> $ERROR_LOG; kill -SIGTERM $$))
39-
ERROR_LOG=error.log
40-
trap onTerminate SIGTERM
41-
42-
onTerminate() {
43-
if [ -f "$ERROR_LOG" ]; then
44-
cat "$ERROR_LOG"
45-
rm -f "$ERROR_LOG"
46-
fi
47-
exit 1 # $? is lost from subprocess in command substitution.
48-
}
49-
50-
function build_jar {
51-
# Usage:
52-
# build_jar package path/to/jar/dir ['/some/sed/command']
53-
#
54-
# Last arg is optional
55-
cd "$DOTTY_ROOT" >& /dev/null
56-
local build_output=$(sbt "$1" || (echo "failed to run: sbt $1" >> $ERROR_LOG; kill -SIGTERM $$))
57-
local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p')
58-
59-
local sedjar="$3"
60-
if [ "$sedjar" == "" ]; then
61-
sedjar="/tests/d; /javadoc/d; /.*\.jar/p"
62-
fi
63-
64-
if [ "$jar" == "" ]; then
65-
# Didn't build a jar - could've run sbt by oneself, get latest jar in target:
66-
jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')"
67-
fi
68-
69-
cd - >& /dev/null
70-
71-
echo "$jar"
72-
}
73-
74-
function update_packages {
75-
echo "$INTERFACES_JAR" > "$DOTTY_ROOT/.packages"
76-
echo "$MAIN_JAR" >> "$DOTTY_ROOT/.packages"
77-
echo "$DOTTY_LIB_JAR" >> "$DOTTY_ROOT/.packages"
78-
echo "$TEST_JAR" >> "$DOTTY_ROOT/.packages"
79-
}
80-
81-
function build_all {
82-
echo "The script is going to build the required jar files"
83-
84-
printf "Building dotty-interfaces..."
85-
INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)
86-
printf "done\n"
87-
88-
printf "Building dotty-compiler..."
89-
MAIN_JAR=$(build_jar dotty-compiler/package "compiler/target/scala-$SCALA_BINARY_VERSION")
90-
printf "done\n"
91-
92-
printf "Building dotty library..."
93-
DOTTY_LIB_JAR=$(build_jar dotty-library/package "library/target/scala-$SCALA_BINARY_VERSION")
94-
printf "done\n"
95-
96-
printf "Building tests..."
97-
TEST_JAR=$(build_jar test:package "compiler/target/scala-$SCALA_BINARY_VERSION" '/dotty.*-tests\.jar/p')
98-
printf "done\n"
99-
100-
update_packages
101-
}
102-
103-
# Check if .packages file does not exist - if so assume old build and rebuild all
104-
if [ ! -f "$DOTTY_ROOT/.packages" ]; then
105-
build_all
106-
else
107-
IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))'
108-
109-
if [ "${#JARS[@]}" == "4" ]; then
110-
INTERFACES_JAR="${JARS[0]}"
111-
MAIN_JAR="${JARS[1]}"
112-
DOTTY_LIB_JAR="${JARS[2]}"
113-
TEST_JAR="${JARS[3]}"
114-
else
115-
echo "Failed to parse .packages file"
116-
build_all
117-
fi
118-
119-
if [ ! -f "$INTERFACES_JAR" -o ! -f "$MAIN_JAR" -o ! -f "$DOTTY_LIB_JAR" -o ! -f "$TEST_JAR" ]; then
120-
echo ".packages file corrupted, rebuilding"
121-
build_all
122-
fi
18+
if [ ! -f "$target" ] || [ ! -z "$new_files" ]; then
19+
echo "Building Dotty..."
20+
sbt "dist-bootstrapped/pack"
12321
fi
12422

125-
################# After this point, jar variables will be set #################
126-
function check_jar {
127-
# Usage:
128-
# check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure'
129-
local new_files="$(find "$DOTTY_ROOT/$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")"
130-
# If the find failed, or if it found new files...
131-
if [ "$?" -ne 0 ] || [ ! -z "$new_files" ]; then
132-
printf "New files detected in $1, rebuilding..."
133-
rm "$2"
134-
eval "$4"
135-
printf "done\n"
136-
update_packages
137-
fi
138-
}
139-
140-
check_jar "dotty-interfaces" "$INTERFACES_JAR" "interfaces/src" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)'
141-
check_jar "dotty-compiler" "$MAIN_JAR" "compiler/src" 'MAIN_JAR=$(build_jar dotty-compiler/package compiler/target/scala-$SCALA_BINARY_VERSION)'
142-
check_jar "dotty-library" "$DOTTY_LIB_JAR" "library/src" 'DOTTY_LIB_JAR=$(build_jar dotty-library/package library/target/scala-$SCALA_BINARY_VERSION)'
143-
check_jar "dotty-tests" "$TEST_JAR" "compiler/test" 'TEST_JAR=$(build_jar dotty-compiler/test:package compiler/target/scala-$SCALA_BINARY_VERSION /dotty.*-tests\.jar/p)'
144-
145-
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
146-
if [ "$SCALA_LIBRARY_JAR" == "" ]; then
147-
SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar")
148-
fi
149-
150-
if [ "$SCALA_ASM_JAR" == "" ]; then
151-
SCALA_ASM_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang.modules/scala-asm/bundles" "scala-asm-$SCALA_ASM_VERSION.jar")
152-
fi
153-
154-
if [ "$SBT_INTERFACE_JAR" == "" ]; then
155-
SBT_INTERFACE_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-sbt/interface/jars" "interface-$SBT_VERSION.jar")
156-
fi
23+
eval "$target" "$@"

bin/dotc

Lines changed: 2 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -1,221 +1,5 @@
11
#!/usr/bin/env bash
22

3-
# This script is used for running compiler standalone(outside of sbt)
4-
# it's based on miniboxing script and paulp's launcher script
3+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
54

6-
# Try to autodetect real location of the script
7-
DOTTY_ROOT="$(readlink "$0")" # relative, symbolic links resolved
8-
if [[ "$DOTTY_ROOT" == "" ]]; then
9-
DOTTY_ROOT="$0"
10-
fi
11-
DOTTY_ROOT="$(dirname "$DOTTY_ROOT")"
12-
DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute
13-
14-
source "$DOTTY_ROOT/bin/common"
15-
16-
# dotc.build test places bootstrapped jar here
17-
DOTTY_JAR="$DOTTY_ROOT/dotty.jar"
18-
19-
CompilerMain=dotty.tools.dotc.Main
20-
FromTasty=dotty.tools.dotc.FromTasty
21-
ReplMain=dotty.tools.dotc.repl.Main
22-
23-
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_ASM_JAR" -o ! -f "$SBT_INTERFACE_JAR" ]
24-
then
25-
echo To use this script please set
26-
echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)"
27-
echo SCALA_ASM_JAR to point to scala-asm-$SCALA_ASM_VERSION.jar "(currently $SCALA_ASM_JAR)"
28-
echo SBT_INTERFACE_JAR to point to interface-$SBT_VERSION.jar "(currently $SBT_INTERFACE_JAR)"
29-
fi
30-
31-
ifdebug () {
32-
[[ -n "$debug" ]] && eval "$@"
33-
}
34-
echoErr () {
35-
echo >&2 "$@"
36-
}
37-
dlog () {
38-
[[ -n "$debug" ]] && echoErr "$@"
39-
}
40-
41-
die() {
42-
echo "Aborting: $@"
43-
exit 1
44-
}
45-
echoArgs () {
46-
echoErr ""
47-
for arg; do
48-
echoErr "$arg"
49-
done
50-
echoErr ""
51-
}
52-
execCommand () {
53-
ifdebug echoArgs "$@"
54-
ignore="$(cat "$HOME/.scala_ignore_crashes" 2>/dev/null)"
55-
if [[ "$ignore" == "true" ]]; then
56-
"$@" 2>&1 | scala-crash-filter
57-
else
58-
$@
59-
fi
60-
}
61-
62-
# restore stty settings (echo in particular)
63-
restoreSttySettings () {
64-
dlog "" && dlog "[restore stty] $saved_stty"
65-
stty "$saved_stty" && saved_stty=""
66-
}
67-
68-
onExit () {
69-
[[ -n "$saved_stty" ]] && restoreSttySettings
70-
exit $scala_exit_status
71-
}
72-
73-
# Get debug set early
74-
for arg in "$@"; do
75-
[[ $arg == "-debug" ]] && debug=true
76-
done
77-
78-
# to reenable echo if we are interrupted before completing.
79-
trap onExit INT
80-
81-
# save terminal settings
82-
saved_stty="$(stty -g 2>/dev/null)"
83-
84-
# clear on error so we don't later try to restore them
85-
[[ $? ]] || saved_stty=""
86-
dlog "[save stty] $saved_stty"
87-
88-
if uname | grep -q ^CYGWIN; then
89-
cygwin="$(uname)"
90-
fi
91-
92-
addJava () {
93-
dlog "[addJava] arg = '$1'"
94-
java_args+=("$1")
95-
}
96-
addScala () {
97-
dlog "[addScala] arg = '$1'"
98-
scala_args+=("$1")
99-
}
100-
addResidual () {
101-
dlog "[residual] arg = '$1'"
102-
residual_args+=("$1")
103-
}
104-
105-
onExit() {
106-
[[ -n "$saved_stty" ]] && restoreSttySettings
107-
exit $scala_exit_status
108-
}
109-
110-
# to reenable echo if we are interrupted before completing.
111-
trap onExit INT
112-
113-
# If using the boot classpath, also pass an empty classpath
114-
# to java to suppress "." from materializing.
115-
classpathArgs () {
116-
if [[ "true" == "$bootstrapped" ]]; then
117-
check_jar "dotty-bootstrapped" "$DOTTY_JAR" "target" 'build_jar "test:runMain dotc.build" target' &> /dev/null
118-
toolchain="$DOTTY_JAR:$DOTTY_LIB_JAR:$SCALA_LIBRARY_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
119-
else
120-
toolchain="$SCALA_LIBRARY_JAR:$DOTTY_LIB_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
121-
fi
122-
bcpJars="$INTERFACES_JAR:$MAIN_JAR:$DOTTY_LIB_JAR"
123-
cpJars="$INTERFACES_JAR:$MAIN_JAR:$DOTTY_LIB_JAR:$TEST_JAR"
124-
125-
if [[ -n "$cygwin" ]]; then
126-
if [[ "$OS" = "Windows_NT" ]] && cygpath -m .>/dev/null 2>/dev/null ; then
127-
format=mixed
128-
else
129-
format=windows
130-
fi
131-
132-
if [[ -n "$bootcp" ]]; then
133-
boot_classpath="$(cygpath --path --$format "$toolchain:$bcpJars")"
134-
classpath="$(cygpath --path --$format "$cpJars")"
135-
cpArgs="-Xbootclasspath/a:$boot_classpath -classpath $classpath"
136-
else
137-
classpath="$(cygpath --path --$format "$toolchain:$cpJars")"
138-
cpArgs="-classpath $classpath"
139-
fi
140-
else
141-
if [[ -n "$bootcp" ]]; then
142-
cpArgs="-Xbootclasspath/a:$toolchain:$bcpJars -classpath $cpJars"
143-
else
144-
cpArgs="-classpath $toolchain:$cpJars"
145-
fi
146-
fi
147-
echo ${cpArgs}
148-
}
149-
150-
# e.g. path -java-home /path/to/java_home
151-
require_arg () {
152-
local type="$1"
153-
local opt="$2"
154-
local arg="$3"
155-
156-
if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
157-
die "$opt requires <$type> argument"
158-
fi
159-
}
160-
161-
162-
main_class="$CompilerMain"
163-
164-
while [[ $# -gt 0 ]]; do
165-
case "$1" in
166-
--) shift; for arg; do addResidual "$arg"; done; set -- ;;
167-
-h|-help) help=true && shift ;;
168-
-bootstrapped) bootstrapped=true && shift ;;
169-
-v|-verbose) verbose=true && addScala "-verbose" && shift ;;
170-
-debug) debug=true && shift ;;
171-
-q|-quiet) quiet=true && shift ;;
172-
173-
# Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222
174-
-Oshort) addJava "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" && shift ;;
175-
-repl) main_class="$ReplMain" && shift ;;
176-
-tasty) main_class="$FromTasty" && shift ;;
177-
-compile) main_class="$CompilerMain" && shift ;;
178-
-run) main_class="$ReplMain" && shift ;;
179-
-fsc) main_class="$FscMain" && shift ;;
180-
-bootcp) bootcp=true && shift ;;
181-
-nobootcp) unset bootcp && shift ;;
182-
-colors) colors=true && shift ;;
183-
-no-colors) unset colors && shift ;;
184-
-jrebel) jrebel=true && shift ;;
185-
-no-jrebel) unset jrebel && shift ;;
186-
187-
-toolcp) require_arg classpath "$1" "$2" && toolcp="$2" && shift 2 ;;
188-
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
189-
190-
# break out -D and -J options and add them to JAVA_OPTS as well
191-
# so they reach the JVM in time to do some good. The -D options
192-
# will be available as system properties.
193-
-D*) addJava "$1" && addScala "$1" && shift ;;
194-
-J*) addJava "${1:2}" && addScala "$1" && shift ;;
195-
*) addResidual "$1" && shift ;;
196-
esac
197-
done
198-
199-
200-
[[ -z $java_cmd ]] && prefix=${java_home:+$java_home/bin/} && java_cmd="${prefix}java"
201-
202-
# note that variables which may intentionally be empty must not
203-
# be quoted: otherwise an empty string will appear as a command line
204-
# argument, and java will think that is the program to run.
205-
execCommand \
206-
"$java_cmd" \
207-
${JAVA_OPTS:-$default_java_opts} \
208-
"${java_args[@]}" \
209-
"$(classpathArgs)" \
210-
-Dscala.usejavacp=true \
211-
"${main_class}" \
212-
"${scala_args[@]}" \
213-
"${residual_args[@]}"
214-
215-
# record the exit status lest it be overwritten:
216-
# then reenable echo and propagate the code.
217-
scala_exit_status=$?
218-
onExit
219-
220-
221-
#echo java -cp $MAIN_JAR: -Dscala.usejavacp=true dotty.tools.dotc.Main $@
5+
eval "$ROOT/bin/common" "$ROOT/dist-bootstrapped/target/pack/bin/dotc" "$@"

0 commit comments

Comments
 (0)