Skip to content

Commit 6b69d6c

Browse files
Cross build to sbt 2.x (#1647)
**Problem/Solution** This cross builds sbt-native-packager for sbt 1.x and 2.0.0-M3. Co-authored-by: João Ferreira <jtjeferreira@gmail.com>
1 parent 06f677b commit 6b69d6c

184 files changed

Lines changed: 1148 additions & 958 deletions

File tree

Some content is hidden

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

.scalafmt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ project.excludePaths = [
1313
# WixHelper.scala:105: error: Unable to format file due to bug in scalafmt
1414
"glob:**/src/main/scala/com/typesafe/sbt/packager/windows/WixHelper.scala"
1515
]
16+
project.layout = StandardConvention

appveyor.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ version: '{build}'
22
os: Windows Server 2012
33
install:
44
- cmd: choco install zulu8 -ia "INSTALLDIR=""C:\zulu"""
5-
- cmd: SET JAVA_HOME="C:\zulu"
5+
- cmd: SET JAVA_HOME=C:\zulu
66
- cmd: choco install sbt -ia "INSTALLDIR=""C:\sbt"""
77
- cmd: SET PATH=C:\sbt\bin;%JAVA_HOME%\bin;%PATH%
88
- cmd: java -version
99
- cmd: SET SBT_OPTS=-Xms4g -Xmx4g
10+
- cmd: mkdir C:\temp
1011
build_script:
11-
- sbt clean compile
12+
- sbt -Djava.io.tmpdir=C:\temp clean ++2.12.x compile
1213
test_script:
13-
- sbt validateWindows
14+
- sbt -Djava.io.tmpdir=C:\temp ++2.12.x validateWindows
1415
cache:
1516
- C:\Users\appveyor\.sbt
1617
- C:\Users\appveyor\.m2

build.sbt

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ organization := "com.github.sbt"
33
homepage := Some(url("https://github.com/sbt/sbt-native-packager"))
44

55
Global / onChangedBuildSource := ReloadOnSourceChanges
6-
Global / scalaVersion := "2.12.20"
76

87
// crossBuildingSettings
8+
lazy val scala212 = "2.12.20"
9+
lazy val scala3 = "3.6.2"
10+
Global / scalaVersion := scala3
11+
crossScalaVersions := Seq(scala3, scala212)
912
(pluginCrossBuild / sbtVersion) := {
1013
scalaBinaryVersion.value match {
11-
case "2.12" => "1.1.6"
12-
case _ => "2.0.0-M2"
14+
case "2.12" => "1.5.8"
15+
case _ => "2.0.0-M3"
1316
}
1417
}
1518
scriptedSbt := {
1619
scalaBinaryVersion.value match {
17-
case "2.12" => "1.10.5"
18-
case _ => "2.0.0-M2"
20+
case "2.12" => "1.10.7"
21+
case _ => "2.0.0-M3"
1922
}
2023
}
2124

@@ -48,8 +51,7 @@ libraryDependencies ++= {
4851
// scala version depended libraries
4952
libraryDependencies ++= {
5053
scalaBinaryVersion.value match {
51-
case "2.10" => Nil
52-
case _ =>
54+
case "2.12" =>
5355
Seq(
5456
// Do NOT upgrade these dependencies to 2.x or newer! sbt-native-packager is a sbt-plugin
5557
// and gets published with Scala 2.12, therefore we need to stay at the same major version
@@ -58,6 +60,8 @@ libraryDependencies ++= {
5860
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2", // Do not upgrade beyond 1.x
5961
"org.scala-lang.modules" %% "scala-xml" % "2.2.0"
6062
)
63+
case _ =>
64+
Nil
6165
}
6266
}
6367

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

8993
// Release configuration
@@ -108,7 +112,8 @@ developers := List(
108112
addCommandAlias("scalafmtFormatAll", "; ^scalafmtAll ; scalafmtSbt")
109113
// ci commands
110114
addCommandAlias("validateFormatting", "; scalafmtCheckAll ; scalafmtSbtCheck")
111-
addCommandAlias("validate", "; clean ; update ; validateFormatting ; test ; mimaReportBinaryIssues")
115+
// Ignore mimaReportBinaryIssues
116+
addCommandAlias("validate", "; clean ; update ; validateFormatting ; test")
112117

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

138143
addCommandAlias("ci-release", "release with-defaults")
144+
145+
// So that publishLocal doesn't continuously create new versions
146+
def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
147+
val snapshotSuffix =
148+
if (out.isSnapshot()) "-SNAPSHOT"
149+
else ""
150+
out.ref.dropPrefix + snapshotSuffix
151+
}
152+
153+
def fallbackVersion(d: java.util.Date): String = s"HEAD-${sbtdynver.DynVer timestamp d}"
154+
155+
ThisBuild / version := dynverGitDescribeOutput.value.mkVersion(versionFmt, fallbackVersion(dynverCurrentDate.value))
156+
ThisBuild / dynver := {
157+
val d = new java.util.Date
158+
sbtdynver.DynVer.getGitDescribeOutput(d).mkVersion(versionFmt, fallbackVersion(d))
159+
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.10.2
1+
sbt.version=1.10.7

src/main/scala-sbt-1.0/com/typesafe/sbt/packager/Compat.scala renamed to src/main/scala-2.12/com/typesafe/sbt/packager/Compat.scala

File renamed without changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.typesafe.sbt.packager
2+
3+
import java.nio.file.{Path => NioPath}
4+
import java.util.jar.Attributes
5+
import sbt.*
6+
import xsbti.FileConverter
7+
8+
object PluginCompat {
9+
type FileRef = java.io.File
10+
type ArtifactPath = java.io.File
11+
type Out = java.io.File
12+
type IncludeArtifact = Artifact => Boolean
13+
14+
val artifactStr = sbt.Keys.artifact.key
15+
val moduleIDStr = sbt.Keys.moduleID.key
16+
def parseModuleIDStrAttribute(m: ModuleID): ModuleID = m
17+
def moduleIDToStr(m: ModuleID): ModuleID = m
18+
private[packager] def parseArtifactStrAttribute(a: Artifact): Artifact = a
19+
def artifactToStr(art: Artifact): Artifact = art
20+
21+
private[packager] def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
22+
a.data.toPath()
23+
private[packager] def toNioPath(ref: File)(implicit conv: FileConverter): NioPath =
24+
ref.toPath()
25+
def toFile(a: Attributed[File])(implicit conv: FileConverter): File =
26+
a.data
27+
def toFile(ref: File)(implicit conv: FileConverter): File =
28+
ref
29+
private[packager] def artifactPathToFile(ref: File)(implicit conv: FileConverter): File =
30+
ref
31+
private[packager] def toArtifactPath(f: File)(implicit conv: FileConverter): ArtifactPath = f
32+
private[packager] def toNioPaths(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[NioPath] =
33+
cp.map(_.data.toPath()).toVector
34+
private[packager] def toFiles(cp: Seq[Attributed[File]])(implicit conv: FileConverter): Vector[File] =
35+
cp.map(_.data).toVector
36+
def toFileRefsMapping(mappings: Seq[(File, String)])(implicit conv: FileConverter): Seq[(FileRef, String)] =
37+
mappings
38+
def toFileRef(x: File)(implicit conv: FileConverter): FileRef =
39+
x
40+
private[packager] def getName(ref: File): String =
41+
ref.getName()
42+
private[packager] def getArtifactPathName(ref: File): String =
43+
ref.getName()
44+
private[packager] def classpathAttr = Attributes.Name.CLASS_PATH
45+
private[packager] def mainclassAttr = Attributes.Name.MAIN_CLASS
46+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.typesafe.sbt.packager
2+
3+
object Compat {}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.typesafe.sbt.packager
2+
3+
import java.io.File
4+
import java.nio.file.{Path => NioPath}
5+
import java.util.jar.Attributes
6+
import sbt.*
7+
import xsbti.{FileConverter, HashedVirtualFileRef, VirtualFile, VirtualFileRef}
8+
import sbt.internal.RemoteCache
9+
10+
object PluginCompat {
11+
type FileRef = HashedVirtualFileRef
12+
type ArtifactPath = VirtualFileRef
13+
type Out = VirtualFile
14+
type IncludeArtifact = Any => Boolean
15+
16+
val artifactStr = Keys.artifactStr
17+
val moduleIDStr = Keys.moduleIDStr
18+
def parseModuleIDStrAttribute(str: String): ModuleID =
19+
Classpaths.moduleIdJsonKeyFormat.read(str)
20+
def moduleIDToStr(m: ModuleID): String =
21+
Classpaths.moduleIdJsonKeyFormat.write(m)
22+
23+
private[packager] def parseArtifactStrAttribute(str: String): Artifact =
24+
import sbt.librarymanagement.LibraryManagementCodec.ArtifactFormat
25+
import sjsonnew.support.scalajson.unsafe.*
26+
Converter.fromJsonUnsafe[Artifact](Parser.parseUnsafe(str))
27+
def artifactToStr(art: Artifact): String =
28+
import sbt.librarymanagement.LibraryManagementCodec.ArtifactFormat
29+
import sjsonnew.support.scalajson.unsafe.*
30+
CompactPrinter(Converter.toJsonUnsafe(art))
31+
32+
private[packager] def toNioPath(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): NioPath =
33+
conv.toPath(a.data)
34+
private[packager] def toNioPath(ref: HashedVirtualFileRef)(using conv: FileConverter): NioPath =
35+
conv.toPath(ref)
36+
def toFile(a: Attributed[HashedVirtualFileRef])(using conv: FileConverter): File =
37+
toNioPath(a).toFile()
38+
def toFile(ref: HashedVirtualFileRef)(using conv: FileConverter): File =
39+
toNioPath(ref).toFile()
40+
private[packager] def artifactPathToFile(ref: VirtualFileRef)(using conv: FileConverter): File =
41+
conv.toPath(ref).toFile()
42+
private[packager] def toArtifactPath(f: File)(using conv: FileConverter): ArtifactPath =
43+
conv.toVirtualFile(f.toPath())
44+
private[packager] def toNioPaths(cp: Seq[Attributed[HashedVirtualFileRef]])(using
45+
conv: FileConverter
46+
): Vector[NioPath] =
47+
cp.map(toNioPath).toVector
48+
private[packager] def toFiles(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Vector[File] =
49+
toNioPaths(cp).map(_.toFile())
50+
def toFileRefsMapping(mappings: Seq[(File, String)])(using conv: FileConverter): Seq[(FileRef, String)] =
51+
mappings.map { case (f, name) => toFileRef(f) -> name }
52+
def toFileRef(x: File)(using conv: FileConverter): FileRef =
53+
conv.toVirtualFile(x.toPath())
54+
private[packager] def getName(ref: FileRef): String =
55+
ref.name()
56+
private[packager] def getArtifactPathName(ref: ArtifactPath): String =
57+
ref.name()
58+
private[packager] def classpathAttr: String = Attributes.Name.CLASS_PATH.toString()
59+
private[packager] def mainclassAttr: String = Attributes.Name.MAIN_CLASS.toString()
60+
}

src/main/scala-sbt-0.13/com/typesafe/sbt/packager/Compat.scala

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

0 commit comments

Comments
 (0)