diff options
author | 2017-06-27 15:28:18 +0200 | |
---|---|---|
committer | 2017-06-28 10:16:47 +0200 | |
commit | 7998f70960f0a4a76f24c015421092910c774003 (patch) | |
tree | 0f9e019b768d9a4ed237b3caf7033e797984e663 /src/main/java/com/google/devtools/build | |
parent | 329d79e3599469186c0e261182550eb57bd6140d (diff) |
Add 'ctx.actions.declare_directory'
RELNOTES: None.
PiperOrigin-RevId: 160267763
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java index 6157392a68..535987f090 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkActionFactory.java @@ -51,7 +51,6 @@ public class SkylarkActionFactory implements SkylarkValue { : ruleContext.getBinOrGenfilesDirectory(); } - @SkylarkCallable( name = "declare_file", doc = @@ -93,7 +92,47 @@ public class SkylarkActionFactory implements SkylarkValue { } } - @Override + @SkylarkCallable( + name = "declare_directory", + doc = + "Declares that rule or aspect create a directory with the given name, in the " + + "current package. You must create an action that generates the file. <br>" + + "Files that are specified in rule's outputs do not need to be declared and are " + + "available through <a href=\"ctx.html#outputs\">ctx.outputs</a>.", + parameters = { + @Param( + name = "filename", + type = String.class, + doc = + "If no 'sibling' provided, path of the new directory, relative " + + "to the current package. Otherwise a base name for a file " + + "('sibling' defines a directory)." + ), + @Param( + name = "sibling", + doc = "A file that lives in the same directory as the newly declared directory.", + type = Artifact.class, + noneable = true, + positional = false, + named = true, + defaultValue = "None" + ) + } + ) + public Artifact declareDirectory(String filename, Object sibling) throws EvalException { + context.checkMutable("actions.declare_directory"); + if (Runtime.NONE.equals(sibling)) { + return ruleContext.getPackageRelativeTreeArtifact( + PathFragment.create(filename), newFileRoot()); + } else { + PathFragment original = ((Artifact) sibling).getRootRelativePath(); + PathFragment fragment = original.replaceName(filename); + return ruleContext.getTreeArtifact(fragment, newFileRoot()); + } + } + + + @Override public boolean isImmutable() { return context.isImmutable(); } |