metrics_atoms_protoc_plugin: Build on Android am: 8007781374 am: 754fb6fbca

Original change: https://android-review.googlesource.com/c/trusty/host/common/+/2757188

Change-Id: Id23df05acfc842e3cfe8bc5156725f5d1784556c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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 454c7e6..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,
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