Skip to content

Commit

Permalink
Cross-build for sbt 2.0.0-M2
Browse files Browse the repository at this point in the history
  • Loading branch information
earldouglas committed Oct 10, 2024
1 parent b6d16d3 commit e5dce8a
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 22 deletions.
25 changes: 20 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ name := "sbt-frege"
sbtPlugin := true
enablePlugins(SbtPlugin)
scalaVersion := "2.12.20"
crossScalaVersions += "3.3.4"
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" => (pluginCrossBuild / sbtVersion).value
case _ => "2.0.0-M2"
}
}
scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.12" =>
Seq(
"-Ywarn-unused-import",
"-Xlint",
"-Ypartial-unification",
"-Yrangepos"
)
case _ =>
Seq.empty // ("-Wunused:all") this is blocked by sbt/sbt#7726
}
}
scalacOptions ++= Seq( "-deprecation"
, "-encoding", "utf8"
, "-feature"
Expand All @@ -15,11 +35,6 @@ scalacOptions ++= Seq( "-deprecation"
, "-language:implicitConversions"
, "-unchecked"
, "-Xfatal-warnings"
, "-Xlint"
, "-Ypartial-unification"
, "-Yrangepos"
, "-Ywarn-unused"
, "-Ywarn-unused-import"
)

// publish to Sonatype, https://www.scala-sbt.org/release/docs/Using-Sonatype.html
Expand Down
13 changes: 13 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ pkgs ? import <nixpkgs> {} }:
let
jdk = pkgs.jdk8;
in
pkgs.mkShell {
nativeBuildInputs = [
(pkgs.sbt.override { jre = jdk; })
];
shellHook = ''
export JAVA_HOME=${jdk}
PATH="${jdk}/bin:$PATH"
'';
}
39 changes: 39 additions & 0 deletions src/main/scala-2.12/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.earldouglas.sbt.frege

import sbt.Def.Initialize
import sbt.Keys._
import sbt._

object Compat {

val Compile_fullClasspath: Initialize[Task[Seq[File]]] =
Def.task {
(Compile / fullClasspath).value
.map(_.data)
}

def dependencyClasspath(scope: Configuration): Initialize[Task[Seq[File]]] =
Def.task {
(scope / sbt.Keys.dependencyClasspath).value
.map(_.data)
}

def managedClasspath(scope: Configuration): Initialize[Task[Seq[File]]] =
Def.task {
(scope / sbt.Keys.managedClasspath).value
.map(_.data)
}

def fregeCompiler(scope: Configuration) = scope / SbtFregec.autoImport.fregeCompiler
def fregeOptions(scope: Configuration) = scope / SbtFregec.autoImport.fregeOptions
def fregeSource(scope: Configuration) = scope / SbtFregec.autoImport.fregeSource
def fregeTarget(scope: Configuration) = scope / SbtFregec.autoImport.fregeTarget
def sourceDirectory(scope: Configuration) = scope / sbt.Keys.sourceDirectory
def sourceGenerators(scope: Configuration) = scope / sbt.Keys.sourceGenerators

def managedJars(config: Configuration): Initialize[Task[Seq[File]]] =
Def.task {
Classpaths.managedJars(config, classpathTypes.value, update.value)
.map(_.data)
}
}
43 changes: 43 additions & 0 deletions src/main/scala-3/Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.earldouglas.sbt.frege

import sbt.Def.Initialize
import sbt.Keys._
import sbt._
import sbt.given

object Compat:

val Compile_fullClasspath: Initialize[Task[Seq[File]]] =
Def.task:
(Compile / fullClasspath).value
.map(_.data)
.map(fileConverter.value.toPath(_))
.map(_.toFile())

def dependencyClasspath(scope: Configuration): Initialize[Task[Seq[File]]] =
Def.task:
(scope / sbt.Keys.dependencyClasspath).value
.map(_.data)
.map(fileConverter.value.toPath(_))
.map(_.toFile())

def managedClasspath(scope: Configuration): Initialize[Task[Seq[File]]] =
Def.task:
(scope / sbt.Keys.managedClasspath).value
.map(_.data)
.map(fileConverter.value.toPath(_))
.map(_.toFile())

