Skip to content

Commit faec21a

Browse files
committed
wip
1 parent cdf5a9b commit faec21a

10 files changed

Lines changed: 215 additions & 124 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
- name: Build and test
4040
shell: bash
4141
run: |
42-
sbt -v clean scripted
42+
sbt -v +compile scripted

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ project/plugins/lib_managed
66
project/plugins/src_managed
77
project/plugins/target
88
project/plugins/project/build.properties
9-
.idea
9+
.idea
10+
metals.sbt

build.sbt

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,36 @@ ThisBuild / version := {
66

77
ThisBuild / organization := "com.eed3si9n"
88

9-
def scala212 = "2.12.18"
10-
ThisBuild / crossScalaVersions := Seq(scala212)
11-
ThisBuild / scalaVersion := scala212
9+
def scala212 = "2.12.20"
10+
def scala3 = "3.3.4"
11+
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
12+
ThisBuild / scalaVersion := scala3
1213

1314
lazy val jarjar = "com.eed3si9n.jarjarabrams" %% "jarjar-abrams-core" % "1.14.0"
1415

1516
lazy val root = (project in file("."))
16-
.enablePlugins(SbtPlugin, ContrabandPlugin, SbtPlugin)
17-
.settings(pomConsistency2021DraftSettings)
17+
.enablePlugins(SbtPlugin, ContrabandPlugin)
1818
.settings(nocomma {
1919
name := "sbt-assembly"
20-
scalacOptions := Seq("-deprecation", "-unchecked", "-Dscalac.patmat.analysisBudget=1024", "-Xfuture")
21-
libraryDependencies += jarjar
20+
scalacOptions := Seq(
21+
"-Xsource:3",
22+
"-deprecation",
23+
"-unchecked",
24+
"-Dscalac.patmat.analysisBudget=1024",
25+
"-Xfuture",
26+
)
27+
libraryDependencies += jarjar.cross(CrossVersion.for3Use2_13)
2228
(pluginCrossBuild / sbtVersion) := {
2329
scalaBinaryVersion.value match {
24-
case "2.12" => "1.2.8"
30+
case "2.12" => "1.5.8"
31+
case _ => "2.0.0-M2"
2532
}
2633
}
2734
Compile / generateContrabands / sourceManaged := baseDirectory.value / "src" / "main" / "scala"
2835
scriptedLaunchOpts := { scriptedLaunchOpts.value ++
2936
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
3037
}
3138
scriptedBufferLog := false
32-
scriptedSbt := "1.9.7"
3339
})
3440

3541
ThisBuild / scmInfo := Some(
@@ -56,30 +62,3 @@ ThisBuild / publishTo := {
5662
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
5763
}
5864
ThisBuild / publishMavenStyle := true
59-
60-
// See https://eed3si9n.com/pom-consistency-for-sbt-plugins
61-
lazy val pomConsistency2021Draft = settingKey[Boolean]("experimental")
62-
63-
/**
64-
* this is an unofficial experiment to re-publish plugins with better Maven compatibility
65-
*/
66-
def pomConsistency2021DraftSettings: Seq[Setting[_]] = Seq(
67-
pomConsistency2021Draft := Set("true", "1")(sys.env.get("POM_CONSISTENCY").getOrElse("false")),
68-
moduleName := {
69-
if (pomConsistency2021Draft.value)
70-
sbtPluginModuleName2021Draft(moduleName.value,
71-
(pluginCrossBuild / sbtBinaryVersion).value)
72-
else moduleName.value
73-
},
74-
projectID := {
75-
if (pomConsistency2021Draft.value) sbtPluginExtra2021Draft(projectID.value)
76-
else projectID.value
77-
},
78-
)
79-
80-
def sbtPluginModuleName2021Draft(n: String, sbtV: String): String =
81-
s"""${n}_sbt${if (sbtV == "1.0") "1" else if (sbtV == "2.0") "2" else sbtV}"""
82-
83-
def sbtPluginExtra2021Draft(m: ModuleID): ModuleID =
84-
m.withExtraAttributes(Map.empty)
85-
.withCrossVersion(CrossVersion.binary)

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.9.9
1+
sbt.version=1.10.2
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package sbtassembly
2+
3+
import java.io.File
4+
import java.nio.file.{ Path => NioPath }
5+
import java.util.jar.{ Manifest => JManifest }
6+
import sbt.*
7+
import sbt.librarymanagement.ModuleID
8+
import xsbti.{ FileConverter, HashedVirtualFileRef }
9+
10+
object PluginCompat:
11+
type JarManifest = PackageOption.JarManifest
12+
type MainClass = PackageOption.MainClass
13+
type ManifestAttributes = PackageOption.ManifestAttributes
14+
15+
val CollectionConverters = scala.collection.parallel.CollectionConverters
16+
17+
val moduleIDStr = Keys.moduleIDStr
18+
def parseModuleIDStrAttribute(str: String): ModuleID =
19+
Classpaths.moduleIdJsonKeyFormat.read(str)
20+
21+
def toNioPath(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): NioPath =
22+
conv.toPath(a.data)
23+
inline def toFile(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): File =
24+
toNioPath(a).toFile()
25+
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[NioPath] =
26+
cp.map(toNioPath).toVector
27+
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[File] =
28+
toNioPaths(cp).map(_.toFile())
29+
30+
object HListFormats
31+
val Streamable = scala.reflect.io.Streamable
32+
33+
extension [A1](init: Def.Initialize[Task[A1]])
34+
def ? : Def.Initialize[Task[Option[A1]]] = Def.optional(init) {
35+
case None => sbt.std.TaskExtra.task { None }
36+
case Some(t) => t.map(Some.apply)
37+
}
38+
39+
def or[A2 >: A1](i: Def.Initialize[Task[A2]]): Def.Initialize[Task[A2]] =
40+
init.?.zipWith(i) { (toa1: Task[Option[A1]], ta2: Task[A2]) =>
41+
(toa1, ta2).mapN {
42+
case (oa1: Option[A1], a2: A2) => oa1.getOrElse(a2)
43+
}
44+
}
45+
46+
val inTask = Project.inTask
47+
48+
type CacheKey = Int
49+
private[sbtassembly] def makeCacheKey(
50+
classes: Vector[NioPath],
51+
filteredJars: Vector[Attributed[HashedVirtualFileRef]],
52+
mergeStrategiesByPathList: Map[String, (Boolean, String)],
53+
jarManifest: JManifest,
54+
ao: AssemblyOption,
55+
): CacheKey = 0
56+
57+
private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)(
58+
buildAssembly: () => File
59+
): File =
60+
buildAssembly()
61+
end PluginCompat

src/main/scala-sbt-1.0/PluginCompat.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)