aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages/RuleSerializer.java
diff options
context:
space:
mode:
authorGravatar Michajlo Matijkiw <michajlo@google.com>2015-11-30 17:42:26 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-11-30 18:30:49 +0000
commit2d699e9f5570cd0a96e712bd8ab89fe36b08ad6d (patch)
treed45923d3f980843bf9dca9c74e342149286a16e1 /src/main/java/com/google/devtools/build/lib/packages/RuleSerializer.java
parent27760a6efefc64f9577ed1add120b60399203be3 (diff)
Simplify rule fingerprinting in RepositoryFunction
-- MOS_MIGRATED_REVID=108986856
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages/RuleSerializer.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/RuleSerializer.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleSerializer.java b/src/main/java/com/google/devtools/build/lib/packages/RuleSerializer.java
new file mode 100644
index 0000000000..5d49b4b420
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleSerializer.java
@@ -0,0 +1,37 @@
+// Copyright 2015 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.packages;
+
+import com.google.devtools.build.lib.query2.proto.proto2api.Build;
+
+/** Serialize a {@link Rule} as its protobuf representation. */
+public class RuleSerializer {
+
+ public static Build.Rule.Builder serializeRule(Rule rule) {
+ Build.Rule.Builder builder = Build.Rule.newBuilder();
+ builder.setName(rule.getLabel().getName());
+ builder.setRuleClass(rule.getRuleClass());
+ builder.setPublicByDefault(rule.getRuleClassObject().isPublicByDefault());
+ for (Attribute attribute : rule.getAttributes()) {
+ builder.addAttribute(
+ AttributeSerializer.getAttributeProto(
+ attribute,
+ AttributeSerializer.getAttributeValues(rule, attribute),
+ rule.isAttributeValueExplicitlySpecified(attribute),
+ /*includeGlobs=*/ true));
+ }
+ return builder;
+ }
+}
+