Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
distribution: 'temurin'
java-version: 17

- run: ./mill -i "__.test" && ./mill -i generateTutorial + generateReference && git diff --exit-code
- run: ./mill -ij1 "__.test" && ./mill -i generateTutorial + generateReference && git diff --exit-code

check-scalafix:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
distribution: 'temurin'
java-version: 11
- name: Publish to Maven Central
run: ./mill --import "ivy:com.lihaoyi::mill-contrib-sonatypecentral:" mill.contrib.sonatypecentral.SonatypeCentralPublishModule/publishAll --publishArtifacts __.publishArtifacts
run: ./mill -i mill.scalalib.SonatypeCentralPublishModule/

- name: Create GitHub Release
id: create_gh_release
Expand Down
1 change: 0 additions & 1 deletion .mill-version

This file was deleted.

88 changes: 45 additions & 43 deletions build.mill
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//| mill-version: 1.0.0
//| repositories:
//| - https://oss.sonatype.org/content/repositories/snapshots
//| mvnDeps:
//| - com.github.lolgab::mill-mima::0.2.0
//| - com.goyeau::mill-scalafix::0.6.0
package build
import $packages._
import $file.docs.generateDocs
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $ivy.`com.github.lolgab::mill-mima::0.1.1`
import $ivy.`com.goyeau::mill-scalafix::0.5.1`
import de.tobiasroeser.mill.vcs.version.VcsVersion
import build.docs
import mill.util.VcsVersion
import com.goyeau.mill.scalafix.ScalafixModule
import mill._, scalalib._, publish._

Expand All @@ -30,7 +32,7 @@ trait CommonBase extends ScalaModule with PublishModule with ScalafixModule { co
)
)

