Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into diagnosticCode
Browse files Browse the repository at this point in the history
  • Loading branch information
ckipp01 committed Aug 13, 2022
2 parents 8520913 + 080d704 commit e4ff173
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 75 deletions.
2 changes: 1 addition & 1 deletion contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
def moduleSourceMap = T.input {
val sources = T.traverse(computeModules) { m =>
m.allSources.map { paths =>
m.millModuleSegments.render -> paths.map(_.path)
name(m) -> paths.map(_.path)
}
}()
Result.Success(sources.toMap)
Expand Down
3 changes: 1 addition & 2 deletions contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ object BloopTests extends TestSuite {
if (scala.util.Properties.isWin) None else Some(readBloopConf("scalanativeModule.json"))

"no-compilation" - {
val workspaceOut =
os.pwd / "target" / "workspace" / "mill" / "contrib" / "bloop" / "BloopTests" / "testEvaluator"
val workspaceOut = os.pwd / "target" / "workspace" / "bloop" / "out"

// Ensuring that bloop config generation didn't trigger compilation
assert(os.exists(workspaceOut / "scalaModule"))
Expand Down
20 changes: 7 additions & 13 deletions contrib/docker/src/DockerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ trait DockerModule { outer: JavaModule =>
}

def dockerfile: T[String] = T {
val jarName = assembly().path.last
val labelRhs = labels()
.map { case (k, v) =>
val lineBrokenValue = v
Expand Down Expand Up @@ -113,30 +112,25 @@ trait DockerModule { outer: JavaModule =>
if (user().isEmpty) "" else s"USER ${user()}"
).filter(_.nonEmpty).mkString(sys.props("line.separator"))

s"""
|FROM ${baseImage()}
s"""FROM ${baseImage()}
|$lines
|COPY $jarName /$jarName
|ENTRYPOINT ["java", "-jar", "/$jarName"]""".stripMargin
|COPY ["${assembly().path}", "/${assembly().path.last}"]
|ENTRYPOINT ["java", "-jar", "/${assembly().path.last}"]""".stripMargin
}

final def build = T {
val dest = T.dest

val asmPath = outer.assembly().path
os.copy(asmPath, dest / asmPath.last)

os.write(dest / "Dockerfile", dockerfile())

val log = T.log
val dockerfilePath = T.dest / "Dockerfile"

os.write(dockerfilePath, dockerfile().replace(T.workspace.toString, ""))

val tagArgs = tags().flatMap(t => List("-t", t))

val (pull, _) = baseImageCacheBuster()
val pullLatestBase = IterableShellable(if (pull) Some("--pull") else None)

val result = os
.proc(executable(), "build", tagArgs, pullLatestBase, dest)
.proc(executable(), "build", tagArgs, pullLatestBase, "-f", dockerfilePath, T.workspace)
.call(stdout = os.Inherit, stderr = os.Inherit)

log.info(s"Docker build completed ${if (result.exitCode == 0) "successfully"
Expand Down
32 changes: 15 additions & 17 deletions contrib/docker/test/src/DockerModuleTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ object DockerModuleTest extends TestSuite {
val eval = new TestEvaluator(Docker)
val Right((dockerfileString, _)) = eval(Docker.dockerDefault.dockerfile)
val expected = multineRegex.replaceAllIn(
"""
|FROM gcr.io/distroless/java:latest
|COPY out.jar /out.jar
|ENTRYPOINT ["java", "-jar", "/out.jar"]""".stripMargin,
s"""FROM gcr.io/distroless/java:latest
|COPY ["${Docker.millSourcePath / "out" / "dockerfile contents" / "default options" / "assembly.dest" / "out.jar"}", "/out.jar"]
|ENTRYPOINT ["java", "-jar", "/out.jar"]""".stripMargin,
sys.props("line.separator")
)
val dockerfileStringRefined = multineRegex.replaceAllIn(
Expand All @@ -112,19 +111,18 @@ object DockerModuleTest extends TestSuite {
val eval = new TestEvaluator(Docker)
val Right((dockerfileString, _)) = eval(Docker.dockerAll.dockerfile)
val expected = multineRegex.replaceAllIn(
"""
|FROM docker.io/openjdk:11
|LABEL "version"="1.0"
|EXPOSE 8080/tcp 443/tcp
|EXPOSE 80/udp
|ENV foo=bar
|ENV foobar=barfoo
|VOLUME ["/v1", "/v2"]
|RUN /bin/bash -c 'echo Hello World!'
|RUN useradd -ms /bin/bash user1
|USER user1
|COPY out.jar /out.jar
|ENTRYPOINT ["java", "-jar", "/out.jar"]""".stripMargin,
s"""FROM docker.io/openjdk:11
|LABEL "version"="1.0"
|EXPOSE 8080/tcp 443/tcp
|EXPOSE 80/udp
|ENV foo=bar
|ENV foobar=barfoo
|VOLUME ["/v1", "/v2"]
|RUN /bin/bash -c 'echo Hello World!'
|RUN useradd -ms /bin/bash user1
|USER user1
|COPY ["${Docker.millSourcePath / "out" / "dockerfile contents" / "all options" / "assembly.dest" / "out.jar"}", "/out.jar"]
|ENTRYPOINT ["java", "-jar", "/out.jar"]""".stripMargin,
sys.props("line.separator")
)
val dockerfileStringRefined = multineRegex.replaceAllIn(
Expand Down
2 changes: 1 addition & 1 deletion contrib/scoverage/test/src/HelloWorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ trait HelloWorldTests extends utest.TestSuite {

assert(
result.path.toIO.getPath.replace("""\""", "/").endsWith(
"mill/target/workspace/mill/contrib/scoverage/HelloWorldTests/eval/HelloWorld/core/scoverage/data/core/scoverage/data.dest"
"mill/target/worksources/mill/contrib/scoverage/HelloWorldTests#HelloWorld/out/HelloWorld/core/scoverage/data/core/scoverage/data.dest"
),
evalCount > 0
)
Expand Down
7 changes: 7 additions & 0 deletions docs/antora/modules/ROOT/pages/Plugin_Docker.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ object docker extends DockerConfig {
def user = "new-user"
// Optionally override the docker executable to use something else
def executable = "podman"
// Optionally override the content of the Dockerfile. Note: All paths need to be absolute and located within the project.
def dockerfile =
s"""FROM ${baseImage()}
|RUN aptitude install -y pidgin
|COPY ${assembly().path} /${assembly().path.last}
|ENTRYPOINT ["java", "-jar", "/${assembly().path.last}"]""".stripMargin
|""".stripMargin
}
----

Expand Down
11 changes: 6 additions & 5 deletions main/test/src/eval/TaskTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,12 @@ object SeqTaskTests extends TaskTests {
object ParTaskTests extends TaskTests {
def withEnv(f: (Build, TestEvaluator) => Unit)(implicit tp: TestPath) = {
object build extends Build
val check = new TestEvaluator(
build,
threads = Some(16),
extraPathEnd = Seq(getClass().getSimpleName())
)
val check =
new TestEvaluator(
build,
threads = Some(16),
extraPathEnd = Seq(getClass().getSimpleName())
)
f(build, check)
}
}
2 changes: 1 addition & 1 deletion main/testkit/src/testkit/MillTestkit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ trait MillTestKit {
debugEnabled: Boolean = false,
extraPathEnd: Seq[String] = Seq.empty
)(implicit fullName: sourcecode.FullName) {
val outPath = getOutPath(testPath) / extraPathEnd
val outPath = module.millSourcePath / "out" / testPath / extraPathEnd

// val logger = DummyLogger
val logger = new mill.util.PrintLogger(
Expand Down
90 changes: 55 additions & 35 deletions scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import java.io.File
import java.util.Optional
import java.util.concurrent.ConcurrentHashMap

import scala.ref.SoftReference
import scala.util.Properties.isWin
import mill.api.Loose.Agg
import mill.api.{CompileProblemReporter, KeyedLockedCache, PathRef, internal}
import mill.scalalib.api.{CompilationResult, ZincWorkerApi, ZincWorkerUtil => Util}
Expand All @@ -17,6 +15,9 @@ import xsbti.compile.{CompilerCache => _, FileAnalysisStore => _, ScalaInstance
import xsbti.{PathBasedFile, VirtualFile}

import scala.annotation.nowarn
import scala.collection.mutable
import scala.ref.SoftReference
import scala.util.Properties.isWin

@internal
class ZincWorkerImpl(
Expand All @@ -32,40 +33,59 @@ class ZincWorkerImpl(
) extends ZincWorkerApi with AutoCloseable {
private val zincLogLevel = if (zincLogDebug) sbt.util.Level.Debug else sbt.util.Level.Info
private[this] val ic = new sbt.internal.inc.IncrementalCompilerImpl()
lazy val javaOnlyCompilers = {
// Keep the classpath as written by the user
val classpathOptions = ClasspathOptions.of(
/*bootLibrary*/ false,
/*compiler*/ false,
/*extra*/ false,
/*autoBoot*/ false,
/*filterLibrary*/ false
)
private val javaOnlyCompilersCache = mutable.Map.empty[Seq[String], SoftReference[Compilers]]

def javaOnlyCompilers(javacOptions: Seq[String]) = {
javaOnlyCompilersCache.get(javacOptions) match {
case Some(SoftReference(compilers)) => compilers
case _ =>
// Keep the classpath as written by the user
val classpathOptions = ClasspathOptions.of(
/*bootLibrary*/ false,
/*compiler*/ false,
/*extra*/ false,
/*autoBoot*/ false,
/*filterLibrary*/ false
)

val dummyFile = new java.io.File("")
// Zinc does not have an entry point for Java-only compilation, so we need
// to make up a dummy ScalaCompiler instance.
val scalac = ZincUtil.scalaCompiler(
new ScalaInstance(
version = "",
loader = null,
loaderCompilerOnly = null,
loaderLibraryOnly = null,
libraryJars = Array(dummyFile),
compilerJars = Array(dummyFile),
allJars = new Array(0),
explicitActual = Some("")
),
dummyFile,
classpathOptions // this is used for javac too
)
val dummyFile = new java.io.File("")
// Zinc does not have an entry point for Java-only compilation, so we need
// to make up a dummy ScalaCompiler instance.
val scalac = ZincUtil.scalaCompiler(
new ScalaInstance(
version = "",
loader = null,
loaderCompilerOnly = null,
loaderLibraryOnly = null,
libraryJars = Array(dummyFile),
compilerJars = Array(dummyFile),
allJars = new Array(0),
explicitActual = Some("")
),
dummyFile,
classpathOptions // this is used for javac too
)

ic.compilers(
instance = null,
classpathOptions,
None,
scalac
)
val javaTools = {
val (javaCompiler, javaDoc) =
// Local java compilers don't accept -J flags so when we put this together if we detect
// any javacOptions starting with -J we ensure we have a non-local Java compiler which
// can handle them.
if (javacOptions.exists(_.startsWith("-J"))) {
(javac.JavaCompiler.fork(None), javac.Javadoc.fork(None))

} else {
val compiler = javac.JavaCompiler.local.getOrElse(javac.JavaCompiler.fork(None))
val docs = javac.Javadoc.local.getOrElse(javac.Javadoc.fork())
(compiler, docs)
}
javac.JavaTools(javaCompiler, javaDoc)
}

val compilers = ic.compilers(javaTools, scalac)
javaOnlyCompilersCache.update(javacOptions, SoftReference(compilers))
compilers
}
}

val compilerBridgeLocks = collection.mutable.Map.empty[String, Object]
Expand Down Expand Up @@ -265,7 +285,7 @@ class ZincWorkerImpl(
compileClasspath,
javacOptions,
scalacOptions = Nil,
javaOnlyCompilers,
javaOnlyCompilers(javacOptions),
reporter
)
}
Expand Down

0 comments on commit e4ff173

Please sign in to comment.