File: metrics_header_names.py

package info (click to toggle)
firefox-esr 140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,539,276 kB
  • sloc: cpp: 7,381,286; javascript: 6,388,710; ansic: 3,710,139; python: 1,393,780; xml: 628,165; asm: 426,918; java: 184,004; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (47 lines) | stat: -rw-r--r-- 2,051 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This file should only contain code that will be acceptable in the context of
# a moz.build sandbox.


# This function turns a metrics.yaml path (eg. "dom/push/metrics.yaml") into a
# header file name (eg. "DomPushMetrics").
# Used by both moz.build and build_scripts/glean_parser_ext/run_glean_parser.py
def convert_yaml_path_to_header_name(filepath):
    # The general rule is to remove the yaml extension then add an
    # upper case letter for each folder separator, - or _ character .
    filepath = filepath[: -(len(".yaml"))]
    path_components = filepath.replace("-", "_").split("/")

    # There are some exceptions to make some names shorter nicer:
    #  NameBaseMetrics -> NameMetrics
    #  NameBaseSomethingMetrics -> NameSomethingMetrics
    if path_components[1] == "base":
        path_components.pop(1)
    # NameComponentsSomethingMetrics -> NameSomethingMetrics
    # BrowserComponentsSomethingMetrics -> SomethingMetrics
    # ToolkitComponentsSomethingMetrics -> SomethingMetrics
    if len(path_components) > 3 and path_components[1] == "components":
        path_components.pop(1)
        if path_components[0] in ["browser", "toolkit"]:
            path_components.pop(0)

    # ModulesSomethingMetrics -> SomethingMetrics
    if len(path_components) > 2 and path_components[0] == "modules":
        path_components.pop(0)

    # MobileSharedModulesGeckoviewMetrics -> GeckoviewMetrics
    if filepath.startswith("mobile/shared/modules/") and len(path_components) > 4:
        path_components = ["geckoview", "metrics"]

    path_components = "_".join(path_components).split("_")
    return "".join(
        [
            path_component[0].upper() + path_component[1:]
            for path_component in path_components
        ]
    )