def scalacOptions = T {
def scalacOptions = Task {
Seq("-Wunused:privates,locals,explicits,implicits,params") ++
Option.when(scalaVersion().startsWith("2."))("-Xsource:3")
}
Expand All @@ -42,19 +44,19 @@ trait CommonBase extends ScalaModule with PublishModule with ScalafixModule { co
trait CommonTest extends ScalaTests with ScalafixModule {
def semanticDbVersion: T[String] = common.semanticDbVersion
def scalacOptions = common.scalacOptions
def ivyDeps = Agg(
ivy"com.github.vertical-blank:sql-formatter:2.0.4",
ivy"com.lihaoyi::mainargs:0.4.0",
ivy"com.lihaoyi::os-lib:0.9.1",
ivy"com.lihaoyi::upickle:3.1.3",
ivy"com.lihaoyi::utest:0.8.2",
ivy"com.h2database:h2:2.2.224",
ivy"org.xerial:sqlite-jdbc:3.43.0.0",
ivy"org.testcontainers:postgresql:1.19.1",
ivy"org.postgresql:postgresql:42.6.0",
ivy"org.testcontainers:mysql:1.19.1",
ivy"mysql:mysql-connector-java:8.0.33",
ivy"com.zaxxer:HikariCP:5.1.0"
def mvnDeps = Seq(
mvn"com.github.vertical-blank:sql-formatter:2.0.4",
mvn"com.lihaoyi::mainargs:0.4.0",
mvn"com.lihaoyi::os-lib:0.9.1",
mvn"com.lihaoyi::upickle:4.2.1",
mvn"com.lihaoyi::utest:0.8.2",
mvn"com.h2database:h2:2.2.224",
mvn"org.xerial:sqlite-jdbc:3.43.0.0",
mvn"org.testcontainers:postgresql:1.19.1",
mvn"org.postgresql:postgresql:42.6.0",
mvn"org.testcontainers:mysql:1.19.1",
mvn"mysql:mysql-connector-java:8.0.33",
mvn"com.zaxxer:HikariCP:5.1.0"
)

def recordedTestsFile: String
Expand All @@ -65,7 +67,7 @@ trait CommonBase extends ScalaModule with PublishModule with ScalafixModule { co
def forkArgs = Seq("-Duser.timezone=Asia/Singapore")

def forkEnv = Map(
"MILL_WORKSPACE_ROOT" -> T.workspace.toString(),
"MILL_WORKSPACE_ROOT" -> mill.api.BuildCtx.workspaceRoot.toString(),
"SCALASQL_RECORDED_TESTS_NAME" -> recordedTestsFile,
"SCALASQL_RECORDED_SUITE_DESCRIPTIONS_NAME" -> recordedSuiteDescriptionsFile
)
Expand All @@ -75,10 +77,10 @@ trait Common extends CommonBase with CrossScalaModule

object `scalasql-namedtuples` extends CommonBase {
def scalaVersion: T[String] = scala3NamedTuples
def millSourcePath: os.Path = scalasql(scala3).millSourcePath / "namedtuples"
def moduleDir: os.Path = scalasql(scala3).moduleDir / "namedtuples"
def moduleDeps: Seq[PublishModule] = Seq(scalasql(scala3))

// override def scalacOptions: Target[Seq[String]] = T {
// override def scalacOptions: Target[Seq[String]] = Task {
// super.scalacOptions() :+ "-Xprint:inlining"
// }

Expand All @@ -93,8 +95,8 @@ object `scalasql-namedtuples` extends CommonBase {
object scalasql extends Cross[ScalaSql](scalaVersions)
trait ScalaSql extends Common { common =>
def moduleDeps = Seq(query, operations)
def ivyDeps = Agg.empty[Dep] ++ Option.when(scalaVersion().startsWith("2."))(
ivy"org.scala-lang:scala-reflect:${scalaVersion()}"
def mvnDeps = Seq.empty[Dep] ++ Option.when(scalaVersion().startsWith("2."))(
mvn"org.scala-lang:scala-reflect:${scalaVersion()}"
)

override def consoleScalacOptions: T[Seq[String]] = Seq("-Xprint:typer")
Expand All @@ -108,15 +110,15 @@ trait ScalaSql extends Common { common =>
code.map(_.split("\n").map(" " + _).mkString("\n")).mkString("\n")

object core extends Common with CrossValue {
def ivyDeps = Agg(
ivy"com.lihaoyi::geny:1.0.0",
ivy"com.lihaoyi::sourcecode:0.3.1",
ivy"com.lihaoyi::pprint:0.8.1"
def mvnDeps = Seq(
mvn"com.lihaoyi::geny:1.0.0",
mvn"com.lihaoyi::sourcecode:0.3.1",
mvn"com.lihaoyi::pprint:0.8.1"
) ++ Option.when(scalaVersion().startsWith("2."))(
ivy"org.scala-lang:scala-reflect:${scalaVersion()}"
mvn"org.scala-lang:scala-reflect:${scalaVersion()}"
)

def generatedSources = T {
def generatedSources = Task {
def commaSep0(i: Int, f: Int => String) = Range.inclusive(1, i).map(f).mkString(", ")

val queryableRowDefs = for (i <- Range.inclusive(2, 22)) yield {
Expand All @@ -135,15 +137,15 @@ trait ScalaSql extends Common { common =>
}

os.write(
T.dest / "Generated.scala",
Task.dest / "Generated.scala",
s"""package scalasql.core.generated
|import scalasql.core.Queryable
|trait QueryableRow{
|${indent(queryableRowDefs)}
|}
|""".stripMargin
)
Seq(PathRef(T.dest / "Generated.scala"))
Seq(PathRef(Task.dest / "Generated.scala"))
}

}
Expand All @@ -155,7 +157,7 @@ trait ScalaSql extends Common { common =>
object query extends Common with CrossValue {
def moduleDeps = Seq(core)

def generatedSources = T {
def generatedSources = Task {
def commaSep0(i: Int, f: Int => String) = Range.inclusive(1, i).map(f).mkString(", ")

def defs(isImpl: Boolean) = {
Expand Down Expand Up @@ -215,7 +217,7 @@ trait ScalaSql extends Common { common =>
}

os.write(
T.dest / "Generated.scala",
Task.dest / "Generated.scala",
s"""package scalasql.generated
|import scalasql.core.{Queryable, Expr}
|import scalasql.query.Column
Expand All @@ -240,21 +242,21 @@ trait ScalaSql extends Common { common =>
|}
|""".stripMargin
)
Seq(PathRef(T.dest / "Generated.scala"))
Seq(PathRef(Task.dest / "Generated.scala"))
}
}
}

val generatedCodeHeader = "[//]: # (GENERATED SOURCES, DO NOT EDIT DIRECTLY)"
def generateTutorial() = T.command {
generateDocs.generateTutorial(
T.workspace / "scalasql" / "test" / "src" / "WorldSqlTests.scala",
T.workspace / "docs" / "tutorial.md"
def generateTutorial() = Task.Command {
docs.generateTutorial(
mill.api.BuildCtx.workspaceRoot / "scalasql" / "test" / "src" / "WorldSqlTests.scala",
mill.api.BuildCtx.workspaceRoot / "docs" / "tutorial.md"
)
}
def generateReference() = T.command {
generateDocs.generateReference(
T.workspace / "docs" / "reference.md",
def generateReference() = Task.Command {
docs.generateReference(
mill.api.BuildCtx.workspaceRoot / "docs" / "reference.md",
(sources, config) =>
mill.scalalib.scalafmt.ScalafmtWorkerModule
.worker()
Expand Down
2 changes: 1 addition & 1 deletion docs/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To facilitate efficient testing, you can choose from several commands based on y
### Full Test Suite with Documentation Generation
* Re-generating docs:
```bash
./mill -i "__.test" + generateTutorial + generateReference
./mill -ij1 "__.test" + generateTutorial + generateReference
```
* Note that ScalaSql's reference docs are extracted from the test suite, and thus we need
to make sure to run the test suite before re-generating them.
Expand Down
13 changes: 7 additions & 6 deletions docs/generateDocs.mill
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package build.docs
import mill.api.BuildCtx
import collection.mutable
val generatedCodeHeader = "[//]: # (GENERATED SOURCES, DO NOT EDIT DIRECTLY)"
def generateTutorial(sourcePath: os.Path, destPath: os.Path) = {
Expand Down Expand Up @@ -29,7 +30,7 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = {
case (s"// +INCLUDE SNIPPET [$key] $rest", _) =>
// reuse the iterator each time,
// basically assume snippets are requested in order.
val sublines: scala.collection.BufferedIterator[String] = snippets.getOrElseUpdate(rest, os.read.lines(mill.api.WorkspaceRoot.workspaceRoot / os.SubPath(rest)).iterator.buffered)
val sublines: scala.collection.BufferedIterator[String] = snippets.getOrElseUpdate(rest, os.read.lines(BuildCtx.workspaceRoot / os.SubPath(rest)).iterator.buffered)
val start = s"// +SNIPPET [$key]"
val end = s"// -SNIPPET [$key]"
while (sublines.hasNext && !sublines.head.contains(start)) {
Expand All @@ -45,7 +46,7 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = {
outputLines.append("")
}
case (s"// +INCLUDE $rest", _) =>
os.read.lines(mill.api.WorkspaceRoot.workspaceRoot / os.SubPath(rest)).foreach(outputLines.append)
os.read.lines(BuildCtx.workspaceRoot / os.SubPath(rest)).foreach(outputLines.append)

case (s"//$rest", false) => outputLines.append(rest.stripPrefix(" "))

Expand All @@ -70,16 +71,16 @@ def generateTutorial(sourcePath: os.Path, destPath: os.Path) = {
def generateReference(dest: os.Path, scalafmtCallback: (Seq[os.Path], os.Path) => Unit) = {
def dropExprPrefix(s: String) = s.split('.').drop(2).mkString(".")
def dropNTExprPrefix(s: String) = s.split('.').drop(3).mkString(".")
val records = upickle.default.read[Seq[Record]](os.read.stream(mill.api.WorkspaceRoot.workspaceRoot / "out" / "recordedTests.json"))
val ntRecords = upickle.default.read[Seq[Record]](os.read.stream(mill.api.WorkspaceRoot.workspaceRoot / "out" / "recordedTestsNT.json"))
val suiteDescriptions = upickle.default.read[Map[String, String]](os.read.stream(mill.api.WorkspaceRoot.workspaceRoot / "out" / "recordedSuiteDescriptions.json"))
val records = upickle.default.read[Seq[Record]](os.read.stream(BuildCtx.workspaceRoot / "out" / "recordedTests.json"))
val ntRecords = upickle.default.read[Seq[Record]](os.read.stream(BuildCtx.workspaceRoot / "out" / "recordedTestsNT.json"))
val suiteDescriptions = upickle.default.read[Map[String, String]](os.read.stream(BuildCtx.workspaceRoot / "out" / "recordedSuiteDescriptions.json"))
.map{case (k, v) => (dropExprPrefix(k), v)}

val rawScalaStrs = (records ++ ntRecords)
.flatMap(r => Seq(r.queryCodeString) ++ r.resultCodeString)
val formattedScalaStrs = {
val tmps = rawScalaStrs.map(os.temp(_, suffix = ".scala"))
scalafmtCallback(tmps, mill.api.WorkspaceRoot.workspaceRoot / ".scalafmt.conf")
scalafmtCallback(tmps, BuildCtx.workspaceRoot / ".scalafmt.conf")

tmps.map(os.read(_).trim)
}
Expand Down
Loading
Loading