Skip to content

Commit d870dd9

Browse files
committed
Add sbt build and new snapshot testing infrastructure
1 parent fbd0166 commit d870dd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1652
-9
lines changed

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"

.github/workflows/ci.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: olafurpg/setup-scala@v10
13+
- run: sbt test
14+
check:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: olafurpg/setup-scala@v10
19+
- run: sbt checkAll

.github/workflows/release.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Release
2+
on:
3+
push:
4+
branches: [main]
5+
tags: ["*"]
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: olafurpg/setup-scala@v10
12+
- uses: olafurpg/setup-gpg@v3
13+
- run: git fetch --unshallow
14+
- name: Publish ${{ github.ref }}
15+
run: sbt ci-release
16+
env:
17+
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
18+
PGP_SECRET: ${{ secrets.PGP_SECRET }}
19+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
20+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

.github/workflows/sourcegraph.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Sourcegraph
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- olafurpg/lets-go
7+
pull_request:
8+
jobs:
9+
lsif:
10+
runs-on: ubuntu-latest
11+
name: "Upload LSIF"
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: olafurpg/setup-scala@v10
15+
- uses: actions/setup-go@v2
16+
with:
17+
go-version: "1.15.6"
18+
- run: go get github.com/sourcegraph/lsif-semanticdb/cmd/lsif-semanticdb
19+
- name: sbt sourcegraphUpload
20+
run: |
21+
mkdir -p bin
22+
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o bin/src
23+
chmod +x bin/src
24+
export PATH="$PATH:$PWD/bin"
25+
sbt sourcegraphUpload
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+52-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,53 @@
1+
*.class
2+
*.log
3+
4+
# sbt specific
5+
.cache
6+
.history
7+
.lib/
8+
dist/*
9+
target/
10+
lib_managed/
11+
src_managed/
12+
project/boot/
13+
project/plugins/project/
14+
.bloop
15+
16+
_site/
17+
18+
# Scala-IDE specific
19+
.scala_dependencies
20+
.worksheet
21+
122
.idea
2-
target
3-
**/spoon.classpath*.tmp
4-
.classpath
5-
*.project
6-
.settings
7-
*.iml
8-
.gradle
9-
examples/**/dump.lsif
10-
build
23+
24+
# ENSIME specific
25+
.ensime_cache/
26+
.ensime
27+
28+
.metals/
29+
metals.sbt
30+
metals/project/
31+
32+
.vscode/
33+
34+
local.*
35+
36+
.DS_Store
37+
38+
node_modules
39+
40+
lib/core/metadata.js
41+
lib/core/MetadataBlog.js
42+
43+
website/translated_docs
44+
website/build/
45+
website/yarn.lock
46+
website/node_modules
47+
website/i18n/*
48+
49+
project/metals.sbt
50+
out/
51+
*.hnir
52+
test-report.json
53+
dump.lsif

.jvmopts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-Xss2m
2+
-Xms1G
3+
-Xmx4G
4+
-Dfile.encoding=UTF-8
5+
-Dsbt.server.autostart=false

.scalafix.conf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
rules = [
2+
OrganizeImports,
3+
]
4+
5+
ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false
6+
7+
OrganizeImports.groupedImports = Explode
8+
OrganizeImports.expandRelative = true
9+
OrganizeImports.removeUnused = true
10+
OrganizeImports.groups = [
11+
"re:javax?\\."
12+
"scala."
13+
"scala.meta."
14+
"*"
15+
]

.scalafmt.conf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version = "2.7.5"
2+
assumeStandardLibraryStripMargin = true
3+
docstrings.style = Asterisk
4+
docstrings.wrap = "yes"
5+
project.git = true
6+
align.preset = none
7+
align.stripMargin = true
8+
newlines.source=unfold

build.sbt

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
def scala213 = "2.13.4"
2+
def scalametaVersion = "4.4.8"
3+
4+
inThisBuild(
5+
List(
6+
scalaVersion := scala213,
7+
crossScalaVersions := List(scala213),
8+
organization := "com.sourcegraph",
9+
scalafixDependencies +=
10+
"com.github.liancheng" %% "organize-imports" % "0.5.0",
11+
scalafixCaching := true,
12+
scalacOptions ++= List("-Wunused:imports"),
13+
semanticdbEnabled := true,
14+
semanticdbVersion := scalametaVersion
15+
)
16+
)
17+
18+
name := "root"
19+
bloopGenerate.in(Compile) := None
20+
bloopGenerate.in(Test) := None
21+
skip.in(publish) := true
22+
23+
commands +=
24+
Command.command("fixAll") { s =>
25+
"scalafixAll" :: "scalafmtAll" :: "scalafmtSbt" :: "javafmtAll" :: s
26+
}
27+
28+
commands +=
29+
Command.command("checkAll") { s =>
30+
"scalafmtCheckAll" :: "scalafmtSbtCheck" :: "scalafixAll --check" ::
31+
"javafmtCheckAll" :: s
32+
}
33+
34+
lazy val testSettings = List(
35+
skip.in(publish) := true,
36+
autoScalaLibrary := true,
37+
testFrameworks := List(new TestFramework("munit.Framework")),
38+
libraryDependencies ++=
39+
List(
40+
"org.scalameta" %% "munit" % "0.7.10",
41+
"org.scalameta" %% "scalameta" % scalametaVersion,
42+
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.0",
43+
"io.get-coursier" %% "coursier" % "2.0.8",
44+
"com.lihaoyi" %% "pprint" % "0.6.1"
45+
)
46+
)
47+
48+
lazy val plugin = project
49+
.in(file("semanticdb-javac"))
50+
.settings(
51+
moduleName := "semanticdb-javac",
52+
autoScalaLibrary := false,
53+
incOptions ~= { old =>
54+
old.withEnabled(false)
55+
},
56+
crossPaths := false,
57+
PB.targets.in(Compile) :=
58+
Seq(PB.gens.java -> (Compile / sourceManaged).value)
59+
)
60+
61+
lazy val minimized = project
62+
.in(file("tests/minimized"))
63+
.settings(
64+
autoScalaLibrary := false,
65+
skip.in(publish) := true,
66+
javacOptions.in(Compile) ++=
67+
List[String](
68+
s"-Arandomtimestamp=${System.nanoTime()}",
69+
List(
70+
s"-Xplugin:semanticdb",
71+
s"-text:on",
72+
s"-verbose",
73+
s"-sourceroot:${baseDirectory.in(ThisBuild).value}",
74+
s"-targetroot:${target.in(Compile).value / "semanticdb"}"
75+
).mkString(" ")
76+
)
77+
)
78+
.dependsOn(plugin)
79+
80+
lazy val minimizedScala = project
81+
.in(file("tests/minimized-scala"))
82+
.settings(
83+
skip.in(publish) := true,
84+
semanticdbOptions ++= List("-P:semanticdb:text:on")
85+
)
86+
.dependsOn(minimized)
87+
88+
lazy val unit = project
89+
.in(file("tests/unit"))
90+
.settings(
91+
testSettings,
92+
buildInfoKeys :=
93+
Seq[BuildInfoKey](
94+
version,
95+
scalaVersion,
96+
"sourceroot" -> baseDirectory.in(ThisBuild).value,
97+
"minimizedJavaSourceDirectory" ->
98+
sourceDirectory.in(minimized, Compile).value / "java",
99+
"minimizedJavaTargetroot" ->
100+
target.in(minimized, Compile).value / "semanticdb",
101+
"minimizedScalaSourceDirectory" ->
102+
sourceDirectory.in(minimizedScala, Compile).value / "scala",
103+
"minimizedScalaTargetroot" ->
104+
semanticdbTargetRoot.in(minimizedScala, Compile).value
105+
),
106+
buildInfoPackage := "tests"
107+
)
108+
.dependsOn(plugin)
109+
.enablePlugins(BuildInfoPlugin)
110+
111+
lazy val snapshots = project
112+
.in(file("tests/snapshots"))
113+
.settings(
114+
testSettings,
115+
buildInfoKeys :=
116+
Seq[BuildInfoKey](
117+
"snapshotDirectory" -> sourceDirectory.in(Compile).value / "generated"
118+
),
119+
buildInfoPackage := "tests.snapshots"
120+
)
121+
.dependsOn(minimizedScala, unit)
122+
.enablePlugins(BuildInfoPlugin)
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sbt.{Compile, Def, File, _}
2+
import sbt.Keys._
3+
import sbt.plugins.JvmPlugin
4+
5+
import scala.util.Properties
6+
7+
/**
8+
* An sbt plugin that automatically adds the Java compiler to the boot classpath
9+
* when necessary.
10+
*/
11+
object JavacBootClasspathPlugin extends AutoPlugin {
12+
override def trigger = allRequirements
13+
override def requires = JvmPlugin
14+
15+
lazy val configSettings = List(
16+
javacOptions ++= List("-target", "1.8", "-source", "1.8"),
17+
javacOptions.in(doc) --= List("-target", "1.8"),
18+
javaHome := Some(javaHomeDirectory),
19+
javacOptions ++= bootclasspathSettings,
20+
javaOptions ++= bootclasspathSettings
21+
)
22+
23+
override lazy val projectSettings: Seq[Def.Setting[_]] =
24+
List(Compile, Test).flatMap(c => inConfig(c)(configSettings)) ++
25+
List(fork := true)
26+
27+
/**
28+
* Returns the local path to tools.jar, which contains the Java compiler
29+
* implementation.
30+
*/
31+
private def toolsJar: File = javaHomeDirectory / "lib" / "tools.jar"
32+
private def javaHomeDirectory: File = {
33+
val home = file(System.getProperty("java.home"))
34+
if (Properties.isJavaAtLeast("8"))
35+
home.getParentFile
36+
else
37+
home
38+
}
39+
40+
private def bootclasspathSettings: List[String] = {
41+
// The tools.jar file includes the bytecode for the Java compiler in the com.sun.source package.
42+
// The Java compiler is available by default in Java 9+, so we only need to add tools.jar to the
43+
// bootclasspath for Java 8.
44+
if (
45+
!Properties.isJavaAtLeast("9") && Properties.isJavaAtLeast("8") &&
46+
toolsJar.isFile
47+
) {
48+
List(s"-Xbootclasspath/p:$toolsJar")
49+
} else {
50+
List()
51+
}
52+
53+
}
54+
}

