Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Oct 8, 2024
1 parent 2cd6c14 commit f099b81
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lazy val root = (project in file("."))
crossSbtVersions := List(scala3, "2.12.20"),
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.2.8"
case "2.12" => "1.5.8"
case _ => "2.0.0-M2"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala-2.12/sbtbuildinfo/BuildInfoKeyMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ final class BuildInfoKeyMacros(val c: blackbox.Context) {

def taskImpl(key: Tree): Tree = {
val A = key.tpe.typeArgs.head
q"$BuildInfoKey.sbtbuildinfoTaskValueEntry[$A]($key.taskValue)($key.key.manifest.typeArguments.head.asInstanceOf[_root_.scala.reflect.Manifest[$A]])"
q"""$BuildInfoKey.sbtbuildinfoTaskValueEntry[$A]($key.taskValue)($key.key.manifest.typeArguments.head.asInstanceOf[_root_.scala.reflect.Manifest[$A]])"""
}
}
35 changes: 35 additions & 0 deletions src/main/scala-2.12/sbtbuildinfo/PluginCompat.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
package sbtbuildinfo

import java.nio.file.{ Path => NioPath }
import sbt.*
import scala.language.higherKinds
import scala.annotation.nowarn

object PluginCompat {
type FileRef = java.io.File
type Out = java.io.File
type Entry[A1] = sbtbuildinfo.BuildInfoKey.Entry[A1]

val Setting = BuildInfoKey.Setting
val Task = BuildInfoKey.Task
val TaskValue = BuildInfoKey.TaskValue
val Constant = BuildInfoKey.Constant
val Mapped = BuildInfoKey.Mapped
val Action = BuildInfoKey.Action

trait BuildInfoKeys0
object BuildInfoKeys0 extends BuildInfoKeys0

def toClasspath(cp: Vector[NioPath]): Seq[Attributed[File]] =
cp.map((x) => Attributed.blank(x.toFile()))

implicit class RichScope(scope: Scope) {
@nowarn
def rescope(ref: Reference): Scope = scope.in(ref)
}
implicit class RichRichTaskable4[A1, A2, A3, A4](
val taskable: Scoped.RichTaskable4[A1, A2, A3, A4]) {
def flatMapN[R](f: (A1, A2, A3, A4) => Task[R]) =
taskable.flatMap(f)
}
implicit class RichRichTaskable11[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11](
val taskable: Scoped.RichTaskable11[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11]) {
def flatMapN[R](f: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) => Task[R]) =
taskable.flatMap(f)
}
}
33 changes: 16 additions & 17 deletions src/main/scala-2.12/sbtbuildinfo/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,48 @@ import sbt._
package object sbtbuildinfo {
type BuildInfoKey = BuildInfoKey.Entry[_]
object BuildInfoKey {
implicit def sbtbuildinfoSettingEntry[A](key: SettingKey[A]): Entry[A] = Setting(key)
implicit def sbtbuildinfoSettingEntry[A](key: SettingKey[A]): Entry[A] = Setting(key, "")
implicit def sbtbuildinfoTaskEntry[A](key: TaskKey[A]): Entry[A] = macro BuildInfoKeyMacros.taskImpl
implicit def sbtbuildinfoTaskValueEntry[A: Manifest](task: sbt.Task[A]): Entry[A] = TaskValue(task)
implicit def sbtbuildinfoConstantEntry[A: Manifest](tuple: (String, A)): Entry[A] = Constant(tuple)
implicit def sbtbuildinfoConstantEntry[A: Manifest](tuple: (String, A)): Entry[A] = Constant(tuple, "")

def apply[A](key: SettingKey[A]): Entry[A] = Setting(key)
def apply[A](key: SettingKey[A]): Entry[A] = Setting(key, "")
def apply[A](key: TaskKey[A]): Entry[A] = macro BuildInfoKeyMacros.taskImpl
def apply[A: Manifest](tuple: (String, A)): Entry[A] = Constant(tuple)
def apply[A: Manifest](tuple: (String, A)): Entry[A] = Constant(tuple, "")
def map[A, B: Manifest](from: Entry[A])(fun: ((String, A)) => (String, B)): Entry[B] =
BuildInfoKey.Mapped(from, fun)
def action[A: Manifest](name: String)(fun: => A): Entry[A] = Action(name, () => fun)
BuildInfoKey.Mapped(from, fun, "")
def action[A: Manifest](name: String)(fun: => A): Entry[A] = Action(name, () => fun, "")

@deprecated("use += (x: BuildInfoKey) instead", "0.10.0")
def of[A](x: BuildInfoKey.Entry[A]): BuildInfoKey.Entry[A] = x
@deprecated("use ++= Seq[BuildInfoKey](...) instead", "0.10.0")
def ofN(xs: BuildInfoKey*): Seq[BuildInfoKey] = xs

def outOfGraphUnsafe[A](key: TaskKey[A]): Entry[A] = Task(key)
def outOfGraphUnsafe[A](key: TaskKey[A]): Entry[A] = Task(key, "")

private[sbtbuildinfo] final case class Setting[A](scoped: SettingKey[A]) extends Entry[A] {
private[sbtbuildinfo] final case class Setting[A](scoped: SettingKey[A], m: String) extends Entry[A] {
def manifest = scoped.key.manifest
}
private[sbtbuildinfo] final case class Task[A](scoped: TaskKey[A]) extends Entry[A] {
private[sbtbuildinfo] final case class Task[A](scoped: TaskKey[A], m: String) extends Entry[A] {
def manifest = scoped.key.manifest.typeArguments.head.asInstanceOf[Manifest[A]]
}

private[sbtbuildinfo] final case class TaskValue[A](task: sbt.Task[A])(implicit val manifest: Manifest[A])
extends Entry[A]

private[sbtbuildinfo] final case class Constant[A](tuple: (String, A))(implicit val manifest: Manifest[A])
private[sbtbuildinfo] final case class Constant[A](tuple: (String, A), m: String)(implicit val manifest: Manifest[A])
extends Entry[A]

private[sbtbuildinfo] final case class Mapped[A1, A2](from: Entry[A1], fun: ((String, A1)) => (String, A2))
private[sbtbuildinfo] final case class Mapped[A1, A2](from: Entry[A1], fun: ((String, A1)) => (String, A2), m: String)
(implicit val manifest: Manifest[A2])
extends Entry[A2] {
type A = A1
}
extends Entry[A2]

private[sbtbuildinfo] final case class Action[A](name: String, fun: () => A)(implicit val manifest: Manifest[A])
private[sbtbuildinfo] final case class Action[A](name: String, fun: () => A, m: String)(implicit val manifest: Manifest[A])
extends Entry[A]

sealed trait Entry[A] {
private[sbtbuildinfo] def manifest: Manifest[A]
sealed trait Entry[A1] {
type A = A1
private[sbtbuildinfo] def manifest: Manifest[A1]
}
}
}
4 changes: 4 additions & 0 deletions src/main/scala-3/sbtbuildinfo/PluginCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ object PluginCompat:
end BuildInfoKeys0

object BuildInfoKeys0 extends BuildInfoKeys0

inline def RichRichTaskable4[A1, A2, A3, A4](tuple: (A1, A2, A3, A4)) = tuple
inline def RichRichTaskable11[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11](tuple: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)) =
tuple
end PluginCompat
11 changes: 6 additions & 5 deletions src/main/scala/sbtbuildinfo/BuildInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sbtbuildinfo

import sbt._, Keys._
import PluginCompat.BuildInfoKeys0.{ given, * }
import PluginCompat.*

case class BuildInfoResult(identifier: String, value: Any, typeExpr: TypeExpression)

Expand Down Expand Up @@ -33,11 +34,11 @@ object BuildInfo {
val typeExpr = TypeExpression.parse(info.manifest.toString())._1

val result = info match {
case PluginCompat.Setting(key, _) => extracted.getOpt(project / key).map((v) => task(ident(key) -> v))
case PluginCompat.Task(key, _) => Some(task(ident(key) -> extracted.runTask(project / key, state)._2))
case PluginCompat.TaskValue(task) => Some(task.map(x => ident(task) -> x))
case PluginCompat.Constant(tuple, _) => Some(task(tuple))
case PluginCompat.Action(name, fun, _ ) => Some(task(name -> fun.apply))
case PluginCompat.Setting(key, _) => extracted.getOpt(project / key).map((v) => task(ident(key) -> v))
case PluginCompat.Task(key, _) => Some(task(ident(key) -> extracted.runTask(project / key, state)._2))
case PluginCompat.TaskValue(task) => Some(task.map(x => ident(task) -> x))
case PluginCompat.Constant(tuple, _) => Some(task(tuple))
case PluginCompat.Action(name, fun, _ ) => Some(task(name -> fun.apply))
case m@PluginCompat.Mapped(from, fun, _) => entry(from).map { (t) => t.map((r) => fun((r.identifier, r.value.asInstanceOf[from.A]))) }
}
result map (_ map { case (identifier, value) => BuildInfoResult(identifier, value, typeExpr) })
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/sbtbuildinfo/BuildInfoPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sbtbuildinfo

import sbt._, Keys._
import java.io.File
import PluginCompat.*

object BuildInfoPlugin extends AutoPlugin {
type BuildInfoKey = PluginCompat.Entry[_]
Expand Down Expand Up @@ -47,7 +48,7 @@ object BuildInfoPlugin extends AutoPlugin {

def buildInfoScopedSettings(conf: Configuration): Seq[Def.Setting[_]] = inConfig(conf)(Seq(
buildInfo := (
(
RichRichTaskable11((
buildInfoRenderer,
sourceManaged,
resourceManaged,
Expand All @@ -59,7 +60,7 @@ object BuildInfoPlugin extends AutoPlugin {
thisProjectRef,
state,
streams,
) flatMapN { (
)).flatMapN { (
renderer: BuildInfoRenderer,
srcDir: File,
resDir: File,
Expand Down Expand Up @@ -89,7 +90,7 @@ object BuildInfoPlugin extends AutoPlugin {
}
).value,
buildInfoValues := (
(buildInfoKeys, buildInfoOptions, thisProjectRef, state) flatMapN ((keys, opts, pr, s) =>
RichRichTaskable4((buildInfoKeys, buildInfoOptions, thisProjectRef, state)).flatMapN ((keys, opts, pr, s) =>
BuildInfo.results(keys, opts, pr, s)
)
).value,
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-buildinfo/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy val root = (project in file("."))
name := "helloworld",
TaskKey[Classpath]("someCp") := {
val c0 = fileConverter.value
implicit val c: FileConverter = c0
implicit val c: xsbti.FileConverter = c0
PluginCompat.toClasspath(Vector(file("/tmp/f.txt").toPath()))
},
buildInfoKeys := Seq[BuildInfoKey](
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/sbtbuildinfo/BuildInfoKeySpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sbtbuildinfo

import sbt._, Keys._
import BuildInfoPlugin.autoImport.{ given, * }
import BuildInfoPlugin.autoImport.{ given, BuildInfoKey => _, * }
import sbt.internal.inc.MappedFileConverter
import xsbti.FileConverter

Expand Down

0 comments on commit f099b81

Please sign in to comment.