Skip to content

Commit 574681e

Browse files
committed
Extract common variables to common script in bin dir
1 parent 156066d commit 574681e

File tree

3 files changed

+141
-154
lines changed

3 files changed

+141
-154
lines changed

bin/common

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
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+
}
9+
10+
# Configuration
11+
SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in")
12+
SCALA_BINARY_VERSION=2.11
13+
SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler")
14+
JLINE_VERSION=$(getLastStringOnLineWith "jline")
15+
SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//')
16+
bootcp=true
17+
bootstrapped=false
18+
default_java_opts="-Xmx768m -Xms768m"
19+
programName=$(basename "$0")
20+
# uncomment next line to enable debug output
21+
#debug=true
22+
23+
declare -a java_args scala_args residual_args
24+
unset verbose quiet cygwin toolcp colors saved_stty CDPATH
25+
26+
function find_jar {
27+
# Usage:
28+
# find_jar path/to/location file.jar
29+
local artifact="$1/$2"
30+
31+
if [ ! -f "$artifact" ]; then
32+
artifact=$(find "$HOME/.coursier/cache" -iname "$2")
33+
fi
34+
35+
echo "$artifact"
36+
}
37+
38+
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
39+
if [ "$SCALA_LIBRARY_JAR" == "" ]; then
40+
SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar")
41+
fi
42+
43+
if [ "$SCALA_REFLECT_JAR" == "" ]; then
44+
SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar")
45+
fi
46+
47+
if [ "$SCALA_COMPILER_JAR" == "" ]; then
48+
SCALA_COMPILER_JAR=$(find_jar "$HOME/.ivy2/cache/me.d-d/scala-compiler/jars" "scala-compiler-$SCALA_COMPILER_VERSION.jar")
49+
fi
50+
51+
if [ "$JLINE_JAR" == "" ]; then
52+
JLINE_JAR=$(find_jar "$HOME/.ivy2/cache/jline/jline/jars" "jline-$JLINE_VERSION.jar")
53+
fi
54+
55+
if [ "$SBT_INTERFACE_JAR" == "" ]; then
56+
SBT_INTERFACE_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-sbt/interface/jars" "interface-$SBT_VERSION.jar")
57+
fi
58+
59+
function build_jar {
60+
# Usage:
61+
# build_jar package path/to/jar/dir ['/some/sed/command']
62+
#
63+
# Last arg is optional
64+
cd $DOTTY_ROOT >& /dev/null
65+
local build_output=$(sbt "$1")
66+
local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p')
67+
68+
local sedjar="$3"
69+
if [ "$sedjar" == "" ]; then
70+
sedjar="/.*\.jar/p"
71+
fi
72+
73+
if [ "$jar" == "" ]; then
74+
# Didn't build a jar - could've run sbt by oneself, get latest jar in target:
75+
jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')"
76+
fi
77+
78+
cd - >& /dev/null
79+
80+
echo $jar
81+
}
82+
83+
function update_packages {
84+
echo "$INTERFACES_JAR" > $DOTTY_ROOT/.packages
85+
echo "$MAIN_JAR" >> $DOTTY_ROOT/.packages
86+
echo "$TEST_JAR" >> $DOTTY_ROOT/.packages
87+
}
88+
89+
function build_all {
90+
echo "The script is going to build the required jar files"
91+
92+
printf "Building dotty-interfaces..."
93+
INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)
94+
printf "done\n"
95+
96+
printf "Building dotty..."
97+
MAIN_JAR=$(build_jar package target/scala-2.11)
98+
printf "done\n"
99+
100+
printf "Building tests..."
101+
TEST_JAR=$(build_jar test:package target/scala-2.11 '/dotty.*-tests\.jar/p')
102+
printf "done\n"
103+
104+
update_packages
105+
}
106+
107+
# Check if .packages file does not exist - if so assume old build and rebuild all
108+
if [ ! -f "$DOTTY_ROOT/.packages" ]; then
109+
build_all
110+
else
111+
IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))'
112+
113+
if [ "${#JARS[@]}" == "3" ]; then
114+
INTERFACES_JAR="${JARS[0]}"
115+
MAIN_JAR="${JARS[1]}"
116+
TEST_JAR="${JARS[2]}"
117+
else
118+
echo "Corrupted .packages file"
119+
build_all
120+
fi
121+
fi
122+
123+
################# After this point, jar variables will be set #################
124+
function check_jar {
125+
# Usage:
126+
# check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure'
127+
local new_files="$(find "$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")"
128+
if [ ! -z "$new_files" ]; then
129+
printf "New files detected in $1, rebuilding..."
130+
eval "$4"
131+
printf "done\n"
132+
update_packages
133+
fi
134+
}
135+
136+
check_jar "dotty-interfaces" $INTERFACES_JAR "interfaces" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)'
137+
check_jar "dotty" $MAIN_JAR "src" 'MAIN_JAR=$(build_jar package target/scala-2.11)'
138+
check_jar "dotty-tests" $TEST_JAR "test" 'TEST_JAR=$(build_jar test:package target/scala-2.11 /dotty.*-tests\.jar/p)'

