From 13f896a36eb275de9784ce3400dde09311afd6bd Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 31 Dec 2017 00:04:49 -0800 Subject: - Convert `T.source` into a generic `Target` that flushes the cache every time - Prepare `T.ctx().base: Path` that `Task`s (including `T.source`) can use to find a "default" path for source files. - Simplify `Cacher` --- .../src/main/scala/mill/scalalib/GenIdea.scala | 5 +-- scalalib/src/main/scala/mill/scalalib/Module.scala | 12 +++--- .../src/main/scala/mill/scalalib/TestRunner.scala | 4 +- .../test/scala/mill/scalalib/AcyclicTests.scala | 2 +- .../scala/mill/scalalib/BetterFilesTests.scala | 2 +- .../test/scala/mill/scalalib/HelloWorldTests.scala | 49 ++++++++++++---------- .../src/test/scala/mill/scalalib/JawnTests.scala | 2 +- 7 files changed, 40 insertions(+), 36 deletions(-) (limited to 'scalalib/src') diff --git a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala index 6fd5031a..8b89fa9a 100644 --- a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala +++ b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala @@ -16,9 +16,8 @@ object GenIdea { rm! pwd/".idea" rm! pwd/".idea_modules" - val workspacePath = pwd / 'out - val evaluator = new Evaluator(workspacePath, mapping, new PrintLogger(true)) + val evaluator = new Evaluator(pwd / 'out, pwd, mapping, new PrintLogger(true)) for((relPath, xml) <- xmlFileLayout(evaluator)){ write.over(pwd/relPath, pp.format(xml)) @@ -85,7 +84,7 @@ object GenIdea { val elem = moduleXmlTemplate( sourcePath.path, - Seq(paths.base), + Seq(paths.out), resolvedDeps.map(pathToLibName), for(m <- mod.projectDeps) yield moduleName(moduleLabels(m)) diff --git a/scalalib/src/main/scala/mill/scalalib/Module.scala b/scalalib/src/main/scala/mill/scalalib/Module.scala index 1ff4c240..76c50aed 100644 --- a/scalalib/src/main/scala/mill/scalalib/Module.scala +++ b/scalalib/src/main/scala/mill/scalalib/Module.scala @@ -191,8 +191,8 @@ trait Module extends mill.Module with TaskModule { outer => def prependShellScript: T[String] = T{ "" } - def sources = T.source{ basePath / 'src } - def resources = T.source{ basePath / 'resources } + def sources = T.source{ PathRef(basePath / 'src) } + def resources = T.source{ PathRef(basePath / 'resources) } def allSources = T{ Seq(sources()) } def compile: T[CompilationResult] = T.persistent{ compileScala( @@ -346,11 +346,11 @@ trait PublishModule extends Module { outer => trait SbtModule extends Module { outer => def basePath: Path - override def sources = T.source{ basePath / 'src / 'main / 'scala } - override def resources = T.source{ basePath / 'src / 'main / 'resources } + override def sources = T.source{ PathRef(basePath / 'src / 'main / 'scala) } + override def resources = T.source{ PathRef(basePath / 'src / 'main / 'resources) } trait Tests extends super.Tests{ def basePath = outer.basePath - override def sources = T.source{ basePath / 'src / 'test / 'scala } - override def resources = T.source{ basePath / 'src / 'test / 'resources } + override def sources = T.source{ PathRef(basePath / 'src / 'test / 'scala) } + override def resources = T.source{ PathRef(basePath / 'src / 'test / 'resources) } } } diff --git a/scalalib/src/main/scala/mill/scalalib/TestRunner.scala b/scalalib/src/main/scala/mill/scalalib/TestRunner.scala index 7d42bdea..d92a9deb 100644 --- a/scalalib/src/main/scala/mill/scalalib/TestRunner.scala +++ b/scalalib/src/main/scala/mill/scalalib/TestRunner.scala @@ -46,9 +46,7 @@ object TestRunner { entireClasspath = args(1).split(" ").map(Path(_)), testClassfilePath = args(2).split(" ").map(Path(_)), args = args(3) match{ case "" => Nil case x => x.split(" ").toList } - )(new LogCtx { - def log = new PrintLogger(true) - }) + )(new PrintLogger(true)) val outputPath = args(4) ammonite.ops.write(Path(outputPath), upickle.default.write(result)) diff --git a/scalalib/src/test/scala/mill/scalalib/AcyclicTests.scala b/scalalib/src/test/scala/mill/scalalib/AcyclicTests.scala index 9b68ea70..44a43702 100644 --- a/scalalib/src/test/scala/mill/scalalib/AcyclicTests.scala +++ b/scalalib/src/test/scala/mill/scalalib/AcyclicTests.scala @@ -53,7 +53,7 @@ object AcyclicTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(AcyclicBuild) - val eval = new TestEvaluator(mapping, workspacePath) + val eval = new TestEvaluator(mapping, workspacePath, srcPath) def check(scalaVersion: String) = { // We can compile diff --git a/scalalib/src/test/scala/mill/scalalib/BetterFilesTests.scala b/scalalib/src/test/scala/mill/scalalib/BetterFilesTests.scala index c3004f7b..1f0a3d70 100644 --- a/scalalib/src/test/scala/mill/scalalib/BetterFilesTests.scala +++ b/scalalib/src/test/scala/mill/scalalib/BetterFilesTests.scala @@ -96,7 +96,7 @@ object BetterFilesTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(BetterFilesBuild) - val eval = new TestEvaluator(mapping, workspacePath) + val eval = new TestEvaluator(mapping, workspacePath, srcPath) 'test - { diff --git a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala index aafd980a..0b6ac62b 100644 --- a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala @@ -17,7 +17,7 @@ import scala.collection.JavaConverters._ trait HelloWorldModule extends scalalib.Module { def scalaVersion = "2.12.4" - def basePath = HelloWorldTests.workspacePath + def basePath = HelloWorldTests.workingSrcPath } object HelloWorld extends HelloWorldModule @@ -66,31 +66,38 @@ object HelloWorldScalaOverride extends HelloWorldModule { object HelloWorldTests extends TestSuite { val srcPath = pwd / 'scalalib / 'src / 'test / 'resource / "hello-world" - val workspacePath = pwd / 'target / 'workspace / "hello-world" - val mainObject = workspacePath / 'src / 'main / 'scala / "Main.scala" + val basePath = pwd / 'target / 'workspace / "hello-world" + val workingSrcPath = basePath / 'src + val outPath = basePath / 'out + val mainObject = workingSrcPath / 'src / 'main / 'scala / "Main.scala" val helloWorldEvaluator = new TestEvaluator( Discovered.mapping(HelloWorld), - workspacePath + outPath, + workingSrcPath ) val helloWorldWithMainEvaluator = new TestEvaluator( Discovered.mapping(HelloWorldWithMain), - workspacePath + outPath, + workingSrcPath ) val helloWorldFatalEvaluator = new TestEvaluator( Discovered.mapping(HelloWorldFatalWarnings), - workspacePath + outPath, + workingSrcPath ) val helloWorldOverrideEvaluator = new TestEvaluator( Discovered.mapping(HelloWorldScalaOverride), - workspacePath + outPath, + workingSrcPath ) val helloWorldCrossEvaluator = new TestEvaluator( Discovered.mapping(CrossHelloWorld), - workspacePath + outPath, + workingSrcPath ) @@ -136,12 +143,11 @@ object HelloWorldTests extends TestSuite { 'fromScratch - { val Right((result, evalCount)) = helloWorldEvaluator(HelloWorld.compile) - val outPath = result.classes.path val analysisFile = result.analysisFile - val outputFiles = ls.rec(outPath) - val expectedClassfiles = compileClassfiles.map(workspacePath / 'compile / 'dest / 'classes / _) + val outputFiles = ls.rec(result.classes.path) + val expectedClassfiles = compileClassfiles.map(outPath / 'compile / 'dest / 'classes / _) assert( - outPath == workspacePath / 'compile / 'dest / 'classes, + result.classes.path == outPath / 'compile / 'dest / 'classes, exists(analysisFile), outputFiles.nonEmpty, outputFiles.forall(expectedClassfiles.contains), @@ -169,7 +175,7 @@ object HelloWorldTests extends TestSuite { assert(err.isInstanceOf[CompileFailed]) val paths = Evaluator.resolveDestPaths( - workspacePath, + outPath, helloWorldEvaluator.evaluator.mapping.targets(HelloWorld.compile) ) @@ -195,7 +201,7 @@ object HelloWorldTests extends TestSuite { assert(evalCount > 0) - val runResult = workspacePath / "hello-mill" + val runResult = basePath / "hello-mill" assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" @@ -210,7 +216,7 @@ object HelloWorldTests extends TestSuite { assert(evalCount > 0) - val runResult = workspacePath / "hello-mill" + val runResult = basePath / "hello-mill" assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" @@ -246,7 +252,7 @@ object HelloWorldTests extends TestSuite { assert(evalCount > 0) - val runResult = workspacePath / "hello-mill" + val runResult = basePath / "hello-mill" assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" @@ -291,7 +297,7 @@ object HelloWorldTests extends TestSuite { %("scala", result.path) - val runResult = workspacePath / "hello-mill" + val runResult = basePath / "hello-mill" assert( exists(runResult), read(runResult) == "hello rockjam, your age is: 25" @@ -300,7 +306,7 @@ object HelloWorldTests extends TestSuite { 'logOutputToFile { helloWorldEvaluator(HelloWorld.compile) - val logFile = workspacePath / 'compile / 'log + val logFile = outPath / 'compile / 'log assert(exists(logFile)) } } @@ -315,9 +321,10 @@ object HelloWorldTests extends TestSuite { ) def prepareWorkspace(): Unit = { - rm(workspacePath) - mkdir(workspacePath / up) - cp(srcPath, workspacePath) + rm(outPath) + rm(workingSrcPath) + mkdir(outPath) + cp(srcPath, workingSrcPath) } } diff --git a/scalalib/src/test/scala/mill/scalalib/JawnTests.scala b/scalalib/src/test/scala/mill/scalalib/JawnTests.scala index 71e4d506..8449cc02 100644 --- a/scalalib/src/test/scala/mill/scalalib/JawnTests.scala +++ b/scalalib/src/test/scala/mill/scalalib/JawnTests.scala @@ -75,7 +75,7 @@ object JawnTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(JawnBuild) - val eval = new TestEvaluator(mapping, workspacePath) + val eval = new TestEvaluator(mapping, workspacePath, srcPath) 'test - { def compileOutput = workspacePath / 'jawn / "2.12.3" / 'Parser / 'compile -- cgit v1.2.3