diff --git a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala index 36a72abe911a..53bb55118e24 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala @@ -47,7 +47,7 @@ class GenBCode extends Phase { } def outputDir(implicit ctx: Context): AbstractFile = - new PlainDirectory(new Directory(new JFile(ctx.settings.d.value))) + new PlainDirectory(ctx.settings.outputDir.value) def run(implicit ctx: Context): Unit = { new GenBCodePipeline(entryPoints.toList, diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index b96bdb47f160..a6048b568a41 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -2,6 +2,7 @@ package dotty.tools.dotc package config import java.io.File +import dotty.tools.io.{ Directory, Path } import PathResolver.Defaults import rewrite.Rewrites @@ -17,7 +18,7 @@ class ScalaSettings extends Settings.SettingGroup { val javaextdirs = PathSetting("-javaextdirs", "Override java extdirs classpath.", Defaults.javaExtDirs) val sourcepath = PathSetting("-sourcepath", "Specify location(s) of source files.", "") // Defaults.scalaSourcePath val classpath = PathSetting("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp" - val d = StringSetting("-d", "directory|jar", "destination for generated classfiles.", ".") + val outputDir = DirectorySetting("-d", "directory|jar", "destination for generated classfiles.", Directory(Path("."))) val priorityclasspath = PathSetting("-priorityclasspath", "class path that takes precedence over all other paths (or testing only)", "") /** Other settings */ diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index eccf6cfd1d65..6b6c4d15391a 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -6,6 +6,8 @@ import scala.util.{ Try, Success, Failure } import reflect.ClassTag import core.Contexts._ import scala.annotation.tailrec +import dotty.tools.io.{ Directory, Path } + // import annotation.unchecked // Dotty deviation: Imports take precedence over definitions in enclosing package // (Note that @unchecked is in scala, not annotation, so annotation.unchecked gives @@ -20,6 +22,7 @@ object Settings { val ListTag = ClassTag(classOf[List[_]]) val VersionTag = ClassTag(classOf[ScalaVersion]) val OptionTag = ClassTag(classOf[Option[_]]) + val DirectoryTag = ClassTag(classOf[Directory]) class SettingsState(initialValues: Seq[Any]) { private var values = ArrayBuffer(initialValues: _*) @@ -158,6 +161,10 @@ object Settings { case Success(v) => update(v, args) case Failure(ex) => fail(ex.getMessage, args) } + case (DirectoryTag, arg :: args) => + val path = Path(arg) + if (path.isDirectory) update(Directory(path), args) + else fail(s"'$arg' does not exist or is not a directory", args) case (_, Nil) => missingArg } @@ -278,5 +285,8 @@ object Settings { def OptionSetting[T: ClassTag](name: String, descr: String): Setting[Option[T]] = publish(Setting(name, descr, None, propertyClass = Some(implicitly[ClassTag[T]].runtimeClass))) + + def DirectorySetting(name: String, helpArg: String, descr: String, default: Directory): Setting[Directory] = + publish(Setting(name, descr, default, helpArg)) } } diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index e0ba8f9d78ee..b2f0f834434a 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -106,10 +106,10 @@ class ReplDriver(settings: Array[String], protected[this] def resetToInitial(): Unit = { rootCtx = initialCtx val outDir: AbstractFile = { - if (rootCtx.settings.d.isDefault(rootCtx)) + if (rootCtx.settings.outputDir.isDefault(rootCtx)) new VirtualDirectory("(memory)", None) else - new PlainDirectory(new Directory(new JFile(rootCtx.settings.d.value(rootCtx)))) + new PlainDirectory(rootCtx.settings.outputDir.value(rootCtx)) } compiler = new ReplCompiler(outDir) rendering = new Rendering(compiler, classLoader) diff --git a/compiler/test/dotc/tests.scala b/compiler/test/dotc/tests.scala index a7af432610bd..052bdd3a98a6 100644 --- a/compiler/test/dotc/tests.scala +++ b/compiler/test/dotc/tests.scala @@ -111,6 +111,7 @@ class tests extends CompilerTest { // remove class files from stdlib and tests compilation Directory(defaultOutputDir + "scala").deleteRecursively() Directory(defaultOutputDir + "java").deleteRecursively() + Directory(defaultOutputDir).createDirectory() } @Test def pickle_pickleOK = compileFiles(testsDir + "pickling/", testPickling) diff --git a/compiler/test/dotty/tools/dotc/SettingsTests.scala b/compiler/test/dotty/tools/dotc/SettingsTests.scala new file mode 100644 index 000000000000..98603b39fb36 --- /dev/null +++ b/compiler/test/dotty/tools/dotc/SettingsTests.scala @@ -0,0 +1,14 @@ +package dotty.tools.dotc + +import org.junit.Test +import org.junit.Assert._ + +class SettingsTests { + + @Test def missingOutputDir: Unit = { + val options = Array("-d", "not_here") + val reporter = Main.process(options) + assertEquals(1, reporter.errorCount) + assertEquals("'not_here' does not exist or is not a directory", reporter.allErrors.head.message) + } +}