Skip to content

Commit 8710969

Browse files
committed
Cross build to sbt 2.x
1 parent cdf5a9b commit 8710969

File tree

43 files changed

+403
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+403
-250
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
include:
15+
- os: ubuntu-latest
16+
java: 8
17+
distribution: zulu
18+
jobtype: 1
1519
- os: ubuntu-latest
1620
java: 8
1721
distribution: temurin
22+
jobtype: 2
1823
- os: ubuntu-latest
1924
java: 21
2025
distribution: temurin
26+
jobtype: 1
2127
- os: ubuntu-latest
2228
java: 24-ea
2329
distribution: temurin
30+
jobtype: 1
2431
- os: windows-latest
2532
java: 11
2633
distribution: temurin
34+
jobtype: 1
2735
env:
2836
# define Java options for both official sbt and sbt-extras
2937
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
@@ -36,7 +44,13 @@ jobs:
3644
distribution: "${{ matrix.distribution }}"
3745
java-version: "${{ matrix.java }}"
3846
cache: sbt
39-
- name: Build and test
47+
- name: Build and test (sbt 1.x)
48+
if: ${{ matrix.jobtype == 1 }}
49+
shell: bash
50+
run: |
51+
sbt -v ++2.12.x scripted
52+
- name: Build and test (sbt 2.x)
53+
if: ${{ matrix.jobtype == 2 }}
4054
shell: bash
4155
run: |
42-
sbt -v clean scripted
56+
sbt -v ++3.x 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: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,42 @@ 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"
32+
}
33+
}
34+
scriptedSbt := {
35+
scalaBinaryVersion.value match {
36+
case "2.12" => "1.10.2"
37+
case _ => "2.0.0-M2"
2538
}
2639
}
2740
Compile / generateContrabands / sourceManaged := baseDirectory.value / "src" / "main" / "scala"
2841
scriptedLaunchOpts := { scriptedLaunchOpts.value ++
2942
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
3043
}
3144
scriptedBufferLog := false
32-
scriptedSbt := "1.9.7"
3345
})
3446

3547
ThisBuild / scmInfo := Some(
@@ -56,30 +68,3 @@ ThisBuild / publishTo := {
5668
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
5769
}
5870
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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 Out = java.io.File
14+
type MainClass = sbt.Package.MainClass
15+
16+
object CollectionConverters
17+
18+
val moduleIDStr = Keys.moduleID.key
19+
def parseModuleIDStrAttribute(m: ModuleID): ModuleID = m
20+
21+
def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
22+
a.data.toPath()
23+
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
24+
a.data
25+
def toOutput(x: File)(implicit conv: FileConverter): File =
26+
x
27+
def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
28+
cp.map(_.data.toPath()).toVector
29+
def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
30+
cp.map(_.data).toVector
31+
32+
type CacheKey = FilesInfo[ModifiedFileInfo] :+:
33+
Map[String, (Boolean, String)] :+: // map of target paths that matched a merge strategy
34+
JManifest :+:
35+
// Assembly options...
36+
Boolean :+:
37+
Option[Seq[String]] :+:
38+
Option[Int] :+:
39+
Boolean :+:
40+
HNil
41+
42+
val HListFormats = sbt.internal.util.HListFormats
43+
val Streamable = scala.tools.nsc.io.Streamable
44+
45+
private[sbtassembly] def makeCacheKey(
46+
classes: Vector[NioPath],
47+
filteredJars: Vector[Attributed[File]],
48+
mergeStrategiesByPathList: Map[String, (Boolean, String)],
49+
jarManifest: JManifest,
50+
ao: AssemblyOption,
51+
): CacheKey =
52+
lastModified(classes.map(_.toFile()).toSet ++ filteredJars.map(_.data).toSet) :+:
53+
mergeStrategiesByPathList :+:
54+
jarManifest :+:
55+
ao.repeatableBuild :+:
56+
ao.prependShellScript :+:
57+
ao.maxHashLength :+:
58+
ao.appendContentHash :+:
59+
HNil
60+
61+
// sbt 1.x style disk cache
62+
private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)(
63+
buildAssembly: () => File
64+
): File = {
65+
import CacheImplicits._
66+
import sbt.internal.util.HListFormats._
67+
import sbt.Package.manifestFormat
68+
val cacheBlock = inputChanged(cacheDir / s"assembly-cacheKey-$scalaVersion") { (inputChanged, _: CacheKey) =>
69+
lastOutput(cacheDir / s"assembly-outputs-$scalaVersion") { (_: Unit, previousOutput: Option[File]) =>
70+
val outputExists = previousOutput.exists(_.exists())
71+
(inputChanged, outputExists) match {
72+
case (false, true) =>
73+
log.info("Assembly jar up to date: " + previousOutput.get.toPath)
74+
previousOutput.get
75+
case (true, true) =>
76+
log.debug("Building assembly jar due to changed inputs...")
77+
IO.delete(previousOutput.get)
78+
buildAssembly()
79+
case (_, _) =>
80+
log.debug("Building assembly jar due to missing output...")
81+
buildAssembly()
82+
}
83+
}
84+
}
85+
cacheBlock(inputs)(Unit)
86+
}
87+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 Out = HashedVirtualFileRef
12+
type JarManifest = PackageOption.JarManifest
13+
type MainClass = PackageOption.MainClass
14+
type ManifestAttributes = PackageOption.ManifestAttributes
15+
type FixedTimestamp = PackageOption.FixedTimestamp
16+
17+
val CollectionConverters = scala.collection.parallel.CollectionConverters
18+
19+
val moduleIDStr = Keys.moduleIDStr
20+
def parseModuleIDStrAttribute(str: String): ModuleID =
21+
Classpaths.moduleIdJsonKeyFormat.read(str)
22+
23+
def toNioPath(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): NioPath =
24+
conv.toPath(a.data)
25+
inline def toFile(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): File =
26+
toNioPath(a).toFile()
27+
def toOutput(x: File)(implicit conv: FileConverter): HashedVirtualFileRef =
28+
conv.toVirtualFile(x.toPath())
29+
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[NioPath] =
30+
cp.map(toNioPath).toVector
31+
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[File] =
32+
toNioPaths(cp).map(_.toFile())
33+
34+
object HListFormats
35+
val Streamable = scala.reflect.io.Streamable
36+
37+
extension [A1](init: Def.Initialize[Task[A1]])
38+
def ? : Def.Initialize[Task[Option[A1]]] = Def.optional(init) {
39+
case None => sbt.std.TaskExtra.task { None }
40+
case Some(t) => t.map(Some.apply)
41+
}
42+
43+
def or[A2 >: A1](i: Def.Initialize[Task[A2]]): Def.Initialize[Task[A2]] =
44+
init.?.zipWith(i) { (toa1: Task[Option[A1]], ta2: Task[A2]) =>
45+
(toa1, ta2).mapN {
46+
case (oa1: Option[A1], a2: A2) => oa1.getOrElse(a2)
47+
}
48+
}
49+
50+
val inTask = Project.inTask
51+
52+
type CacheKey = Int
53+
private[sbtassembly] def makeCacheKey(
54+
classes: Vector[NioPath],
55+
filteredJars: Vector[Attributed[HashedVirtualFileRef]],
56+
mergeStrategiesByPathList: Map[String, (Boolean, String)],
57+
jarManifest: JManifest,
58+
ao: AssemblyOption,
59+
): CacheKey = 0
60+
61+
private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)(
62+
buildAssembly: () => PluginCompat.Out
63+
): PluginCompat.Out =
64+
buildAssembly()
65+
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)