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        ":com.android.example.apex",
108        ":com.android.example-legacy.apex",
109        ":com.android.example-logging_parent.apex",
110        ":com.android.example-overridden_package_name.apex",
111        ":apexer_test_host_tools",
112        "testdata/com.android.example.apex.avbpubkey",
113        "testdata/com.android.example.apex.pem",
114        "testdata/com.android.example.apex.pk8",
115        "testdata/com.android.example.apex.x509.pem",
116        "testdata/manifest.json",
117    ],
118    test_suites: ["general-tests"],
119    libs: [
120        "apex_manifest",
121    ],
122    version: {
123        py3: {
124            embedded_launcher: true,
125        },
126    },
127}
128
129apexer_deps_minus_go_tools = apexer_tools + [
130    "apexer",
131    "deapexer",
132    "debugfs_static",
133    "blkid",
134    "fsck.erofs",
135]
136
137apexer_deps_tools = apexer_deps_minus_go_tools + apexer_go_tools
138
139genrule_defaults {
140    name: "apexer_test_host_tools_list",
141    tools: apexer_deps_tools + [
142        "signapk",
143    ],
144    srcs: [
145        ":current_android_jar",
146    ],
147}
148
149genrule {
150    name: "apexer_test_host_tools",
151    srcs: [
152        ":current_android_jar",
153    ],
154    out: ["apexer_test_host_tools.zip"],
155    tools: apexer_deps_tools + [
156        // To force signapk.jar generated in out/host
157        "signapk",
158        "bundletool",
159    ],
160    cmd: "HOST_OUT_BIN=$$(dirname $(location apexer)) && " +
161        "HOST_SOONG_OUT=$$(dirname $$HOST_OUT_BIN) && " +
162        "SIGNAPK_JAR=$$(find $${HOST_SOONG_OUT}/framework -name \"signapk*\") && " +
163        "BUNDLETOOL_JAR=$$(find $${HOST_SOONG_OUT}/framework -name \"bundletool*.jar\") && " +
164        "LIBCPLUSPLUS=$$(find $${HOST_SOONG_OUT}/lib64 -name \"libc++.*\") && " +
165        "LIBCONSCRYPT_OPENJDK_JNI=$$(find $${HOST_SOONG_OUT}/lib64 -name \"libconscrypt_openjdk_jni.*\") && " +
166        "BASE=$(genDir)/binary_files && " +
167        "BIN=$$BASE/bin && " +
168        "LIB=$$BASE/lib64 && " +
169        "mkdir -p $$BIN && " +
170        "mkdir -p $$LIB && " +
171        "cp $(in) $$BIN && " +
172        "cp $(location apexer) $$BIN && " +
173        "cp $(location conv_apex_manifest) $$BIN && " +
174        "cp $(location deapexer) $$BIN && " +
175        "cp $(location avbtool) $$BIN && " +
176        "cp $(location aapt2) $$BIN && " +
177        "cp $(location e2fsdroid) $$BIN && " +
178        "cp $(location make_erofs) $$BIN && " +
179        "cp $(location merge_zips) $$BIN && " +
180        "cp $(location mke2fs) $$BIN && " +
181        "cp $(location resize2fs) $$BIN && " +
182        "cp $(location sefcontext_compile) $$BIN && " +
183        "cp $(location soong_zip) $$BIN && " +
184        "cp $(location fec) $$BIN && " +
185        "cp $(location zipalign) $$BIN && " +
186        "cp $(location debugfs_static) $$BIN && " +
187        "cp $(location blkid) $$BIN && " +
188        "cp $(location fsck.erofs) $$BIN && " +
189        "cp $$SIGNAPK_JAR $$BIN && " +
190        "cp $$BUNDLETOOL_JAR $$BIN && " +
191        "cp $$LIBCPLUSPLUS $$LIB && " +
192        "cp $$LIBCONSCRYPT_OPENJDK_JNI $$LIB && " +
193        "$(location soong_zip) -C $$BASE -D $$BASE -o $(out) && " +
194        "rm -rf $$BASE",
195}
196