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

Fix window path #5560

Merged
merged 9 commits into from
Dec 10, 2018
Merged

Fix window path #5560

merged 9 commits into from
Dec 10, 2018

Conversation

liufengyun
Copy link
Contributor

Fix window path

@@ -174,7 +174,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
if (inPackage == "") Nil
else {
packageToModuleBases.getOrElse(inPackage, Nil).flatMap(x =>
Files.list(x.resolve(inPackage.replace('.', '/'))).iterator().asScala.filter(_.getFileName.toString.endsWith(".class"))).map(x =>
Files.list(x.resolve(FileUtils.dirPath(inPackage))).iterator().asScala.filter(_.getFileName.toString.endsWith(".class"))).map(x =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is actually broken ? This code comes straight from scalac (https://github.com/scala/scala/blob/2.13.x/src/compiler/scala/tools/nsc/classpath/DirectoryClassPath.scala#L207) which I assume has received adequate testing under Windows /cc @retronym

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it causes a problem, just get to this by a search. I'm wondering if there is any reason to use / instead of File.separator.

bench/src/main/scala/Benchmarks.scala Show resolved Hide resolved
project/Build.scala Outdated Show resolved Hide resolved
project/Build.scala Outdated Show resolved Hide resolved
@liufengyun
Copy link
Contributor Author

Please don't merge, until we test this on windows.

In QuoteDriver, previous we have path like the following on windows:

/C:/Users/dotty/My%20Programs/Java/Test/bin/myJar.jar

Credit: https://stackoverflow.com/questions/6164448/convert-url-to-normal-windows-filename-java
@liufengyun
Copy link
Contributor Author

@allanrenucci @nicolasstucki Could you please have a look at the last commit?

@@ -96,7 +96,8 @@ object QuoteDriver {
case cl: URLClassLoader =>
// Loads the classes loaded by this class loader
// When executing `run` or `test` in sbt the classpath is not in the property java.class.path
val newClasspath = cl.getURLs.map(_.getFile())
import java.nio.file.Paths
val newClasspath = cl.getURLs.map(url => Paths.get(url.toURI).toFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a conversion to File here? It seems we are only interested in the String representation of these paths. I would make the conversion to String explicit. E.g.

val newClasspath = cl.getURLs.map(url => Paths.get(url.toURI).toString)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, toString is better and I just tested it works on windows.

Copy link
Contributor

@michelou michelou Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like Allan's suggestion and I will test it ASAP:

val newClasspath = cl.getURLs.map(url => Paths.get(url.toURI).toString)

For comparison here is my local change (pending PR for several weeks now):

val newClasspath = cl.getURLs.map(url => new JFile(url.getFile).getAbsolutePath)

Copy link
Contributor

@michelou michelou Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way the same issue exists in source file compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala.
My local change in function createProcess is:

  val url = classOf[ChildJVMMain].getProtectionDomain.getCodeSource.getLocation
  val cp = Paths.get(url.toURI).toString + JFile.pathSeparator + Properties.scalaLibrary

instead of

  val cp =
    classOf[ChildJVMMain].getProtectionDomain.getCodeSource.getLocation.getFile + JFile.pathSeparator +
        Properties.scalaLibrary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @michelou . It seems there are a lot of changes needed for the tests. I propose to restrict this PR for the compiler fixes, and make a separate PR for the test fixes.

val assetLen = pageLocation.getAbsolutePath.split(sep).length
"../" * (assetLen - rootLen - 1 + additionalDepth) + "."
val rootLen = root.toPath.normalize.getNameCount
val assetLen = pageLocation.toPath.normalize.getNameCount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to convert to absolute path as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage of absolute path info in URL seems problematic. For now, I added toAbstractPath to keep the logic as before.

@liufengyun liufengyun merged commit 67c8678 into scala:master Dec 10, 2018
@liufengyun liufengyun deleted the path-fix branch December 10, 2018 11:57
allanrenucci added a commit that referenced this pull request Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants