Skip to content

Commit ff7957a

Browse files
authored
Merge pull request #26 from olafurpg/fix-javacopts
More fixes
2 parents 74cde98 + 0d3539a commit ff7957a

File tree

12 files changed

+117
-13
lines changed

12 files changed

+117
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v2
1212
- uses: olafurpg/setup-scala@v13
13-
- run: sbt +test
13+
- run: sbt scripted +test
1414
check:
1515
runs-on: ubuntu-latest
1616
steps:

build.sbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,11 @@ buildInfoKeys := List[BuildInfoKey](
7575
)
7676
buildInfoPackage := "com.sourcegraph.sbtsourcegraph"
7777
enablePlugins(BuildInfoPlugin)
78+
enablePlugins(ScriptedPlugin)
79+
scriptedBufferLog := false
80+
scriptedLaunchOpts ++= Seq(
81+
"-Xmx2048M",
82+
s"-Dplugin.version=${version.value}"
83+
)
7884

7985
def isCI = "true" == System.getenv("CI")

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
44
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29")
55
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.8-94-1cfdf0bd")
66

7+
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
8+
79
Compile / unmanagedSourceDirectories +=
810
(ThisBuild / baseDirectory).value.getParentFile /
911
"src" / "main" / "scala"

src/main/scala/com/sourcegraph/sbtsourcegraph/SourcegraphEnable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object SourcegraphEnable {
4343
javacOptions.in(p) += s"-Xplugin:semanticdb " +
4444
s"-build-tool:sbt " +
4545
s"-sourceroot:${baseDirectory.in(ThisBuild).value} " +
46-
s"-targetroot:${classDirectory.in(Compile).value.toPath().resolveSibling("semanticdb-classes")}"
46+
s"-targetroot:${classDirectory.in(p, Compile).value.toPath().resolveSibling("semanticdb-classes")}"
4747
),
4848
overriddenScalaVersion.map(v => scalaVersion.in(p) := v),
4949
Option(SemanticdbPlugin.semanticdbEnabled.in(p) := true),

