xref: /aosp_15_r20/system/apex/apexer/Android.bp (revision 33f3758387333dbd2962d7edbd98681940d895da)
1// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package {
16    default_applicable_licenses: ["Android-Apache-2.0"],
17}
18
19apexer_tools = [
20    "aapt2",
21    "avbtool",
22    "conv_apex_manifest",
23    "e2fsdroid",
24    "mke2fs",
25    "resize2fs",
26    "sefcontext_compile",
27    "zipalign",
28    "make_f2fs",
29    "sload_f2fs",
30    "make_erofs",
31    // TODO(b/124476339) apex doesn't follow 'required' dependencies so we need to include this
32    // manually for 'avbtool'.
33    "fec",
34]
35
36// TODO(b/157110982): cannot specify "required" dependency on go binary
37apexer_go_tools = [
38    "merge_zips",
39    "soong_zip",
40]
41
42python_library_host {
43    name: "apex_manifest",
44    srcs: [
45        "apex_manifest.py",
46    ],
47    libs: [
48        "apex_manifest_proto",
49    ],
50}
51
52// This is a hack to move mke2fs_conf into the current folder for bazel builds.
53// Normally bazel would keep it under a system/extras/ext4_utils/ folder.
54genrule {
55    name: "mke2fs_conf_for_apexer",
56    srcs: [":mke2fs_conf"],
57    out: ["mke2fs.conf"],
58    cmd: "cp $(in) $(out)",
59}
60
61python_binary_host {
62    name: "apexer",
63    srcs: [
64        "apexer.py",
65    ],
66    // TODO(b/157625953) mke2fs.conf can't embedded directly.
67    data: [
68        ":mke2fs_conf_for_apexer",
69    ],
70    version: {
71        py3: {
72            embedded_launcher: true,
73        },
74    },
75    libs: [
76        "apex_manifest",
77        "apex_build_info_proto",
78        "manifest_utils",
79    ],
80    required: apexer_tools,
81}
82
83python_binary_host {
84    name: "conv_apex_manifest",
85    srcs: [
86        "conv_apex_manifest.py",
87    ],
88    version: {
89        py3: {
90            embedded_launcher: true,
91        },
92    },
93    libs: [
94        "apex_manifest_proto",
95    ],
96}
97
98// TODO(b/148659029): this test can't run in TEST_MAPPING.
99python_test_host {
100    name: "apexer_test",
101    pkg_path: "apexer_test",
102    main: "apexer_test.py",
103    srcs: [
104        "apexer_test.py",
105    ],
106    data: [
107        ":apexer_test_host_tools",
108        "testdata/com.android.example.apex.avbpubkey",
109        "testdata/com.android.example.apex.pem",
110        "testdata/com.android.example.apex.pk8",
111        "testdata/com.android.example.apex.x509.pem",
112        "testdata/manifest.json",
113    ],
114    device_common_data: [
115        ":com.android.example.apex",
116        ":com.android.example-legacy.apex",
117        ":com.android.example-logging_parent.apex",
118        ":com.android.example-overridden_package_name.apex",
119    ],
120    test_suites: ["general-tests"],
121    libs: [
122        "apex_manifest",
123    ],
124    version: {
125        py3: {
126            embedded_launcher: true,
127        },
128    },
129}
130
131apexer_deps_minus_go_tools = apexer_tools + [
132    "apexer",
133    "deapexer",
134    "debugfs_static",
135    "blkid",
136    "fsck.erofs",
137]
138
139apexer_deps_tools = apexer_deps_minus_go_tools + apexer_go_tools
140
141genrule_defaults {
142    name: "apexer_test_host_tools_list",
143    tools: apexer_deps_tools + [
144        "signapk",
145    ],
146    srcs: [
147        ":current_android_jar",
148    ],
149}
150
151genrule {
152    name: "apexer_test_host_tools",
153    srcs: [
154        ":current_android_jar",
155    ],
156    out: ["apexer_test_host_tools.zip"],
157    tools: apexer_deps_tools + [
158        // To force signapk.jar generated in out/host
159        "signapk",
160        "bundletool",
161    ],
162    cmd: "HOST_OUT_BIN=$$(dirname $(location apexer)) && " +
163        "HOST_SOONG_OUT=$$(dirname $$HOST_OUT_BIN) && " +
164        "SIGNAPK_JAR=$$(find $${HOST_SOONG_OUT}/framework -name \"signapk*\") && " +
165        "BUNDLETOOL_JAR=$$(find $${HOST_SOONG_OUT}/framework -name \"bundletool*.jar\") && " +
166        "LIBCPLUSPLUS=$$(find $${HOST_SOONG_OUT}/lib64 -name \"libc++.*\") && " +
167        "LIBCONSCRYPT_OPENJDK_JNI=$$(find $${HOST_SOONG_OUT}/lib64 -name \"libconscrypt_openjdk_jni.*\") && " +
168        "BASE=$(genDir)/binary_files && " +
169        "BIN=$$BASE/bin && " +
170        "LIB=$$BASE/lib64 && " +
171        "mkdir -p $$BIN && " +
172        "mkdir -p $$LIB && " +
173        "cp $(in) $$BIN && " +
174        "cp $(location apexer) $$BIN && " +
175        "cp $(location conv_apex_manifest) $$BIN && " +
176        "cp $(location deapexer) $$BIN && " +
177        "cp $(location avbtool) $$BIN && " +
178        "cp $(location aapt2) $$BIN && " +
179        "cp $(location e2fsdroid) $$BIN && " +
180        "cp $(location make_erofs) $$BIN && " +
181        "cp $(location merge_zips) $$BIN && " +
182        "cp $(location mke2fs) $$BIN && " +
183        "cp $(location resize2fs) $$BIN && " +
184        "cp $(location sefcontext_compile) $$BIN && " +
185        "cp $(location soong_zip) $$BIN && " +
186        "cp $(location fec) $$BIN && " +
187        "cp $(location zipalign) $$BIN && " +
188        "cp $(location debugfs_static) $$BIN && " +
189        "cp $(location blkid) $$BIN && " +
190        "cp $(location fsck.erofs) $$BIN && " +
191        "cp $$SIGNAPK_JAR $$BIN && " +
192        "cp $$BUNDLETOOL_JAR $$BIN && " +
193        "cp $$LIBCPLUSPLUS $$LIB && " +
194        "cp $$LIBCONSCRYPT_OPENJDK_JNI $$LIB && " +
195        "$(location soong_zip) -C $$BASE -D $$BASE -o $(out) && " +
196        "rm -rf $$BASE",
197}
198