Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Mar 19, 2018
2 parents 7f9d508 + e7ac732 commit 1c507ef
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ environment:
JAVA_HOME: C:\Program Files\Java\jdk9

cache:
- build.sc -> '%LOCALAPPDATA%\Coursier\cache'
- '%LOCALAPPDATA%\Coursier\cache'

install:
- SET MILL_URL=https://github.com/lihaoyi/mill/releases/download/0.1.6/0.1.6-3-43d230
Expand Down
4 changes: 2 additions & 2 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ trait MillModule extends MillPublishModule{ outer =>

object clientserver extends MillModule{
def ivyDeps = Agg(
ivy"com.lihaoyi:::ammonite:1.0.5-4-c0cdbaf",
ivy"com.lihaoyi:::ammonite:1.0.5-7-f032887",
ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.0"
)
val test = new Tests(implicitly)
Expand All @@ -84,7 +84,7 @@ object core extends MillModule {

def ivyDeps = Agg(
ivy"com.lihaoyi::sourcecode:0.1.4",
ivy"com.lihaoyi:::ammonite:1.0.5-4-c0cdbaf",
ivy"com.lihaoyi:::ammonite:1.0.5-7-f032887",
ivy"jline:jline:2.14.5"
)

Expand Down
7 changes: 0 additions & 7 deletions clientserver/src/mill/clientserver/Client.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package mill.clientserver;

import io.github.retronym.java9rtexport.Export;
import org.scalasbt.ipcsocket.*;

import java.io.*;
import java.net.Socket;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand All @@ -29,11 +27,6 @@ static void initServer(String lockBase, boolean setJnaNoSys) throws IOException,
}
if (!System.getProperty("java.specification.version").startsWith("1.")) {
selfJars.addAll(Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator)));
File rtFile = new File(lockBase + "/rt-" + System.getProperty("java.version") + ".jar");
if (!rtFile.exists()) {
Files.copy(Export.export().toPath(), rtFile.toPath());
}
selfJars.add(rtFile.getCanonicalPath());
}
ArrayList<String> l = new java.util.ArrayList<String>();
l.add("java");
Expand Down
6 changes: 4 additions & 2 deletions core/src/mill/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ case class Labelled[T](task: NamedTask[T],
case _ => None
}
}
case class Evaluator[T](outPath: Path,
case class Evaluator[T](home: Path,
outPath: Path,
externalOutPath: Path,
rootModule: mill.define.BaseModule,
log: Logger,
Expand Down Expand Up @@ -265,7 +266,8 @@ case class Evaluator[T](outPath: Path,
throw new Exception("No `dest` folder available here")
}
},
multiLogger
multiLogger,
home
)

val out = System.out
Expand Down
11 changes: 9 additions & 2 deletions core/src/mill/util/ClassLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ import java.net.{URL, URLClassLoader}
import io.github.retronym.java9rtexport.Export