project/build.properties

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.4.7

project/plugins.sbt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.5")
2+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
3+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
4+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.25")
5+
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0")
6+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.6-21-464e4ec4")
7+
addSbtPlugin("com.sourcegraph" % "sbt-sourcegraph" % "0.1.8")
8+
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.6.0")
9+
10+
// sbt-jdi-tools appears to fix an error related to this message:
11+
// [error] (plugin / Compile / compileIncremental) java.lang.NoClassDefFoundError: com/sun/tools/javac/code/Symbol
12+
addSbtPlugin("org.scala-debugger" % "sbt-jdi-tools" % "1.1.1")
13+
14+
libraryDependencies ++=
15+
List("com.thesamet.scalapb" %% "compilerplugin" % "0.10.10")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package minimized
2+
3+
// format: off
4+
object MinimizedScalaMain {
5+
def main(args: Array[String]): Unit = {
6+
TypeVariables.app(new TypeVariables.CT());
7+
System.out.println(
8+
Methods.app(42, "42") +
9+
Enums.app() +
10+
Docstrings.app() +
11+
InnerClasses.app() +
12+
ForComprehensions.app(42) +
13+
AnonymousClasses.app(42) +
14+
Primitives.app() +
15+
new ParameterizedTypes[Integer, String]()
16+
.app(42, "42") +
17+
RawTypes.x.toString +
18+
ClassOf.app() +
19+
SubClasses.app() +
20+
Fields.app()
21+
)
22+
}
23+
}

0 commit comments

Comments
 (0)