Skip to content

Commit 4e39251

Browse files
committed
Make outputDir a PathSetting
1 parent ee7a8f1 commit 4e39251

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ class GenBCode extends Phase {
5252
private[this] var jarFS: JarFS = _
5353

5454
def outputDir(implicit ctx: Context): AbstractFile = {
55-
val path = ctx.settings.outputDir.value
56-
if (path.isDirectory) new PlainDirectory(path.toDirectory)
57-
else {
55+
val path = Directory(ctx.settings.outputDir.value)
56+
if (path.extension == "jar") {
5857
if (jarFS == null) {
5958
path.delete()
6059
jarFS = JarFS.create(path)
6160
}
6261
jarFS.getRoot()
6362
}
63+
else new PlainDirectory(path)
6464
}
6565

6666
def run(implicit ctx: Context): Unit = {

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ScalaSettings extends Settings.SettingGroup {
1818
val javaextdirs = PathSetting("-javaextdirs", "Override java extdirs classpath.", Defaults.javaExtDirs)
1919
val sourcepath = PathSetting("-sourcepath", "Specify location(s) of source files.", "") // Defaults.scalaSourcePath
2020
val classpath = PathSetting("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp"
21-
val outputDir = DirectoryJarSetting("-d", "directory|jar", "destination for generated classfiles.", Directory("."))
21+
val outputDir = PathSetting("-d", "directory|jar", "destination for generated classfiles.", ".")
2222
val priorityclasspath = PathSetting("-priorityclasspath", "class path that takes precedence over all other paths (or testing only)", "")
2323

2424
/** Other settings */

compiler/src/dotty/tools/dotc/config/Settings.scala

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.util.{ Try, Success, Failure }
66
import reflect.ClassTag
77
import core.Contexts._
88
import scala.annotation.tailrec
9-
import dotty.tools.io.{ Directory, Path }
9+
import dotty.tools.io.{ Directory, File, Path }
1010

1111
// import annotation.unchecked
1212
// Dotty deviation: Imports take precedence over definitions in enclosing package
@@ -22,7 +22,6 @@ object Settings {
2222
val ListTag = ClassTag(classOf[List[_]])
2323
val VersionTag = ClassTag(classOf[ScalaVersion])
2424
val OptionTag = ClassTag(classOf[Option[_]])
25-
val DirectoryJarTag = ClassTag(classOf[Path])
2625

2726
class SettingsState(initialValues: Seq[Any]) {
2827
private[this] var values = ArrayBuffer(initialValues: _*)
@@ -141,6 +140,15 @@ object Settings {
141140
else if (!choices.contains(argRest))
142141
fail(s"$arg is not a valid choice for $name", args)
143142
else update(argRest, args)
143+
case (StringTag, arg :: args) if name == "-d" =>
144+
Path(arg) match {
145+
case _: Directory =>
146+
update(arg, args)
147+
case p if p.extension == "jar" =>
148+
update(arg, args)
149+
case _ =>
150+
fail(s"'$arg' does not exist or is not a directory", args)
151+
}
144152
case (StringTag, arg2 :: args2) =>
145153
update(arg2, args2)
146154
case (IntTag, arg2 :: args2) =>
@@ -161,11 +169,6 @@ object Settings {
161169
case Success(v) => update(v, args)
162170
case Failure(ex) => fail(ex.getMessage, args)
163171
}
164-
case (DirectoryJarTag, arg :: args) =>
165-
val path = Path(arg)
166-
if (path.isDirectory) update(path, args)
167-
else if (path.extension == "jar") update(path, args)
168-
else fail(s"'$arg' does not exist or is not a directory", args)
169172
case (_, Nil) =>
170173
missingArg
171174
}
@@ -275,6 +278,9 @@ object Settings {
275278
def PathSetting(name: String, descr: String, default: String): Setting[String] =
276279
publish(Setting(name, descr, default))
277280

281+
def PathSetting(name: String, helpArg: String, descr: String, default: String): Setting[String] =
282+
publish(Setting(name, descr, default, helpArg))
283+
278284
def PhasesSetting(name: String, descr: String, default: String = ""): Setting[List[String]] =
279285
publish(Setting(name, descr, if (default.isEmpty) Nil else List(default)))
280286

@@ -286,8 +292,5 @@ object Settings {
286292

287293
def OptionSetting[T: ClassTag](name: String, descr: String): Setting[Option[T]] =
288294
publish(Setting(name, descr, None, propertyClass = Some(implicitly[ClassTag[T]].runtimeClass)))
289-
290-
def DirectoryJarSetting(name: String, helpArg: String, descr: String, default: Directory): Setting[Path] =
291-
publish(Setting(name, descr, default, helpArg))
292295
}
293296
}

compiler/src/dotty/tools/io/JarFS.scala

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ class JarFS private (private[this] var jarFS: FileSystem) {
1515
new PlainDirectory(Directory(root))
1616
}
1717

18-
def close() = {
19-
jarFS.close()
20-
jarFS = null
21-
}
18+
def close() = jarFS.close()
2219
}
2320

2421
object JarFS {

compiler/src/dotty/tools/repl/ReplDriver.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ class ReplDriver(settings: Array[String],
109109
if (rootCtx.settings.outputDir.isDefault(rootCtx))
110110
new VirtualDirectory("(memory)", None)
111111
else {
112-
val path = rootCtx.settings.outputDir.value(rootCtx)
112+
val path = Directory(rootCtx.settings.outputDir.value(rootCtx))
113113
assert(path.isDirectory)
114-
new PlainDirectory(path.toDirectory)
114+
new PlainDirectory(path)
115115
}
116116
}
117117
compiler = new ReplCompiler(outDir)

0 commit comments

Comments
 (0)