From f9c8cc51c5b5281ae37e7111ec16072451f56f4a Mon Sep 17 00:00:00 2001 From: Miguel Alcon Pinto Date: Thu, 21 Jan 2016 14:59:33 +0000 Subject: Allow more flexibility on proto output formatter. -- MOS_MIGRATED_REVID=112681274 --- .../lib/query2/output/ProtoOutputFormatter.java | 86 ++++++++++++++-------- 1 file changed, 57 insertions(+), 29 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib') 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> entry : aspectsDependencies.asMap().entrySet()) { Attribute attribute = entry.getKey(); + if (!includeAttribute(rule, attribute)) { + continue; + } Collection