def main(): args = parser.parse_args() data = model.Model(open(args.input).read()) codegen.Template( data, args.output, 'structured_events.h', file_template=templates.HEADER_FILE_TEMPLATE, project_template=templates.HEADER_PROJECT_TEMPLATE, event_template=templates.HEADER_EVENT_TEMPLATE, metric_template=templates.HEADER_METRIC_TEMPLATE).write_file() codegen.Template( data, args.output, 'structured_events.cc', file_template=templates.IMPL_FILE_TEMPLATE, project_template=templates.IMPL_PROJECT_TEMPLATE, event_template=templates.IMPL_EVENT_TEMPLATE, metric_template=templates.IMPL_METRIC_TEMPLATE).write_file() return 0
HEADER = codegen.Template(basename="ukm_builders.h", file_template=""" // Generated from gen_builders.py. DO NOT EDIT! // source: ukm.xml #ifndef {file.guard_path} #define {file.guard_path} #include <cstdint> #include "services/metrics/public/cpp/ukm_entry_builder_base.h" namespace ukm {{ namespace builders {{ {event_code} }} // namespace builders }} // namespace ukm #endif // {file.guard_path} """, event_template=""" class {event.name} : public ::ukm::internal::UkmEntryBuilderBase {{ public: {event.name}(ukm::SourceId source_id); ~{event.name}() override; static const char kEntryName[]; static const uint64_t kEntryNameHash = UINT64_C({event.hash}); {metric_code} }}; """, metric_template=""" static const char k{metric.name}Name[]; static const uint64_t k{metric.name}NameHash = UINT64_C({metric.hash}); {event.name}& Set{metric.name}(int64_t value); """)
import codegen HEADER = codegen.Template(basename="ukm_decode.h", file_template=""" // Generated from gen_builders.py. DO NOT EDIT! // source: ukm.xml #ifndef {file.guard_path} #define {file.guard_path} #include <cstdint> #include <map> namespace ukm {{ namespace builders {{ {event_code} typedef std::map<uint64_t, const char*> DecodeMap; DecodeMap CreateDecodeMap(); }} // namespace builders }} // namespace ukm #endif // {file.guard_path} """, event_template="", metric_template="") IMPL = codegen.Template(basename="ukm_decode.cc", file_template="""
{event.name}(); ~{event.name}() override; static constexpr uint64_t kEventNameHash = UINT64_C({event.hash});\ {metric_code} }};\ """ HEADER_METRIC_TEMPLATE = """ static constexpr uint64_t k{metric.name}NameHash = UINT64_C({metric.hash}); {event.name}& Set{metric.name}(const {metric.type} value);\ """ HEADER = codegen.Template(basename="structured_events.h", file_template=HEADER_FILE_TEMPLATE, event_template=HEADER_EVENT_TEMPLATE, metric_template=HEADER_METRIC_TEMPLATE) ###### # IMPL ###### IMPL_FILE_TEMPLATE = """\ // Generated from gen_events.py. DO NOT EDIT! // source: structured.xml #include "{file.dir_path}/structured_events.h" namespace metrics {{ namespace structured {{ namespace events {{\