|
| 1 | +package sbtassembly |
| 2 | + |
| 3 | +import java.nio.file.{ Path => NioPath } |
| 4 | +import java.util.jar.{ Manifest => JManifest } |
| 5 | +import sbt.* |
| 6 | +import sbt.internal.util.HNil |
| 7 | +import sbt.internal.util.Types.:+: |
| 8 | +import sbt.util.FileInfo.lastModified |
| 9 | +import sbt.util.Tracked.{ inputChanged, lastOutput } |
| 10 | +import xsbti.FileConverter |
| 11 | + |
| 12 | +private[sbtassembly] object PluginCompat { |
| 13 | + type MainClass = sbt.Package.MainClass |
| 14 | + |
| 15 | + object CollectionConverters |
| 16 | + |
| 17 | + val moduleIDStr = Keys.moduleID.key |
| 18 | + def parseModuleIDStrAttribute(m: ModuleID): ModuleID = m |
| 19 | + |
| 20 | + def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath = |
| 21 | + a.data.toPath() |
| 22 | + def toFile(a: Attributed[File])(implicit conv: FileConverter): File = |
| 23 | + a.data |
| 24 | + def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] = |
| 25 | + cp.map(_.data.toPath()).toVector |
| 26 | + def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] = |
| 27 | + cp.map(_.data).toVector |
| 28 | + |
| 29 | + type CacheKey = FilesInfo[ModifiedFileInfo] :+: |
| 30 | + Map[String, (Boolean, String)] :+: // map of target paths that matched a merge strategy |
| 31 | + JManifest :+: |
| 32 | + // Assembly options... |
| 33 | + Boolean :+: |
| 34 | + Option[Seq[String]] :+: |
| 35 | + Option[Int] :+: |
| 36 | + Boolean :+: |
| 37 | + HNil |
| 38 | + |
| 39 | + val HListFormats = sbt.internal.util.HListFormats |
| 40 | + val Streamable = scala.tools.nsc.io.Streamable |
| 41 | + |
| 42 | + private[sbtassembly] def makeCacheKey( |
| 43 | + classes: Vector[NioPath], |
| 44 | + filteredJars: Vector[Attributed[File]], |
| 45 | + mergeStrategiesByPathList: Map[String, (Boolean, String)], |
| 46 | + jarManifest: JManifest, |
| 47 | + ao: AssemblyOption, |
| 48 | + ): CacheKey = |
| 49 | + lastModified(classes.map(_.toFile()).toSet ++ filteredJars.map(_.data).toSet) :+: |
| 50 | + mergeStrategiesByPathList :+: |
| 51 | + jarManifest :+: |
| 52 | + ao.repeatableBuild :+: |
| 53 | + ao.prependShellScript :+: |
| 54 | + ao.maxHashLength :+: |
| 55 | + ao.appendContentHash :+: |
| 56 | + HNil |
| 57 | + |
| 58 | + // sbt 1.x style disk cache |
| 59 | + private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)( |
| 60 | + buildAssembly: () => File |
| 61 | + ): File = { |
| 62 | + import CacheImplicits._ |
| 63 | + import sbt.internal.util.HListFormats._ |
| 64 | + import sbt.Package.manifestFormat |
| 65 | + val cacheBlock = inputChanged(cacheDir / s"assembly-cacheKey-$scalaVersion") { (inputChanged, _: CacheKey) => |
| 66 | + lastOutput(cacheDir / s"assembly-outputs-$scalaVersion") { (_: Unit, previousOutput: Option[File]) => |
| 67 | + val outputExists = previousOutput.exists(_.exists()) |
| 68 | + (inputChanged, outputExists) match { |
| 69 | + case (false, true) => |
| 70 | + log.info("Assembly jar up to date: " + previousOutput.get.toPath) |
| 71 | + previousOutput.get |
| 72 | + case (true, true) => |
| 73 | + log.debug("Building assembly jar due to changed inputs...") |
| 74 | + IO.delete(previousOutput.get) |
| 75 | + buildAssembly() |
| 76 | + case (_, _) => |
| 77 | + log.debug("Building assembly jar due to missing output...") |
| 78 | + buildAssembly() |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + cacheBlock(inputs)(Unit) |
| 83 | + } |
| 84 | +} |
0 commit comments