aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2016-06-27 15:18:14 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-06-27 17:06:56 +0000
commit48c98c9837d6b3768862bc66b53cae4708a147b7 (patch)
treeb4416a5f11fa6afd1f17ab478456c37788aa52cc /src/main
parent6c07f6218d436912efc165a7074f82e1f1887cb9 (diff)
Fixed java_stub_template.txt after disabling runfiles on Windows
-- Change-Id: Ia5def69207f6f69809ff09cda67910844749e63e Reviewed-on: https://bazel-review.googlesource.com/#/c/3907 MOS_MIGRATED_REVID=125957512
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java57
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt38
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java18
3 files changed, 86 insertions, 27 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
index 641aa2bf96..8446aca46d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
@@ -53,6 +53,7 @@ import com.google.devtools.build.lib.util.ShellEscaper;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -165,23 +166,26 @@ public class BazelJavaSemantics implements JavaSemantics {
Preconditions.checkNotNull(javaExecutable);
List<Substitution> arguments = new ArrayList<>();
- String workspacePrefix = ruleContext.getWorkspaceName();
- if (!workspacePrefix.isEmpty()) {
- workspacePrefix += "/";
- }
+ String workspaceName = ruleContext.getWorkspaceName();
+ final String workspacePrefix = workspaceName + (workspaceName.isEmpty() ? "" : "/");
+ final boolean isRunfilesEnabled = ruleContext.getConfiguration().runfilesEnabled();
+
arguments.add(Substitution.of("%workspace_prefix%", workspacePrefix));
arguments.add(Substitution.of("%javabin%", javaExecutable));
arguments.add(Substitution.of("%needs_runfiles%",
ruleContext.getFragment(Jvm.class).getJavaExecutable().isAbsolute() ? "0" : "1"));
- arguments.add(new ComputedSubstitution("%classpath%") {
- @Override
- public String getValue() {
- StringBuilder buffer = new StringBuilder();
- Iterable<Artifact> jars = javaCommon.getRuntimeClasspath();
- appendRunfilesRelativeEntries(buffer, jars, ':');
- return buffer.toString();
- }
- });
+ arguments.add(
+ new ComputedSubstitution("%classpath%") {
+ @Override
+ public String getValue() {
+ StringBuilder buffer = new StringBuilder();
+ Iterable<Artifact> jars = javaCommon.getRuntimeClasspath();
+ char delimiter = File.pathSeparatorChar;
+ appendRunfilesRelativeEntries(
+ buffer, jars, workspacePrefix, delimiter, isRunfilesEnabled);
+ return buffer.toString();
+ }
+ });
arguments.add(Substitution.of("%java_start_class%",
ShellEscaper.escapeString(javaStartClass)));
@@ -194,22 +198,35 @@ public class BazelJavaSemantics implements JavaSemantics {
/**
* Builds a class path by concatenating the root relative paths of the artifacts separated by the
* delimiter. Each relative path entry is prepended with "${RUNPATH}" which will be expanded by
- * the stub script at runtime, to either "${JAVA_RUNFILES}/" or if we are lucky, the empty
- * string.
+ * the stub script at runtime, to either "${JAVA_RUNFILES}/" or if we are lucky, the empty string.
*
* @param buffer the buffer to use for concatenating the entries
* @param artifacts the entries to concatenate in the buffer
* @param delimiter the delimiter character to separate the entries
*/
- private static void appendRunfilesRelativeEntries(StringBuilder buffer,
- Iterable<Artifact> artifacts, char delimiter) {
+ private static void appendRunfilesRelativeEntries(
+ StringBuilder buffer,
+ Iterable<Artifact> artifacts,
+ String workspacePrefix,
+ char delimiter,
+ boolean isRunfilesEnabled) {
+ buffer.append("\"");
for (Artifact artifact : artifacts) {
- if (buffer.length() > 0) {
+ if (buffer.length() > 1) {
buffer.append(delimiter);
}
- buffer.append("${RUNPATH}");
- buffer.append(artifact.getRunfilesPath().getPathString());
+ if (!isRunfilesEnabled) {
+ buffer.append("$(rlocation ");
+ PathFragment runfilePath =
+ new PathFragment(new PathFragment(workspacePrefix), artifact.getRunfilesPath());
+ buffer.append(runfilePath.normalize().getPathString());
+ buffer.append(")");
+ } else {
+ buffer.append("${RUNPATH}");
+ buffer.append(artifact.getRunfilesPath().getPathString());
+ }
}
+ buffer.append("\"");
}
private TransitiveInfoCollection getTestSupport(RuleContext ruleContext) {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
index 25dbc1b39f..443c697e58 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
@@ -73,6 +73,17 @@ die() {
exit 1
}
+# Windows
+PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
+function is_windows() {
+ # On windows, the shell test actually running on msys
+ if [ "${PLATFORM}" == "msys_nt-6.1" ]; then
+ true
+ else
+ false
+ fi
+}
+
# Parse arguments sequentially until the first unrecognized arg is encountered.
# Scan the remaining args for --wrapper_script_flag=X options and process them.
ARGS=()
@@ -142,10 +153,29 @@ if [[ "$SINGLEJAR" != 1 || "%needs_runfiles%" == 1 ]]; then
fi
fi
-# This script is running with msys on Windows, so CLASSPATH has to be unix format. If JAVA_RUNFILES
-# is like C:/blah/blah, we need convert it to /c/blah/blah, otherwise CLASSPATH doesn't work.
-if [ ${JAVA_RUNFILES:1:1} == : ]; then
- JAVA_RUNFILES=$(cygpath --unix "$JAVA_RUNFILES")
+# If we are running on Windows, we need a windows style runfiles path for constructing CLASSPATH
+if is_windows; then
+ JAVA_RUNFILES=$(cygpath --windows "$JAVA_RUNFILES")
+fi
+
+RUNFILES_MANIFEST_FILE="${JAVA_RUNFILES}/MANIFEST"
+
+if [ -z "$RUNFILES_MANIFEST_ONLY" ]; then
+ function rlocation() {
+ if [[ "$1" = /* ]]; then
+ echo $1
+ else
+ echo "$(dirname $RUNFILES_MANIFEST_FILE)/$1"
+ fi
+ }
+else
+ function rlocation() {
+ if [[ "$1" = /* ]]; then
+ echo $1
+ else
+ echo $(grep "^$1 " $RUNFILES_MANIFEST_FILE | awk '{ print $2 }')
+ fi
+ }
fi
# Set JAVABIN to the path to the JVM launcher.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
index 1a564abfa9..fbb22daeab 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
@@ -462,9 +462,21 @@ public class JavaCommon {
javaExecutable = ruleContext.getFragment(Jvm.class).getRunfilesJavaExecutable();
}
- String pathPrefix = javaExecutable.isAbsolute() ? "" : "${JAVA_RUNFILES}/"
- + ruleContext.getRule().getWorkspaceName() + "/";
- return "JAVABIN=${JAVABIN:-" + pathPrefix + javaExecutable.getPathString() + "}";
+ if (!javaExecutable.isAbsolute()) {
+ javaExecutable =
+ new PathFragment(new PathFragment(ruleContext.getWorkspaceName()), javaExecutable);
+ }
+ javaExecutable = javaExecutable.normalize();
+
+ if (ruleContext.getConfiguration().runfilesEnabled()) {
+ String prefix = "";
+ if (!javaExecutable.isAbsolute()) {
+ prefix = "${JAVA_RUNFILES}/";
+ }
+ return "JAVABIN=${JAVABIN:-" + prefix + javaExecutable.getPathString() + "}";
+ } else {
+ return "JAVABIN=${JAVABIN:-$(rlocation " + javaExecutable.getPathString() + ")}";
+ }
}
/**