Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Cross build to sbt 2.x #1647

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 15 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ 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.3.4"
Global / scalaVersion := scala3
crossScalaVersions := Seq(scala3, scala212)
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.1.6"
case "2.12" => "1.5.8"
case _ => "2.0.0-M2"
}
}
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
44 changes: 44 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,44 @@
package com.typesafe.sbt.packager

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

private[packager] 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
def parseArtifactStrAttribute(a: Artifact): Artifact = a
def artifactToStr(art: Artifact): Artifact = art

def toNioPath(a: Attributed[File])(implicit conv: FileConverter): NioPath =
a.data.toPath()
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
def artifactPathToFile(ref: File)(implicit conv: FileConverter): File =
ref
def toArtifactPath(f: File)(implicit conv: FileConverter): ArtifactPath = f
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
def toFileRef(x: File)(implicit conv: FileConverter): FileRef =
x
def getName(ref: File): String =
ref.getName()
def getArtifactPathName(ref: File): String =
ref.getName()
def classpathAttr = Attributes.Name.CLASS_PATH
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 {}
56 changes: 56 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,56 @@
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

private[packager] 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)

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))

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

This file was deleted.

130 changes: 0 additions & 130 deletions src/main/scala-sbt-0.13/com/typesafe/sbt/packager/MappingsHelper.scala

This file was deleted.

Loading
Loading