aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-10-10 17:21:24 +0000
committerGravatar Yue Gan <yueg@google.com>2016-10-11 08:44:32 +0000
commitba41c2df007f4d81e0987ae76824c855e5f4c437 (patch)
tree2762a4c96e887d753e2ff564bec6e5e545faad03 /src
parent3e5ac9db368b6aee2e9dbe4be0aca16abeb24645 (diff)
Add bin_dir and genfiles_dir to ctx
-- MOS_MIGRATED_REVID=135689610
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java23
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java2
-rwxr-xr-xsrc/test/shell/bazel/bazel_worker_test.sh2
5 files changed, 19 insertions, 24 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 4b9b72a3a0..ecb2e89dd3 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -76,7 +76,6 @@ import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.rules.AliasProvider;
import com.google.devtools.build.lib.rules.fileset.FilesetProvider;
import com.google.devtools.build.lib.shell.ShellUtils;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.FileTypeSet;
@@ -522,25 +521,9 @@ public final class RuleContext extends TargetContext
* which this target (which must be an OutputFile or a Rule) is associated.
*/
public Root getBinOrGenfilesDirectory() {
- return rule.hasBinaryOutput() ? getBinDirectory() : getGenfilesDirectory();
- }
-
- /**
- * Returns the bin directory for this build configuration.
- */
- @SkylarkCallable(name = "bin_dir", structField = true,
- doc = "The root corresponding to bin directory.")
- public Root getBinDirectory() {
- return getConfiguration().getBinDirectory(rule.getRepository());
- }
-
- /**
- * Returns the genfiles directory for this build configuration.
- */
- @SkylarkCallable(name = "genfiles_dir", structField = true,
- doc = "The root corresponding to genfiles directory.")
- public Root getGenfilesDirectory() {
- return getConfiguration().getGenfilesDirectory(rule.getRepository());
+ return rule.hasBinaryOutput()
+ ? getConfiguration().getBinDirectory(rule.getRepository())
+ : getConfiguration().getGenfilesDirectory(rule.getRepository());
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
index 594ace937e..31ad28093e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
@@ -511,6 +511,18 @@ public final class SkylarkRuleContext {
return ImmutableList.copyOf(ruleContext.getFeatures());
}
+ @SkylarkCallable(name = "bin_dir", structField = true,
+ doc = "The root corresponding to bin directory.")
+ public Root getBinDirectory() {
+ return getConfiguration().getBinDirectory(ruleContext.getRule().getRepository());
+ }
+
+ @SkylarkCallable(name = "genfiles_dir", structField = true,
+ doc = "The root corresponding to genfiles directory.")
+ public Root getGenfilesDirectory() {
+ return getConfiguration().getGenfilesDirectory(ruleContext.getRule().getRepository());
+ }
+
@SkylarkCallable(structField = true, doc = OUTPUTS_DOC)
public SkylarkClassObject outputs() throws EvalException {
if (outputsObject == null) {
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
index 41a857577d..674aa40bdb 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
@@ -739,7 +739,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
Object result =
evalRuleContextCode(
ruleContext,
- "ruleContext.new_file(ruleContext.configuration.genfiles_dir," + " 'a/b.txt')");
+ "ruleContext.new_file(ruleContext.genfiles_dir," + " 'a/b.txt')");
PathFragment fragment = ((Artifact) result).getRootRelativePath();
assertEquals("foo/a/b.txt", fragment.getPathString());
}
@@ -758,7 +758,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase {
Object result =
evalRuleContextCode(
ruleContext,
- "ruleContext.new_file(ruleContext.configuration.bin_dir,"
+ "ruleContext.new_file(ruleContext.bin_dir,"
+ "ruleContext.files.tools[0], '.params')");
PathFragment fragment = ((Artifact) result).getRootRelativePath();
assertEquals("foo/t.exe.params", fragment.getPathString());
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index 719afd4ef9..cb22278311 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -1142,7 +1142,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
@Test
public void testBinDirPath() throws Exception {
SkylarkRuleContext ctx = createRuleContext("//foo:bar");
- Object result = evalRuleContextCode(ctx, "ruleContext.configuration.bin_dir.path");
+ Object result = evalRuleContextCode(ctx, "ruleContext.bin_dir.path");
assertEquals(ctx.getConfiguration().getBinFragment().getPathString(), result);
}
diff --git a/src/test/shell/bazel/bazel_worker_test.sh b/src/test/shell/bazel/bazel_worker_test.sh
index 224fa9e205..4256b1bfd9 100755
--- a/src/test/shell/bazel/bazel_worker_test.sh
+++ b/src/test/shell/bazel/bazel_worker_test.sh
@@ -94,7 +94,7 @@ def _impl(ctx):
output = ctx.outputs.out
# Generate the "@"-file containing the command-line args for the unit of work.
- argfile = ctx.new_file(ctx.configuration.bin_dir, "%s_worker_input" % ctx.label.name)
+ argfile = ctx.new_file(ctx.bin_dir, "%s_worker_input" % ctx.label.name)
argfile_contents = "\n".join(["--output_file=" + output.path] + ctx.attr.args)
ctx.file_action(output=argfile, content=argfile_contents)