Skip to content

Commit

Permalink
Cross build to sbt 2.x (#1647)
Browse files Browse the repository at this point in the history
**Problem/Solution**
This cross builds sbt-native-packager for sbt 1.x and 2.0.0-M3.

Co-authored-by: João Ferreira <[email protected]>
  • Loading branch information
eed3si9n and jtjeferreira authored Jan 5, 2025
1 parent 06f677b commit 6b69d6c
Show file tree
Hide file tree
Showing 184 changed files with 1,148 additions and 958 deletions.
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ project.excludePaths = [
# WixHelper.scala:105: error: Unable to format file due to bug in scalafmt
"glob:**/src/main/scala/com/typesafe/sbt/packager/windows/WixHelper.scala"
]
project.layout = StandardConvention
7 changes: 4 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ version: '{build}'
os: Windows Server 2012
install:
- cmd: choco install zulu8 -ia "INSTALLDIR=""C:\zulu"""
- cmd: SET JAVA_HOME="C:\zulu"
- cmd: SET JAVA_HOME=C:\zulu
- cmd: choco install sbt -ia "INSTALLDIR=""C:\sbt"""
- cmd: SET PATH=C:\sbt\bin;%JAVA_HOME%\bin;%PATH%
- cmd: java -version
- cmd: SET SBT_OPTS=-Xms4g -Xmx4g
- cmd: mkdir C:\temp
build_script:
- sbt clean compile
- sbt -Djava.io.tmpdir=C:\temp clean ++2.12.x compile
test_script:
- sbt validateWindows
- sbt -Djava.io.tmpdir=C:\temp ++2.12.x validateWindows
cache:
- C:\Users\appveyor\.sbt
- C:\Users\appveyor\.m2
Expand Down
47 changes: 34 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ organization := "com.github.sbt"
homepage := Some(url("https://github.com/sbt/sbt-native-packager"))

Global / onChangedBuildSource := ReloadOnSourceChanges
Global / scalaVersion := "2.12.20"

// crossBuildingSettings
lazy val scala212 = "2.12.20"
lazy val scala3 = "3.6.2"
Global / scalaVersion := scala3
crossScalaVersions := Seq(scala3, scala212)
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.1.6"
case _ => "2.0.0-M2"
case "2.12" => "1.5.8"
case _ => "2.0.0-M3"
}
}
scriptedSbt := {
scalaBinaryVersion.value match {
case "2.12" => "1.10.5"
case _ => "2.0.0-M2"
case "2.12" => "1.10.7"
case _ => "2.0.0-M3"
}
}

