diff options
Diffstat (limited to 'main/core')
-rw-r--r-- | main/core/src/mill/define/BaseModule.scala | 3 | ||||
-rw-r--r-- | main/core/src/mill/define/Ctx.scala | 6 | ||||
-rw-r--r-- | main/core/src/mill/define/Module.scala | 3 | ||||
-rw-r--r-- | main/core/src/mill/define/Task.scala | 4 | ||||
-rw-r--r-- | main/core/src/mill/eval/Evaluator.scala | 50 | ||||
-rw-r--r-- | main/core/src/mill/eval/PathRef.scala | 37 | ||||
-rw-r--r-- | main/core/src/mill/util/ClassLoader.scala | 2 | ||||
-rw-r--r-- | main/core/src/mill/util/Ctx.scala | 11 | ||||
-rw-r--r-- | main/core/src/mill/util/JsonFormatters.scala | 15 | ||||
-rw-r--r-- | main/core/src/mill/util/Logger.scala | 7 | ||||
-rw-r--r-- | main/core/src/mill/util/Scripts.scala | 14 |
11 files changed, 68 insertions, 84 deletions
diff --git a/main/core/src/mill/define/BaseModule.scala b/main/core/src/mill/define/BaseModule.scala index 03bdeccc..cd79f73e 100644 --- a/main/core/src/mill/define/BaseModule.scala +++ b/main/core/src/mill/define/BaseModule.scala @@ -1,12 +1,11 @@ package mill.define -import ammonite.ops.Path object BaseModule{ case class Implicit(value: BaseModule) } -abstract class BaseModule(millSourcePath0: Path, +abstract class BaseModule(millSourcePath0: os.Path, external0: Boolean = false, foreign0 : Boolean = false) (implicit millModuleEnclosing0: sourcecode.Enclosing, diff --git a/main/core/src/mill/define/Ctx.scala b/main/core/src/mill/define/Ctx.scala index ba4fae9e..c21e53b4 100644 --- a/main/core/src/mill/define/Ctx.scala +++ b/main/core/src/mill/define/Ctx.scala @@ -1,8 +1,6 @@ package mill.define -import ammonite.ops.Path - import scala.annotation.implicitNotFound sealed trait Segment{ @@ -18,7 +16,7 @@ object Segment{ case class Cross(value: Seq[Any]) extends Segment } -case class BasePath(value: Path) +case class BasePath(value: os.Path) /** @@ -64,7 +62,7 @@ object Segments { case class Ctx(enclosing: String, lineNum: Int, segment: Segment, - millSourcePath: Path, + millSourcePath: os.Path, segments: Segments, overrides: Int, external: Boolean, diff --git a/main/core/src/mill/define/Module.scala b/main/core/src/mill/define/Module.scala index f72ec8ca..a8fc5be7 100644 --- a/main/core/src/mill/define/Module.scala +++ b/main/core/src/mill/define/Module.scala @@ -2,7 +2,6 @@ package mill.define import java.lang.reflect.Modifier -import ammonite.ops.Path import mill.util.ParseArgs import scala.language.experimental.macros @@ -27,7 +26,7 @@ class Module(implicit outerCtx0: mill.define.Ctx) lazy val millModuleDirectChildren = millInternal.reflectNestedObjects[Module].toSeq def millOuterCtx = outerCtx0 - def millSourcePath: Path = millOuterCtx.millSourcePath / millOuterCtx.segment.pathSegments + def millSourcePath: os.Path = millOuterCtx.millSourcePath / millOuterCtx.segment.pathSegments implicit def millModuleExternal: Ctx.External = Ctx.External(millOuterCtx.external) implicit def millModuleShared: Ctx.Foreign = Ctx.Foreign(millOuterCtx.foreign) implicit def millModuleBasePath: BasePath = BasePath(millSourcePath) diff --git a/main/core/src/mill/define/Task.scala b/main/core/src/mill/define/Task.scala index 64e868f8..07576724 100644 --- a/main/core/src/mill/define/Task.scala +++ b/main/core/src/mill/define/Task.scala @@ -109,11 +109,11 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul ) } - def sources(values: Result[ammonite.ops.Path]*) + def sources(values: Result[os.Path]*) (implicit ctx: mill.define.Ctx): Sources = macro sourcesImpl1 def sourcesImpl1(c: Context) - (values: c.Expr[Result[ammonite.ops.Path]]*) + (values: c.Expr[Result[os.Path]]*) (ctx: c.Expr[mill.define.Ctx]): c.Expr[Sources] = { import c.universe._ val wrapped = diff --git a/main/core/src/mill/eval/Evaluator.scala b/main/core/src/mill/eval/Evaluator.scala index 2ffc469b..7cf55fdb 100644 --- a/main/core/src/mill/eval/Evaluator.scala +++ b/main/core/src/mill/eval/Evaluator.scala @@ -5,7 +5,6 @@ import java.net.URLClassLoader import scala.collection.JavaConverters._ import mill.util.Router.EntryPoint -import ammonite.ops._ import ammonite.runtime.SpecialClassLoader import mill.define.{Ctx => _, _} import mill.eval.Result.OuterStack @@ -29,17 +28,17 @@ case class Labelled[T](task: NamedTask[T], } } -case class Evaluator(home: Path, - outPath: Path, - externalOutPath: Path, +case class Evaluator(home: os.Path, + outPath: os.Path, + externalOutPath: os.Path, rootModule: mill.define.BaseModule, log: Logger, - classLoaderSig: Seq[(Either[String, Path], Long)] = Evaluator.classLoaderSig, + classLoaderSig: Seq[(Either[String, os.Path], Long)] = Evaluator.classLoaderSig, workerCache: mutable.Map[Segments, (Int, Any)] = mutable.Map.empty, env : Map[String, String] = Evaluator.defaultEnv){ val classLoaderSignHash = classLoaderSig.hashCode() def evaluate(goals: Agg[Task[_]]): Evaluator.Results = { - mkdir(outPath) + os.makeDir.all(outPath) val (sortedGroups, transitive) = Evaluator.plan(rootModule, goals) @@ -76,7 +75,7 @@ case class Evaluator(home: Path, vs.items.flatMap(results.get).collect{case f: Result.Failing[_] => f.map(_._1)} ) } - write.over( + os.write.over( outPath / "mill-profile.json", upickle.default.write( timings .map{case (k, v, b) => @@ -133,7 +132,7 @@ case class Evaluator(home: Path, destSegments(labelledNamedTask) ) - if (!exists(paths.out)) mkdir(paths.out) + if (!os.exists(paths.out)) os.makeDir.all(paths.out) val cached = for{ cached <- try Some(upickle.default.read[Evaluator.Cached](paths.meta.toIO)) @@ -158,14 +157,13 @@ case class Evaluator(home: Path, (newResults, Nil, true) case _ => - val Seq(first, rest @_*) = labelledNamedTask.segments.value val msgParts = Seq(first.asInstanceOf[Segment.Label].value) ++ rest.map{ case Segment.Label(s) => "." + s case Segment.Cross(s) => "[" + s.mkString(",") + "]" } - if (labelledNamedTask.task.flushDest) rm(paths.dest) + if (labelledNamedTask.task.flushDest) os.remove.all(paths.dest) val (newResults, newEvaluated) = evaluateGroup( group, @@ -188,7 +186,7 @@ case class Evaluator(home: Path, // a following run won't look at the cached metadata file and // assume it's associated with the possibly-borked state of the // destPath after an evaluation failure. - rm(paths.meta) + os.remove.all(paths.meta) } (newResults, newEvaluated, false) @@ -218,7 +216,7 @@ case class Evaluator(home: Path, def handleTaskResult(v: Any, hashCode: Int, - metaPath: Path, + metaPath: os.Path, inputsHash: Int, labelledNamedTask: Labelled[_]) = { labelledNamedTask.task.asWorker match{ @@ -230,7 +228,7 @@ case class Evaluator(home: Path, .map(w => upickle.default.writeJs(v)(w) -> v) for((json, v) <- terminalResult){ - write.over( + os.write.over( metaPath, upickle.default.write( Evaluator.Cached(json, hashCode, inputsHash), @@ -270,7 +268,13 @@ case class Evaluator(home: Path, for (task <- nonEvaluatedTargets) { newEvaluated.append(task) val targetInputValues = task.inputs - .map(x => newResults.getOrElse(x, results(x))) + .map{x => + val res = newResults.getOrElse(x, results(x)) + if (!res.isInstanceOf[Result.Success[_]]){ + println("FAILURE " + x) + } + res + } .collect{ case Result.Success((v, hashCode)) => v } val res = @@ -291,7 +295,7 @@ case class Evaluator(home: Path, paths match{ case Some(dest) => - if (usedDest.isEmpty) mkdir(dest.dest) + if (usedDest.isEmpty) os.makeDir.all(dest.dest) usedDest = Some((task, new Exception().getStackTrace)) dest.dest case None => @@ -340,7 +344,7 @@ case class Evaluator(home: Path, (newResults, newEvaluated) } - def resolveLogger(logPath: Option[Path]): Logger = logPath match{ + def resolveLogger(logPath: Option[os.Path]): Logger = logPath match{ case None => log case Some(path) => MultiLogger(log.colored, log, FileLogger(log.colored, path, debugEnabled = true)) } @@ -355,9 +359,9 @@ object Evaluator{ implicit val rw: upickle.default.ReadWriter[Cached] = upickle.default.macroRW } case class State(rootModule: mill.define.BaseModule, - classLoaderSig: Seq[(Either[String, Path], Long)], + classLoaderSig: Seq[(Either[String, os.Path], Long)], workerCache: mutable.Map[Segments, (Int, Any)], - watched: Seq[(Path, Long)]) + watched: Seq[(os.Path, Long)]) // This needs to be a ThreadLocal because we need to pass it into the body of // the TargetScopt#read call, which does not accept additional parameters. // Until we migrate our CLI parsing off of Scopt (so we can pass the BaseModule @@ -366,15 +370,15 @@ object Evaluator{ val defaultEnv: Map[String, String] = System.getenv().asScala.toMap - case class Paths(out: Path, - dest: Path, - meta: Path, - log: Path) + case class Paths(out: os.Path, + dest: os.Path, + meta: os.Path, + log: os.Path) def makeSegmentStrings(segments: Segments) = segments.value.flatMap{ case Segment.Label(s) => Seq(s) case Segment.Cross(values) => values.map(_.toString) } - def resolveDestPaths(workspacePath: Path, segments: Segments): Paths = { + def resolveDestPaths(workspacePath: os.Path, segments: Segments): Paths = { val segmentStrings = makeSegmentStrings(segments) val targetPath = workspacePath / segmentStrings Paths(targetPath, targetPath / 'dest, targetPath / "meta.json", targetPath / 'log) diff --git a/main/core/src/mill/eval/PathRef.scala b/main/core/src/mill/eval/PathRef.scala index 4983f040..92ef8d24 100644 --- a/main/core/src/mill/eval/PathRef.scala +++ b/main/core/src/mill/eval/PathRef.scala @@ -7,54 +7,41 @@ import java.nio.{file => jnio} import java.security.{DigestOutputStream, MessageDigest} import upickle.default.{ReadWriter => RW} -import ammonite.ops.Path import mill.util.{DummyOutputStream, IO, JsonFormatters} /** - * A wrapper around `ammonite.ops.Path` that calculates it's hashcode based + * A wrapper around `os.Path` that calculates it's hashcode based * on the contents of the filesystem underneath it. Used to ensure filesystem * changes can bust caches which are keyed off hashcodes. */ -case class PathRef(path: ammonite.ops.Path, quick: Boolean, sig: Int){ +case class PathRef(path: os.Path, quick: Boolean, sig: Int){ override def hashCode() = sig } object PathRef{ - def apply(path: ammonite.ops.Path, quick: Boolean = false) = { + def apply(path: os.Path, quick: Boolean = false) = { val sig = { val digest = MessageDigest.getInstance("MD5") val digestOut = new DigestOutputStream(DummyOutputStream, digest) - jnio.Files.walkFileTree( - path.toNIO, - java.util.EnumSet.of(jnio.FileVisitOption.FOLLOW_LINKS), - Integer.MAX_VALUE, - new FileVisitor[jnio.Path] { - def preVisitDirectory(dir: jnio.Path, attrs: BasicFileAttributes) = { - digest.update(dir.toAbsolutePath.toString.getBytes) - FileVisitResult.CONTINUE - } - - def visitFile(file: jnio.Path, attrs: BasicFileAttributes) = { - digest.update(file.toAbsolutePath.toString.getBytes) + if (os.exists(path)){ + for((path, attrs) <- os.walk.attrs(path, includeTarget = true, followLinks = true)){ + digest.update(path.toString.getBytes) + if (!attrs.isDir) { if (quick){ - val value = (path.mtime.toMillis, path.size).hashCode() + val value = (attrs.mtime, attrs.size).hashCode() digest.update((value >>> 24).toByte) digest.update((value >>> 16).toByte) digest.update((value >>> 8).toByte) digest.update(value.toByte) - } else if (jnio.Files.isReadable(file)) { - val is = jnio.Files.newInputStream(file) + } else if (jnio.Files.isReadable(path.toNIO)) { + val is = os.read.inputStream(path) IO.stream(is, digestOut) is.close() } - FileVisitResult.CONTINUE } - - def visitFileFailed(file: jnio.Path, exc: IOException) = FileVisitResult.CONTINUE - def postVisitDirectory(dir: jnio.Path, exc: IOException) = FileVisitResult.CONTINUE } - ) + } java.util.Arrays.hashCode(digest.digest()) @@ -71,7 +58,7 @@ object PathRef{ s => { val Array(prefix, hex, path) = s.split(":", 3) PathRef( - Path(path), + os.Path(path), prefix match{ case "qref" => true case "ref" => false}, // Parsing to a long and casting to an int is the only way to make // round-trip handling of negative numbers work =( diff --git a/main/core/src/mill/util/ClassLoader.scala b/main/core/src/mill/util/ClassLoader.scala index ebe8e50b..07ab1ca9 100644 --- a/main/core/src/mill/util/ClassLoader.scala +++ b/main/core/src/mill/util/ClassLoader.scala @@ -2,7 +2,7 @@ package mill.util import java.net.{URL, URLClassLoader} -import ammonite.ops._ + import io.github.retronym.java9rtexport.Export import scala.util.Try diff --git a/main/core/src/mill/util/Ctx.scala b/main/core/src/mill/util/Ctx.scala index 6c8b2afb..bbc243b7 100644 --- a/main/core/src/mill/util/Ctx.scala +++ b/main/core/src/mill/util/Ctx.scala @@ -1,6 +1,5 @@ package mill.util -import ammonite.ops.Path import mill.define.Applicative.ImplicitStub import scala.annotation.compileTimeOnly @@ -12,16 +11,16 @@ object Ctx{ implicit def taskCtx: Ctx = ??? object Dest { - implicit def pathToCtx(path: Path): Dest = new Dest { def dest = path } + implicit def pathToCtx(path: os.Path): Dest = new Dest { def dest = path } } trait Dest{ - def dest: Path + def dest: os.Path } trait Log{ def log: Logger } trait Home{ - def home: Path + def home: os.Path } trait Env{ def env: Map[String, String] @@ -37,9 +36,9 @@ object Ctx{ } class Ctx(val args: IndexedSeq[_], - dest0: () => Path, + dest0: () => os.Path, val log: Logger, - val home: Path, + val home: os.Path, val env : Map[String, String]) extends Ctx.Dest with Ctx.Log diff --git a/main/core/src/mill/util/JsonFormatters.scala b/main/core/src/mill/util/JsonFormatters.scala index 2728d94d..e2c3073f 100644 --- a/main/core/src/mill/util/JsonFormatters.scala +++ b/main/core/src/mill/util/JsonFormatters.scala @@ -1,15 +1,14 @@ package mill.util -import ammonite.ops.{Bytes, Path} import upickle.Js import upickle.default.{ReadWriter => RW} import scala.util.matching.Regex object JsonFormatters extends JsonFormatters trait JsonFormatters { - implicit val pathReadWrite: RW[ammonite.ops.Path] = upickle.default.readwriter[String] - .bimap[ammonite.ops.Path]( + implicit val pathReadWrite: RW[os.Path] = upickle.default.readwriter[String] + .bimap[os.Path]( _.toString, - Path(_) + os.Path(_) ) implicit val regexReadWrite: RW[Regex] = upickle.default.readwriter[String] @@ -18,14 +17,14 @@ trait JsonFormatters { _.r ) - implicit val bytesReadWrite: RW[Bytes] = upickle.default.readwriter[String] + implicit val bytesReadWrite: RW[os.Bytes] = upickle.default.readwriter[String] .bimap( - o => javax.xml.bind.DatatypeConverter.printBase64Binary(o.array), - str => new Bytes(javax.xml.bind.DatatypeConverter.parseBase64Binary(str)) + o => java.util.Base64.getEncoder.encodeToString(o.array), + str => new os.Bytes(java.util.Base64.getDecoder.decode(str)) ) - implicit lazy val crFormat: RW[ammonite.ops.CommandResult] = upickle.default.macroRW + implicit lazy val crFormat: RW[os.CommandResult] = upickle.default.macroRW implicit lazy val modFormat: RW[coursier.Module] = upickle.default.macroRW implicit lazy val depFormat: RW[coursier.Dependency]= upickle.default.macroRW diff --git a/main/core/src/mill/util/Logger.scala b/main/core/src/mill/util/Logger.scala index 1db66039..4857953d 100644 --- a/main/core/src/mill/util/Logger.scala +++ b/main/core/src/mill/util/Logger.scala @@ -2,7 +2,6 @@ package mill.util import java.io._ -import ammonite.ops.{Path, rm} import ammonite.util.Colors /** @@ -142,17 +141,17 @@ case class PrintLogger( } } -case class FileLogger(colored: Boolean, file: Path, debugEnabled: Boolean) extends Logger { +case class FileLogger(colored: Boolean, file: os.Path, debugEnabled: Boolean) extends Logger { private[this] var outputStreamUsed: Boolean = false lazy val outputStream = { - if (!outputStreamUsed) rm(file) + if (!outputStreamUsed) os.remove.all(file) outputStreamUsed = true new PrintStream(new FileOutputStream(file.toIO.getAbsolutePath)) } lazy val errorStream = { - if (!outputStreamUsed) rm(file) + if (!outputStreamUsed) os.remove.all(file) outputStreamUsed = true new PrintStream(new FileOutputStream(file.toIO.getAbsolutePath)) } diff --git a/main/core/src/mill/util/Scripts.scala b/main/core/src/mill/util/Scripts.scala index 1815b6de..65eb6b2b 100644 --- a/main/core/src/mill/util/Scripts.scala +++ b/main/core/src/mill/util/Scripts.scala @@ -2,7 +2,7 @@ package mill.util import java.nio.file.NoSuchFileException -import ammonite.ops._ + import ammonite.runtime.Evaluator.AmmoniteExit import ammonite.util.Name.backtickWrap import ammonite.util.Util.CodeSource @@ -31,15 +31,15 @@ object Scripts { scriptArgs } - def runScript(wd: Path, - path: Path, + def runScript(wd: os.Path, + path: os.Path, interp: ammonite.interp.Interpreter, scriptArgs: Seq[(String, Option[String])] = Nil) = { interp.watch(path) val (pkg, wrapper) = Util.pathToPackageWrapper(Seq(), path relativeTo wd) for{ - scriptTxt <- try Res.Success(Util.normalizeNewlines(read(path))) catch{ + scriptTxt <- try Res.Success(Util.normalizeNewlines(os.read(path))) catch{ case e: NoSuchFileException => Res.Failure("Script file not found: " + path) } @@ -169,7 +169,7 @@ object Scripts { for((lhs, rhs) <- args) yield { val lhsPadded = lhs.padTo(leftColWidth, ' ') - val rhsPadded = rhs.lines.mkString(Util.newLine) + val rhsPadded = rhs.linesIterator.mkString(Util.newLine) s"$leftIndentStr $lhsPadded $rhsPadded" } val mainDocSuffix = main.doc match{ @@ -273,7 +273,7 @@ object Scripts { } def softWrap(s: String, leftOffset: Int, maxWidth: Int) = { - val oneLine = s.lines.mkString(" ").split(' ') + val oneLine = s.linesIterator.mkString(" ").split(' ') lazy val indent = " " * leftOffset @@ -325,6 +325,6 @@ object Scripts { /** * Additional [[scopt.Read]] instance to teach it how to read Ammonite paths */ - implicit def pathScoptRead: scopt.Read[Path] = scopt.Read.stringRead.map(Path(_, pwd)) + implicit def pathScoptRead: scopt.Read[os.Path] = scopt.Read.stringRead.map(os.Path(_, os.pwd)) } |