Skip to content

Commit cf0e8bd

Browse files
authored
Merge pull request #165 from tgodzik/another-update
Another update
2 parents 8f65ccc + 456fa24 commit cf0e8bd

File tree

16 files changed

+154
-44
lines changed

16 files changed

+154
-44
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
- uses: coursier/[email protected]
3939
with:
4040
jvm: "temurin:17"
41+
apps: sbt
4142
- name: Tests
4243
run: |
4344
.github/setup-test-projects.sh &&\
@@ -64,6 +65,7 @@ jobs:
6465
- uses: coursier/[email protected]
6566
with:
6667
jvm: "temurin:17"
68+
apps: sbt
6769
- name: Compile and test main projects
6870
# Only running the tests in 2.12 for now. Many test fixtures need
6971
# to be updated for 2.13.

backend/src/main/scala/bloop/Compiler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.util.concurrent.Executor
88

99
import scala.collection.mutable
1010
import scala.concurrent.Promise
11-
import scala.util.control.NonFatal
11+
import scala.util.Try
1212

1313
import bloop.io.AbsolutePath
1414
import bloop.io.ParallelOps

backend/src/main/scala/bloop/ScalaInstance.scala

+20-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ final class ScalaInstance private (
2323
val organization: String,
2424
val name: String,
2525
override val version: String,
26-
override val allJars: Array[File]
26+
override val allJars: Array[File],
27+
val bridgeJarsOpt: Option[Seq[File]] = None
2728
) extends xsbti.compile.ScalaInstance {
2829

2930
override lazy val loaderCompilerOnly: ClassLoader =
@@ -153,6 +154,15 @@ object ScalaInstance {
153154

154155
private[ScalaInstance] final val ScalacCompilerName = "scala-compiler"
155156

157+
def apply(
158+
scalaOrg: String,
159+
scalaName: String,
160+
scalaVersion: String,
161+
allJars: Seq[AbsolutePath],
162+
logger: Logger
163+
): ScalaInstance =
164+
apply(scalaOrg, scalaName, scalaVersion, allJars, logger, None)
165+
156166
/**
157167
* Reuses all jars to create an Scala instance if and only if all of them exist.
158168
*
@@ -170,7 +180,8 @@ object ScalaInstance {
170180
scalaName: String,
171181
scalaVersion: String,
172182
allJars: Seq[AbsolutePath],
173-
logger: Logger
183+
logger: Logger,
184+
bridgeJarsOpt: Option[Seq[AbsolutePath]]
174185
): ScalaInstance = {
175186
val jarsKey = allJars.map(_.underlying).sortBy(_.toString).toList
176187
if (allJars.nonEmpty) {
@@ -179,7 +190,13 @@ object ScalaInstance {
179190
DebugFilter.Compilation
180191
)
181192
jarsKey.foreach(p => logger.debug(s" => $p")(DebugFilter.Compilation))
182-
new ScalaInstance(scalaOrg, scalaName, scalaVersion, allJars.map(_.toFile).toArray)
193+
new ScalaInstance(
194+
scalaOrg,
195+
scalaName,
196+
scalaVersion,
197+
allJars.map(_.toFile).toArray,
198+
bridgeJarsOpt.map(_.map(_.toFile))
199+
)
183200
}
184201

185202
val nonExistingJars = allJars.filter(j => !Files.exists(j.underlying))

backend/src/main/scala/sbt/internal/inc/BloopComponentCompiler.scala

+25-18
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ object BloopComponentCompiler {
116116
*/
117117
private def compiledBridge(bridgeSources: ModuleID, scalaInstance: ScalaInstance): File = {
118118
val raw = new RawCompiler(scalaInstance, ClasspathOptionsUtil.auto, logger)
119-
val zinc = new BloopComponentCompiler(raw, manager, bridgeSources, logger)
119+
val bridgeJarsOpt = scalaInstance match {
120+
case b: _root_.bloop.ScalaInstance => b.bridgeJarsOpt
121+
case _ => None
122+
}
123+
val zinc = new BloopComponentCompiler(raw, manager, bridgeSources, bridgeJarsOpt, logger)
120124
logger.debug(s"Getting $bridgeSources for Scala ${scalaInstance.version}")(
121125
DebugFilter.Compilation
122126
)
@@ -229,6 +233,7 @@ private[inc] class BloopComponentCompiler(
229233
compiler: RawCompiler,
230234
manager: BloopComponentManager,
231235
bridgeSources: ModuleID,
236+
bridgeJarsOpt: Option[Seq[File]],
232237
logger: BloopLogger
233238
) {
234239
implicit val debugFilter: DebugFilter.Compilation.type = DebugFilter.Compilation
@@ -257,23 +262,25 @@ private[inc] class BloopComponentCompiler(
257262
IO.withTemporaryDirectory { _ =>
258263
val shouldResolveSources =
259264
bridgeSources.explicitArtifacts.exists(_.`type` == "src")
260-
val allArtifacts = BloopDependencyResolution.resolveWithErrors(
261-
List(
262-
BloopDependencyResolution
263-
.Artifact(bridgeSources.organization, bridgeSources.name, bridgeSources.revision)
264-
),
265-
logger,
266-
resolveSources = shouldResolveSources,
267-
List(
268-
coursierapi.MavenRepository.of(
269-
"https://scala-ci.typesafe.com/artifactory/scala-integration/"
265+
val allArtifacts = bridgeJarsOpt.map(_.map(_.toPath)).getOrElse {
266+
BloopDependencyResolution.resolveWithErrors(
267+
List(
268+
BloopDependencyResolution
269+
.Artifact(bridgeSources.organization, bridgeSources.name, bridgeSources.revision)
270+
),
271+
logger,
272+
resolveSources = shouldResolveSources,
273+
List(
274+
coursierapi.MavenRepository.of(
275+
"https://scala-ci.typesafe.com/artifactory/scala-integration/"
276+
)
270277
)
271-
)
272-
) match {
273-
case Right(paths) => paths.map(_.underlying).toVector
274-
case Left(t) =>
275-
val msg = s"Couldn't retrieve module $bridgeSources"
276-
throw new InvalidComponent(msg, t)
278+
) match {
279+
case Right(paths) => paths.map(_.underlying).toVector
280+
case Left(t) =>
281+
val msg = s"Couldn't retrieve module $bridgeSources"
282+
throw new InvalidComponent(msg, t)
283+
}
277284
}
278285

279286
if (!shouldResolveSources) {
@@ -286,7 +293,7 @@ private[inc] class BloopComponentCompiler(
286293
if (!HydraSupport.isEnabled(compiler.scalaInstance)) (bridgeSources.name, sources)
287294
else {
288295
val hydraBridgeModule = HydraSupport.getModuleForBridgeSources(compiler.scalaInstance)
289-
mergeBloopAndHydraBridges(sources, hydraBridgeModule) match {
296+
mergeBloopAndHydraBridges(sources.toVector, hydraBridgeModule) match {
290297
case Right(mergedHydraBridgeSourceJar) =>
291298
(hydraBridgeModule.name, mergedHydraBridgeSourceJar)
292299
case Left(error) =>

build.sc

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Dependencies {
3232

3333
def asm = ivy"org.ow2.asm:asm:$asmVersion"
3434
def asmUtil = ivy"org.ow2.asm:asm-util:$asmVersion"
35-
def bloopConfig = ivy"ch.epfl.scala::bloop-config:1.5.5"
35+
def bloopConfig = ivy"ch.epfl.scala::bloop-config:2.0.0"
3636
def brave = ivy"io.zipkin.brave:brave:5.18.1"
3737
def bsp4j = ivy"ch.epfl.scala:bsp4j:2.1.1"
3838
def bsp4s = ivy"ch.epfl.scala::bsp4s:2.1.1"
@@ -61,7 +61,7 @@ object Dependencies {
6161
def munit = ivy"org.scalameta::munit:0.7.29"
6262
def nailgun = ivy"io.github.alexarchambault.bleep:nailgun-server:1.0.7"
6363
def osLib = ivy"com.lihaoyi::os-lib:0.9.0"
64-
def pprint = ivy"com.lihaoyi::pprint:0.8.1"
64+
def pprint = ivy"com.lihaoyi::pprint:0.9.0"
6565
def sbtTestAgent = ivy"org.scala-sbt:test-agent:1.9.9"
6666
def sbtTestInterface = ivy"org.scala-sbt:test-interface:1.0"
6767
def scalaDebugAdapter = ivy"ch.epfl.scala::scala-debug-adapter:4.0.3"
@@ -72,12 +72,12 @@ object Dependencies {
7272
def scalaJsSbtTestAdapter1 = ivy"org.scala-js::scalajs-sbt-test-adapter:$scalaJs1Version"
7373
def scalaJsLogging1 = ivy"org.scala-js::scalajs-logging:1.1.1"
7474
def scalaNativeTools04 = ivy"org.scala-native::tools:0.4.17"
75-
def scalaNativeTools05 = ivy"org.scala-native::tools:0.5.0-RC2"
75+
def scalaNativeTools05 = ivy"org.scala-native::tools:0.5.1"
7676
def scalazCore = ivy"org.scalaz::scalaz-core:7.3.8"
7777
def snailgun = ivy"io.github.alexarchambault.scala-cli.snailgun::snailgun-core:0.4.1-sc2"
78-
def sourcecode = ivy"com.lihaoyi::sourcecode:0.3.1"
78+
def sourcecode = ivy"com.lihaoyi::sourcecode:0.4.1"
7979
def svm = ivy"org.graalvm.nativeimage:svm:$graalvmVersion"
80-
def utest = ivy"com.lihaoyi::utest:0.8.2"
80+
def utest = ivy"com.lihaoyi::utest:0.8.3"
8181
def xxHashLibrary = ivy"net.jpountz.lz4:lz4:1.3.0"
8282
def zinc = ivy"org.scala-sbt::zinc:1.9.5"
8383
def zipkinSender = ivy"io.zipkin.reporter2:zipkin-sender-urlconnection:2.17.2"

frontend/src/main/scala/bloop/bsp/BloopBspServices.scala

+35-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ final class BloopBspServices(
130130
.requestAsync(endpoints.BuildTarget.sources)(p => schedule(sources(p)))
131131
.requestAsync(endpoints.BuildTarget.inverseSources)(p => schedule(inverseSources(p)))
132132
.requestAsync(endpoints.BuildTarget.resources)(p => schedule(resources(p)))
133+
.requestAsync(endpoints.BuildTarget.outputPaths)(p => schedule(outputPaths(p)))
133134
.requestAsync(endpoints.BuildTarget.scalacOptions)(p => schedule(scalacOptions(p)))
134135
.requestAsync(endpoints.BuildTarget.javacOptions)(p => schedule(javacOptions(p)))
135136
.requestAsync(endpoints.BuildTarget.compile)(p => schedule(compile(p)))
@@ -311,7 +312,7 @@ final class BloopBspServices(
311312
dependencySourcesProvider = Some(true),
312313
dependencyModulesProvider = Some(true),
313314
resourcesProvider = Some(true),
314-
outputPathsProvider = None,
315+
outputPathsProvider = Some(true),
315316
buildTargetChangedProvider = Some(false),
316317
jvmTestEnvironmentProvider = Some(true),
317318
jvmRunEnvironmentProvider = Some(true),
@@ -1204,6 +1205,39 @@ final class BloopBspServices(
12041205
}
12051206
}
12061207

1208+
def outputPaths(
1209+
request: bsp.OutputPathsParams
1210+
): BspEndpointResponse[bsp.OutputPathsResult] = {
1211+
def outputPaths(
1212+
projects: Seq[ProjectMapping],
1213+
state: State
1214+
): BspResult[bsp.OutputPathsResult] = {
1215+
1216+
val response = bsp.OutputPathsResult(
1217+
projects.iterator.map {
1218+
case (target, project) =>
1219+
val outputPathItems =
1220+
List(
1221+
bsp.OutputPathItem(bsp.Uri(project.out.toBspUri), bsp.OutputPathItemKind.Directory)
1222+
)
1223+
bsp.OutputPathsItem(target, outputPathItems)
1224+
}.toList
1225+
)
1226+
1227+
Task.now((state, Right(response)))
1228+
}
1229+
1230+
ifInitialized(None) { (state: State, logger: BspServerLogger) =>
1231+
mapToProjects(request.targets, state) match {
1232+
case Left(error) =>
1233+
// Log the mapping error to the user via a log event + an error status code
1234+
logger.error(error)
1235+
Task.now((state, Right(bsp.OutputPathsResult(Nil))))
1236+
case Right(mappings) => outputPaths(mappings, state)
1237+
}
1238+
}
1239+
}
1240+
12071241
def dependencyModules(
12081242
request: bsp.DependencyModulesParams
12091243
): BspEndpointResponse[bsp.DependencyModulesResult] = {

frontend/src/main/scala/bloop/bsp/ProjectUris.scala

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ import bloop.engine.State
1212
import bloop.io.AbsolutePath
1313

1414
object ProjectUris {
15+
private val queryPrefix = "id="
1516
def getProjectDagFromUri(projectUri: String, state: State): Either[String, Option[Project]] = {
1617
if (projectUri.isEmpty) Left("URI cannot be empty.")
1718
else {
18-
val query = Try(new URI(projectUri).getRawQuery().split("&").map(_.split("="))).toEither
19-
query match {
20-
case Left(_) =>
19+
Try(new URI(projectUri).getQuery()).toEither match {
20+
case Right(query) if query.startsWith(queryPrefix) =>
21+
val projectName = query.stripPrefix(queryPrefix)
22+
Right(state.build.getProjectFor(projectName))
23+
case _ =>
2124
Left(s"URI '${projectUri}' has invalid format. Example: ${ProjectUris.Example}")
22-
case Right(parsed) =>
23-
parsed.headOption match {
24-
case Some(Array("id", projectName)) => Right(state.build.getProjectFor(projectName))
25-
case _ =>
26-
Left(s"URI '${projectUri}' has invalid format. Example: ${ProjectUris.Example}")
27-
}
2825
}
2926
}
3027
}
@@ -39,7 +36,7 @@ object ProjectUris {
3936
existingUri.getHost,
4037
existingUri.getPort,
4138
existingUri.getPath,
42-
s"id=${id}",
39+
s"$queryPrefix${id}",
4340
existingUri.getFragment
4441
)
4542
}

frontend/src/main/scala/bloop/data/ClientInfo.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import scala.collection.mutable
1111
import scala.util.control.NonFatal
1212
import scala.util.matching.Regex
1313

14+
import bloop.ClientClassesObserver
1415
import bloop.io.AbsolutePath
1516
import bloop.io.Filenames
1617
import bloop.io.Paths
1718
import bloop.util.UUIDUtil
18-
import bloop.ClientClassesObserver
1919

2020
sealed trait ClientInfo {
2121

frontend/src/main/scala/bloop/data/Project.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ object Project {
290290
else {
291291
val scalaJars = scala.jars.map(AbsolutePath.apply)
292292
Some(
293-
ScalaInstance(scala.organization, scala.name, scala.version, scalaJars, logger)
293+
ScalaInstance(
294+
scala.organization,
295+
scala.name,
296+
scala.version,
297+
scalaJars,
298+
logger,
299+
scala.bridgeJars.map(_.map(AbsolutePath(_)))
300+
)
294301
)
295302
}
296303
}

frontend/src/main/scala/bloop/engine/tasks/compilation/CompileBundle.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bloop.engine.tasks.compilation
22

33
import scala.concurrent.Promise
44

5+
import bloop.ClientClassesObserver
56
import bloop.CompileOutPaths
67
import bloop.Compiler
78
import bloop.ScalaInstance
@@ -23,7 +24,6 @@ import bloop.tracing.BraveTracer
2324

2425
import monix.reactive.Observable
2526
import sbt.internal.inc.PlainVirtualFileConverter
26-
import bloop.ClientClassesObserver
2727

2828
sealed trait CompileBundle
2929

frontend/src/main/scala/bloop/engine/tasks/toolchains/ScalaNativeToolchain.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bloop.engine.tasks.toolchains
33
import java.lang.reflect.InvocationTargetException
44
import java.nio.file.Path
55

6+
import scala.concurrent.Future
67
import scala.util.Try
78

89
import bloop.DependencyResolution
@@ -14,7 +15,6 @@ import bloop.internal.build.BuildInfo
1415
import bloop.io.AbsolutePath
1516
import bloop.logging.Logger
1617
import bloop.task.Task
17-
import scala.concurrent.Future
1818

1919
final class ScalaNativeToolchain private (classLoader: ClassLoader) {
2020

frontend/src/test/resources/cross-test-build-scala-native-0.5/project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
2-
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.0-RC2")
2+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.1")
33

44
val pluginVersion = sys.props.getOrElse(
55
"bloopVersion",

frontend/src/test/scala/bloop/bsp/BspBaseSuite.scala

+13
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ abstract class BspBaseSuite extends BaseSuite with BspClientTest {
349349
TestUtil.await(FiniteDuration(5, "s"))(resourcesTask)
350350
}
351351

352+
def requestOutputPaths(project: TestProject): bsp.OutputPathsResult = {
353+
val outputPathsTask = {
354+
client0
355+
.request(endpoints.BuildTarget.outputPaths, bsp.OutputPathsParams(List(project.bspId)))
356+
.map {
357+
case RpcFailure(_, error) => fail(s"Received error ${error}")
358+
case RpcSuccess(resources, _) => resources
359+
}
360+
}
361+
362+
TestUtil.await(FiniteDuration(5, "s"))(outputPathsTask)
363+
}
364+
352365
def requestDependencyModules(project: TestProject): bsp.DependencyModulesResult = {
353366
val dependencyModulesTask = {
354367
client0

frontend/src/test/scala/bloop/bsp/BspProtocolSpec.scala

+31
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,37 @@ class BspProtocolSpec(
516516
}
517517
}
518518

519+
test("outputPaths request works") {
520+
TestUtil.withinWorkspace { workspace =>
521+
val logger = new RecordingLogger(ansiCodesSupported = false)
522+
loadBspBuildFromResources("cross-test-build-scalajs-0.6", workspace, logger) { build =>
523+
val mainProject = build.projectFor("test-project")
524+
val testProject = build.projectFor("test-project-test")
525+
val mainJsProject = build.projectFor("test-projectJS")
526+
val testJsProject = build.projectFor("test-projectJS-test")
527+
val rootMain = build.projectFor("cross-test-build-scalajs-0-6")
528+
val rootTest = build.projectFor("cross-test-build-scalajs-0-6-test")
529+
530+
def checkOutputPaths(project: TestProject): Unit = {
531+
val outputPathsResult = build.state.requestOutputPaths(project)
532+
assert(outputPathsResult.items.size == 1)
533+
val outputPathsItem = outputPathsResult.items.head
534+
assert(outputPathsItem.target == project.bspId)
535+
val outputPaths = outputPathsItem.outputPaths.map(_.uri.toPath)
536+
val expectedOutputPaths = List(project.config.out.toAbsolutePath())
537+
assert(outputPaths == expectedOutputPaths)
538+
}
539+
540+
checkOutputPaths(mainProject)
541+
checkOutputPaths(testProject)
542+
checkOutputPaths(mainJsProject)
543+
checkOutputPaths(testJsProject)
544+
checkOutputPaths(rootMain)
545+
checkOutputPaths(rootTest)
546+
}
547+
}
548+
}
549+
519550
test("dependency modules request works") {
520551
TestUtil.withinWorkspace { workspace =>
521552
val logger = new RecordingLogger(ansiCodesSupported = false)

0 commit comments

Comments
 (0)