Skip to content

Commit 67c8678

Browse files
authored
Merge pull request #5560 from dotty-staging/path-fix
Fix window path
2 parents 9a7b67b + 23764fd commit 67c8678

File tree

9 files changed

+32
-26
lines changed

9 files changed

+32
-26
lines changed

bench/src/main/scala/Benchmarks.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ object Bench {
3030
val iterations = if (intArgs.length > 1) intArgs(1).toInt else 20
3131
val forks = if (intArgs.length > 2) intArgs(2).toInt else 1
3232

33+
34+
import File.{ separator => sep }
35+
3336
val args2 = args1.map { arg =>
34-
if ((arg.endsWith(".scala") || arg.endsWith(".java")) && arg.head != '/') "../" + arg
37+
if ((arg.endsWith(".scala") || arg.endsWith(".java")) && !(new File(arg)).isAbsolute) ".." + sep + arg
3538
else arg
3639
}
3740
storeCompileOptions(args2)
@@ -61,9 +64,10 @@ object Bench {
6164
val libs = if (args.contains("-with-compiler")) compiler_libs else standard_libs
6265
var argsNorm = args.filter(_ != "-with-compiler")
6366

67+
import File.{ pathSeparator => sep }
6468
var cpIndex = argsNorm.indexOf("-classpath")
6569
if (cpIndex == -1) cpIndex = argsNorm.indexOf("-cp")
66-
if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + java.io.File.pathSeparator + libs
70+
if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + sep + libs
6771
else argsNorm = argsNorm :+ "-classpath" :+ libs
6872

6973
val file = new File(COMPILE_OPTS_FILE)

compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
174174
if (inPackage == "") Nil
175175
else {
176176
packageToModuleBases.getOrElse(inPackage, Nil).flatMap(x =>
177-
Files.list(x.resolve(inPackage.replace('.', '/'))).iterator().asScala.filter(_.getFileName.toString.endsWith(".class"))).map(x =>
177+
Files.list(x.resolve(FileUtils.dirPath(inPackage))).iterator().asScala.filter(_.getFileName.toString.endsWith(".class"))).map(x =>
178178
ClassFileEntryImpl(new PlainFile(new dotty.tools.io.File(x)))).toVector
179179
}
180180
}
@@ -193,7 +193,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
193193
else {
194194
val inPackage = packageOf(className)
195195
packageToModuleBases.getOrElse(inPackage, Nil).iterator.flatMap{x =>
196-
val file = x.resolve(className.replace('.', '/') + ".class")
196+
val file = x.resolve(FileUtils.dirPath(className) + ".class")
197197
if (Files.exists(file)) new PlainFile(new dotty.tools.io.File(file)) :: Nil else Nil
198198
}.take(1).toList.headOption
199199
}
@@ -207,7 +207,7 @@ case class DirectoryClassPath(dir: JFile) extends JFileDirectoryLookup[ClassFile
207207

208208
def findClassFile(className: String): Option[AbstractFile] = {
209209
val relativePath = FileUtils.dirPath(className)
210-
val classFile = new JFile(s"$dir/$relativePath.class")
210+
val classFile = new JFile(dir, relativePath + ".class")
211211
if (classFile.exists) {
212212
val wrappedClassFile = new dotty.tools.io.File(classFile.toPath)
213213
val abstractClassFile = new PlainFile(wrappedClassFile)
@@ -232,7 +232,7 @@ case class DirectorySourcePath(dir: JFile) extends JFileDirectoryLookup[SourceFi
232232
private def findSourceFile(className: String): Option[AbstractFile] = {
233233
val relativePath = FileUtils.dirPath(className)
234234
val sourceFile = Stream("scala", "java")
235-
.map(ext => new JFile(s"$dir/$relativePath.$ext"))
235+
.map(ext => new JFile(dir, relativePath + "." + ext))
236236
.collectFirst { case file if file.exists() => file }
237237

238238
sourceFile.map { file =>

compiler/src/dotty/tools/dotc/classpath/FileUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object FileUtils {
4343
else throw new FatalError("Unexpected source file ending: " + fileName)
4444
}
4545

46-
def dirPath(forPackage: String): String = forPackage.replace('.', '/')
46+
def dirPath(forPackage: String): String = forPackage.replace('.', JFile.separatorChar)
4747

4848
def endsClass(fileName: String): Boolean =
4949
fileName.length > 6 && fileName.substring(fileName.length - 6) == ".class"

compiler/src/dotty/tools/dotc/classpath/VirtualDirectoryClassPath.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
2424

2525
protected def emptyFiles: Array[AbstractFile] = Array.empty
2626
protected def getSubDir(packageDirName: String): Option[AbstractFile] =
27-
Option(lookupPath(dir)(packageDirName.split('/'), directory = true))
27+
Option(lookupPath(dir)(packageDirName.split(java.io.File.separator), directory = true))
2828
protected def listChildren(dir: AbstractFile, filter: Option[AbstractFile => Boolean] = None): Array[F] = filter match {
2929
case Some(f) => dir.iterator.filter(f).toArray
3030
case _ => dir.toArray
@@ -41,7 +41,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
4141

4242
def findClassFile(className: String): Option[AbstractFile] = {
4343
val relativePath = FileUtils.dirPath(className) + ".class"
44-
Option(lookupPath(dir)(relativePath split '/', directory = false))
44+
Option(lookupPath(dir)(relativePath.split(java.io.File.separator), directory = false))
4545
}
4646

4747
private[dotty] def classes(inPackage: String): Seq[ClassFileEntry] = files(inPackage)

compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends ClassPa
6666
}
6767

6868
private def findDirEntry(pkg: String): Option[archive.DirEntry] = {
69-
val dirName = s"${FileUtils.dirPath(pkg)}/"
69+
val dirName = pkg.replace('.', '/') + "/"
7070
archive.allDirs.get(dirName)
7171
}
7272

compiler/src/dotty/tools/dotc/consumetasty/ConsumeTasty.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ object ConsumeTasty {
1717
}
1818

1919
val currentClasspath = QuoteDriver.currentClasspath
20-
val args = "-from-tasty" +: "-classpath" +: s"$classpath:$currentClasspath" +: classes
20+
import java.io.File.{ pathSeparator => sep }
21+
val args = "-from-tasty" +: "-classpath" +: s"$classpath$sep$currentClasspath" +: classes
2122
(new Consume).process(args.toArray)
2223
}
2324
}

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ object QuoteDriver {
9696
case cl: URLClassLoader =>
9797
// Loads the classes loaded by this class loader
9898
// When executing `run` or `test` in sbt the classpath is not in the property java.class.path
99-
val newClasspath = cl.getURLs.map(_.getFile())
99+
import java.nio.file.Paths
100+
val newClasspath = cl.getURLs.map(url => Paths.get(url.toURI).toString)
100101
newClasspath.mkString("", java.io.File.pathSeparator, if (classpath0 == "") "" else java.io.File.pathSeparator + classpath0)
101102
case _ => classpath0
102103
}

doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.io.{ File => JFile, OutputStreamWriter, BufferedWriter, ByteArrayInp
88
import java.util.{ List => JList, Arrays }
99
import java.nio.file.Path
1010
import java.nio.charset.StandardCharsets
11+
import java.io.File.{ separator => sep }
1112

1213
import com.vladsch.flexmark.parser.ParserEmulationProfile
1314
import com.vladsch.flexmark.parser.Parser
@@ -166,9 +167,9 @@ case class Site(
166167
private def defaultParams(pageLocation: JFile, additionalDepth: Int = 0): DefaultParams = {
167168
val pathFromRoot = stripRoot(pageLocation)
168169
val baseUrl: String = {
169-
val rootLen = root.getAbsolutePath.split('/').length
170-
val assetLen = pageLocation.getAbsolutePath.split('/').length
171-
"../" * (assetLen - rootLen - 1 + additionalDepth) + "."
170+
val rootLen = root.toPath.toAbsolutePath.normalize.getNameCount
171+
val assetLen = pageLocation.toPath.toAbsolutePath.normalize.getNameCount
172+
"../" * (assetLen - rootLen + additionalDepth) + "."
172173
}
173174

174175
DefaultParams(
@@ -197,16 +198,16 @@ case class Site(
197198
// Suffix is index.html for packages and therefore the additional depth
198199
// is increased by 1
199200
val (suffix, offset) =
200-
if (e.kind == "package") ("/index.html", -1)
201+
if (e.kind == "package") (sep + "index.html", -1)
201202
else (".html", 0)
202203

203204
val path = if (scala.util.Properties.isWin)
204205
e.path.map(_.replace("<", "_").replace(">", "_"))
205-
else
206+
else
206207
e.path
207-
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + "/api/" + path.mkString("/") + suffix))
208+
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + "api" + sep + path.mkString(sep) + suffix))
208209
val params = defaultParams(target.toFile, -1).withPosts(blogInfo).withEntity(Some(e)).toMap
209-
val page = new HtmlPage("_layouts/api-page.html", layouts("api-page").content, params, includes)
210+
val page = new HtmlPage("_layouts" + sep + "api-page.html", layouts("api-page").content, params, includes)
210211

211212
render(page).foreach { rendered =>
212213
val source = new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8))
@@ -223,9 +224,9 @@ case class Site(
223224
}
224225

225226
// generate search page:
226-
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + "/api/search.html"))
227+
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + "api" + sep + "search.html"))
227228
val searchPageParams = defaultParams(target.toFile, -1).withPosts(blogInfo).toMap
228-
val searchPage = new HtmlPage("_layouts/search.html", layouts("search").content, searchPageParams, includes)
229+
val searchPage = new HtmlPage("_layouts" + sep + "search.html", layouts("search").content, searchPageParams, includes)
229230
render(searchPage).foreach { rendered =>
230231
Files.copy(
231232
new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8)),

project/Build.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,7 @@ object Build {
628628
val dottyLib = jars("dotty-library")
629629

630630
def run(args: List[String]): Unit = {
631-
val sep = File.pathSeparator
632-
val fullArgs = insertClasspathInArgs(args, s".$sep$dottyLib$sep$scalaLib")
631+
val fullArgs = insertClasspathInArgs(args, List(".", dottyLib, scalaLib).mkString(File.pathSeparator))
633632
runProcess("java" :: fullArgs, wait = true)
634633
}
635634

@@ -645,7 +644,7 @@ object Build {
645644
val asm = findLib(attList, "scala-asm")
646645
val dottyCompiler = jars("dotty-compiler")
647646
val dottyInterfaces = jars("dotty-interfaces")
648-
run(insertClasspathInArgs(args1, s"$dottyCompiler:$dottyInterfaces:$asm"))
647+
run(insertClasspathInArgs(args1, List(dottyCompiler, dottyInterfaces, asm).mkString(File.pathSeparator)))
649648
} else run(args)
650649
},
651650

@@ -1092,8 +1091,8 @@ object Build {
10921091
Developer(
10931092
id = "liufengyun",
10941093
name = "Liu Fengyun",
1095-
email = "[email protected]",
1096-
url = url("http://chaos-lab.com")
1094+
email = "[email protected]",
1095+
url = url("https://fengy.me")
10971096
),
10981097
Developer(
10991098
id = "nicolasstucki",

0 commit comments

Comments
 (0)