Skip to content

Commit

Permalink
Cross build to sbt 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Oct 6, 2024
1 parent cdf5a9b commit 8710969
Show file tree
Hide file tree
Showing 43 changed files with 403 additions and 250 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
java: 8
distribution: zulu
jobtype: 1
- os: ubuntu-latest
java: 8
distribution: temurin
jobtype: 2
- os: ubuntu-latest
java: 21
distribution: temurin
jobtype: 1
- os: ubuntu-latest
java: 24-ea
distribution: temurin
jobtype: 1
- os: windows-latest
java: 11
distribution: temurin
jobtype: 1
env:
# define Java options for both official sbt and sbt-extras
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
Expand All @@ -36,7 +44,13 @@ jobs:
distribution: "${{ matrix.distribution }}"
java-version: "${{ matrix.java }}"
cache: sbt
- name: Build and test
- name: Build and test (sbt 1.x)
if: ${{ matrix.jobtype == 1 }}
shell: bash
run: |
sbt -v ++2.12.x scripted
- name: Build and test (sbt 2.x)
if: ${{ matrix.jobtype == 2 }}
shell: bash
run: |
sbt -v clean scripted
sbt -v ++3.x scripted
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ project/plugins/lib_managed
project/plugins/src_managed
project/plugins/target
project/plugins/project/build.properties
.idea
.idea
metals.sbt
57 changes: 21 additions & 36 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,42 @@ ThisBuild / version := {

ThisBuild / organization := "com.eed3si9n"

def scala212 = "2.12.18"
ThisBuild / crossScalaVersions := Seq(scala212)
ThisBuild / scalaVersion := scala212
def scala212 = "2.12.20"
def scala3 = "3.3.4"
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
ThisBuild / scalaVersion := scala3

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

lazy val root = (project in file("."))
.enablePlugins(SbtPlugin, ContrabandPlugin, SbtPlugin)
.settings(pomConsistency2021DraftSettings)
.enablePlugins(SbtPlugin, ContrabandPlugin)
.settings(nocomma {
name := "sbt-assembly"
scalacOptions := Seq("-deprecation", "-unchecked", "-Dscalac.patmat.analysisBudget=1024", "-Xfuture")
libraryDependencies += jarjar
scalacOptions := Seq(
"-Xsource:3",
"-deprecation",
"-unchecked",
"-Dscalac.patmat.analysisBudget=1024",
"-Xfuture",
)
libraryDependencies += jarjar.cross(CrossVersion.for3Use2_13)
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.2.8"
case "2.12" => "1.5.8"
case _ => "2.0.0-M2"
}
}
scriptedSbt := {
scalaBinaryVersion.value match {
case "2.12" => "1.10.2"
case _ => "2.0.0-M2"
}
}
Compile / generateContrabands / sourceManaged := baseDirectory.value / "src" / "main" / "scala"
scriptedLaunchOpts := { scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
}
scriptedBufferLog := false
scriptedSbt := "1.9.7"
})

