aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Miguel Alcon Pinto <malcon@google.com>2016-01-21 14:59:33 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-01-21 16:22:26 +0000
commitf9c8cc51c5b5281ae37e7111ec16072451f56f4a (patch)
treea9bf3ed38ba870d7e275f8754fd71db3e6721f45 /src/main/java/com/google/devtools/build/lib
parentc88508c594d535311b092d6fdba94b2b4b9cfa12 (diff)
Allow more flexibility on proto output formatter.
-- MOS_MIGRATED_REVID=112681274
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java86
1 files changed, 57 insertions, 29 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
index da5a2fab6a..abf1e08c88 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
@@ -41,7 +41,9 @@ import com.google.devtools.build.lib.query2.output.AspectResolver.BuildFileDepen
import com.google.devtools.build.lib.query2.output.OutputFormatter.AbstractUnorderedFormatter;
import com.google.devtools.build.lib.query2.output.QueryOptions.OrderOutput;
import com.google.devtools.build.lib.query2.proto.proto2api.Build;
+import com.google.devtools.build.lib.query2.proto.proto2api.Build.GeneratedFile;
import com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult.Builder;
+import com.google.devtools.build.lib.query2.proto.proto2api.Build.SourceFile;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.util.BinaryPredicate;
@@ -135,8 +137,11 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
Rule rule = (Rule) target;
Build.Rule.Builder rulePb = Build.Rule.newBuilder()
.setName(rule.getLabel().toString())
- .setRuleClass(rule.getRuleClass())
- .setLocation(location);
+ .setRuleClass(rule.getRuleClass());
+ if (includeLocation()) {
+ rulePb.setLocation(location);
+ }
+
for (Attribute attr : rule.getAttributes()) {
if (!includeDefaultValues && !rule.isAttributeValueExplicitlySpecified(attr)
|| !includeAttribute(rule, attr)) {
@@ -160,7 +165,7 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
postProcess(rule, rulePb);
Environment env = rule.getRuleClassObject().getRuleDefinitionEnvironment();
- if (env != null) {
+ if (env != null && includeRuleDefinitionEnvironment()) {
// The RuleDefinitionEnvironment is always defined for Skylark rules and
// always null for non Skylark rules.
rulePb.addAttribute(
@@ -176,6 +181,9 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
// Add information about additional attributes from aspects.
for (Entry<Attribute, Collection<Label>> entry : aspectsDependencies.asMap().entrySet()) {
Attribute attribute = entry.getKey();
+ if (!includeAttribute(rule, attribute)) {
+ continue;
+ }
Collection<Label> labels = entry.getValue();
Object attributeValue = getAspectAttributeValue(attribute, labels);
Build.Attribute serializedAttribute =
@@ -187,21 +195,23 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
/*encodeBooleanAndTriStateAsIntegerAndString=*/ true);
rulePb.addAttribute(serializedAttribute);
}
- // Add all deps from aspects as rule inputs of current target.
- for (Label label : aspectsDependencies.values()) {
- rulePb.addRuleInput(label.toString());
- }
+ if (includeRuleInputsAndOutputs()) {
+ // Add all deps from aspects as rule inputs of current target.
+ for (Label label : aspectsDependencies.values()) {
+ rulePb.addRuleInput(label.toString());
+ }
- // Include explicit elements for all direct inputs and outputs of a rule;
- // this goes beyond what is available from the attributes above, since it
- // may also (depending on options) include implicit outputs,
- // host-configuration outputs, and default values.
- for (Label label : rule.getLabels(dependencyFilter)) {
- rulePb.addRuleInput(label.toString());
- }
- for (OutputFile outputFile : rule.getOutputFiles()) {
- Label fileLabel = outputFile.getLabel();
- rulePb.addRuleOutput(fileLabel.toString());
+ // Include explicit elements for all direct inputs and outputs of a rule;
+ // this goes beyond what is available from the attributes above, since it
+ // may also (depending on options) include implicit outputs,
+ // host-configuration outputs, and default values.
+ for (Label label : rule.getLabels(dependencyFilter)) {
+ rulePb.addRuleInput(label.toString());
+ }
+ for (OutputFile outputFile : rule.getOutputFiles()) {
+ Label fileLabel = outputFile.getLabel();
+ rulePb.addRuleOutput(fileLabel.toString());
+ }
}
for (String feature : rule.getFeatures()) {
rulePb.addDefaultSetting(feature);
@@ -214,22 +224,27 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
Label label = outputFile.getLabel();
Rule generatingRule = outputFile.getGeneratingRule();
- Build.GeneratedFile output = Build.GeneratedFile.newBuilder()
- .setLocation(location)
- .setGeneratingRule(generatingRule.getLabel().toString())
- .setName(label.toString())
- .build();
+ GeneratedFile.Builder output =
+ GeneratedFile.newBuilder()
+ .setGeneratingRule(generatingRule.getLabel().toString())
+ .setName(label.toString());
+ if (includeLocation()) {
+ output.setLocation(location);
+ }
targetPb.setType(GENERATED_FILE);
- targetPb.setGeneratedFile(output);
+ targetPb.setGeneratedFile(output.build());
} else if (target instanceof InputFile) {
InputFile inputFile = (InputFile) target;
Label label = inputFile.getLabel();
Build.SourceFile.Builder input = Build.SourceFile.newBuilder()
- .setLocation(location)
.setName(label.toString());
+ if (includeLocation()) {
+ input.setLocation(location);
+ }
+
if (inputFile.getName().equals("BUILD")) {
Set<Label> subincludeLabels = new LinkedHashSet<>();
subincludeLabels.addAll(aspectResolver == null
@@ -264,13 +279,14 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
targetPb.setSourceFile(input);
} else if (target instanceof FakeSubincludeTarget) {
Label label = target.getLabel();
- Build.SourceFile input = Build.SourceFile.newBuilder()
- .setLocation(location)
- .setName(label.toString())
- .build();
+ SourceFile.Builder input = SourceFile.newBuilder()
+ .setName(label.toString());
+ if (includeLocation()) {
+ input.setLocation(location);
+ }
targetPb.setType(SOURCE_FILE);
- targetPb.setSourceFile(input);
+ targetPb.setSourceFile(input.build());
} else if (target instanceof PackageGroup) {
PackageGroup packageGroup = (PackageGroup) target;
Build.PackageGroup.Builder packageGroupPb = Build.PackageGroup.newBuilder()
@@ -328,4 +344,16 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
protected boolean includeAttribute(Rule rule, Attribute attr) {
return true;
}
+
+ protected boolean includeRuleDefinitionEnvironment() {
+ return true;
+ }
+
+ protected boolean includeRuleInputsAndOutputs() {
+ return true;
+ }
+
+ protected boolean includeLocation() {
+ return true;
+ }
}