Skip to content

Commit 0814ca7

Browse files
committed
Merge branch 'path-fix' into michelou-batch-files
* path-fix: Address review Refactor without using JFile.separator (thanks @michelou) More fix for window path Fix window path in ClassPath Fix window path check for illegal chars in entity path (Windows)
2 parents 6f4169e + 0ff65a5 commit 0814ca7

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
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/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
}

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

Lines changed: 18 additions & 11 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
@@ -127,7 +128,9 @@ case class Site(
127128
}
128129

129130
/** Copy static files to `outDir` */
130-
def copyStaticFiles(outDir: JFile = new JFile(root.getAbsolutePath + "/_site"))(implicit ctx: Context): this.type =
131+
private[this] val defaultOutDir = new JFile(root.getAbsolutePath + JFile.separator + "_site")
132+
133+
def copyStaticFiles(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
131134
createOutput (outDir) {
132135
// Copy user-defined static assets
133136
staticAssets.foreach { asset =>
@@ -164,8 +167,8 @@ case class Site(
164167
private def defaultParams(pageLocation: JFile, additionalDepth: Int = 0): DefaultParams = {
165168
val pathFromRoot = stripRoot(pageLocation)
166169
val baseUrl: String = {
167-
val rootLen = root.getAbsolutePath.split('/').length
168-
val assetLen = pageLocation.getAbsolutePath.split('/').length
170+
val rootLen = root.getAbsolutePath.split(sep).length
171+
val assetLen = pageLocation.getAbsolutePath.split(sep).length
169172
"../" * (assetLen - rootLen - 1 + additionalDepth) + "."
170173
}
171174

@@ -188,19 +191,23 @@ case class Site(
188191
}
189192

190193
/** Generate HTML for the API documentation */
191-
def generateApiDocs(outDir: JFile = new JFile(root.getAbsolutePath + "/_site"))(implicit ctx: Context): this.type =
194+
def generateApiDocs(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
192195
createOutput(outDir) {
193196
def genDoc(e: model.Entity): Unit = {
194197
ctx.docbase.echo(s"Generating doc page for: ${e.path.mkString(".")}")
195198
// Suffix is index.html for packages and therefore the additional depth
196199
// is increased by 1
197200
val (suffix, offset) =
198-
if (e.kind == "package") ("/index.html", -1)
201+
if (e.kind == "package") (sep + "index.html", -1)
199202
else (".html", 0)
200203

201-
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + "/api/" + e.path.mkString("/") + suffix))
204+
val path = if (scala.util.Properties.isWin)
205+
e.path.map(_.replace("<", "_").replace(">", "_"))
206+
else
207+
e.path
208+
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + "api" + sep + path.mkString(sep) + suffix))
202209
val params = defaultParams(target.toFile, -1).withPosts(blogInfo).withEntity(Some(e)).toMap
203-
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)
204211

205212
render(page).foreach { rendered =>
206213
val source = new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8))
@@ -217,9 +224,9 @@ case class Site(
217224
}
218225

219226
// generate search page:
220-
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + "/api/search.html"))
227+
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + "api" + sep + "search.html"))
221228
val searchPageParams = defaultParams(target.toFile, -1).withPosts(blogInfo).toMap
222-
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)
223230
render(searchPage).foreach { rendered =>
224231
Files.copy(
225232
new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8)),
@@ -230,7 +237,7 @@ case class Site(
230237
}
231238

232239
/** Generate HTML files from markdown and .html sources */
233-
def generateHtmlFiles(outDir: JFile = new JFile(root.getAbsolutePath + "/_site"))(implicit ctx: Context): this.type =
240+
def generateHtmlFiles(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
234241
createOutput(outDir) {
235242
compilableFiles.foreach { asset =>
236243
val pathFromRoot = stripRoot(asset)
@@ -250,7 +257,7 @@ case class Site(
250257
}
251258

252259
/** Generate blog from files in `blog/_posts` and output in `outDir` */
253-
def generateBlog(outDir: JFile = new JFile(root.getAbsolutePath + "/_site"))(implicit ctx: Context): this.type =
260+
def generateBlog(outDir: JFile = defaultOutDir)(implicit ctx: Context): this.type =
254261
createOutput(outDir) {
255262
blogposts.foreach { file =>
256263
val BlogPost.extract(year, month, day, name, ext) = file.getName

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)