get builder tests passing on windows
diff --git a/scripts/win.bat b/scripts/win.bat
new file mode 100644
index 0000000..6dcefd2
--- /dev/null
+++ b/scripts/win.bat
@@ -0,0 +1,18 @@
+:: script for developing with virtualbox. Rsyncs files using Robocopy and then runs any builds/tests.
+SET REAL_SRC="z:\github.com\bazelbuild\rules_kotlin"
+
+pushd %~dp0
+ SET TARGET_DIR=%CD%\..
+popd
+
+robocopy %REAL_SRC% %TARGET_DIR% /mir /xo /xd bazel-* /NFL /NDL
+
+ bazel ^
+ --output_base "c:\tmp\bazel" ^
+ --output_user_root "c:\tmp\bazel_rules_kotlin" ^
+ build //src/main/kotlin:builder
+
+ bazel ^
+ --output_base "c:\tmp\bazel" ^
+ --output_user_root "c:\tmp\bazel_rules_kotlin" ^
+ test -- //src/test/kotlin/io/bazel/kotlin/builder:builder_tests
diff --git a/src/main/kotlin/bootstrap.bzl b/src/main/kotlin/bootstrap.bzl
index 5901cda..2668fc0 100644
--- a/src/main/kotlin/bootstrap.bzl
+++ b/src/main/kotlin/bootstrap.bzl
@@ -47,32 +47,47 @@
visibility = ["//visibility:private"],
)
command = """
-KOTLIN_HOME=external/com_github_jetbrains_kotlin
-
function join_by { local IFS="$$1"; shift; echo "$$*"; }
-
+case "$$(uname -s)" in
+ CYGWIN*|MINGW32*|MSYS*)
+ SEP=";"
+ ;;
+ *)
+ SEP=":"
+ ;;
+esac
NAME=%s
-CP="$$(join_by : $(locations :%s))"
+CP="$$(join_by $$SEP $(locations :%s))"
ARGS="%s"
-java -Xmx256M -Xms32M -noverify \
- -cp $${KOTLIN_HOME}/lib/kotlin-preloader.jar org.jetbrains.kotlin.preloading.Preloader \
- -cp $${KOTLIN_HOME}/lib/kotlin-compiler.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler \
- -cp $${CP} -d $${NAME}_temp.jar $${ARGS} $(SRCS)
+$(JAVA) -Xmx256M -Xms32M -noverify \
+ -cp $(location @com_github_jetbrains_kotlin//:kotlin-preloader) org.jetbrains.kotlin.preloading.Preloader \
+ -cp $(location @com_github_jetbrains_kotlin//:kotlin-compiler) org.jetbrains.kotlin.cli.jvm.K2JVMCompiler \
+ -cp $${CP} -d $(@D)/$${NAME}_temp.jar $${ARGS} $(SRCS)
-$(location @bazel_tools//tools/jdk:singlejar) \
+case "$(location @bazel_tools//tools/jdk:singlejar)" in
+ *.jar)
+ SJ="$(JAVA) -jar $(location @bazel_tools//tools/jdk:singlejar)"
+ ;;
+ *)
+ SJ="$(location @bazel_tools//tools/jdk:singlejar)"
+ ;;
+esac
+
+$$SJ \
--normalize \
--compression \
- --sources $${NAME}_temp.jar \
+ --sources $(@D)/$${NAME}_temp.jar \
--output $(OUTS)
-rm $${NAME}_temp.jar
+rm $(@D)/$${NAME}_temp.jar
""" % (name, dep_label, " ".join(_BOOTSTRAP_LIB_ARGS))
native.genrule(
name = jar_label,
tools = [
"@com_github_jetbrains_kotlin//:home",
- "@local_jdk//:jdk",
+ "@com_github_jetbrains_kotlin//:kotlin-preloader",
+ "@com_github_jetbrains_kotlin//:kotlin-compiler",
"@bazel_tools//tools/jdk:singlejar",
dep_label,
],
@@ -80,6 +95,9 @@
outs = [name + ".jar"],
tags = ["no-ide"],
visibility = ["//visibility:private"],
+ toolchains = [
+ "@bazel_tools//tools/jdk:current_host_java_runtime",
+ ],
cmd = command,
)
native.java_import(
diff --git a/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt b/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt
index 83cc7e8..181fe8f 100644
--- a/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt
+++ b/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt
@@ -66,7 +66,7 @@
JdepsParser.parse(
command.info.label,
command.outputs.jdeps,
- joinedClasspath,
+ command.inputs.classpathList,
it,
isKotlinImplicit
)
diff --git a/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt b/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt
index c7385bb..606f644 100644
--- a/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt
+++ b/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt
@@ -20,6 +20,7 @@
import io.bazel.kotlin.builder.utils.addAll
import io.bazel.kotlin.builder.utils.joinedClasspath
import io.bazel.kotlin.model.JvmCompilationTask
+import java.io.File
import java.io.PrintWriter
import javax.inject.Inject
import javax.inject.Singleton
@@ -28,12 +29,18 @@
internal class JavaCompiler @Inject constructor(
private val javacInvoker: KotlinToolchain.JavacInvoker
) {
+ companion object {
+ /**
+ * Separator for a directory in the classpath.
+ */
+ private val DIR_SEP = "${File.separatorChar}${File.pathSeparator}"
+ }
fun compile(context: CompilationTaskContext, command: JvmCompilationTask) {
val i = command.inputs
val d = command.directories
if (i.javaSourcesList.isNotEmpty()) {
val args = mutableListOf(
- "-cp", "${d.classes}/:${d.temp}/:${i.joinedClasspath}",
+ "-cp", "${d.classes}$DIR_SEP${d.temp}$DIR_SEP${i.joinedClasspath}",
"-d", d.classes
).also {
it.addAll(
diff --git a/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParser.kt b/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParser.kt
index 0c923e6..c2c053e 100644
--- a/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParser.kt
+++ b/src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParser.kt
@@ -113,15 +113,14 @@
fun parse(
label: String,
classJar: String,
- classPath: String,
- jdepLines: List<String>,
+ classPath: MutableList<String>,
+ lines: List<String>,
isImplicit: Predicate<String>
): Deps.Dependencies {
val filename = Paths.get(classJar).fileName.toString()
val jdepsParser = JdepsParser(filename, isImplicit)
- classPath.split(":".toRegex()).dropLastWhile { it.isEmpty() }.stream()
- .forEach { x -> jdepsParser.consumeJarLine(x, Deps.Dependency.Kind.UNUSED) }
- jdepLines.forEach { jdepsParser.processLine(it) }
+ classPath.forEach { x -> jdepsParser.consumeJarLine(x, Deps.Dependency.Kind.UNUSED) }
+ lines.forEach { jdepsParser.processLine(it) }
val rootBuilder = Deps.Dependencies.newBuilder()
rootBuilder.success = false
diff --git a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt
index 167ba0f..5fbf9e7 100644
--- a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt
+++ b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt
@@ -15,6 +15,7 @@
*/
package io.bazel.kotlin.builder.toolchain
+import io.bazel.kotlin.builder.utils.BazelRunFiles
import io.bazel.kotlin.builder.utils.resolveVerified
import org.jetbrains.kotlin.preloading.ClassPreloadingUtils
import org.jetbrains.kotlin.preloading.Preloader
@@ -45,31 +46,38 @@
internal val NO_ARGS = arrayOf<Any>()
private val isJdk9OrNewer = !System.getProperty("java.version").startsWith("1.")
- private val javaRunfiles get() = Paths.get(System.getenv("JAVA_RUNFILES"))
- private fun createClassLoader(javaHome: Path, kotlinHome: Path): ClassLoader {
- val preloadJars = mutableListOf<File>().also {
- it += kotlinHome.resolveVerified("lib", "kotlin-compiler.jar")
- it += javaRunfiles.resolveVerified("io_bazel_rules_kotlin", "src", "main", "kotlin", "compiler_lib.jar")
- if (!isJdk9OrNewer) {
- it += javaHome.resolveVerified("lib", "tools.jar")
- }
- }
- return ClassPreloadingUtils.preloadClasses(
- preloadJars,
+ private fun createClassLoader(javaHome: Path, baseJars: List<File>): ClassLoader =
+ ClassPreloadingUtils.preloadClasses(
+ mutableListOf<File>().also {
+ it += baseJars
+ if (!isJdk9OrNewer) {
+ it += javaHome.resolveVerified("lib", "tools.jar")
+ }
+ },
Preloader.DEFAULT_CLASS_NUMBER_ESTIMATE,
ClassLoader.getSystemClassLoader(),
null
)
- }
@JvmStatic
fun createToolchain(): KotlinToolchain {
- val kotlinHome = Paths.get("external", "com_github_jetbrains_kotlin")
val javaHome = Paths.get(System.getProperty("java.home")).let { path ->
path.takeIf { !it.endsWith(Paths.get("jre")) } ?: path.parent
}
- return KotlinToolchain(kotlinHome, createClassLoader(javaHome, kotlinHome))
+ val kotlinCompilerJar = BazelRunFiles.resolveVerified(
+ "external", "com_github_jetbrains_kotlin", "lib", "kotlin-compiler.jar")
+ return KotlinToolchain(
+ kotlinCompilerJar.toPath().parent.parent,
+ createClassLoader(
+ javaHome,
+ listOf(
+ kotlinCompilerJar,
+ BazelRunFiles.resolveVerified(
+ "io_bazel_rules_kotlin", "src", "main", "kotlin", "compiler_lib.jar")
+ )
+ )
+ )
}
}
diff --git a/src/main/kotlin/io/bazel/kotlin/builder/utils/BazelUtils.kt b/src/main/kotlin/io/bazel/kotlin/builder/utils/BazelUtils.kt
new file mode 100644
index 0000000..311327e
--- /dev/null
+++ b/src/main/kotlin/io/bazel/kotlin/builder/utils/BazelUtils.kt
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2018 The Bazel Authors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.bazel.kotlin.builder.utils
+
+import java.io.File
+import java.io.FileInputStream
+import java.nio.charset.Charset
+import java.nio.file.Paths
+import java.util.*
+
+/** Utility class for getting runfiles on windows and *nix. */
+object BazelRunFiles {
+ private val isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0
+ /**
+ * Populated on windows. The RUNFILES_MANIFEST_FILE is set on platforms other then windows but it can be empty,]
+ */
+ private val manifestFile: String? =
+ if (isWindows) {
+ checkNotNull(System.getenv("RUNFILES_MANIFEST_FILE")) { "RUNFILES_MANIFEST_FILE not set in environment" }
+ } else null
+
+ private val javaRunFiles = Paths.get(System.getenv("JAVA_RUNFILES"))
+
+ private val runfiles by lazy {
+ with(mutableMapOf<String, String>()) {
+ FileInputStream(manifestFile)
+ .bufferedReader(Charset.forName("UTF-8"))
+ .lines()
+ .forEach { it ->
+ val line = it.trim { it <= ' ' }
+ if (!line.isEmpty()) {
+ // TODO(bazel-team): This is buggy when the path contains spaces, we should fix the manifest format.
+ line.split(" ").also {
+ check(it.size == 2) { "RunFiles manifest entry $line contains more than one space" }
+ put(it[0], it[1])
+ }
+ }
+ }
+ Collections.unmodifiableMap(this)
+ }
+ }
+
+ /**
+ * Resolve a run file on windows or *nix.
+ */
+ @JvmStatic
+ fun resolveVerified(vararg path: String): File {
+ check(path.isNotEmpty())
+ val fromManifest = manifestFile?.let { mf ->
+ path.joinToString("/").let { rfPath ->
+ // trim off the external/ prefix if it is present.
+ val trimmedPath =
+ if (rfPath.startsWith("external/")) {
+ rfPath.replaceFirst("external/", "")
+ } else {
+ rfPath
+ }
+ File(
+ checkNotNull(runfiles[trimmedPath]) {
+ "runfile manifest $mf did not contain path mapping for $rfPath"
+ }
+ )
+ }.also {
+ check(it.exists()) { "file $it resolved from runfiles did not exist" }
+ }
+ }
+ if(fromManifest != null) {
+ return fromManifest
+ }
+
+ /// if it could not be resolved from the manifest then first try to resolve it directly.
+ val resolvedDirect = File(path.joinToString(File.separator)).takeIf { it.exists() }
+ if(resolvedDirect != null) {
+ return resolvedDirect
+ }
+
+ // Try the java runfiles as the last resort.
+ return javaRunFiles.resolveVerified(path.joinToString(File.separator))
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/io/bazel/kotlin/compiler/BazelK2JVMCompiler.kt b/src/main/kotlin/io/bazel/kotlin/compiler/BazelK2JVMCompiler.kt
index baa7f49..061b962 100644
--- a/src/main/kotlin/io/bazel/kotlin/compiler/BazelK2JVMCompiler.kt
+++ b/src/main/kotlin/io/bazel/kotlin/compiler/BazelK2JVMCompiler.kt
@@ -21,6 +21,7 @@
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.config.Services
+import java.io.File
@Suppress("unused")
class BazelK2JVMCompiler(private val delegate: K2JVMCompiler = K2JVMCompiler()) {
@@ -34,7 +35,7 @@
// https://github.com/bazelbuild/rules_kotlin/issues/69: remove once jetbrains adds a flag for it.
args[i].startsWith("--friend-paths") -> {
i++
- friendsPaths = args[i].split(":").toTypedArray()
+ friendsPaths = args[i].split(File.pathSeparator).toTypedArray()
}
else -> tally += args[i]
}
diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderJvmTestTask.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderJvmTestTask.java
index de9321c..bc80def 100644
--- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderJvmTestTask.java
+++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderJvmTestTask.java
@@ -60,10 +60,9 @@
Dep.merge(dependencies)
.compileJars()
.forEach(
- (dependency) -> {
- assert dependency.toFile().exists();
- String depString = dependency.toString();
- taskBuilder.getInputsBuilder().addClasspath(depString);
- });
+ (dependency) ->
+ taskBuilder
+ .getInputsBuilder()
+ .addClasspath(dependency));
}
}
diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderResource.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderResource.java
index ab13e04..699104f 100644
--- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderResource.java
+++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinBuilderResource.java
@@ -2,6 +2,7 @@
import io.bazel.kotlin.builder.toolchain.CompilationException;
import io.bazel.kotlin.builder.toolchain.CompilationStatusException;
+import io.bazel.kotlin.builder.utils.BazelRunFiles;
import io.bazel.kotlin.builder.utils.CompilationTaskContext;
import io.bazel.kotlin.model.*;
import org.junit.rules.ExternalResource;
@@ -51,17 +52,17 @@
public abstract static class Dep {
private Dep() {}
- abstract Stream<Path> compileJars();
+ abstract Stream<String> compileJars();
private static class Simple extends Dep {
- private final List<Path> compileJars;
+ private final List<String> compileJars;
- private Simple(List<Path> compileJars) {
+ private Simple(List<String> compileJars) {
this.compileJars = compileJars;
}
@Override
- Stream<Path> compileJars() {
+ Stream<String> compileJars() {
return compileJars.stream();
}
}
@@ -72,16 +73,12 @@
}
public static List<String> classpathOf(Dep... dependencies) {
- return merge(dependencies).compileJars().map(Path::toString).collect(Collectors.toList());
+ return merge(dependencies).compileJars().collect(Collectors.toList());
}
public static Dep simpleOf(String compileJar) {
- return new Simple(Collections.singletonList(toPlatformPath(compileJar).toAbsolutePath()));
- }
-
- @SuppressWarnings("unused")
- static Dep simpleOf(Path compileJar) {
- return new Simple(Collections.singletonList(compileJar));
+ return new Simple(
+ Collections.singletonList(BazelRunFiles.resolveVerified(compileJar).getAbsolutePath()));
}
}
@@ -304,12 +301,17 @@
* @return a path string suitable for the target platform.
*/
private static Path toPlatformPath(String path) {
+ assert !path.startsWith("/") : path + " is an absolute path";
String[] parts = path.split("/");
return parts.length == 1
? Paths.get(parts[0])
: Paths.get(parts[0], Arrays.copyOfRange(parts, 1, parts.length));
}
+ public final String toPlatform(String path) {
+ return KotlinBuilderResource.toPlatformPath(path).toString();
+ }
+
@SuppressWarnings("unused")
private Stream<Path> directoryContents(DirectoryType type) {
try {
diff --git a/src/test/kotlin/io/bazel/kotlin/builder/tasks/js/KotlinBuilderJsTest.java b/src/test/kotlin/io/bazel/kotlin/builder/tasks/js/KotlinBuilderJsTest.java
index 131a97d..de300cf 100644
--- a/src/test/kotlin/io/bazel/kotlin/builder/tasks/js/KotlinBuilderJsTest.java
+++ b/src/test/kotlin/io/bazel/kotlin/builder/tasks/js/KotlinBuilderJsTest.java
@@ -30,7 +30,8 @@
public void testJsErrorRendering() {
ctx.addSource("AClass.kt", "package something", "class AClass{");
ctx.runFailingCompileTaskAndValidateOutput(
- this::jsCompilationTask, lines -> assertThat(lines.get(0)).startsWith("sources/AClass.kt"));
+ this::jsCompilationTask,
+ lines -> assertThat(lines.get(0)).startsWith(ctx.toPlatform("sources/AClass.kt")));
}
private void jsCompilationTask(CompilationTaskContext taskContext, JsCompilationTask task) {
diff --git a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParserTest.java b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParserTest.java
index f18a9c0..e3d2759 100644
--- a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParserTest.java
+++ b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/JdepsParserTest.java
@@ -15,67 +15,71 @@
*/
package io.bazel.kotlin.builder.tasks.jvm;
+import com.google.common.truth.Truth;
import com.google.devtools.build.lib.view.proto.Deps;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
-import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
-@SuppressWarnings("KotlinInternalInJava")
+@SuppressWarnings({"KotlinInternalInJava", "SpellCheckingInspection"})
@RunWith(JUnit4.class)
public class JdepsParserTest {
- private static final String JDK8_FIXTURE =
- "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk7.jar\n"
- + "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib.jar\n"
- + "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/extensions/postgres/postgres.jar\n"
- + "alt.jar -> bazel-server-cloud/bazel-out/darwin-fastbuild/bin/cloud/qa/integrationtests/pkg/alt/alt.runfiles/__main__/external/org_postgresql_postgresql/jar/postgresql-42.1.1.jar\n"
- + "alt.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar\n"
- + "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/utils/utils.jar\n"
- + " com.axsy.testing.alt (alt.jar)\n"
- + " -> com.axsy.testing.extensions.postgres postgres.jar\n"
- + " -> com.axsy.testing.pkg.utils utils.jar\n"
- + " -> java.io \n"
- + " -> java.lang \n"
- + " -> java.sql \n"
- + " -> javax.sql \n"
- + " -> kotlin kotlin-stdlib.jar\n"
- + " -> kotlin.jdk7 kotlin-stdlib-jdk7.jar\n"
- + " -> kotlin.jvm.internal kotlin-stdlib.jar\n"
- + " -> org.postgresql.ds postgresql-42.1.1.jar\n"
- + " com.axsy.testing.alt.sub (alt.jar)\n"
- + " -> java.lang \n"
- + " -> kotlin kotlin-stdlib.jar\n";
+ private static final List<String> JDK8_FIXTURE =
+ toPlatformPaths(
+ "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk7.jar",
+ "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib.jar",
+ "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/extensions/postgres/postgres.jar",
+ "alt.jar -> bazel-server-cloud/bazel-out/darwin-fastbuild/bin/cloud/qa/integrationtests/pkg/alt/alt.runfiles/__main__/external/org_postgresql_postgresql/jar/postgresql-42.1.1.jar",
+ "alt.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar",
+ "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/utils/utils.jar",
+ " com.axsy.testing.alt (alt.jar)",
+ " -> com.axsy.testing.extensions.postgres postgres.jar",
+ " -> com.axsy.testing.pkg.utils utils.jar",
+ " -> java.io ",
+ " -> java.lang ",
+ " -> java.sql ",
+ " -> javax.sql ",
+ " -> kotlin kotlin-stdlib.jar",
+ " -> kotlin.jdk7 kotlin-stdlib-jdk7.jar",
+ " -> kotlin.jvm.internal kotlin-stdlib.jar",
+ " -> org.postgresql.ds postgresql-42.1.1.jar",
+ " com.axsy.testing.alt.sub (alt.jar)",
+ " -> java.lang ",
+ " -> kotlin kotlin-stdlib.jar");
- private static final String JDK9_FIXTURE =
- "alt.jar -> java.base\n"
- + "alt.jar -> java.sql\n"
- + "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk7.jar\n"
- + "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib.jar\n"
- + "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/extensions/postgres/postgres.jar\n"
- + "alt.jar -> bazel-server-cloud/bazel-out/darwin-fastbuild/bin/cloud/qa/integrationtests/pkg/alt/alt.runfiles/__main__/external/org_postgresql_postgresql/jar/postgresql-42.1.1.jar\n"
- + "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/utils/utils.jar\n"
- + " com.axsy.testing.alt -> com.axsy.testing.extensions.postgres postgres.jar\n"
- + " com.axsy.testing.alt -> com.axsy.testing.pkg.utils utils.jar\n"
- + " com.axsy.testing.alt -> java.io java.base\n"
- + " com.axsy.testing.alt -> java.lang java.base\n"
- + " com.axsy.testing.alt -> java.sql java.sql\n"
- + " com.axsy.testing.alt -> javax.sql java.sql\n"
- + " com.axsy.testing.alt -> kotlin kotlin-stdlib.jar\n"
- + " com.axsy.testing.alt -> kotlin.jdk7 kotlin-stdlib-jdk7.jar\n"
- + " com.axsy.testing.alt -> kotlin.jvm.internal kotlin-stdlib.jar\n"
- + " com.axsy.testing.alt -> org.postgresql.ds postgresql-42.1.1.jar\n"
- + " com.axsy.testing.alt.sub -> java.lang java.base\n"
- + " com.axsy.testing.alt.sub -> kotlin kotlin-stdlib.jar\n";
+ private static final List<String> JDK9_FIXTURE =
+ toPlatformPaths(
+ "alt.jar -> java.base",
+ "alt.jar -> java.sql",
+ "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk7.jar",
+ "alt.jar -> bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib.jar",
+ "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/extensions/postgres/postgres.jar",
+ "alt.jar -> bazel-server-cloud/bazel-out/darwin-fastbuild/bin/cloud/qa/integrationtests/pkg/alt/alt.runfiles/__main__/external/org_postgresql_postgresql/jar/postgresql-42.1.1.jar",
+ "alt.jar -> bazel-bin/cloud/qa/integrationtests/pkg/utils/utils.jar",
+ " com.axsy.testing.alt -> com.axsy.testing.extensions.postgres postgres.jar",
+ " com.axsy.testing.alt -> com.axsy.testing.pkg.utils utils.jar",
+ " com.axsy.testing.alt -> java.io java.base",
+ " com.axsy.testing.alt -> java.lang java.base",
+ " com.axsy.testing.alt -> java.sql java.sql",
+ " com.axsy.testing.alt -> javax.sql java.sql",
+ " com.axsy.testing.alt -> kotlin kotlin-stdlib.jar",
+ " com.axsy.testing.alt -> kotlin.jdk7 kotlin-stdlib-jdk7.jar",
+ " com.axsy.testing.alt -> kotlin.jvm.internal kotlin-stdlib.jar",
+ " com.axsy.testing.alt -> org.postgresql.ds postgresql-42.1.1.jar",
+ " com.axsy.testing.alt.sub -> java.lang java.base",
+ " com.axsy.testing.alt.sub -> kotlin kotlin-stdlib.jar");
private static final List<String> CLASSPATH =
- Arrays.asList(
+ toPlatformPaths(
"bazel-bin/cloud/qa/integrationtests/pkg/extensions/postgres/unused.jar",
"bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk8.jar",
"bazel-server-cloud/external/com_github_jetbrains_kotlin/lib/kotlin-stdlib-jdk7.jar",
@@ -85,7 +89,7 @@
"bazel-bin/cloud/qa/integrationtests/pkg/utils/utils.jar");
private static final String LABEL = "//cloud/qa/integrationtests/pkg/alt";
- private static final String CLASS_JAR = "bazel-bin/something/alt.jar";
+ private static final String CLASS_JAR = toPlatformPath("bazel-bin/something/alt.jar");
private static final Predicate<String> IS_KOTLIN_IMPLICIT =
JdepsParser.Companion.pathSuffixMatchingPredicate(
@@ -104,16 +108,20 @@
testWithFixture(JDK9_FIXTURE);
}
- private void testWithFixture(String fixture) throws IOException {
+ private static void testWithFixture(List<String> fixture) throws IOException {
Deps.Dependencies result =
- JdepsParser.Companion.parse(
- LABEL,
- CLASS_JAR,
- CLASSPATH.stream().collect(Collectors.joining(":")),
- Arrays.asList(fixture.split("\n")),
- IS_KOTLIN_IMPLICIT);
+ JdepsParser.Companion.parse(LABEL, CLASS_JAR, CLASSPATH, fixture, IS_KOTLIN_IMPLICIT);
+
Assert.assertEquals(LABEL, result.getRuleLabel());
+ Truth.assertThat(
+ result
+ .getDependencyList()
+ .stream()
+ .map(Deps.Dependency::getPath)
+ .collect(Collectors.toSet()))
+ .containsExactlyElementsIn(CLASSPATH);
+
Assert.assertEquals(7, result.getDependencyCount());
Assert.assertEquals(1, depKinds(result, Deps.Dependency.Kind.UNUSED).size());
Assert.assertEquals(3, depKinds(result, Deps.Dependency.Kind.IMPLICIT).size());
@@ -125,7 +133,16 @@
System.out.flush();
}
- private List<Deps.Dependency> depKinds(Deps.Dependencies result, Deps.Dependency.Kind kind) {
+ private static List<String> toPlatformPaths(String... lines) {
+ return Stream.of(lines).map(JdepsParserTest::toPlatformPath).collect(Collectors.toList());
+ }
+
+ // on windows translate absolute paths to c:\ . Also swap the seperators from "/" to "\".
+ private static String toPlatformPath(String it) {
+ return File.separatorChar != '/' ? it.replace(" /", "c:\\").replace("/", File.separator) : it;
+ }
+
+ private static List<Deps.Dependency> depKinds(Deps.Dependencies result, Deps.Dependency.Kind kind) {
return result
.getDependencyList()
.stream()
diff --git a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmTest.java b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmTest.java
index 1fbc04e..3fff0e0 100644
--- a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmTest.java
+++ b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmTest.java
@@ -158,7 +158,8 @@
public void testKotlinErrorRendering() {
ctx.addSource("AClass.kt", "package something;" + "class AClass{");
ctx.runFailingCompileTaskAndValidateOutput(
- this::jvmCompilationTask, lines -> assertThat(lines.get(0)).startsWith("sources/AClass"));
+ this::jvmCompilationTask,
+ lines -> assertThat(lines.get(0)).startsWith(ctx.toPlatform("sources/AClass")));
}
@Test
@@ -167,7 +168,7 @@
ctx.addSource("AnotherClass.java", "package something;", "", "class AnotherClass{");
ctx.runFailingCompileTaskAndValidateOutput(
this::jvmCompilationTask,
- lines -> assertThat(lines.get(0)).startsWith("sources/AnotherClass"));
+ lines -> assertThat(lines.get(0)).startsWith(ctx.toPlatform("sources/AnotherClass")));
}
@Test