-
Notifications
You must be signed in to change notification settings - Fork 149
fix for 3307 (windows launcher rejects filenames with utf8 chars) #3923
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
base: main
Are you sure you want to change the base?
Conversation
|
The error messages for the failing tests are the result of having Windows code page 437 active. The failure is that a script named object TestÅÄÖåäö {
def main(args: Array[String]): Unit = {
println("Hello from TestÅÄÖåäö")
}
}failed with this error message: [950] Error: Could not find or load main class TestÅÄÖåäö
[950] Caused by: java.lang.ClassNotFoundException: TestÅÄÖåäö# ./mill integration.test.native 'scala.cli.integration.RunTestsDefault.UTF-8'[949] Produced artifacts:
[949] C:\Users\philwalk\workspace\scala-cli-3307\out\cli\3.3.7\base-image\nativeImage.dest\scala-cli.build_artifacts.txt (txt)
[949] C:\Users\philwalk\workspace\scala-cli-3307\out\cli\3.3.7\base-image\nativeImage.dest\scala-cli.exe (executable)
[949] ========================================================================================================================
[949] Finished generating 'scala-cli' in 3m 49s.
[950/950] integration.test.native
[950] >==== Running 'UTF-8' from RunTestDefinitions
[950] Running warmup testà
[950] Compiling project (Scala 3.7.3, JVM (17))
[950] Compiled project (Scala 3.7.3, JVM (17))
[950] Done running warmup test.
[950] Compiling project (Scala 3.7.3, JVM (17))
[950] Compiled project (Scala 3.7.3, JVM (17))
[950] Error: Could not find or load main class TestÅÄÖåäö
[950] Caused by: java.lang.ClassNotFoundException: TestÅÄÖåäö
[950] X==== Finishing 'UTF-8' from RunTestDefinitions
[950] scala.cli.integration.RunTestsDefault:
[950] ==> X scala.cli.integration.RunTestsDefault.UTF-8 2.017s os.SubprocessException: Result of C:\Users\philwalk\workspace\scala-cli-3307\out\cli\3.3.7\base-image\nativeImage.dest\scala-cli.exeà: 1
[950]
[950] at os.proc.call(ProcessOps.scala:232)
[950] at scala.cli.integration.RunTestDefinitions.$anonfun$new$117(RunTestDefinitions.scala:1080)
[950] at scala.cli.integration.RunTestDefinitions.$anonfun$new$117$adapted(RunTestDefinitions.scala:1072)
[950] at scala.cli.integration.TestInputs.$anonfun$fromRoot$1(TestInputs.scala:35)
[950] at scala.cli.integration.TestInputs$.scala$cli$integration$TestInputs$$withTmpDir(TestInputs.scala:95)
[950] at scala.cli.integration.TestInputs.fromRoot(TestInputs.scala:33)
[950] at scala.cli.integration.RunTestDefinitions.$anonfun$new$116(RunTestDefinitions.scala:1072)
[950] at scala.cli.integration.WithWarmUpScalaCliSuite.$anonfun$test$1(WithWarmUpScalaCliSuite.scala:34)
[950] at scala.cli.integration.WithWarmUpScalaCliSuite.$anonfun$test$2(WithWarmUpScalaCliSuite.scala:37)
[950/950, 1 failed] ============================== integration.test.native scala.cli.integration.RunTestsDefault.UTF-8 ============================== 265s
1 tasks failed
integration.test.native 1 tests failed:
scala.cli.integration.RunTestsDefault.UTF-8 scala.cli.integration.RunTestsDefault.UTF-8
philwalk@d5 MSYS ~/workspace/scala-cli-3307 |
Do you maybe know how to do it? Can't say I'm familiar with code pages in Windows, myself. |
This comment was marked as outdated.
This comment was marked as outdated.
Depends what "running with JDK18" means here. scala-cli/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala Lines 37 to 59 in 863bec3
scala-cli -Dfile.encoding=UTF-8 compile (...)If, however, this would mean the |
This comment was marked as outdated.
This comment was marked as outdated.
|
It turns out that when an
If I duplicate the test in a
The same is true of the launcher # time ./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.UTF-8'
# time ./mill integration.test.native 'scala.cli.integration.RunTestsDefault.UTF-8' Here's the demo shell script. Run it with the current release in your PATH and it fails, run it with scala-cli from this PR build and it succeeds. #!/bin/bash
cat > "/tmp/testÅÄÖåäö" <<'EOF'
#!/usr/bin/env -S scala-cli shebang
//> using dep com.lihaoyi::os-lib:0.11.6
object TestÅÄÖåäö {
import java.nio.charset.Charset
def showEncoding(fileOpt: Option[os.Path] = None): Unit = {
printf("======= jvm encoding configuration:\n")
printf("%s\n", s"sun.jnu.encoding = ${System.getProperty("sun.jnu.encoding")}")
printf("%s\n", s"file.encoding = ${System.getProperty("file.encoding")}")
printf("%s\n", s"Charset.defaultCharset = ${Charset.defaultCharset()}")
printf("%s\n", s"Class name = ${getClass.getName}")
printf("fileName[%s]\n", sys.props("scala.source.names"))
fileOpt.foreach { file =>
printf("======= filename and file contents encoding:\n")
printf("### [%s]\n", file)
if (!os.exists(file)) {
printf("########### not found: [%s]\n", file)
printf("nio: [%s]\n", file.toNIO.toString)
} else {
val str = os.read(file)
val nonAscii = str.replaceAll("[\\x00-\\x7F]", "")
printf("####### str[%s]\nnonAscii[%s]\nnonAscii.getBytes.length[%d]\n", str, nonAscii, nonAscii.getBytes.length)
}
}
}
val filename = "testÅÄÖåäö.sc"
val scriptPath = sys.props("scala.sources")
def main(args: Array[String]): Unit = {
showEncoding(Some(os.Path(scriptPath)))
println(s"Hello from $filename")
println(s"Hello from $scriptPath")
}
}
EOF
FNAME=/tmp/testÅÄÖåäö.sc
scala-cli.exe run $FNAME # okay
echo "######################################" 1>&2
java -Xmx512m -Xms128m -jar 'out/cli/3.3.7/standaloneLauncher.dest/launcher.bat' $FNAMEHere's a self-contained #!/usr/bin/env -S scala-cli shebang
//> using dep com.lihaoyi::os-lib:0.11.6
object TestÅÄÖåäö {
import java.nio.charset.Charset
// with version 1.9.1 in the path, the `os.proc` call fails, but succeeds with the new version.
var launcherName = "scala-cli.exe"
val filename = "testÅÄÖåäö.sc"
def showEncoding(fileOpt: Option[os.Path] = None): Unit = {
printf("======= jvm encoding configuration:\n")
import scala.jdk.CollectionConverters.*
import scala.sys.process.*
System.err.printf("code-page: [%s]\n", ("chcp.com".!!).trim)
System.err.printf("JAVA_TOOL_OPTIONS[%s]\n", System.getenv("JAVA_TOOL_OPTIONS"))
System.err.printf("native.encoding = %s\n", System.getProperty("native.encoding"))
System.err.printf("sun.jnu.encoding = %s\n", System.getProperty("sun.jnu.encoding"))
System.err.printf("file.encoding = %s\n", System.getProperty("file.encoding"))
System.err.printf("Charset.defaultCharset = %s\n", java.nio.charset.Charset.defaultCharset())
System.err.printf("Class name = %s\n", this.getClass.getName)
printf("fileName[%s]\n", sys.props("scala.source.names"))
}
def main(args: Array[String]): Unit = {
showEncoding(Some(os.Path(scriptPath)))
println(s"Hello from $filename")
println(s"Hello from $scriptPath")
printf("launcher: %s\n", launcher)
val endOfCopy = "=== script cloning ends here ==="
//
val content = os.read(os.Path(scriptPath))
val topPart = content.split("[\r\n]+").takeWhile(!_.contains(endOfCopy)).filter(!_.contains("launcher")).mkString("\n")+"\n }\n}"
val filepath = s"/tmp/$filename"
os.write.over(os.Path(filepath), topPart)
val extraArgs = Seq("--bloop-startup-timeout", "2min", "--bloop-bsp-timeout", "1min")
printf("\nos.proc.call cloned copy: filepath [%s]\n", filepath)
val res = os.proc(
launcher,
filepath
)
.call()
val outstr = res.out.text(scala.io.Codec.UTF8).trim
printf("outstr[%s]\n", outstr)
}
import scala.sys.process.*
lazy val launcher = Seq("where.exe", launcherName).!!.trim.replace('\\', '/').split("[\r\n]+").toSeq.head
} |
This PR modifies
generate-native-image.shto generatescala-cli.exewith code page set to 65001 if running in Windows:Using a test script named
/opt/ue/jsrc/løp.sc:and with the PATH set to use the generated
scala-cli.exe:PATH="out/cli/3.3.7/base-image/nativeImage.dest:$PATH"Manual verification that the bug and the fix depend on the code page set during GraalVM compile.
verify the bug
create a buggy
scala-cli.exeby runninggenerated-native-image.shtemporarily modified to set code page 437Verify that the bug manifests itself when attempting to execute the script:
Verify the fix
create fixed
scala-cli.exeby runninggenerated-native-image.shas proposed in this PR (set code page 65001)Verify that the bug is fixed:
# /opt/ue/jsrc/løp.sc Hello /opt/ue/jsrc/løp.sc Hello C:/opt/ue/jsrc/løp.sc Hello løp.sc