-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
insert compiler libraries head of user-specified classpath - fix for 13552 #13562
Conversation
Maybe we could add some unit tests, for example in CoursierTests suite? |
I'm working on adding some unit tests. I ran into a puzzle, though, perhaps someone can suggest what might be going on. bin/scala compiler/test-resources/scripting/classpathReport.sc # this works as expected
dist/target/pack/bin/scala compiler/test-resources/scripting/classpathReport.sc # this works
compiler/test-resources/scripting/classpathReport.sc # this fails catastrophically in Windows In my environment, calling the script directly prints almost half a million compiler error messages (a bit more than 452,000, to be more precise). Looking at the first few error messages, it seems that the compiler is trying to parse jar files as if they were scala sources: �[31m-- [E103] Syntax Error: dist\target\pack\lib\antlr-runtime-3.5.1.jar:1:0 -------------------------------------------------------------------------------------------------------------------------------�[0m
�[31m1 |�[0mPK��
|�[31m^^^^�[0m
|Illegal start of toplevel definition
longer explanation available when compiling with `-explain`
�[31m-- Error: dist\target\pack\lib\antlr-runtime-3.5.1.jar:2:0 ---------------------------------------------------------------------------------------------------------------------------------------------�[0m
�[31m2 |�[0m If the Windows jvm doesn't see a semicolon in a wildcard classpath, it treats it as a glob reference and expands it to a list of files. See #10761 and #11633. My hunch was correct. Here's the jvm invocation, with compiler libraries classpath replaced by
The reason the problem is hidden in the first 2 command lines above is because the hashbang line is discarded, avoiding the problem. The fix for this was implemented in #11633, and is mentioned in the -cp*|-classpath*) # partial fix for #10761
# hashbang can combine args, e.g. "-classpath 'lib/*'"
CLASS_PATH="${1#* *}${PSEP}"
let class_path_count+=1
shift
;; |
I just tested it on Linux and all 3 commands succeed, however, the last one has many many libraries on classpath, few I recognize from scaladoc |
I'll commit what I have so far, and file a bug report on the bug regression issue. I added a test to CoursierScalaTests to verify acceptance of an |
…dows classpath regression
Changes in this commit:
The Windows classpath bugs have to be avoided before the jvm is called, since the jvm expands wildcard classpaths before passing control to |
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.
Good work, but there are some things to fix before merging.
To fix test: You can create some private function to handle that. The problem is that we try to map to files strings that actually can be enumerated classpath with classpath separators |
Ouch, I commited bad code (it doesn't compile) ... will commit correct version soon. |
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.
Changes look good, just three little nitpicks
It looks as though we don't check to see if there is a pre-compiled jar (created via The relevant section of dist/bin/scala in 167 case "${execute_mode-}" in
168 script)
169 if [ "$CLASS_PATH" ]; then
170 script_cp_arg="-classpath '$CLASS_PATH'"
171 fi
172 setScriptName="-Dscript.path=$target_script"
173 target_jar="${target_script%.*}.jar"
174 if [[ $save_compiled == true && "$target_jar" -nt "$target_script" ]]; then
175 eval "\"$JAVACMD\"" $setScriptName -jar "$target_jar" "${script_args[@]}"
176 scala_exit_status=$?
177 else I have an implementation I will commit after some more testing. |
I found and fixed 2 problems, and will commit after some more testing. For some reason, I can't do the following in my environment, so I have to run the full test suite. testOnly dotty.tools.coursier.* |
The tests are in their own sbt configuration so you need to run: scala3-compiler-bootstrapped/Scala3CompilerCoursierTest/test |
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.
Looks good
@BarkingBad Here's the bug and the one-line fix. On line 108 of MainGenericRunner: val globdir = cp.replaceAll("[\\/][^\\/]*$", "") // slash/backslash agnostic the regex should have quadruple backslashes, like this: val globdir = cp.replaceAll("[\\\\/][^\\\\/]*$", "") // slash/backslash agnostic The following script fails to compile without the fix: #!bin/scala -classpath 'dist/target/pack/lib/*'
// import won't compile unless the hashbang line is effective in setting the classpath
import org.jline.terminal.Terminal
def main(args: Array[String]) =
val cp = sys.props("java.class.path")
printf("unglobbed classpath:\n%s\n", cp) I can incorporate this test in dotty.tools.scripting.ClasspathTests |
Yes, fresh PR seems reasonable. Please mention me when you create one |
fix and new unit test added by #13619 |
Reordered
scalaArgs
ahead of-script <scriptName>
arguments when implementingExecuteMode.Script
, as expected byscripting.Main
.Expanded argument file, following the pattern in
dotty.tools.dotc.config.CliCommand
.