def fregeCompiler(scope: Configuration) = scope / SbtFregec.autoImport.fregeCompiler
def fregeOptions(scope: Configuration) = scope / SbtFregec.autoImport.fregeOptions
def fregeSource(scope: Configuration) = scope / SbtFregec.autoImport.fregeSource
def fregeTarget(scope: Configuration) = scope / SbtFregec.autoImport.fregeTarget
def sourceDirectory(scope: Configuration) = scope / sbt.Keys.sourceDirectory
def sourceGenerators(scope: Configuration) = scope / sbt.Keys.sourceGenerators

def managedJars(config: Configuration): Initialize[Task[Seq[File]]] =
Def.task:
Classpaths.managedJars(config, classpathTypes.value, update.value, fileConverter.value)
.map(_.data)
.map(fileConverter.value.toPath(_))
.map(_.toFile())
37 changes: 20 additions & 17 deletions src/main/scala/SbtFrege.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.earldouglas.sbt.frege

import sbt._
import sbt.Keys._

Expand All @@ -17,11 +19,11 @@ object SbtFregec extends AutoPlugin {
override def trigger = allRequirements
override def requires = plugins.JvmPlugin

def fregec(cp: Seq[sbt.Attributed[File]], fregeSource: File, fregeTarget: File,
def fregec(cp: Seq[File], fregeSource: File, fregeTarget: File,
fregeCompiler: String, fregeOptions: Seq[String])
(fregeSrcs: Set[File]): Set[File] = {

val cps = cp.map(_.data).mkString(String.valueOf(File.pathSeparatorChar))
val cps = cp.mkString(String.valueOf(File.pathSeparatorChar))

fregeTarget.mkdirs()

Expand All @@ -39,26 +41,26 @@ object SbtFregec extends AutoPlugin {
if (result != 0) {
throw new RuntimeException("Frege compilation error")
} else {
(PathFinder(fregeTarget) ** "*.java").get.toSet
(PathFinder(fregeTarget) ** "*.java").get().toSet
}
}

def scopedSettings(scope: Configuration, dirName: String) = Seq(
scope / fregeSource := (scope / sourceDirectory).value / "frege",
scope / fregeTarget := baseDirectory.value / "target" / dirName,
scope / sourceGenerators += Def.task {
Compat.fregeSource(scope) := (Compat.sourceDirectory(scope)).value / "frege",
Compat.fregeTarget(scope) := baseDirectory.value / "target" / dirName,
Compat.sourceGenerators(scope) += Def.task {
val cacheDir = streams.value.cacheDirectory / dirName
val cached = FileFunction.cached(
cacheDir, FilesInfo.lastModified, FilesInfo.exists) {
fregec((scope / managedClasspath).value ++ (scope / dependencyClasspath).value,
(scope / fregeSource).value,
(scope / fregeTarget).value,
(scope / fregeCompiler).value,
(scope / fregeOptions).value)
fregec((Compat.managedClasspath(scope)).value ++ (Compat.dependencyClasspath(scope)).value,
(Compat.fregeSource(scope)).value,
(Compat.fregeTarget(scope)).value,
(Compat.fregeCompiler(scope)).value,
(Compat.fregeOptions(scope)).value)
}
cached(((scope / fregeSource).value ** "*.fr").get.toSet).toSeq
cached(((Compat.fregeSource(scope)).value ** "*.fr").get().toSet).toSeq
}.taskValue,
watchSources ++= ((scope / fregeSource).value ** "*").get.map(x=>WatchSource(x))
watchSources ++= ((Compat.fregeSource(scope)).value ** "*").get().map(x=>WatchSource(x))
)

override def projectSettings =
Expand Down Expand Up @@ -100,10 +102,11 @@ object SbtFregeRepl extends AutoPlugin {
libraryDependencies += "org.frege-lang" % "frege-repl-core" % fregeReplVersion.value % FregeReplConfig,
fregeReplMainClass := "frege.repl.FregeRepl",
fregeRepl := {
val cp: String = Path.makeString((
Classpaths.managedJars(FregeReplConfig, classpathTypes.value, update.value) ++
(Compile / fullClasspath).value
).map(_.data))
val cp: String =
Path.makeString(
Compat.managedJars(FregeReplConfig).value ++
(Compat.Compile_fullClasspath).value
)
val forkOptions = ForkOptions().withConnectInput(true).withOutputStrategy(Some(sbt.StdoutOutput))
val mainClass: String = fregeReplMainClass.value
new Fork("java", None).fork(forkOptions, Seq("-cp", cp, mainClass)).exitValue()
Expand Down

0 comments on commit e5dce8a

Please sign in to comment.