Skip to content

Commit

Permalink
For Kotlin only generate GleanBuildInfo.kt when explicitly requeste…
Browse files Browse the repository at this point in the history
…d (with `with_buildinfo=true`)
  • Loading branch information
badboy committed May 28, 2021
1 parent bae988e commit 27d290f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- For Kotlin only generate `GleanBuildInfo.kt` when explicitly requested (with `with_buildinfo=true`)

## 3.3.2 (2021-05-18)

- Fix another bug in the Swift code generation when generating extra keys ([#334](https://github.com/mozilla/glean_parser/pull/334))
Expand Down
24 changes: 14 additions & 10 deletions glean_parser/kotlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,30 +236,34 @@ def output_kotlin(
- `glean_namespace`: The package namespace of the glean library itself.
This is where glean objects will be imported from in the generated
code.
- `with_buildinfo`: If "true" a `GleanBuildInfo.kt` file is generated.
Otherwise generation of that file is skipped.
"""
if options is None:
options = {}

namespace = options.get("namespace", "GleanMetrics")
glean_namespace = options.get("glean_namespace", "mozilla.components.service.glean")
namespace_package = namespace[: namespace.rfind(".")]
with_buildinfo = options.get("with_buildinfo", "false").lower() == "true"

# Write out the special "build info" object
template = util.get_jinja2_template(
"kotlin.buildinfo.jinja2",
)

# This filename needs to start with "Glean" so it can never clash with a
# metric category
with (output_dir / "GleanBuildInfo.kt").open("w", encoding="utf-8") as fd:
fd.write(
template.render(
namespace=namespace,
namespace_package=namespace_package,
glean_namespace=glean_namespace,
if with_buildinfo:
# This filename needs to start with "Glean" so it can never clash with a
# metric category
with (output_dir / "GleanBuildInfo.kt").open("w", encoding="utf-8") as fd:
fd.write(
template.render(
namespace=namespace,
namespace_package=namespace_package,
glean_namespace=glean_namespace,
)
)
)
fd.write("\n")
fd.write("\n")

template = util.get_jinja2_template(
"kotlin.jinja2",
Expand Down

0 comments on commit 27d290f

Please sign in to comment.