Skip to content

Commit

Permalink
Bloop: Fix ordering of classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
tindzk committed May 1, 2020
1 parent 8098ab7 commit 636b83e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 27 deletions.
5 changes: 2 additions & 3 deletions src/main/scala/seed/generation/Bloop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ object Bloop {
dependencies = dependencies,
classpath = scalaCompiler.fold(List[Path]())(
sc =>
(sc.libraries.map(_.libraryJar) ++
sc.classPath.map(_.toAbsolutePath)).sorted
sc.libraries.map(_.libraryJar) ++ sc.classPath.map(_.toAbsolutePath)
),
out = classesDir.toAbsolutePath,
classesDir = classesDir.toAbsolutePath,
Expand All @@ -65,7 +64,7 @@ object Bloop {
name = "scala-compiler",
version = scalaCompiler.scalaVersion,
options = scalaOptions,
jars = scalaCompiler.compilerJars.sorted,
jars = scalaCompiler.compilerJars,
analysis = Some(classesDir.resolve("analysis.bin").toAbsolutePath),
setup = Some(
Config.CompileSetup(
Expand Down
11 changes: 5 additions & 6 deletions src/test/scala/seed/artefact/ArtefactResolutionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import seed.Log
import seed.artefact.ArtefactResolution.{Regular, Test}
import seed.config.BuildConfig.ModuleConfig
import seed.config.{BuildConfig, BuildConfigSpec}
import seed.generation.util.ProjectGeneration
import seed.generation.util.{BloopUtil, ProjectGeneration}
import seed.model.Build.{JavaDep, Module, Resolvers, ScalaDep, VersionTag}
import seed.model.Platform.{JVM, JavaScript, Native}
import seed.generation.util.BuildUtil.tempPath
Expand Down Expand Up @@ -347,7 +347,6 @@ object ArtefactResolutionSpec extends SimpleTestSuite {
}

import seed.generation.BloopIntegrationSpec.packageConfig
import seed.generation.BloopIntegrationSpec.readBloopJson

test("Resolve library versions requested by modules") {
val projectPath = Paths.get("test", "resolve-dep-versions")
Expand All @@ -367,10 +366,10 @@ object ArtefactResolutionSpec extends SimpleTestSuite {

val bloopPath = buildPath.resolve(".bloop")

val a = readBloopJson(bloopPath.resolve("a.json"))
val b = readBloopJson(bloopPath.resolve("b.json"))
val example1 = readBloopJson(bloopPath.resolve("example1.json"))
val example2 = readBloopJson(bloopPath.resolve("example2.json"))
val a = BloopUtil.readJson(bloopPath.resolve("a.json"))
val b = BloopUtil.readJson(bloopPath.resolve("b.json"))
val example1 = BloopUtil.readJson(bloopPath.resolve("example1.json"))
val example2 = BloopUtil.readJson(bloopPath.resolve("example2.json"))

def artefact(path: Path): String = path.getFileName.toString

Expand Down
26 changes: 10 additions & 16 deletions src/test/scala/seed/generation/BloopIntegrationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ object BloopIntegrationSpec extends TestSuite[Unit] {
override def setup(): Unit = ()
override def tearDown(env: Unit): Unit = ()

def readBloopJson(path: Path): bloop.config.Config.File = {
val content = FileUtils.readFileToString(path.toFile, "UTF-8")

import io.circe.parser._
decode[bloop.config.Config.File](content)(
ConfigEncoderDecoders.allDecoder
).right.get
}

def compileAndRun(projectPath: Path) = {
def compile =
TestProcessHelper.runBloop(projectPath)("compile", "example").map { x =>
Expand Down Expand Up @@ -80,7 +71,7 @@ object BloopIntegrationSpec extends TestSuite[Unit] {
val bloopBuildPath = buildPath.resolve("build").resolve("bloop")

val bloopPath = buildPath.resolve(".bloop")
val root = readBloopJson(bloopPath.resolve("root.json"))
val root = util.BloopUtil.readJson(bloopPath.resolve("root.json"))
val paths = root.project.classpath.filter(_.startsWith(buildPath))
assertEquals(
paths,
Expand Down Expand Up @@ -187,10 +178,13 @@ object BloopIntegrationSpec extends TestSuite[Unit] {

val bloopPath = buildPath.resolve(".bloop")

val macrosJvm = readBloopJson(bloopPath.resolve("macros-jvm.json"))
val macrosJs = readBloopJson(bloopPath.resolve("macros-js.json"))
val exampleJvm = readBloopJson(bloopPath.resolve("example-jvm.json"))
val exampleJs = readBloopJson(bloopPath.resolve("example-js.json"))
val macrosJvm =
util.BloopUtil.readJson(bloopPath.resolve("macros-jvm.json"))
val macrosJs = util.BloopUtil.readJson(bloopPath.resolve("macros-js.json"))
val exampleJvm =
util.BloopUtil.readJson(bloopPath.resolve("example-jvm.json"))
val exampleJs =
util.BloopUtil.readJson(bloopPath.resolve("example-js.json"))

def getFileName(path: String): String = path.drop(path.lastIndexOf('/') + 1)

Expand Down Expand Up @@ -337,7 +331,7 @@ object BloopIntegrationSpec extends TestSuite[Unit] {
.resolve("custom-command-target")
.resolve(".bloop")
.resolve("demo.json")
val result = readBloopJson(path)
val result = util.BloopUtil.readJson(path)

// Do not include the `utils` classpath since the module is only a custom
// build target and does not have a JVM target.
Expand Down Expand Up @@ -412,7 +406,7 @@ object BloopIntegrationSpec extends TestSuite[Unit] {

val bloopPath = buildPath.resolve(".bloop")

val root = readBloopJson(bloopPath.resolve("example.json"))
val root = util.BloopUtil.readJson(bloopPath.resolve("example.json"))
val paths = root.project.classpath.filter(_.startsWith(buildPath))

assertEquals(
Expand Down
22 changes: 21 additions & 1 deletion src/test/scala/seed/generation/GenerateSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package seed.generation

import java.nio.file.{Files, Paths}
import java.nio.file.{Files, Path, Paths}

import minitest.SimpleTestSuite
import seed.Cli.Command
Expand Down Expand Up @@ -49,5 +49,25 @@ object GenerateSpec extends SimpleTestSuite {
Command.Bloop(packageConfig),
Log.urgent
)

val bloopPath = buildPath.resolve(".bloop")

val root = util.BloopUtil.readJson(bloopPath.resolve("example-test.json"))
val paths = root.project.classpath

def artefact(path: Path): String = path.getFileName.toString
assertEquals(
paths.map(artefact),
List(
"scalajs-junit-test-runtime_2.13-1.0.1.jar",
"scalajs-library_2.13-1.0.1.jar",
"scalajs-test-interface_2.13-1.0.1.jar",
"scala-library-2.13.2.jar",
"scala-reflect-2.13.2.jar",
"munit_sjs1_2.13-0.7.3.jar",
"scalajs-test-bridge_2.13-1.0.1.jar",
"example"
)
)
}
}
17 changes: 17 additions & 0 deletions src/test/scala/seed/generation/util/BloopUtil.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seed.generation.util

import java.nio.file.Path

import bloop.config.ConfigEncoderDecoders
import org.apache.commons.io.FileUtils

object BloopUtil {
def readJson(path: Path): bloop.config.Config.File = {
val content = FileUtils.readFileToString(path.toFile, "UTF-8")

import io.circe.parser._
decode[bloop.config.Config.File](content)(
ConfigEncoderDecoders.allDecoder
).right.get
}
}
2 changes: 1 addition & 1 deletion test/test-scalajs-10/build.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ sources = ["src"]

[module.example.test.js]
sources = ["test"]
scalaDeps = [["org.scalameta", "munit", "0.7.3"]]
scalaDeps = [["org.scalameta", "munit", "0.7.4"]]
moduleKind = "commonjs"

0 comments on commit 636b83e

Please sign in to comment.