Skip to content

Commit

Permalink
Merge pull request #214 from eed3si9n/wip/cross-build
Browse files Browse the repository at this point in the history
Cross build to sbt 2.x
  • Loading branch information
eed3si9n authored Oct 5, 2024
2 parents cac21ad + 7c0d086 commit 7bbc399
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 146 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ jobs:
- name: Build and test
if: ${{ matrix.jobtype == 1 }}
shell: bash
run: sbt -v clean +test +scripted
run: sbt -v clean test scripted
- name: Scalafmt
if: ${{ matrix.jobtype == 2 }}
shell: bash
run: sbt -v clean scalafmtSbtCheck +scalafmtCheckAll
- name: Scala 3
if: ${{ matrix.jobtype == 3 }}
shell: bash
run: sbt -v '++ 3.3.4!' library/test
run: sbt -v '++ 3.3.4!' library/test scripted
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ThisBuild / Compile / scalacOptions := Seq("-feature", "-deprecation", "-Xlint")
// Because we're both a library and an sbt plugin, we use crossScalaVersions rather than crossSbtVersions for
// cross building. So you can use commands like +scripted.
lazy val scala212 = "2.12.15"
ThisBuild / crossScalaVersions := Seq(scala212)
lazy val scala3 = "3.3.4"
ThisBuild / crossScalaVersions := Seq(scala212, scala3)
ThisBuild / scalaVersion := scala212

ThisBuild / scalafmtOnCompile := true
Expand Down Expand Up @@ -46,7 +47,7 @@ lazy val plugin = (project in file("sbt-pgp"))
scriptedLaunchOpts += s"-Dproject.version=${version.value}",
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.2.8"
case "2.12" => "1.5.8"
case _ => "2.0.0-M2"
}
}
Expand Down
68 changes: 68 additions & 0 deletions sbt-pgp/src/main/scala-2.12/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package sbt
package sbtpgp

import sbt.{ librarymanagement => lm }
import sbt.internal.{ librarymanagement => ilm }
import Keys._
import com.jsuereth.sbtpgp.PgpKeys._
import com.jsuereth.sbtpgp.gpgExtension

object Compat {
val IvyActions = ilm.IvyActions
type IvySbt = ilm.IvySbt
type IvyScala = lm.ScalaModuleInfo
type UpdateConfiguration = lm.UpdateConfiguration
type UnresolvedWarning = lm.UnresolvedWarning
type UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration
val UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration

val ivyScala = Keys.scalaModuleInfo

def pgpRequires: Plugins = sbt.plugins.IvyPlugin

def subConfiguration(m: ModuleID, confs: Boolean): ModuleID =
m.withConfigurations(
if (confs) m.configurations
else None
)

def subExplicitArtifacts(m: ModuleID, artifacts: Vector[Artifact]): ModuleID =
m.withExplicitArtifacts(artifacts)

// This hack to access private[sbt]
def updateEither(
module: IvySbt#Module,
configuration: UpdateConfiguration,
uwconfig: UnresolvedWarningConfiguration,
logicalClock: LogicalClock,
depDir: Option[File],
log: Logger
): Either[UnresolvedWarning, UpdateReport] =
IvyActions.updateEither(module, configuration, uwconfig, log)

val signedArtifacts = TaskKey[Map[Artifact, File]](
"signed-artifacts",
"Packages all artifacts for publishing and maps the Artifact definition to the generated file."
)

def signingSettings0: Seq[Setting[_]] = Seq(
// conditional
signedArtifacts := {
if (!(pgpSigner / skip).value) {
val artifacts = packagedArtifacts.value
val r = pgpSigner.value
val s = streams.value
artifacts flatMap {
case (art, file) =>
Seq(
art -> file,
art.withExtension(art.extension + gpgExtension) -> r
.sign(file, new File(file.getAbsolutePath + gpgExtension), s)
)
}
} else packagedArtifacts.value
}
)

def toFile(x: File, c: xsbti.FileConverter): File = x
}
72 changes: 72 additions & 0 deletions sbt-pgp/src/main/scala-3/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package sbt
package sbtpgp

import sbt.{ librarymanagement => lm }
import sbt.internal.{ librarymanagement => ilm }
import Keys._
import com.jsuereth.sbtpgp.PgpKeys._
import com.jsuereth.sbtpgp.gpgExtension

