Skip to content

Commit ce469dd

Browse files
committed
#3071: create new directory setting and use for '-d' parameter
also make sure that directory exists
1 parent 2516575 commit ce469dd

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GenBCode extends Phase {
4747
}
4848

4949
def outputDir(implicit ctx: Context): AbstractFile =
50-
new PlainDirectory(new Directory(new JFile(ctx.settings.d.value)))
50+
new PlainDirectory(ctx.settings.d.value)
5151

5252
def run(implicit ctx: Context): Unit = {
5353
new GenBCodePipeline(entryPoints.toList,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.dotc
22
package config
33

44
import java.io.File
5+
import dotty.tools.io.{ Directory, Path }
56

67
import PathResolver.Defaults
78
import rewrite.Rewrites
@@ -17,7 +18,7 @@ class ScalaSettings extends Settings.SettingGroup {
1718
val javaextdirs = PathSetting("-javaextdirs", "Override java extdirs classpath.", Defaults.javaExtDirs)
1819
val sourcepath = PathSetting("-sourcepath", "Specify location(s) of source files.", "") // Defaults.scalaSourcePath
1920
val classpath = PathSetting("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp"
20-
val d = StringSetting("-d", "directory|jar", "destination for generated classfiles.", ".")
21+
val d = DirectorySetting("-d", "directory|jar", "destination for generated classfiles.", Directory(Path(".")))
2122
val priorityclasspath = PathSetting("-priorityclasspath", "class path that takes precedence over all other paths (or testing only)", "")
2223

2324
/** Other settings */

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ 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 }
10+
911
// import annotation.unchecked
1012
// Dotty deviation: Imports take precedence over definitions in enclosing package
1113
// (Note that @unchecked is in scala, not annotation, so annotation.unchecked gives
@@ -20,6 +22,7 @@ object Settings {
2022
val ListTag = ClassTag(classOf[List[_]])
2123
val VersionTag = ClassTag(classOf[ScalaVersion])
2224
val OptionTag = ClassTag(classOf[Option[_]])
25+
val DirectoryTag = ClassTag(classOf[Directory])
2326

2427
class SettingsState(initialValues: Seq[Any]) {
2528
private var values = ArrayBuffer(initialValues: _*)
@@ -158,6 +161,10 @@ object Settings {
158161
case Success(v) => update(v, args)
159162
case Failure(ex) => fail(ex.getMessage, args)
160163
}
164+
case (DirectoryTag, arg :: args) =>
165+
val path = Path(arg)
166+
if (path.isDirectory) update(arg, args)
167+
else fail(s"'$arg' does not exist or is not a directory", args)
161168
case (_, Nil) =>
162169
missingArg
163170
}
@@ -278,5 +285,8 @@ object Settings {
278285

279286
def OptionSetting[T: ClassTag](name: String, descr: String): Setting[Option[T]] =
280287
publish(Setting(name, descr, None, propertyClass = Some(implicitly[ClassTag[T]].runtimeClass)))
288+
289+
def DirectorySetting(name: String, helpArg: String, descr: String, default: Directory): Setting[Directory] =
290+
publish(Setting(name, descr, default, helpArg))
281291
}
282292
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class ReplDriver(settings: Array[String],
109109
if (rootCtx.settings.d.isDefault(rootCtx))
110110
new VirtualDirectory("(memory)", None)
111111
else
112-
new PlainDirectory(new Directory(new JFile(rootCtx.settings.d.value(rootCtx))))
112+
new PlainDirectory(rootCtx.settings.d.value(rootCtx))
113113
}
114114
compiler = new ReplCompiler(outDir)
115115
rendering = new Rendering(compiler, classLoader)

0 commit comments

Comments
 (0)