src/main/scala/com/sourcegraph/sbtsourcegraph/SourcegraphPlugin.scala

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ object SourcegraphPlugin extends AutoPlugin {
2222
taskKey[File](
2323
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
2424
)
25+
val sourcegraphTargetRoots: TaskKey[List[String]] =
26+
taskKey[List[String]](
27+
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
28+
)
29+
val sourcegraphTargetRootsFile: TaskKey[File] =
30+
taskKey[File](
31+
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
32+
)
2533
val sourcegraphLsifJavaVersion: SettingKey[String] =
2634
settingKey[String]("The version of the `lsif-java` command-line tool.")
2735
val sourcegraphSemanticdbDirectories: TaskKey[List[File]] =
@@ -75,20 +83,36 @@ object SourcegraphPlugin extends AutoPlugin {
7583
scala.util.Properties
7684
.propOrElse("lsif-java-version", Versions.semanticdbJavacVersion())
7785
},
78-
sourcegraphLsif := {
79-
val out = target.in(Sourcegraph).value / "dump.lsif"
80-
out.getParentFile.mkdirs()
86+
sourcegraphTargetRoots := {
8187
val directories =
8288
sourcegraphSemanticdbDirectories.all(anyProjectFilter).value
8389
val directoryArguments = directories.iterator.flatten
8490
.map(_.getAbsolutePath())
8591
.toList
92+
.distinct
8693
if (directoryArguments.isEmpty) {
8794
throw new TaskException(
8895
"Can't upload LSIF index to Sourcegraph because there are no SemanticDB directories. " +
8996
"To fix this problem, run the `sourcegraphEnable` command before `sourcegraphLsif` like this: sbt sourcegraphEnable sourcegraphLsif"
9097
)
9198
}
99+
directoryArguments
100+
},
101+
sourcegraphTargetRootsFile := {
102+
val roots = sourcegraphTargetRoots.value
103+
val out = target.in(Sourcegraph).value / "targetroots.txt"
104+
Files.createDirectories(out.toPath().getParent())
105+
Files.write(
106+
out.toPath(),
107+
roots.asJava,
108+
StandardOpenOption.CREATE,
109+
StandardOpenOption.TRUNCATE_EXISTING
110+
)
111+
out
112+
},
113+
sourcegraphLsif := {
114+
val out = target.in(Sourcegraph).value / "dump.lsif"
115+
out.getParentFile.mkdirs()
92116
runProcess(
93117
sourcegraphCoursierBinary.value ::
94118
"launch" ::
@@ -97,7 +121,7 @@ object SourcegraphPlugin extends AutoPlugin {
97121
"--" ::
98122
"index-semanticdb" ::
99123
s"--output=$out" ::
100-
directoryArguments
124+
sourcegraphTargetRoots.value
101125
)
102126
out
103127
},
@@ -169,7 +193,7 @@ object SourcegraphPlugin extends AutoPlugin {
169193
val javacTargetroot = sourcegraphJavacTargetroot.value
170194
val jars = fullClasspath.result.value match {
171195
case Value(value) => value.map(_.data)
172-
case _ => Nil
196+
case other => Nil
173197
}
174198
val results = List(
175199
javacTargetroot,
@@ -178,12 +202,14 @@ object SourcegraphPlugin extends AutoPlugin {
178202
.map(f => f / "META-INF" / "semanticdb")
179203
.filter(_.isDirectory())
180204
results.headOption.foreach { dir =>
181-
Files.write(
182-
dir.toPath.resolve("javacopts.txt"),
183-
List("-classpath", jars.mkString(File.pathSeparator)).asJava,
184-
StandardOpenOption.CREATE,
185-
StandardOpenOption.TRUNCATE_EXISTING
186-
)
205+
if (jars.nonEmpty) {
206+
Files.write(
207+
dir.toPath.resolve("javacopts.txt"),
208+
List("-classpath", jars.mkString(File.pathSeparator)).asJava,
209+
StandardOpenOption.CREATE,
210+
StandardOpenOption.TRUNCATE_EXISTING
211+
)
212+
}
187213
}
188214
results
189215
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package aj;
2+
3+
import geny.Generator;
4+
import org.junit.Assert;
5+
6+
public class A {
7+
public geny.Generator x = a.A.generator();
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package a
2+
3+
import org.junit.Assert
4+
5+
object A extends App {
6+
def generator = geny.Generator(1)
7+
Assert.assertEquals(generator, "")
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package bj;
2+
3+
public class B {
4+
public geny.Generator generator = a.A.generator();
5+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import scala.collection.JavaConverters._
2+
import java.nio.file.Paths
3+
import java.nio.file.Files
4+
5+
inThisBuild(
6+
List(
7+
scalaVersion := "2.12.14",
8+
organization := "com.example"
9+
)
10+
)
11+
12+
lazy val a = project
13+
.settings(
14+
libraryDependencies += "com.lihaoyi" %% "geny" % "0.6.10",
15+
libraryDependencies += "junit" % "junit" % "4.13.2"
16+
)
17+
18+
lazy val b = project
19+
.dependsOn(a)
20+
21+
commands += Command.command("checkLsif") { s =>
22+
val dumpPath =
23+
(ThisBuild / baseDirectory).value / "target" / "sbt-sourcegraph" / "dump.lsif"
24+
val dump = Files.readAllLines(dumpPath.toPath).asScala
25+
val packageInformation =
26+
""".*"name":"(.*)","manager":"jvm-dependencies"}""".r
27+
val jvmDependencies = dump
28+
.collect { case packageInformation(name) =>
29+
name
30+
}
31+
.distinct
32+
.sorted
33+
if (
34+
jvmDependencies != List(
35+
"jdk",
36+
"maven/com.lihaoyi/geny_2.12",
37+
"maven/junit/junit",
38+
"maven/org.scala-lang/scala-library"
39+
)
40+
) {
41+
sys.error(jvmDependencies.toString)
42+
}
43+
s
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.5.2

0 commit comments

Comments
 (0)