Skip to content
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

single wildcard classpath entry in Windows gets globbed in dist/bin/scala #13618

Closed
philwalk opened this issue Sep 27, 2021 · 1 comment
Closed

Comments

@philwalk
Copy link
Contributor

philwalk commented Sep 27, 2021

Compiler version

Scala code runner version 3.1.1-RC1-bin-SNAPSHOT-git-3f978b3 -- Copyright 2002-2021, LAMP/EPFL

Minimized code

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)

Added a test to verify this fix in dotty.tools.scripting.ClasspathTests

Output

Because the wildcard classpath is explanded by dist/bin/scala, only the first jar in the glob expansion becomes the classpath entry, and all others are added as command line arguments (jar files are intepreted by compiler as scala sources).
The attempt to run the script results in 456763 lines of error messages. Here are the last few lines:

-------------------------------------------------------------------------
3917 |v�RH�����֍Yݘ��􃎃1���Dw���(P�xNa��Q�	�0Q�NT=���`NŔ�qv:HE˧��)n�Yh&��(vt���μc�8�}����y�D�r��h�՞��hLמ���~�)����QV�a��ʕ�1��i�Fy\���BX*��Y͠�B[��pD�l!�ѣX
     |^
     |Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:6246:0 ----------------------------------------------------------------------------------------------------------------------------------------------
6246 |��*�n��@�0gb���ΛT���,"�zG�0���Q�-
     |^
     |Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:14210:0 ---------------------------------------------------------------------------------------------------------------------------------------------
14210 |��(��"~A+
      |^
      |Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:16269:0 ---------------------------------------------------------------------------------------------------------------------------------------------
16269 |��U�κCgъ��[<NH��p�U�o����d�TTڬ{J,x�
      |^
      |Line is indented too far to the left, or a `}` is missing
7 warnings found
114151 errors found
Error: Errors encountered during compilation

Expectation

Script should run without error, printing something like the following:

unglobbed classpath: C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala-library-2.13.6.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-library_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala-asm-9.1.0-scala-1.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/compiler-interface-1.3.5.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-interfaces-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-compiler_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/tasty-core_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-staging_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-tasty-inspector_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-reader-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-terminal-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-terminal-jna-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jna-5.3.1.jar;;

The fix plus unit tests to verify it will be submitted as a PR very soon.

NOTE: the reason the error is specific to Windows is due to the fact that the half-quotes surrounding the wildcard classpath in the hashbang line of the script prevent globbing in Linux and other environments, but not in Windows.

In the scala3-3.0.2 release (and earlier), this bug was fixed by appending a semicolon to wildcard classpath arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants