-
Notifications
You must be signed in to change notification settings - Fork 1.1k
avoid duplicate call to dist/bin/common via refactored scalac #12197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
490b91e
3984c3a
c7212b9
9e3d4f2
a49e578
c42e314
24ee36e
2290dbc
58f9b23
48262d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
scala> val d: java.sql.Date = new java.sql.Date(100L) | ||
val d: java.sql.Date = 1970-01-01 | ||
|
||
scala> val d: Long = (new java.sql.Date(100L)).getTime | ||
val d: Long = 100 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Try to autodetect real location of the script | ||
|
||
if [ -z "$PROG_HOME" ] ; then | ||
if [ -z "${PROG_HOME-}" ] ; then | ||
## resolve links - $0 may be a link to PROG_HOME | ||
PRG="$0" | ||
|
||
|
@@ -27,8 +26,8 @@ if [ -z "$PROG_HOME" ] ; then | |
cd "$saveddir" | ||
fi | ||
|
||
addJvmOptions () { | ||
jvm_options+=("'$1'") | ||
addJava () { | ||
java_args+=("'$1'") | ||
} | ||
|
||
addScalacOptions () { | ||
|
@@ -65,7 +64,7 @@ while [[ $# -gt 0 ]]; do | |
execute_run=true | ||
shift | ||
;; | ||
-cp | -classpath ) | ||
-cp | -classpath) | ||
CLASS_PATH="$2${PSEP}" | ||
class_path_count+=1 | ||
shift | ||
|
@@ -100,23 +99,33 @@ while [[ $# -gt 0 ]]; do | |
;; | ||
-version) | ||
# defer to scalac, then exit | ||
addScalacOptions "${1}" | ||
shift | ||
eval "\"$PROG_HOME/bin/scalac\" ${cp_arg-} ${java_options[@]}" | ||
eval "\"$PROG_HOME/bin/scalac\" -version" | ||
scala_exit_status=$? | ||
onExit | ||
;; | ||
-J*) | ||
addJvmOptions "${1:2}" | ||
addJava "${1:2}" | ||
addScalacOptions "${1}" | ||
shift ;; | ||
*) | ||
if [ $execute_script == false ]; then | ||
# is a script if extension .scala or .sc or if has scala hash bang | ||
if [[ -e "$1" && ("$1" == *.scala || "$1" == *.sc || -f "$1" && `head -n 1 -- "$1" | grep '#!.*scala'`) ]]; then | ||
if [[ "$1" == *.scala || "$1" == *.sc ]]; then | ||
# is a script if extension .scala or .sc | ||
# (even if file not found, to avoid adding likely typo to residual_args) | ||
execute_script=true | ||
target_script="$1" | ||
elif [[ (-f "$1" && `head -n 1 -- "$1" | grep '#!.*scala'`) ]]; then | ||
execute_script=true | ||
target_script="$1" | ||
if [ ! -f $target_script ]; then | ||
# likely a typo or missing script file, quit early | ||
echo "not found: $target_script" 1>&2 | ||
scala_exit_status=2 | ||
onExit | ||
fi | ||
else | ||
# unrecognized args appearing prior to a script name | ||
residual_args+=("$1") | ||
fi | ||
else | ||
|
@@ -128,8 +137,8 @@ while [[ $# -gt 0 ]]; do | |
esac | ||
done | ||
|
||
[ -n "${script_trace-}" ] && set -x | ||
if [ $execute_script == true ]; then | ||
[ -n "${script_trace-}" ] && set -x | ||
if [ "$CLASS_PATH" ]; then | ||
cp_arg="-classpath \"$CLASS_PATH\"" | ||
fi | ||
|
@@ -141,8 +150,20 @@ if [ $execute_script == true ]; then | |
scala_exit_status=$? | ||
else | ||
[[ $save_compiled == true ]] && rm -f $target_jar | ||
residual_args+=($setScriptName) | ||
eval "\"$PROG_HOME/bin/scalac\" ${cp_arg-} ${java_options[@]} ${residual_args[@]} -script $target_script ${script_args[@]}" | ||
set -- ${cp_arg-} ${java_options[@]} ${residual_args[@]} -script "$target_script" ${script_args[@]} | ||
PROG_MAIN=$ScriptingMain | ||
prepScalacCommandLine "$@" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering what arguments are expected to be parsed here? If it's only 1 or 2, can we do it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered trying to do a less extensive change, but ran into problems. One concern is has to do with alternate ways for launching a script. The following two command lines are currently supported valid ways to launch a script: scala hello.sc
scalac -script hello.sc These and other similar issues are tested in My assumption is that we want a functionally neutral refactoring, so scripts should use the same default values, for example They should leverage a single toolchain classpath, and should have access to and respond the same way to scalac options such as Anyway, that's what led me to the current implementation, which can no doubt be improved in various ways. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am not sure if Scala 2 supports the above. If not, I think it does not have to be supported.
This can be either duplicated or moved to
Given that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Okay, I see what you have in mind. I'll will review it again.
I don't think it's supported by scala 2, although both ways of launching the script must provide There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liufengyun |
||
# exec here would prevent onExit from being called, leaving terminal in unusable state | ||
eval "\"$JAVACMD\"" \ | ||
${JAVA_OPTS:-$default_java_opts} \ | ||
"${DEBUG-}" \ | ||
"${java_args[@]}" \ | ||
"-classpath \"$jvm_cp_args\"" \ | ||
-Dscala.usejavacp=true \ | ||
"$PROG_NAME" \ | ||
"${scala_args[@]}" \ | ||
"${residual_args[@]}" \ | ||
"${scripting_string-}" | ||
scala_exit_status=$? | ||
fi | ||
elif [ $execute_repl == true ] || ([ $execute_run == false ] && [ $options_indicator == 0 ]); then | ||
|
@@ -151,7 +172,7 @@ elif [ $execute_repl == true ] || ([ $execute_run == false ] && [ $options_indic | |
fi | ||
eval "\"$PROG_HOME/bin/scalac\" ${cp_arg-} ${java_options[@]} -repl ${residual_args[@]}" | ||
scala_exit_status=$? | ||
elif [ $execute_repl == true ] || [ ${#residual_args[@]} -ne 0 ]; then | ||
elif [ ${#residual_args[@]} -ne 0 ]; then | ||
cp_arg="$DOTTY_LIB$PSEP$SCALA_LIB" | ||
if [ -z "$CLASS_PATH" ]; then | ||
cp_arg+="$PSEP." | ||
|
@@ -165,7 +186,7 @@ elif [ $execute_repl == true ] || [ ${#residual_args[@]} -ne 0 ]; then | |
cp_arg+="$PSEP$DOTTY_COMP$PSEP$TASTY_CORE$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$PSEP$DOTTY_STAGING$PSEP$DOTTY_TASTY_INSPECTOR" | ||
fi | ||
# exec here would prevent onExit from being called, leaving terminal in unusable state | ||
eval "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${jvm_options[@]}" "${residual_args[@]}" | ||
eval "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${java_args[@]}" "${residual_args[@]}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the refactoring 👍 |
||
scala_exit_status=$? | ||
else | ||
echo "warning: command option is not correct." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename it to reflect that it's used for the compiler JVM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liufengyun - good idea. I didn't see this until after I pushed changes, so we'll have to do that when we update the two other calls to
bin/scalac
.