Snap for 11463929 from 5e6f46b0980d6f673dddb039aced816db057578b to 24D1-release
Change-Id: I9888b4af1eb72e085e7bccc54eb9f213f79b46c5
diff --git a/scripts/metrics_atoms_protoc_plugin/Android.bp b/scripts/metrics_atoms_protoc_plugin/Android.bp
new file mode 100644
index 0000000..9ef1775
--- /dev/null
+++ b/scripts/metrics_atoms_protoc_plugin/Android.bp
@@ -0,0 +1,36 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+python_binary_host {
+ name: "trusty_metrics_atoms_protoc_plugin",
+ main: "metrics_atoms_protoc_plugin.py",
+ srcs: ["metrics_atoms_protoc_plugin.py"],
+ data: [
+ "templates_package/templates/metrics_atoms.c.j2",
+ "templates_package/templates/metrics_atoms.h.j2",
+ ],
+ version: {
+ py3: {
+ embedded_launcher: true,
+ },
+ },
+ libs: [
+ "libprotobuf-python",
+ "py-jinja",
+ ],
+}
diff --git a/scripts/metrics_atoms_protoc_plugin/metrics_atoms_protoc_plugin.py b/scripts/metrics_atoms_protoc_plugin/metrics_atoms_protoc_plugin.py
index 42cdd92..43e229d 100755
--- a/scripts/metrics_atoms_protoc_plugin/metrics_atoms_protoc_plugin.py
+++ b/scripts/metrics_atoms_protoc_plugin/metrics_atoms_protoc_plugin.py
@@ -60,14 +60,11 @@
from google.protobuf.descriptor_pb2 import FileDescriptorProto
from google.protobuf.descriptor_pb2 import DescriptorProto
from google.protobuf.descriptor_pb2 import FieldDescriptorProto
-from jinja2 import FileSystemLoader, Environment
+from jinja2 import Environment, PackageLoader
DEBUG_READ_PB = False
-SCRIPT_DIR = Path(__file__).parent
-ROOT_DIR = SCRIPT_DIR.parents[4]
-
-jinja_template_loader = FileSystemLoader(searchpath=SCRIPT_DIR / "templates")
+jinja_template_loader = PackageLoader("templates_package")
jinja_template_env = Environment(
loader=jinja_template_loader,
trim_blocks=True,
@@ -344,11 +341,11 @@
]
proto_name = Path(proto_file.name).stem
for item in [
- dict(tpl="metrics_atoms.c.j2", ext='c'),
- dict(tpl="metrics_atoms.h.j2", ext='h')
+ {"tpl":"metrics_atoms.c.j2", "ext":'c'},
+ {"tpl":"metrics_atoms.h.j2", "ext":'h'},
]:
tm = jinja_template_env.get_template(item["tpl"])
- tm_env = dict(env=VendorAtomEnv)
+ tm_env = {"env":VendorAtomEnv}
rendered = tm.render(**tm_env)
file = response.file.add()
file_path = pkg.split('/')
diff --git a/scripts/metrics_atoms_protoc_plugin/templates/metrics_atoms.c.j2 b/scripts/metrics_atoms_protoc_plugin/templates_package/templates/metrics_atoms.c.j2
similarity index 100%
rename from scripts/metrics_atoms_protoc_plugin/templates/metrics_atoms.c.j2
rename to scripts/metrics_atoms_protoc_plugin/templates_package/templates/metrics_atoms.c.j2
diff --git a/scripts/metrics_atoms_protoc_plugin/templates/metrics_atoms.h.j2 b/scripts/metrics_atoms_protoc_plugin/templates_package/templates/metrics_atoms.h.j2
similarity index 100%
rename from scripts/metrics_atoms_protoc_plugin/templates/metrics_atoms.h.j2
rename to scripts/metrics_atoms_protoc_plugin/templates_package/templates/metrics_atoms.h.j2