ThisBuild / scmInfo := Some(
Expand All @@ -56,30 +68,3 @@ ThisBuild / publishTo := {
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
ThisBuild / publishMavenStyle := true

// See https://eed3si9n.com/pom-consistency-for-sbt-plugins
lazy val pomConsistency2021Draft = settingKey[Boolean]("experimental")

/**
* this is an unofficial experiment to re-publish plugins with better Maven compatibility
*/
def pomConsistency2021DraftSettings: Seq[Setting[_]] = Seq(
pomConsistency2021Draft := Set("true", "1")(sys.env.get("POM_CONSISTENCY").getOrElse("false")),
moduleName := {
if (pomConsistency2021Draft.value)
sbtPluginModuleName2021Draft(moduleName.value,
(pluginCrossBuild / sbtBinaryVersion).value)
else moduleName.value
},
projectID := {
if (pomConsistency2021Draft.value) sbtPluginExtra2021Draft(projectID.value)
else projectID.value
},
)

def sbtPluginModuleName2021Draft(n: String, sbtV: String): String =
s"""${n}_sbt${if (sbtV == "1.0") "1" else if (sbtV == "2.0") "2" else sbtV}"""

def sbtPluginExtra2021Draft(m: ModuleID): ModuleID =
m.withExtraAttributes(Map.empty)
.withCrossVersion(CrossVersion.binary)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.10.2
87 changes: 87 additions & 0 deletions src/main/scala-2.12/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package sbtassembly

import java.nio.file.{ Path => NioPath }
import java.util.jar.{ Manifest => JManifest }
import sbt.*
import sbt.internal.util.HNil
import sbt.internal.util.Types.:+:
import sbt.util.FileInfo.lastModified
import sbt.util.Tracked.{ inputChanged, lastOutput }
import xsbti.FileConverter

private[sbtassembly] object PluginCompat {
type Out = java.io.File
type MainClass = sbt.Package.MainClass

object CollectionConverters

val moduleIDStr = Keys.moduleID.key
def parseModuleIDStrAttribute(m: ModuleID): ModuleID = m

def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
a.data.toPath()
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
a.data
def toOutput(x: File)(implicit conv: FileConverter): File =
x
def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
cp.map(_.data.toPath()).toVector
def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
cp.map(_.data).toVector

type CacheKey = FilesInfo[ModifiedFileInfo] :+:
Map[String, (Boolean, String)] :+: // map of target paths that matched a merge strategy
JManifest :+:
// Assembly options...
Boolean :+:
Option[Seq[String]] :+:
Option[Int] :+:
Boolean :+:
HNil

val HListFormats = sbt.internal.util.HListFormats
val Streamable = scala.tools.nsc.io.Streamable

private[sbtassembly] def makeCacheKey(
classes: Vector[NioPath],
filteredJars: Vector[Attributed[File]],
mergeStrategiesByPathList: Map[String, (Boolean, String)],
jarManifest: JManifest,
ao: AssemblyOption,
): CacheKey =
lastModified(classes.map(_.toFile()).toSet ++ filteredJars.map(_.data).toSet) :+:
mergeStrategiesByPathList :+:
jarManifest :+:
ao.repeatableBuild :+:
ao.prependShellScript :+:
ao.maxHashLength :+:
ao.appendContentHash :+:
HNil

// sbt 1.x style disk cache
private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)(
buildAssembly: () => File
): File = {
import CacheImplicits._
import sbt.internal.util.HListFormats._
import sbt.Package.manifestFormat
val cacheBlock = inputChanged(cacheDir / s"assembly-cacheKey-$scalaVersion") { (inputChanged, _: CacheKey) =>
lastOutput(cacheDir / s"assembly-outputs-$scalaVersion") { (_: Unit, previousOutput: Option[File]) =>
val outputExists = previousOutput.exists(_.exists())
(inputChanged, outputExists) match {
case (false, true) =>
log.info("Assembly jar up to date: " + previousOutput.get.toPath)
previousOutput.get
case (true, true) =>
log.debug("Building assembly jar due to changed inputs...")
IO.delete(previousOutput.get)
buildAssembly()
case (_, _) =>
log.debug("Building assembly jar due to missing output...")
buildAssembly()
}
}
}
cacheBlock(inputs)(Unit)
}
}
65 changes: 65 additions & 0 deletions src/main/scala-3/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package sbtassembly

import java.io.File
import java.nio.file.{ Path => NioPath }
import java.util.jar.{ Manifest => JManifest }
import sbt.*
import sbt.librarymanagement.ModuleID
import xsbti.{ FileConverter, HashedVirtualFileRef }

object PluginCompat:
type Out = HashedVirtualFileRef
type JarManifest = PackageOption.JarManifest
type MainClass = PackageOption.MainClass
type ManifestAttributes = PackageOption.ManifestAttributes
type FixedTimestamp = PackageOption.FixedTimestamp

val CollectionConverters = scala.collection.parallel.CollectionConverters

val moduleIDStr = Keys.moduleIDStr
def parseModuleIDStrAttribute(str: String): ModuleID =
Classpaths.moduleIdJsonKeyFormat.read(str)

def toNioPath(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): NioPath =
conv.toPath(a.data)
inline def toFile(a: Attributed[HashedVirtualFileRef])(implicit conv: FileConverter): File =
toNioPath(a).toFile()
def toOutput(x: File)(implicit conv: FileConverter): HashedVirtualFileRef =
conv.toVirtualFile(x.toPath())
def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[NioPath] =
cp.map(toNioPath).toVector
inline def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(implicit conv: FileConverter): Vector[File] =
toNioPaths(cp).map(_.toFile())

object HListFormats
val Streamable = scala.reflect.io.Streamable

extension [A1](init: Def.Initialize[Task[A1]])
def ? : Def.Initialize[Task[Option[A1]]] = Def.optional(init) {
case None => sbt.std.TaskExtra.task { None }
case Some(t) => t.map(Some.apply)
}

def or[A2 >: A1](i: Def.Initialize[Task[A2]]): Def.Initialize[Task[A2]] =
init.?.zipWith(i) { (toa1: Task[Option[A1]], ta2: Task[A2]) =>
(toa1, ta2).mapN {
case (oa1: Option[A1], a2: A2) => oa1.getOrElse(a2)
}
}

val inTask = Project.inTask

type CacheKey = Int
private[sbtassembly] def makeCacheKey(
classes: Vector[NioPath],
filteredJars: Vector[Attributed[HashedVirtualFileRef]],
mergeStrategiesByPathList: Map[String, (Boolean, String)],
jarManifest: JManifest,
ao: AssemblyOption,
): CacheKey = 0

private[sbtassembly] def cachedAssembly(inputs: CacheKey, cacheDir: File, scalaVersion: String, log: Logger)(
buildAssembly: () => PluginCompat.Out
): PluginCompat.Out =
buildAssembly()
end PluginCompat
9 changes: 0 additions & 9 deletions src/main/scala-sbt-1.0/PluginCompat.scala

This file was deleted.

Loading

0 comments on commit 8710969

Please sign in to comment.