object ClassLoader {
def create(urls: Seq[URL], parent: java.lang.ClassLoader): URLClassLoader = {
def create(urls: Seq[URL],
parent: java.lang.ClassLoader)
(implicit ctx: Ctx.Home): URLClassLoader = {
val cl = new URLClassLoader(urls.toArray, parent)
if (!ammonite.util.Util.java9OrAbove) return cl
try {
cl.loadClass("javax.script.ScriptEngineManager")
cl
} catch {
case _: ClassNotFoundException =>
new URLClassLoader((urls ++ Some(Export.export().toURI.toURL)).toArray, parent)
val path = ctx.home
val rtFile = new java.io.File(path.toIO, s"rt-${System.getProperty("java.version")}.jar")
if (!rtFile.exists) {
java.nio.file.Files.copy(Export.export().toPath, rtFile.toPath)
}
new URLClassLoader((urls ++ Some(rtFile.toURI.toURL)).toArray, parent)
}
}
}
11 changes: 9 additions & 2 deletions core/src/mill/util/Ctx.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@ object Ctx{
trait Log{
def log: Logger
}
trait Home{
def home: Path
}
object Log{
implicit def logToCtx(l: Logger): Log = new Log { def log = l }
}
trait Args{
def args: IndexedSeq[_]
}

def defaultHome = ammonite.ops.home / ".mill" / "ammonite"

}
class Ctx(val args: IndexedSeq[_],
dest0: () => Path,
val log: Logger)
val log: Logger,
val home: Path)
extends Ctx.Dest
with Ctx.Log
with Ctx.Args{
with Ctx.Args
with Ctx.Home{

def dest = dest0()
def length = args.length
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/1 - Intro to Mill.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ $ mill foo.jar # bundle the classfiles into a jar

$ mill foo.assembly # bundle classfiles and all dependencies into a jar

$ mill foo.console # start a Scala console within your project
$ mill -i foo.console # start a Scala console within your project (in interactive mode: "-i")

$ mill foo.repl # start an Ammonite REPL within your project
$ mill -i foo.repl # start an Ammonite REPL within your project (in interactive mode: "-i")
```

You can run `mill resolve __` to see a full list of the different tasks that are
Expand Down
6 changes: 4 additions & 2 deletions main/src/mill/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object Main {
val millArgSignature =
Cli.genericSignature.filter(a => !removed(a.name)) :+ interactiveSignature

val millHome = home / ".mill" / "ammonite"
val millHome = mill.util.Ctx.defaultHome

Cli.groupArgs(
args.toList,
Expand Down Expand Up @@ -88,12 +88,14 @@ object Main {
stderr.println("Build repl needs to be run with the -i/--interactive flag")
(false, stateCache)
}else{
val tqs = "\"\"\""
val config =
if(!repl) cliConfig
else cliConfig.copy(
predefCode =
"""import $file.build, build._
s"""import $$file.build, build._
|implicit val replApplyHandler = mill.main.ReplApplyHandler(
| ammonite.ops.Path($tqs${cliConfig.home.toIO.getCanonicalPath.replaceAllLiterally("$", "$$")}$tqs),
| interp.colors(),
| repl.pprinter(),
| build.millSelf.get,
Expand Down
1 change: 1 addition & 0 deletions main/src/mill/main/MainRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MainRunner(val config: ammonite.main.Cli.Config,
printing = true,
mainCfg => {
val (result, interpWatched) = RunScript.runScript(
config.home,
mainCfg.wd,
scriptPath,
mainCfg.instantiateInterpreter(),
Expand Down
5 changes: 4 additions & 1 deletion main/src/mill/main/ReplApplyHandler.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mill.main


import ammonite.ops.Path
import mill.define.Applicative.ApplyHandler
import mill.define.Segment.Label
import mill.define._
Expand All @@ -9,13 +10,15 @@ import mill.util.Strict.Agg

import scala.collection.mutable
object ReplApplyHandler{
def apply[T](colors: ammonite.util.Colors,
def apply[T](home: Path,
colors: ammonite.util.Colors,
pprinter0: pprint.PPrinter,
rootModule: mill.define.BaseModule,
discover: Discover[_]) = {
new ReplApplyHandler(
pprinter0,
new Evaluator(
home,
ammonite.ops.pwd / 'out,
ammonite.ops.pwd / 'out,
rootModule,
Expand Down
5 changes: 3 additions & 2 deletions main/src/mill/main/RunScript.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import scala.reflect.ClassTag
* subsystem
*/
object RunScript{
def runScript(wd: Path,
def runScript(home: Path,
wd: Path,
path: Path,
instantiateInterpreter: => Either[(Res.Failing, Seq[(Path, Long)]), ammonite.interp.Interpreter],
scriptArgs: Seq[String],
Expand Down Expand Up @@ -52,7 +53,7 @@ object RunScript{

val evalRes =
for(s <- evalState)
yield new Evaluator[Any](wd / 'out, wd / 'out, s.rootModule, log, s.classLoaderSig, s.workerCache)
yield new Evaluator[Any](home, wd / 'out, wd / 'out, s.rootModule, log, s.classLoaderSig, s.workerCache)

val evaluated = for{
evaluator <- evalRes
Expand Down
3 changes: 2 additions & 1 deletion main/src/mill/modules/Jvm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ object Jvm {

def inprocess[T](classPath: Agg[Path],
classLoaderOverrideSbtTesting: Boolean,
body: ClassLoader => T): T = {
body: ClassLoader => T)
(implicit ctx: Ctx.Home): T = {
val cl = if (classLoaderOverrideSbtTesting) {
val outerClassLoader = getClass.getClassLoader
new URLClassLoader(classPath.map(_.toIO.toURI.toURL).toArray, mill.util.ClassLoader.create(Seq(), null)){
Expand Down
2 changes: 1 addition & 1 deletion main/test/src/mill/util/TestEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestEvaluator[T <: TestUtil.BaseModule](module: T)
// true,
// ammonite.util.Colors.Default, System.out, System.out, System.err, System.in
// )
val evaluator = new Evaluator(outPath, TestEvaluator.externalOutPath, module, logger)
val evaluator = new Evaluator(Ctx.defaultHome, outPath, TestEvaluator.externalOutPath, module, logger)

def apply[T](t: Task[T]): Either[Result.Failing[T], (T, Int)] = {
val evaluated = evaluator.evaluate(Agg(t))
Expand Down
13 changes: 9 additions & 4 deletions scalajslib/src/mill/scalajslib/ScalaJSBridge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.net.URLClassLoader

import ammonite.ops.Path
import mill.define.Discover
import mill.util.Ctx
import mill.{Agg, T}

sealed trait OptimizeMode
Expand All @@ -21,7 +22,8 @@ object ModuleKind{
class ScalaJSWorker {
private var scalaInstanceCache = Option.empty[(Long, ScalaJSBridge)]

private def bridge(toolsClasspath: Agg[Path]) = {
private def bridge(toolsClasspath: Agg[Path])
(implicit ctx: Ctx.Home) = {
val classloaderSig =
toolsClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum
scalaInstanceCache match {
Expand All @@ -47,7 +49,8 @@ class ScalaJSWorker {
dest: File,
main: Option[String],
fullOpt: Boolean,
moduleKind: ModuleKind): Unit = {
moduleKind: ModuleKind)
(implicit ctx: Ctx.Home): Unit = {
bridge(toolsClasspath).link(
sources.items.map(_.toIO).toArray,
libraries.items.map(_.toIO).toArray,
Expand All @@ -58,14 +61,16 @@ class ScalaJSWorker {
)
}

def run(toolsClasspath: Agg[Path], config: NodeJSConfig, linkedFile: File): Unit = {
def run(toolsClasspath: Agg[Path], config: NodeJSConfig, linkedFile: File)
(implicit ctx: Ctx.Home): Unit = {
bridge(toolsClasspath).run(config, linkedFile)
}

def getFramework(toolsClasspath: Agg[Path],
config: NodeJSConfig,
frameworkName: String,
linkedFile: File): (() => Unit, sbt.testing.Framework) = {
linkedFile: File)
(implicit ctx: Ctx.Home): (() => Unit, sbt.testing.Framework) = {
bridge(toolsClasspath).getFramework(config, frameworkName, linkedFile)
}

Expand Down
2 changes: 1 addition & 1 deletion scalajslib/src/mill/scalajslib/ScalaJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
runClasspath: Agg[PathRef],
mainClass: Option[String],
mode: OptimizeMode,
moduleKind: ModuleKind)(implicit ctx: Ctx.Dest): PathRef = {
moduleKind: ModuleKind)(implicit ctx: Ctx): PathRef = {
val outputPath = ctx.dest / "out.js"

mkdir(ctx.dest)
Expand Down
7 changes: 4 additions & 3 deletions scalalib/src/mill/scalalib/GenIdea.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import coursier.maven.MavenRepository
import mill.define._
import mill.eval.{Evaluator, PathRef, Result}
import mill.{T, scalalib}
import mill.util.Ctx.Log
import mill.util.Ctx.{Home, Log}
import mill.util.{Loose, PrintLogger, Strict}
import mill.util.Strict.Agg

import scala.util.Try


Expand All @@ -27,7 +28,7 @@ object GenIdeaModule extends ExternalModule {
}
object GenIdea {

def apply(ctx: Log,
def apply(ctx: Log with Home,
rootModule: BaseModule,
discover: Discover[_]): Unit = {
val pp = new scala.xml.PrettyPrinter(999, 4)
Expand All @@ -38,7 +39,7 @@ object GenIdea {
rm! pwd/".idea_modules"


val evaluator = new Evaluator(pwd / 'out, pwd / 'out, rootModule, ctx.log)
val evaluator = new Evaluator(ctx.home, pwd / 'out, pwd / 'out, rootModule, ctx.log)

for((relPath, xml) <- xmlFileLayout(evaluator, rootModule, jdkInfo)){
write.over(pwd/relPath, pp.format(xml))
Expand Down
7 changes: 5 additions & 2 deletions scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
def defaultCommandName() = "run"
trait Tests extends TestModule{
def scalaVersion = outer.scalaVersion()
override def repositories = outer.repositories
override def scalacPluginIvyDeps = outer.scalacPluginIvyDeps
override def scalacOptions = outer.scalacOptions
override def scalaWorker = outer.scalaWorker
override def moduleDeps = Seq(outer)
}
Expand Down Expand Up @@ -316,7 +319,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
}

def ammoniteReplClasspath = T{
resolveDeps(T.task{Agg(ivy"com.lihaoyi:::ammonite:1.0.5-4-c0cdbaf")})()
resolveDeps(T.task{Agg(ivy"com.lihaoyi:::ammonite:1.0.5-7-f032887")})()
}
def repl() = T.command{
if (T.ctx().log.inStream == DummyInputStream){
Expand Down Expand Up @@ -382,7 +385,7 @@ trait TestModule extends ScalaModule with TaskModule {
runClasspath().map(_.path.toString) ++
Seq(args.length.toString) ++
args ++
Seq(outputPath.toString, T.ctx().log.colored.toString, compile().classes.path.toString),
Seq(outputPath.toString, T.ctx().log.colored.toString, compile().classes.path.toString, T.ctx().home.toString),
workingDir = forkWorkingDir
)

Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/ScalaWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ trait ScalaWorkerApi {
entireClasspath: Agg[Path],
testClassfilePath: Agg[Path],
args: Seq[String])
(implicit ctx: mill.util.Ctx.Log): (String, Seq[Result])
(implicit ctx: mill.util.Ctx.Log with mill.util.Ctx.Home): (String, Seq[Result])

def discoverMainClasses(compilationResult: CompilationResult)
(implicit ctx: mill.util.Ctx): Seq[String]
Expand Down
Loading

0 comments on commit 1c507ef

Please sign in to comment.