Skip to content

Commit

Permalink
Make cross platform (#1)
Browse files Browse the repository at this point in the history
Update `./bazel` script (in `/examples`) to download correct version for current platform.
  • Loading branch information
aishfenton authored Jan 3, 2023
1 parent 6cace6f commit 3713554
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 37 deletions.
10 changes: 5 additions & 5 deletions examples/simple-no-errors/.bsp/bazel-bsp.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

{
"name": "BazelBsp",
"version": "0.0.1",
"bspVersion": "2.0.0",
"version": "0.0.13",
"bspVersion": "2.0.0-M2",
"languages": [
"scala"
],
"argv": [
"../../target/universal/stage/bin/bazel-bsp",
"--verbose"
"bazel-bsp"
]
}
}
Binary file modified examples/simple-no-errors/bazel
Binary file not shown.
10 changes: 5 additions & 5 deletions examples/simple-with-errors/.bsp/bazel-bsp.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

{
"name": "BazelBsp",
"version": "0.0.1",
"bspVersion": "2.0.0",
"version": "0.0.13",
"bspVersion": "2.0.0-M2",
"languages": [
"scala"
],
"argv": [
"../../target/universal/stage/bin/bazel-bsp",
"--verbose"
"bazel-bsp"
]
}
}
Binary file modified examples/simple-with-errors/bazel
Binary file not shown.
48 changes: 30 additions & 18 deletions src/main/scala/afenton/bazel/bsp/BazelBspApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ import fs2.Pipe
import fs2.Stream
import fs2.io.file.Files
import fs2.io.file.Flags
import fs2.io.file.Path
import fs2.text
import io.bazel.rules_scala.diagnostics.diagnostics.FileDiagnostics
import io.circe.Json
import io.circe.syntax.*

import java.net.ServerSocket
import java.nio.file.Path
import java.nio.file.Paths
import cats.data.Nested
import java.nio.file.StandardOpenOption
import scala.concurrent.duration.FiniteDuration
import java.util.concurrent.TimeUnit

object BazelBspApp
extends CommandIOApp(
Expand Down Expand Up @@ -72,7 +75,11 @@ object BazelBspApp

def main: Opts[IO[ExitCode]] =
(verboseOpt, verifySetupOpt, setupOpt).mapN { (verbose, verify, setup) =>
if setup then writeBspConfig(BuildMetaData.Version).as(ExitCode.Success)
if setup then
for
cwd <- FilesIO.cwd
_ <- writeBspConfig(cwd)
yield ExitCode.Success
else if verify then
for
result <- Verifier.validateSetup
Expand All @@ -92,27 +99,32 @@ object BazelBspApp
}
}

private def writeBspConfig(version: String): IO[Unit] =
val toPath = fs2.io.file.Path(".bsp/bazel-bsp.json")
def writeBspConfig(workspaceRoot: Path): IO[Unit] =
val toPath = workspaceRoot.resolve(".bsp")

Stream
.emits(bspConfig(version).getBytes())
.through(
fs2.io.file.Files[IO].writeAll(toPath)
)
.compile
.drain
.flatMap(_ =>
Console[IO].println(
s"Write setup config to ${toPath.toNioPath.toAbsolutePath()}"
for
_ <- Files[IO].createDirectories(toPath)
_ <- Stream
.emits(bspConfig.getBytes())
.through(
Files[IO].writeAll(
toPath.resolve("bazel-bsp.json"),
List(
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
)
)
)
)
.compile
.drain
_ <- Console[IO].println(s"Wrote setup config to ${toPath}")
yield ()

private def bspConfig(version: String): String = """
private lazy val bspConfig: String = s"""
{
"name": "BazelBsp",
"version": "${version}",
"bspVersion": "2.1.0-M1",
"version": "${BuildMetaData.Version}",
"bspVersion": "${BuildMetaData.BspVersion}",
"languages": [
"scala"
],
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/afenton/bazel/bsp/BuildMetaData.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package afenton.bazel.bsp

object BuildMetaData {
val Version = "0.0.2-alpha"
val Version = "0.0.13"
val BspVersion = "2.0.0-M2"
}
3 changes: 3 additions & 0 deletions src/main/scala/afenton/bazel/bsp/FilesIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import java.nio.file.Path
import java.nio.file.PathMatcher
import scala.jdk.CollectionConverters.*
import scala.util.Try
import java.nio.file.Paths

object FilesIO:

private val fileSystem: FileSystem = FileSystems.getDefault

def cwd: IO[Path] = IO.blocking(Paths.get("").toAbsolutePath.normalize)

def readLines(file: Path): IO[Either[Throwable, List[String]]] =
IO.blocking {
Try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/afenton/bazel/bsp/runner/BazelRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ object BazelRunner:
)
.withArgs(command.asString :: expr.toList)
.runUntilExit
.timeout(FiniteDuration(30, TimeUnit.SECONDS))
.timeout(FiniteDuration(30, TimeUnit.MINUTES))
_ <- logger.info(s"Exited with ${er.exitCode}")
yield er

Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/afenton/bazel/bsp/End2EndTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import scala.reflect.Typeable

class End2EndTest extends munit.CatsEffectSuite with BspHelpers:

override val munitTimeout = 1.minute
override val munitTimeout = 2.minute

val projectRoot = Paths.get("").toAbsolutePath

Expand All @@ -45,7 +45,7 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers:
.test("should successfully initialize") { (root, bazel) =>

val (responses, notifications) = Lsp.start
.runFor(root, 2.seconds)
.runFor(root, 30.seconds)
.unsafeRunSync()

assertEquals(notifications, Nil)
Expand All @@ -54,8 +54,8 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers:
responses.select[InitializeBuildResult],
InitializeBuildResult(
"Bazel",
"0.1",
"2.0.0-M2",
BuildMetaData.Version,
BuildMetaData.BspVersion,
BuildServerCapabilities(
compileProvider = Some(CompileProvider(List("scala"))),
inverseSourcesProvider = Some(true),
Expand All @@ -71,7 +71,7 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers:

val (_, notifications) = Lsp.start
.compile("//...")
.runFor(root, 10.seconds)
.runFor(root, 30.seconds)
.unsafeRunSync()

assertEquals(notifications.length, 2)
Expand All @@ -96,7 +96,7 @@ class End2EndTest extends munit.CatsEffectSuite with BspHelpers:

val (_, notifications) = Lsp.start
.compile("//...")
.runFor(root, 10.seconds)
.runFor(root, 30.seconds)
.unsafeRunSync()

assertEquals(notifications.length, 6)
Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/afenton/bazel/bsp/runner/SubProcessTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class SubProcessTest extends munit.CatsEffectSuite:
.runUntilExit
.unsafeRunSync()

assertEquals(er2.exitCode, 2)
// Note: Specific exit code is different on Mac vs. Linux
assert(er2.exitCode > 0)
assert(
er2.stderrLines.unsafeRunSync().head.endsWith("No such file or directory")
)
Expand Down

0 comments on commit 3713554

Please sign in to comment.