aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-01-07 19:14:42 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-01-07 20:22:19 +0000
commit43b0f9e2e6768f29c02da3baac8f248db7f0f5da (patch)
tree9e596c7f7b3cdff15ec02d08a454cd544fa8d7f1 /src/main
parent0dbc1f9526928f398d18844ef671bfa092ba6590 (diff)
Allow relative paths for local_repository()s
Fixes #733. RELNOTES: Relative paths can now be used for 'path' with new_local_repository and local_repository. -- MOS_MIGRATED_REVID=111620894
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java15
5 files changed, 9 insertions, 23 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
index ed8a3c7f05..02252f488a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
@@ -76,7 +76,7 @@ public class AndroidNdkRepositoryFunction extends RepositoryFunction {
public SkyValue fetch(Rule rule, Path outputDirectory, Environment env)
throws SkyFunctionException {
prepareLocalRepositorySymlinkTree(rule, outputDirectory);
- PathFragment pathFragment = getTargetPath(rule);
+ PathFragment pathFragment = getTargetPath(rule, getWorkspace());
Path ndkSymlinkTreeDirectory = outputDirectory.getRelative("ndk");
try {
ndkSymlinkTreeDirectory.createDirectory();
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
index 9997f66315..71996c8c18 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
@@ -41,7 +41,7 @@ public class AndroidSdkRepositoryFunction extends RepositoryFunction {
public SkyValue fetch(Rule rule, Path outputDirectory, Environment env)
throws SkyFunctionException {
prepareLocalRepositorySymlinkTree(rule, outputDirectory);
- PathFragment pathFragment = getTargetPath(rule);
+ PathFragment pathFragment = getTargetPath(rule, getWorkspace());
if (!symlinkLocalRepositoryContents(
outputDirectory,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
index 58f584d11a..7bb54e1c1a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
@@ -19,7 +19,6 @@ import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.skyframe.FileValue;
import com.google.devtools.build.lib.skyframe.RepositoryValue;
-import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -43,15 +42,7 @@ public class LocalRepositoryFunction extends RepositoryFunction {
public SkyValue fetch(Rule rule, Path outputDirectory, Environment env)
throws SkyFunctionException {
AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
- String path = mapper.get("path", Type.STRING);
- PathFragment pathFragment = new PathFragment(path);
- if (!pathFragment.isAbsolute()) {
- throw new RepositoryFunctionException(
- new EvalException(
- rule.getLocation(),
- "In " + rule + " the 'path' attribute must specify an absolute path"),
- Transience.PERSISTENT);
- }
+ PathFragment pathFragment = new PathFragment(mapper.get("path", Type.STRING));
try {
outputDirectory.createSymbolicLink(pathFragment);
} catch (IOException e) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
index 964b9072ff..3557a3bc76 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
@@ -40,7 +40,7 @@ public class NewLocalRepositoryFunction extends RepositoryFunction {
return null;
}
prepareLocalRepositorySymlinkTree(rule, outputDirectory);
- PathFragment pathFragment = getTargetPath(rule);
+ PathFragment pathFragment = getTargetPath(rule, getWorkspace());
// Link x/y/z to /some/path/to/y/z.
if (!symlinkLocalRepositoryContents(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java
index 00a67eb0ca..c67c254225 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.rules.repository;
+import com.google.common.annotations.VisibleForTesting;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.cmdline.Label;
@@ -298,19 +299,13 @@ public abstract class RepositoryFunction {
return RepositoryValue.create(outputDirectory);
}
- protected static PathFragment getTargetPath(Rule rule) throws RepositoryFunctionException {
+ @VisibleForTesting
+ protected static PathFragment getTargetPath(Rule rule, Path workspace)
+ throws RepositoryFunctionException {
AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
String path = mapper.get("path", Type.STRING);
PathFragment pathFragment = new PathFragment(path);
- if (!pathFragment.isAbsolute()) {
- throw new RepositoryFunctionException(
- new EvalException(
- rule.getLocation(),
- "In " + rule + " the 'path' attribute must specify an absolute path"),
- Transience.PERSISTENT);
- }
-
- return pathFragment;
+ return workspace.getRelative(pathFragment).asFragment();
}
/**