|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
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. |
9 | 5 |
|
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)/.." |
21 | 7 |
|
22 | | -declare -a java_args scala_args residual_args |
23 | | -unset verbose quiet cygwin toolcp colors saved_stty CDPATH |
| 8 | +target="$1" |
24 | 9 |
|
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) |
29 | 11 |
|
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" |
33 | 14 |
|
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)" |
36 | 17 |
|
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" |
123 | 21 | fi |
124 | 22 |
|
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" "$@" |
0 commit comments