Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Unified Diff: Source/build/scripts/make_use_counter.py

Issue 729393002: Auto generate UseCounter::Feature enum from an .in file (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/build/scripts/make_use_counter.py
diff --git a/Source/build/scripts/make_use_counter.py b/Source/build/scripts/make_use_counter.py
new file mode 100755
index 0000000000000000000000000000000000000000..35de71e7b3295537fa657a854d8910c21e30e3ed
--- /dev/null
+++ b/Source/build/scripts/make_use_counter.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import media_feature_symbol
+import in_generator
+import template_expander
+import name_utilities
+import sys
+
+
+feature_values = set()
+
+
+def unique_value(value, feature):
+ global feature_values
+ if not value or type(value) is bool:
haraken 2014/11/24 09:38:49 Just help me understand: What is the 'type(value)
+ print "'%s' values isn't defined, please define it!" % feature
+ exit(1)
+ if value in feature_values:
+ print "'%s' value is already defined, please change it!" % feature
+ exit(1)
+ feature_values.add(value)
+ return value
+
+
+class MakeUseCounterWriter(in_generator.Writer):
+ defaults = {
+ 'value': None,
+ }
+ filters = {
+ 'unique_value': unique_value,
+ }
+ default_parameters = {
+ 'value': '',
+ }
+
+ def __init__(self, in_file_path):
+ super(MakeUseCounterWriter, self).__init__(in_file_path)
+
Timothy Loh 2014/11/24 11:02:40 The whole unique_value thing is a bit awkward, why
+ self._outputs = {
+ ('UseCounterGenerated.h'): self.generate_header,
Timothy Loh 2014/11/24 11:02:40 Unneeded brackets here
+ }
+ self._template_context = {
Timothy Loh 2014/11/24 11:02:40 This dict makes more sense to just have inline in
+ 'features': self.in_file.name_dictionaries,
+ }
+
+ @template_expander.use_jinja('UseCounterGenerated.h.tmpl', filters=filters)
+ def generate_header(self):
+ return self._template_context
+
+if __name__ == '__main__':
+ in_generator.Maker(MakeUseCounterWriter).main(sys.argv)

Powered by Google App Engine
This is Rietveld 408576698