Skip to content

#3071: create new directory setting and use for '-d' parameter #3120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand Down
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: _*)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
}
}
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions compiler/test/dotty/tools/dotc/SettingsTests.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}