Skip to content

Commit

Permalink
Move the runfiles for external repositories to under the x.runfiles/ …
Browse files Browse the repository at this point in the history
…directory

This also sets the Bazel workspace name to io_bazel_source.

Fixes #848.

Relevant to #1116, #1124,

RELNOTES[INC]: All repositories are now directly under the x.runfiles directory in the runfiles tree (previously, external repositories were at x.runfiles/main-repo/external/other-repo. This simplifies handling remote repository runfiles considerably, but will break existing references to external repository runfiles.
---
Furthermore, if a Bazel project does not provide a workspace name in the WORKSPACE file, Bazel will now default to using __main__ as the workspace name (instead of "", as previously). The repository's runfiles will appear under x.runfiles/__main__/.

--
MOS_MIGRATED_REVID=120224534
  • Loading branch information
kchodorow authored and damienmg committed Apr 20, 2016
1 parent 0b26f44 commit 857cda2
Show file tree
Hide file tree
Showing 62 changed files with 623 additions and 328 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
workspace(name = "io_bazel")

load("/tools/build_defs/jsonnet/jsonnet", "jsonnet_repositories")
load("/tools/build_rules/rust/rust", "rust_repositories")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static String convertStreamToString(InputStream is) throws Exception {
public void hello(String obj) throws Exception {
String greeting = "Hello";
try {
String greetFile = getRunfiles() + "/examples/java-skylark/src/main/resources/greeting.txt";
String greetFile = getRunfiles()
+ "/io_bazel/examples/java-skylark/src/main/resources/greeting.txt";
greeting = convertStreamToString(new FileInputStream(greetFile));
} catch (FileNotFoundException e) {
// use default.
Expand Down
3 changes: 1 addition & 2 deletions examples/shell/bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ set -eu

# This allows the script to be both a binary and a library script. If our binary has defined
# RUNFILES then we use it, otherwise we look for our own runfiles.
RUNFILES=${RUNFILES:-$0.runfiles}
RUNFILES=${RUNFILES:-$0.runfiles/io_bazel}

source "${RUNFILES}/examples/shell/lib.sh"

showfile

3 changes: 1 addition & 2 deletions examples/shell/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ set -eu

# This allows the script to be both a binary and a library script. If our binary has defined
# RUNFILES then we use it, otherwise we look for our own runfiles.
RUNFILES=${RUNFILES:-$0.runfiles}
RUNFILES=${RUNFILES:-$0.runfiles/io_bazel}

function showfile {
cat "${RUNFILES}/examples/shell/data/file.txt"
}

2 changes: 1 addition & 1 deletion scripts/bash_completion_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }
: ${COMMAND_ALIASES:=bazel}

# Completion script
: ${COMPLETION:="$TEST_SRCDIR/scripts/bazel-complete.bash"}
: ${COMPLETION:="$TEST_SRCDIR/io_bazel/scripts/bazel-complete.bash"}

# Set this to test completion with package path (if enabled)
: ${PACKAGE_PATH_PREFIX:=}
Expand Down
4 changes: 2 additions & 2 deletions scripts/testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; }

# Load the unit-testing framework
source "${TEST_SRCDIR}/src/test/shell/unittest.bash" || \
{ echo "Failed to source unittest.bash" >&2; exit 1; }
source "${TEST_SRCDIR}/io_bazel/src/test/shell/unittest.bash" \
|| { echo "Failed to source unittest.bash" >&2; exit 1; }

set_up() {
mkdir -p $TEST_TMPDIR/workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ genrule(
outs = ["JavacBootclasspathLocations.java"],
cmd = """
declare -a paths=($(SRCS)) && paths=($${paths[@]#$(GENDIR)/}) &&
paths=($$(echo $${paths[@]} | sed s_external/__g)) &&
IFS=: &&
cat > $@ <<EOF
package com.google.devtools.build.java.bazel;
Expand Down Expand Up @@ -44,7 +45,7 @@ genrule(
srcs = ["//third_party/java/jdk/langtools:javac_jar"],
outs = ["JavaLangtoolsLocation.java"],
cmd = """
path=$(SRCS) && path=$${path#$(GENDIR)/} &&
path=$(SRCS) && path=$${path#$(GENDIR)/} && path="io_bazel/$${path}" &&
cat > $@ <<EOF
package com.google.devtools.build.java.bazel;
public class JavaLangtoolsLocation {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/google/devtools/build/lib/actions/Artifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,21 @@ public final PathFragment getRootRelativePath() {
return rootRelativePath;
}

/**
* For targets in external repositories, this returns the path the artifact live at in the
* runfiles tree. For local targets, it returns the rootRelativePath.
*/
public final PathFragment getRunfilesPath() {
PathFragment relativePath = rootRelativePath;
if (relativePath.segmentCount() > 1
&& relativePath.getSegment(0).equals(Label.EXTERNAL_PATH_PREFIX)) {
// Turn external/repo/foo into ../repo/foo.
relativePath = relativePath.relativeTo(Label.EXTERNAL_PATH_PREFIX);
relativePath = new PathFragment("..").getRelative(relativePath);
}
return relativePath;
}

/**
* Returns this.getExecPath().getPathString().
*/
Expand Down
Loading

0 comments on commit 857cda2

Please sign in to comment.