Expand Down Expand Up @@ -48,8 +51,7 @@ libraryDependencies ++= {
// scala version depended libraries
libraryDependencies ++= {
scalaBinaryVersion.value match {
case "2.10" => Nil
case _ =>
case "2.12" =>
Seq(
// Do NOT upgrade these dependencies to 2.x or newer! sbt-native-packager is a sbt-plugin
// and gets published with Scala 2.12, therefore we need to stay at the same major version
Expand All @@ -58,6 +60,8 @@ libraryDependencies ++= {
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2", // Do not upgrade beyond 1.x
"org.scala-lang.modules" %% "scala-xml" % "2.2.0"
)
case _ =>
Nil
}
}

Expand All @@ -79,11 +83,11 @@ mimaPreviousArtifacts := {
val m = "com.typesafe.sbt" %% moduleName.value % "1.3.15"
val sbtBinV = (pluginCrossBuild / sbtBinaryVersion).value
val scalaBinV = (update / scalaBinaryVersion).value
if (scalaBinV == "2.10") {
println(s"Skip MiMa check for SBT binary version ${sbtBinV} as scala ${scalaBinV} is not supported")
Set.empty
} else
Set(Defaults.sbtPluginExtra(m cross CrossVersion.disabled, sbtBinV, scalaBinV))
scalaBinV match {
case "2.12" =>
Set(Defaults.sbtPluginExtra(m cross CrossVersion.disabled, sbtBinV, scalaBinV))
case _ => Set.empty
}
}

// Release configuration
Expand All @@ -108,7 +112,8 @@ developers := List(
addCommandAlias("scalafmtFormatAll", "; ^scalafmtAll ; scalafmtSbt")
// ci commands
addCommandAlias("validateFormatting", "; scalafmtCheckAll ; scalafmtSbtCheck")
addCommandAlias("validate", "; clean ; update ; validateFormatting ; test ; mimaReportBinaryIssues")
// Ignore mimaReportBinaryIssues
addCommandAlias("validate", "; clean ; update ; validateFormatting ; test")

// List all scripted test separately to schedule them in different travis-ci jobs.
// Travis-CI has hard timeouts for jobs, so we run them in smaller jobs as the scripted
Expand Down Expand Up @@ -136,3 +141,19 @@ addCommandAlias("validateWindows", "; testOnly * -- -n windows ; scripted univer
addCommandAlias("validateJlink", "scripted jlink/*")

addCommandAlias("ci-release", "release with-defaults")

// So that publishLocal doesn't continuously create new versions
def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
val snapshotSuffix =
if (out.isSnapshot()) "-SNAPSHOT"
else ""
out.ref.dropPrefix + snapshotSuffix
}

def fallbackVersion(d: java.util.Date): String = s"HEAD-${sbtdynver.DynVer timestamp d}"

ThisBuild / version := dynverGitDescribeOutput.value.mkVersion(versionFmt, fallbackVersion(dynverCurrentDate.value))
ThisBuild / dynver := {
val d = new java.util.Date
sbtdynver.DynVer.getGitDescribeOutput(d).mkVersion(versionFmt, fallbackVersion(d))
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.2
sbt.version=1.10.7
46 changes: 46 additions & 0 deletions src/main/scala-2.12/com/typesafe/sbt/packager/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.typesafe.sbt.packager

import java.nio.file.{Path => NioPath}
import java.util.jar.Attributes
import sbt.*
import xsbti.FileConverter

object PluginCompat {
type FileRef = java.io.File
type ArtifactPath = java.io.File
type Out = java.io.File
type IncludeArtifact = Artifact => Boolean

val artifactStr = sbt.Keys.artifact.key
val moduleIDStr = sbt.Keys.moduleID.key
def parseModuleIDStrAttribute(m: ModuleID): ModuleID = m
def moduleIDToStr(m: ModuleID): ModuleID = m
private[packager] def parseArtifactStrAttribute(a: Artifact): Artifact = a
def artifactToStr(art: Artifact): Artifact = art

private[packager] def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
a.data.toPath()
private[packager] def toNioPath(ref: File)(implicit conv: FileConverter): NioPath =
ref.toPath()
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
a.data
def toFile(ref: File)(implicit conv: FileConverter): File =
ref
private[packager] def artifactPathToFile(ref: File)(implicit conv: FileConverter): File =
ref
private[packager] def toArtifactPath(f: File)(implicit conv: FileConverter): ArtifactPath = f
private[packager] def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
cp.map(_.data.toPath()).toVector
private[packager] def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
cp.map(_.data).toVector
def toFileRefsMapping(mappings: Seq[(File, String)])(implicit conv: FileConverter): Seq[(FileRef, String)] =
mappings
def toFileRef(x: File)(implicit conv: FileConverter): FileRef =
x
private[packager] def getName(ref: File): String =
ref.getName()
private[packager] def getArtifactPathName(ref: File): String =
ref.getName()
private[packager] def classpathAttr = Attributes.Name.CLASS_PATH
private[packager] def mainclassAttr = Attributes.Name.MAIN_CLASS
}
3 changes: 3 additions & 0 deletions src/main/scala-3/com/typesafe/sbt/packager/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.typesafe.sbt.packager

object Compat {}
60 changes: 60 additions & 0 deletions src/main/scala-3/com/typesafe/sbt/packager/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.typesafe.sbt.packager

import java.io.File
import java.nio.file.{Path => NioPath}
import java.util.jar.Attributes
import sbt.*
import xsbti.{FileConverter, HashedVirtualFileRef, VirtualFile, VirtualFileRef}
import sbt.internal.RemoteCache

object PluginCompat {
type FileRef = HashedVirtualFileRef
type ArtifactPath = VirtualFileRef
type Out = VirtualFile
type IncludeArtifact = Any => Boolean

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

private[packager] def parseArtifactStrAttribute(str: String): Artifact =
import sbt.librarymanagement.LibraryManagementCodec.ArtifactFormat
import sjsonnew.support.scalajson.unsafe.*
Converter.fromJsonUnsafe[Artifact](Parser.parseUnsafe(str))
def artifactToStr(art: Artifact): String =
import sbt.librarymanagement.LibraryManagementCodec.ArtifactFormat
import sjsonnew.support.scalajson.unsafe.*
CompactPrinter(Converter.toJsonUnsafe(art))

private[packager] def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
conv.toPath(a.data)
private[packager] def toNioPath(ref: HashedVirtualFileRef)(using conv: FileConverter): NioPath =
conv.toPath(ref)
def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File =
toNioPath(a).toFile()
def toFile(ref: HashedVirtualFileRef)(using conv: FileConverter): File =
toNioPath(ref).toFile()
private[packager] def artifactPathToFile(ref: VirtualFileRef)(using conv: FileConverter): File =
conv.toPath(ref).toFile()
private[packager] def toArtifactPath(f: File)(using conv: FileConverter): ArtifactPath =
conv.toVirtualFile(f.toPath())
private[packager] def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using
conv: FileConverter
): Vector[NioPath] =
cp.map(toNioPath).toVector
private[packager] def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] =
toNioPaths(cp).map(_.toFile())
def toFileRefsMapping(mappings: Seq[(File, String)])(using conv: FileConverter): Seq[(FileRef, String)] =
mappings.map { case (f, name) => toFileRef(f) -> name }
def toFileRef(x: File)(using conv: FileConverter): FileRef =
conv.toVirtualFile(x.toPath())
private[packager] def getName(ref: FileRef): String =
ref.name()
private[packager] def getArtifactPathName(ref: ArtifactPath): String =
ref.name()
private[packager] def classpathAttr: String = Attributes.Name.CLASS_PATH.toString()
private[packager] def mainclassAttr: String = Attributes.Name.MAIN_CLASS.toString()
}
50 changes: 0 additions & 50 deletions src/main/scala-sbt-0.13/com/typesafe/sbt/packager/Compat.scala

This file was deleted.

Loading

0 comments on commit 6b69d6c

Please sign in to comment.