aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2016-02-24 12:41:12 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-02-24 17:59:44 +0000
commit44847d8442d5c93c2ffbf76e11fd76e9a1567ff3 (patch)
tree890f58080b82de06df9fed13160fe00e12d700d4 /src/test/java/com/google/devtools
parent29d861e4eca0f56d91755cfed86465eaf1a6ae32 (diff)
Enable access to file values in repository context
ctx.path now works with labels. When given a label, ctx.path() will returns the path to the corresponding file if the label point to a file, or error out if it does not point to file. Also fix a small case with repository_ctx.symlink that wasn't creating its directories. This is needed to enable reading template files to create a template function (see http://goo.gl/fD4ZsY) for issue #893 (step 4 of http://goo.gl/OZV3o0). -- MOS_MIGRATED_REVID=115438400
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r--src/test/java/com/google/devtools/build/lib/BUILD1
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContextTest.java9
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java28
3 files changed, 36 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index 2951ca5e3c..7d2a2d0637 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -1053,6 +1053,7 @@ java_test(
"//third_party:guava-testlib",
"//third_party:jsr305",
"//third_party:junit4",
+ "//third_party:mockito",
"//third_party:truth",
],
)
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContextTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContextTest.java
index 22b185e603..7d7a81444e 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContextTest.java
@@ -35,11 +35,13 @@ import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.skyframe.SkyFunction;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import org.mockito.Mockito;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -87,7 +89,12 @@ public class SkylarkRepositoryContextTest {
.externalPackageData()
.createAndAddRepositoryRule(
packageBuilder, buildRuleClass(attributes), null, kwargs, ast);
- context = new SkylarkRepositoryContext(rule, outputDirectory, ImmutableMap.of("FOO", "BAR"));
+ context =
+ new SkylarkRepositoryContext(
+ rule,
+ outputDirectory,
+ Mockito.mock(SkyFunction.Environment.class),
+ ImmutableMap.of("FOO", "BAR"));
}
protected void setUpContexForRule(String name) throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java
index 86a2a485a5..aaca4d0edb 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java
@@ -153,7 +153,7 @@ public class SkylarkRepositoryIntegrationTest extends BuildViewTestCase {
scratch.file(
"def.bzl",
"def _impl(ctx):",
- " ctx.symlink(ctx.path(ctx.attr.path), ctx.path(''))",
+ " ctx.symlink(ctx.attr.path, '')",
"",
"repo = repository_rule(",
" implementation=_impl,",
@@ -169,4 +169,30 @@ public class SkylarkRepositoryIntegrationTest extends BuildViewTestCase {
Object path = target.getTarget().getAssociatedRule().getAttributeContainer().getAttr("path");
assertThat(path).isEqualTo("foo");
}
+
+ @Test
+ public void testSkylarkSymlinkFileFromRepository() throws Exception {
+ scratch.file("/repo2/bar.txt", "filegroup(name='bar', srcs=['foo.txt'], path='foo')");
+ scratch.file("/repo2/BUILD");
+ scratch.file("/repo2/WORKSPACE");
+ scratch.file(
+ "def.bzl",
+ "def _impl(ctx):",
+ " ctx.symlink(Label('@repo2//:bar.txt'), 'BUILD')",
+ " ctx.file('foo.txt', 'foo')",
+ "",
+ "repo = repository_rule(",
+ " implementation=_impl,",
+ " local=True)");
+ scratch.file(rootDirectory.getRelative("BUILD").getPathString());
+ scratch.overwriteFile(
+ rootDirectory.getRelative("WORKSPACE").getPathString(),
+ "local_repository(name='repo2', path='/repo2')",
+ "load('//:def.bzl', 'repo')",
+ "repo(name='foo')");
+ invalidatePackages();
+ ConfiguredTarget target = getConfiguredTarget("@foo//:bar");
+ Object path = target.getTarget().getAssociatedRule().getAttributeContainer().getAttr("path");
+ assertThat(path).isEqualTo("foo");
+ }
}