Backed out changeset f594e6f00208 (bug 1940883) for causing crashes in bug 1941164.
[gecko.git] / toolkit / components / telemetry / build_scripts / gen_scalar_enum.py
blob321cd047d749c31fe1ae18937bdbef81336ccd99
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 # Write out a C++ enum definition whose members are the names of
6 # scalar types.
8 # The scalars are defined in files provided as command-line arguments.
10 import sys
12 import buildconfig
13 from mozparsers import parse_scalars
14 from mozparsers.shared_telemetry_utils import ParserError
16 banner = """/* This file is auto-generated, see gen_scalar_enum.py. */
17 """
19 file_header = """\
20 #ifndef mozilla_TelemetryScalarEnums_h
21 #define mozilla_TelemetryScalarEnums_h
22 namespace mozilla {
23 namespace Telemetry {
24 enum class ScalarID : uint32_t {\
25 """
27 file_footer = """\
29 } // namespace mozilla
30 } // namespace Telemetry
31 #endif // mozilla_TelemetryScalarEnums_h
32 """
35 def main(output, *filenames):
36 # Load the scalars first.
37 scalars = []
38 for filename in filenames:
39 try:
40 batch = parse_scalars.load_scalars(filename)
41 scalars.extend(batch)
42 except ParserError as ex:
43 print("\nError processing %s:\n%s\n" % (filename, str(ex)), file=sys.stderr)
44 sys.exit(1)
46 # Write the enum file.
47 print(banner, file=output)
48 print(file_header, file=output)
50 for s in scalars:
51 if s.record_on_os(buildconfig.substs["OS_TARGET"]):
52 print(" %s," % s.enum_label, file=output)
54 print(" ScalarCount,", file=output)
56 print(file_footer, file=output)
59 if __name__ == "__main__":
60 main(sys.stdout, *sys.argv[1:])