bin/dotc

Lines changed: 1 addition & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -10,110 +10,7 @@ fi
1010
DOTTY_ROOT="$(dirname "$DOTTY_ROOT")"
1111
DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute
1212

13-
# Finds in dotty build file a line containing PATTERN
14-
# returns last "" escaped string in this line
15-
function getLastStringOnLineWith {
16-
PATTERN="$1"
17-
grep "$PATTERN" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p
18-
}
19-
20-
# Configuration
21-
SCALA_VERSION=$(getLastStringOnLineWith "scalaVersion in")
22-
SCALA_BINARY_VERSION=2.11
23-
SCALA_COMPILER_VERSION=$(getLastStringOnLineWith "scala-compiler")
24-
JLINE_VERSION=$(getLastStringOnLineWith "jline")
25-
SBT_VERSION=$(grep "sbt.version=" "$DOTTY_ROOT/project/build.properties" | sed 's/sbt.version=//')
26-
bootcp=true
27-
bootstrapped=false
28-
default_java_opts="-Xmx768m -Xms768m"
29-
programName=$(basename "$0")
30-
# uncomment next line to enable debug output
31-
#debug=true
32-
33-
declare -a java_args scala_args residual_args
34-
unset verbose quiet cygwin toolcp colors saved_stty CDPATH
35-
36-
function build_jar {
37-
# Usage:
38-
# build_jar package path/to/jar/dir ['/some/sed/command']
39-
#
40-
# Last arg is optional
41-
cd $DOTTY_ROOT >& /dev/null
42-
local build_output=$(sbt "$1")
43-
local jar=$(echo $build_output | sed -n 's/.*Packaging //g; s/ \.\.\..*//g; /^\/.*/p')
44-
45-
local sedjar="$3"
46-
if [ "$sedjar" == "" ]; then
47-
sedjar="/.*\.jar/p"
48-
fi
49-
50-
if [ "$jar" == "" ]; then
51-
# Didn't build a jar - could've run sbt by oneself, get latest jar in target:
52-
jar="$DOTTY_ROOT/$2/$(ls -1t "$2" | sed -n "$sedjar" | awk 'NR==1')"
53-
fi
54-
55-
cd - >& /dev/null
56-
57-
echo $jar
58-
}
59-
60-
function update_packages {
61-
echo "$INTERFACES_JAR" > $DOTTY_ROOT/.packages
62-
echo "$MAIN_JAR" >> $DOTTY_ROOT/.packages
63-
echo "$TEST_JAR" >> $DOTTY_ROOT/.packages
64-
}
65-
66-
function build_all {
67-
echo "The script is going to build the required jar files"
68-
69-
printf "Building dotty-interfaces..."
70-
INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)
71-
printf "done\n"
72-
73-
printf "Building dotty..."
74-
MAIN_JAR=$(build_jar package target/scala-2.11)
75-
printf "done\n"
76-
77-
printf "Building tests..."
78-
TEST_JAR=$(build_jar test:package target/scala-2.11 '/dotty.*-tests\.jar/p')
79-
printf "done\n"
80-
81-
update_packages
82-
}
83-
84-
85-
# Check if .packages file does not exist - if so assume old build and rebuild all
86-
if [ ! -f "$DOTTY_ROOT/.packages" ]; then
87-
build_all
88-
else
89-
IFS=$'\r\n' GLOBIGNORE='*' command eval 'JARS=($(cat $DOTTY_ROOT/.packages))'
90-
91-
if [ "${#JARS[@]}" == "3" ]; then
92-
INTERFACES_JAR="${JARS[0]}"
93-
MAIN_JAR="${JARS[1]}"
94-
TEST_JAR="${JARS[2]}"
95-
else
96-
echo "Corrupted .packages file"
97-
build_all
98-
fi
99-
fi
100-
101-
################# After this point, jar variables will be set #################
102-
function check_jar {
103-
# Usage:
104-
# check_jar "name" "path/to/package.jar" "sources/dir" 'lambda to exec on failure'
105-
local new_files="$(find "$3" \( -iname "*.scala" -o -iname "*.java" \) -newer "$2")"
106-
if [ ! -z "$new_files" ]; then
107-
printf "New files detected in $1, rebuilding..."
108-
eval "$4"
109-
printf "done\n"
110-
update_packages
111-
fi
112-
}
113-
114-
check_jar "dotty-interfaces" $INTERFACES_JAR "interfaces" 'INTERFACES_JAR=$(build_jar dotty-interfaces/package interfaces/target)'
115-
check_jar "dotty" $MAIN_JAR "src" 'MAIN_JAR=$(build_jar package target/scala-2.11)'
116-
check_jar "dotty-tests" $TEST_JAR "test" 'TEST_JAR=$(build_jar test:package target/scala-2.11 /dotty.*-tests\.jar/p)'
13+
source $DOTTY_ROOT/bin/common
11714

