Bug 1686668 [wpt PR 27185] - Update wpt metadata, a=testonly
[gecko.git] / dom / base / gen-usecounters.py
blob0a491319ec527e06a3a85cd100d0beccf354bfcf
1 #!/usr/bin/env python
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from __future__ import print_function
9 import json
10 import os
11 import sys
13 sys.path.append(os.path.dirname(__file__))
15 import usecounters
17 AUTOGENERATED_WARNING_COMMENT = (
18 "/* THIS FILE IS AUTOGENERATED BY gen-usecounters.py - DO NOT EDIT */"
22 def generate_list(f, counters):
23 def print_optional_macro_declare(name):
24 print(
25 """
26 #ifndef %(name)s
27 #define %(name)s(interface_, name_) // nothing
28 #define DEFINED_%(name)s
29 #endif
30 """
31 % {"name": name},
32 file=f,
35 def print_optional_macro_undeclare(name):
36 print(
37 """
38 #ifdef DEFINED_%(name)s
39 #undef DEFINED_%(name)s
40 #undef %(name)s
41 #endif
42 """
43 % {"name": name},
44 file=f,
47 print(AUTOGENERATED_WARNING_COMMENT, file=f)
49 print_optional_macro_declare("USE_COUNTER_DOM_METHOD")
50 print_optional_macro_declare("USE_COUNTER_DOM_ATTRIBUTE")
51 print_optional_macro_declare("USE_COUNTER_CUSTOM")
53 for counter in counters:
54 if counter["type"] == "method":
55 print(
56 "USE_COUNTER_DOM_METHOD(%s, %s)"
57 % (counter["interface_name"], counter["method_name"]),
58 file=f,
60 elif counter["type"] == "attribute":
61 print(
62 "USE_COUNTER_DOM_ATTRIBUTE(%s, %s)"
63 % (counter["interface_name"], counter["attribute_name"]),
64 file=f,
66 elif counter["type"] == "custom":
67 desc = counter["desc"].replace("\\", r"\\").replace('"', r"\"")
68 print('USE_COUNTER_CUSTOM(%s, "%s")' % (counter["name"], desc), file=f)
70 print_optional_macro_undeclare("USE_COUNTER_DOM_METHOD")
71 print_optional_macro_undeclare("USE_COUNTER_DOM_ATTRIBUTE")
72 print_optional_macro_undeclare("USE_COUNTER_CUSTOM")
75 def use_counter_list(output_header, conf_filename):
76 counters = usecounters.read_conf(conf_filename)
77 generate_list(output_header, counters)