object Compat {
val IvyActions = ilm.IvyActions
type IvySbt = ilm.IvySbt
type IvyScala = lm.ScalaModuleInfo
type UpdateConfiguration = lm.UpdateConfiguration
type UnresolvedWarning = lm.UnresolvedWarning
type UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration
val UnresolvedWarningConfiguration = lm.UnresolvedWarningConfiguration

val ivyScala = Keys.scalaModuleInfo

def pgpRequires: Plugins = sbt.plugins.IvyPlugin

def subConfiguration(m: ModuleID, confs: Boolean): ModuleID =
m.withConfigurations(
if (confs) m.configurations
else None
)

def subExplicitArtifacts(m: ModuleID, artifacts: Vector[Artifact]): ModuleID =
m.withExplicitArtifacts(artifacts)

// This hack to access private[sbt]
def updateEither(
module: IvySbt#Module,
configuration: UpdateConfiguration,
uwconfig: UnresolvedWarningConfiguration,
logicalClock: LogicalClock,
depDir: Option[File],
log: Logger
): Either[UnresolvedWarning, UpdateReport] =
IvyActions.updateEither(module, configuration, uwconfig, log)

val signedArtifacts = taskKey[Map[Artifact, xsbti.HashedVirtualFileRef]](
"Packages all artifacts for publishing and maps the Artifact definition to the generated file."
)

def signingSettings0: Seq[Setting[_]] = Seq(
// conditional
signedArtifacts := {
if (!(pgpSigner / skip).value) {
val artifacts = packagedArtifacts.value
val r = pgpSigner.value
val s = streams.value
val c = fileConverter.value
artifacts.flatMap {
case (art, file) =>
val p = c.toPath(file)
val signed = c.toVirtualFile(
r.sign(p.toFile(), new File(p.toFile().getAbsolutePath + gpgExtension), s).toPath()
)
Seq(
art -> file,
art.withExtension(art.extension + gpgExtension) -> signed
)
}
} else packagedArtifacts.value
}
)

def toFile(vf: xsbti.HashedVirtualFileRef, c: xsbti.FileConverter): File =
c.toPath(vf).toFile()
}
100 changes: 0 additions & 100 deletions sbt-pgp/src/main/scala-sbt-1.0/Compat.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ case class SendKey(pubKey: String, hkpUrl: String) extends HkpCommand {
val key = pubring findPubKeyRing pubKey getOrElse sys.error("Could not find public key: " + pubKey)
val client = hkpClient
log.info("Sending " + key + " to " + client)
client.pushKeyRing(key, { s: String =>
client.pushKeyRing(key, { (s: String) =>
log.debug(s)
})
}
Expand Down
6 changes: 2 additions & 4 deletions sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jsuereth.sbtpgp

import sbt._
import com.jsuereth.pgp._
import sbt.sbtpgp.Compat._
import sbt.sbtpgp.Compat, Compat._

/** SBT Keys for the PGP plugin. */
object PgpKeys {
Expand Down Expand Up @@ -46,9 +46,7 @@ object PgpKeys {
val publishSignedConfiguration = taskKey[PublishConfiguration]("Configuration for publishing to a repository.")
val publishLocalSignedConfiguration =
taskKey[PublishConfiguration]("Configuration for publishing to the local repository.")
val signedArtifacts = taskKey[Map[Artifact, File]](
"Packages all artifacts for publishing and maps the Artifact definition to the generated file."
)
val signedArtifacts = Compat.signedArtifacts
val publishSigned = taskKey[Unit]("Publishing all artifacts, but SIGNED using PGP.")
val publishLocalSigned = taskKey[Unit]("Publishing all artifacts to a local repository, but SIGNED using PGP.")
val pgpMakeIvy = taskKey[Option[File]]("Generates the Ivy file.")
Expand Down
59 changes: 40 additions & 19 deletions sbt-pgp/src/main/scala/com/jsuereth/sbtpgp/PgpSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ object PgpSettings {
/** Settings this plugin defines. TODO - require manual setting of these... */
lazy val projectSettings: Seq[Setting[_]] = signingSettings ++ verifySettings

def deliverPattern(outputPath: File): String =
(outputPath / "[artifact]-[revision](-[classifier]).[ext]").absolutePath

/** Configuration for GPG command line */
lazy val gpgConfigurationSettings: Seq[Setting[_]] = Seq(
useGpg := {
Expand Down Expand Up @@ -136,30 +139,48 @@ object PgpSettings {
* artifacts. While this isn't as friendly to other plugins that want to
* use our signed artifacts in normal publish flow, it should be more user friendly.
*/
lazy val signingSettings: Seq[Setting[_]] = Seq(
signedArtifacts := {
val artifacts = packagedArtifacts.value
val r = pgpSigner.value
val skipZ = (pgpSigner / skip).value
val s = streams.value
if (!skipZ) {
artifacts flatMap {
case (art, file) =>
Seq(
art -> file,
subExtension(art, art.extension + gpgExtension) -> r
.sign(file, new File(file.getAbsolutePath + gpgExtension), s)
)
}
} else artifacts
},
lazy val signingSettings: Seq[Setting[_]] = signingSettings0 ++ Seq(
pgpMakeIvy := (Def.taskDyn {
val style = publishMavenStyle.value
if (style) Def.task { (None: Option[File]) } else Def.task { Option(deliver.value) }
}).value,
publishSignedConfiguration := publishSignedConfigurationTask.value,
publishSignedConfiguration := {
val _ = pgpMakeIvy.value
val c = fileConverter.value
Classpaths.publishConfig(
publishMavenStyle.value,
deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
PgpKeys.signedArtifacts.value.toVector.map {
case (a, x) =>
a -> toFile(x, c)
},
checksums = (publish / checksums).value.toVector,
resolverName = Classpaths.getPublishTo(publishTo.value).name,
logging = ivyLoggingLevel.value,
overwrite = publishConfiguration.value.overwrite
)
},
publishSigned := publishSignedTask(publishSignedConfiguration, deliver).value,
publishLocalSignedConfiguration := publishLocalSignedConfigurationTask.value,
publishLocalSignedConfiguration := {
val _ = deliverLocal.value
val c = fileConverter.value
Classpaths.publishConfig(
publishMavenStyle.value,
deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
PgpKeys.signedArtifacts.value.toVector.map {
case (a, x) =>
a -> toFile(x, c)
},
(publishLocal / checksums).value.toVector,
resolverName = "local",
logging = ivyLoggingLevel.value,
overwrite = publishConfiguration.value.overwrite
)
},
publishLocalSigned := publishSignedTask(publishLocalSignedConfiguration, deliver).value
)

Expand Down
Loading

0 comments on commit 7bbc399

Please sign in to comment.