11815
# dotc.build test places bootstrapped jar here
11916
DOTTY_JAR=$DOTTY_ROOT/dotty.jar
@@ -122,39 +19,6 @@ CompilerMain=dotty.tools.dotc.Main
12219
FromTasty=dotty.tools.dotc.FromTasty
12320
ReplMain=dotty.tools.dotc.repl.Main
12421

125-
function find_jar {
126-
# Usage:
127-
# find_jar path/to/location file.jar
128-
local artifact="$1/$2"
129-
130-
if [ ! -f "$artifact" ]; then
131-
artifact=$(find "$HOME/.coursier/cache" -iname "$2")
132-
fi
133-
134-
echo "$artifact"
135-
}
136-
137-
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
138-
if [ "$SCALA_LIBRARY_JAR" == "" ]; then
139-
SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar")
140-
fi
141-
142-
if [ "$SCALA_REFLECT_JAR" == "" ]; then
143-
SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar")
144-
fi
145-
146-
if [ "$SCALA_COMPILER_JAR" == "" ]; then
147-
SCALA_COMPILER_JAR=$(find_jar "$HOME/.ivy2/cache/me.d-d/scala-compiler/jars" "scala-compiler-$SCALA_COMPILER_VERSION.jar")
148-
fi
149-
150-
if [ "$JLINE_JAR" == "" ]; then
151-
JLINE_JAR=$(find_jar "$HOME/.ivy2/cache/jline/jline/jars" "jline-$JLINE_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
157-
15822
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" -o ! -f "$JLINE_JAR" -o ! -f "$SBT_INTERFACE_JAR" ]
15923
then
16024
echo To use this script please set

bin/dotr

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,9 @@ if [[ "$DOTTY_ROOT" == "" ]]; then
77
fi
88
DOTTY_ROOT="$(dirname "$DOTTY_ROOT")"
99
DOTTY_ROOT="$( cd "$DOTTY_ROOT" >& /dev/null && pwd )/.." # absolute
10-
SCALA_VERSION=$(grep "scalaVersion in" "$DOTTY_ROOT/project/Build.scala"|sed -n 's/.*\"\(.*\)\".*/\1/'p)
1110

12-
function find_jar {
13-
# Usage:
14-
# find_jar path/to/location file.jar
15-
local artifact="$1/$2"
16-
17-
if [ ! -f "$artifact" ]; then
18-
artifact=$(find "$HOME/.coursier/cache" -iname "$2")
19-
fi
20-
21-
echo "$artifact"
22-
}
23-
24-
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
25-
if [ "$SCALA_LIBRARY_JAR" == "" ]; then
26-
SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar")
27-
fi
11+
# Load common functions and variables
12+
source $DOTTY_ROOT/bin/common
2813

2914
# CLASS_PATH is derived from the DOTTY_ROOT and SCALA_LIBRARY_JAR
3015
CLASS_PATH="-Xbootclasspath/a:.:$DOTTY_ROOT/target/scala-2.11/classes/:.:$SCALA_LIBRARY_JAR"

0 commit comments

Comments
 (0)