Commit d2f2dad4 authored by Asanka Herath's avatar Asanka Herath Committed by Commit Bot

[ukm-builders] constexprs need definitions.

Until C++17 a static constexpr member variable needs a definition.

Without this, kEntryNameHash members and similar metrics name hashes
can't be odr-used (ill-defined).

So now generated UKM builders .cc files will go from (only modified
snippet shown for a sample event):

    const char Identifiability::kEntryName[] = "Identifiability";

to:

    const char Identifiability::kEntryName[] = "Identifiability";
    const uint64_t kEntryNameHash;

And similarly for metrics hashes.

While we are here, this CL cleans up the include header so that it
doesn't include a double //.

I.e. This:

    #include "services/metrics/public/cpp//ukm_builders.h"

Becomes this:

    #include "services/metrics/public/cpp/ukm_builders.h"

Bug: 973801
Change-Id: Icfd234ef953f2cefee5376803be266a2321df020
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2203767Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Commit-Queue: Asanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770780}
parent c15135e1
......@@ -48,13 +48,12 @@ metric_template="""
{event.name}& Set{metric.name}(int64_t value);
""")
IMPL = codegen.Template(
basename="ukm_builders.cc",
file_template="""
IMPL = codegen.Template(basename="ukm_builders.cc",
file_template="""
// Generated from gen_builders.py. DO NOT EDIT!
// source: ukm.xml
#include "{file.dir_path}/ukm_builders.h"
#include "{file.dir_path}ukm_builders.h"
namespace ukm {{
namespace builders {{
......@@ -64,8 +63,9 @@ namespace builders {{
}} // namespace builders
}} // namespace ukm
""",
event_template="""
event_template="""
const char {event.name}::kEntryName[] = "{event.raw_name}";
const uint64_t {event.name}::kEntryNameHash;
{event.name}::{event.name}(ukm::SourceId source_id) :
::ukm::internal::UkmEntryBuilderBase(source_id, kEntryNameHash) {{
......@@ -79,8 +79,9 @@ const char {event.name}::kEntryName[] = "{event.raw_name}";
{metric_code}
""",
metric_template="""
metric_template="""
const char {event.name}::k{metric.name}Name[] = "{metric.raw_name}";
const uint64_t {event.name}::k{metric.name}NameHash;
{event.name}& {event.name}::Set{metric.name}(int64_t value) {{
SetMetricInternal(k{metric.name}NameHash, value);
......
......@@ -71,6 +71,7 @@ class {name} final : public ::ukm::internal::UkmEntryBuilderBase {{
self.assertIn(
"""
const char {name}::kEntryName[] = "{rawName}";
const uint64_t {name}::kEntryNameHash;
{name}::{name}(ukm::SourceId source_id) :
::ukm::internal::UkmEntryBuilderBase(source_id, kEntryNameHash) {{
......@@ -84,6 +85,7 @@ const char {name}::kEntryName[] = "{rawName}";
self.assertIn(
"""
const char {eventName}::k{metricName}Name[] = "{metricRawName}";
const uint64_t {eventName}::k{metricName}NameHash;
{eventName}& {eventName}::Set{metricName}(int64_t value) {{
SetMetricInternal(k{metricName}NameHash, value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment