Skip to content

Commit

Permalink
Add --post-compile-merge-dir option in zinc (#7917)
Browse files Browse the repository at this point in the history
Prerequisite for #7869, so resources like
```
META-INF/services/
META-INF/services/javax.annotation.processing.Processor
```
in the z.jar can be added by zinc wrapper instead of post processing by Pants.
  • Loading branch information
wisechengyi committed Jun 23, 2019
1 parent f86c1f3 commit 4aad44d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/scala/org/pantsbuild/zinc/compiler/Main.scala
Expand Up @@ -10,6 +10,7 @@ import scala.collection.JavaConverters._

import sbt.internal.inc.IncrementalCompilerImpl
import sbt.internal.util.{ ConsoleLogger, ConsoleOut }
import sbt.io.IO
import sbt.util.Level
import xsbti.CompileFailed

Expand Down Expand Up @@ -160,6 +161,11 @@ object Main {
// Run the compile.
val result = new IncrementalCompilerImpl().compile(inputs, log)

// post compile merge dir
if (settings.postCompileMergeDir.isDefined) {
IO.copyDirectory(new File(settings.postCompileMergeDir.get.toURI), new File(settings.classesDirectory.toURI))
}

// Store the output if the result changed.
if (result.hasModified) {
targetAnalysisStore.set(
Expand Down
7 changes: 7 additions & 0 deletions src/scala/org/pantsbuild/zinc/compiler/Settings.scala
Expand Up @@ -28,6 +28,7 @@ case class Settings(
_sources: Seq[File] = Seq.empty,
classpath: Seq[File] = Seq.empty,
_classesDirectory: Option[File] = None,
_postCompileMergeDir: Option[File] = None,
outputJar: Option[File] = None,
scala: ScalaLocation = ScalaLocation(),
scalacOptions: Seq[String] = Seq.empty,
Expand All @@ -47,6 +48,8 @@ case class Settings(
lazy val classesDirectory: File =
normalise(_classesDirectory.getOrElse(defaultClassesDirectory()))

lazy val postCompileMergeDir: Option[File] = _postCompileMergeDir.map(normalise)

lazy val incOptions: IncOptions = {
_incOptions.copy(
apiDumpDirectory = _incOptions.apiDumpDirectory map normalise,
Expand Down Expand Up @@ -282,6 +285,10 @@ object Settings {
.action((x, c) => c.copy(classpath = x))
.text("Specify the classpath")

opt[File]("post-compile-merge-dir")
.action((x, c) => c.copy(_postCompileMergeDir = Some(x)))
.text("Directory to merge with compile outputs after compilation")

opt[File]("class-destination")
.abbr("d")
.action((x, c) => c.copy(_classesDirectory = Some(x)))
Expand Down

0 comments on commit 4aad44d

Please sign in to comment.