blob: 4cbdec8d3720c4155d97f64c34574e8268569b3b [file] [log] [blame]
Inseob Kimb462b9c2020-08-11 15:38:20 +09001#!/usr/bin/env python3
Jae Shinca625dd2017-11-30 15:58:00 +09002#
3# Copyright (C) 2017 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
Jae Shin94075212018-06-14 14:54:34 +090018import argparse
Justin Yun9e48f542023-04-17 12:23:01 +090019from collections import defaultdict
Jae Shin9bc4fd02017-12-26 13:07:18 +090020import glob
Inseob Kim748307e2019-06-12 10:45:48 +090021import json
Jae Shin94075212018-06-14 14:54:34 +090022import logging
Jae Shinca625dd2017-11-30 15:58:00 +090023import os
24import sys
25
Justin Yun3e789772021-11-22 12:45:23 +090026import collect_licenses
Jae Shin5233fe12017-12-18 22:29:48 +090027import utils
28
Jae Shinca625dd2017-11-30 15:58:00 +090029
30class GenBuildFile(object):
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -080031 """Generates Android.bp for VNDK snapshot.
Jae Shinca625dd2017-11-30 15:58:00 +090032
Jae Shin4db81a52017-12-29 13:24:54 +090033 VNDK snapshot directory structure under prebuilts/vndk/v{version}:
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -080034 Android.bp
Jae Shinaf0c0032018-06-21 11:54:05 +090035 {SNAPSHOT_ARCH}/
Jae Shin4db81a52017-12-29 13:24:54 +090036 Android.bp
37 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
38 shared/
39 vndk-core/
40 (VNDK-core libraries, e.g. libbinder.so)
41 vndk-sp/
42 (VNDK-SP libraries, e.g. libc++.so)
43 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
44 shared/
45 vndk-core/
46 (VNDK-core libraries, e.g. libbinder.so)
47 vndk-sp/
48 (VNDK-SP libraries, e.g. libc++.so)
Jae Shinaf0c0032018-06-21 11:54:05 +090049 binder32/
50 (This directory is newly introduced in v28 (Android P) to hold
51 prebuilts built for 32-bit binder interface.)
52 Android.bp
53 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
54 ...
Jae Shin4db81a52017-12-29 13:24:54 +090055 configs/
56 (various *.txt configuration files, e.g. ld.config.*.txt)
Jae Shinaf0c0032018-06-21 11:54:05 +090057 ... (other {SNAPSHOT_ARCH}/ directories)
Jae Shin4db81a52017-12-29 13:24:54 +090058 common/
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -080059 Android.bp
Jae Shin4db81a52017-12-29 13:24:54 +090060 NOTICE_FILES/
61 (license files, e.g. libfoo.so.txt)
62 """
Jae Shinca625dd2017-11-30 15:58:00 +090063 INDENT = ' '
Jae Shin4db81a52017-12-29 13:24:54 +090064 ETC_MODULES = [
Kiyoung Kimb04fe602019-10-07 13:42:57 +090065 'llndk.libraries.txt',
66 'vndksp.libraries.txt',
67 'vndkcore.libraries.txt',
Justin Yunba2a7e12020-11-27 20:14:28 +090068 'vndkprivate.libraries.txt',
69 'vndkproduct.libraries.txt',
Jae Shin4db81a52017-12-29 13:24:54 +090070 ]
Jae Shinca625dd2017-11-30 15:58:00 +090071
Jae Shinca625dd2017-11-30 15:58:00 +090072 def __init__(self, install_dir, vndk_version):
73 """GenBuildFile constructor.
74
75 Args:
76 install_dir: string, absolute path to the prebuilts/vndk/v{version}
77 directory where the build files will be generated.
Justin Yunef95d092020-11-30 10:19:43 +090078 vndk_version: int, VNDK snapshot version (e.g. 30)
Jae Shinca625dd2017-11-30 15:58:00 +090079 """
80 self._install_dir = install_dir
81 self._vndk_version = vndk_version
Jae Shin4db81a52017-12-29 13:24:54 +090082 self._etc_paths = self._get_etc_paths()
Jae Shinaf0c0032018-06-21 11:54:05 +090083 self._snapshot_archs = utils.get_snapshot_archs(install_dir)
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -080084 self._root_bpfile = os.path.join(install_dir, utils.ROOT_BP_PATH)
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -080085 self._common_bpfile = os.path.join(install_dir, utils.COMMON_BP_PATH)
Bill Peckhamdba5e0f2021-05-12 17:21:17 -070086 self._llndk = self._parse_lib_list(
87 os.path.basename(self._etc_paths['llndk.libraries.txt']))
Kiyoung Kimb04fe602019-10-07 13:42:57 +090088 self._vndk_core = self._parse_lib_list(
89 os.path.basename(self._etc_paths['vndkcore.libraries.txt']))
Jae Shin4db81a52017-12-29 13:24:54 +090090 self._vndk_sp = self._parse_lib_list(
91 os.path.basename(self._etc_paths['vndksp.libraries.txt']))
Kiyoung Kimb04fe602019-10-07 13:42:57 +090092 self._vndk_private = self._parse_lib_list(
93 os.path.basename(self._etc_paths['vndkprivate.libraries.txt']))
Justin Yunba2a7e12020-11-27 20:14:28 +090094 self._vndk_product = self._parse_lib_list(
95 os.path.basename(self._etc_paths['vndkproduct.libraries.txt']))
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -080096 self._modules_with_notice = self._get_modules_with_notice()
Justin Yun9e48f542023-04-17 12:23:01 +090097 self._license_in_json = not self._modules_with_notice
98 self._license_kinds_map = defaultdict(set)
99 self._license_texts_map = defaultdict(set)
100 self.modules_with_restricted_lic = set()
Jae Shinca625dd2017-11-30 15:58:00 +0900101
Jae Shin4db81a52017-12-29 13:24:54 +0900102 def _get_etc_paths(self):
103 """Returns a map of relative file paths for each ETC module."""
104
105 etc_paths = dict()
106 for etc_module in self.ETC_MODULES:
107 etc_pattern = '{}*'.format(os.path.splitext(etc_module)[0])
Inseob Kim04c21ae2019-10-23 15:48:31 +0900108 globbed = glob.glob(
Jae Shin4db81a52017-12-29 13:24:54 +0900109 os.path.join(self._install_dir, utils.CONFIG_DIR_PATH_PATTERN,
Inseob Kim04c21ae2019-10-23 15:48:31 +0900110 etc_pattern))
111 if len(globbed) > 0:
112 rel_etc_path = globbed[0].replace(self._install_dir, '')[1:]
113 etc_paths[etc_module] = rel_etc_path
Jae Shin4db81a52017-12-29 13:24:54 +0900114 return etc_paths
115
Jae Shinca625dd2017-11-30 15:58:00 +0900116 def _parse_lib_list(self, txt_filename):
Jae Shinaf0c0032018-06-21 11:54:05 +0900117 """Returns a map of VNDK library lists per VNDK snapshot arch.
Jae Shinca625dd2017-11-30 15:58:00 +0900118
119 Args:
Jae Shin4db81a52017-12-29 13:24:54 +0900120 txt_filename: string, name of snapshot config file
Jae Shinca625dd2017-11-30 15:58:00 +0900121
Jae Shin4db81a52017-12-29 13:24:54 +0900122 Returns:
123 dict, e.g. {'arm64': ['libfoo.so', 'libbar.so', ...], ...}
124 """
125 lib_map = dict()
126 for txt_path in utils.find(self._install_dir, [txt_filename]):
Jae Shinaf0c0032018-06-21 11:54:05 +0900127 arch = utils.snapshot_arch_from_path(txt_path)
Jae Shin4db81a52017-12-29 13:24:54 +0900128 abs_path_of_txt = os.path.join(self._install_dir, txt_path)
129 with open(abs_path_of_txt, 'r') as f:
Jae Shinaf0c0032018-06-21 11:54:05 +0900130 lib_map[arch] = f.read().strip().split('\n')
Justin Yunba2a7e12020-11-27 20:14:28 +0900131 if lib_map[arch] == ['']:
132 lib_map[arch].clear()
Jae Shin4db81a52017-12-29 13:24:54 +0900133 return lib_map
Jae Shinca625dd2017-11-30 15:58:00 +0900134
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800135 def _get_modules_with_notice(self):
136 """Returns a list of modules that have associated notice files. """
137 notice_paths = glob.glob(
138 os.path.join(self._install_dir, utils.NOTICE_FILES_DIR_PATH,
139 '*.txt'))
Yo Chiangf2480f82020-06-10 14:52:37 +0800140 return sorted(os.path.splitext(os.path.basename(p))[0] for p in notice_paths)
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800141
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800142 def generate_root_android_bp(self):
143 """Autogenerates Android.bp."""
Jae Shinca625dd2017-11-30 15:58:00 +0900144
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800145 logging.info('Generating Android.bp for snapshot v{}'.format(
Jae Shinaf0c0032018-06-21 11:54:05 +0900146 self._vndk_version))
Justin Yun1aad56c2020-11-30 10:24:58 +0900147 prebuilt_buildrules = []
Jae Shin4db81a52017-12-29 13:24:54 +0900148 for prebuilt in self.ETC_MODULES:
Justin Yun1aad56c2020-11-30 10:24:58 +0900149 prebuilt_buildrules.append(self._gen_etc_prebuilt(prebuilt))
150
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800151 with open(self._root_bpfile, 'w') as bpfile:
152 bpfile.write(self._gen_autogen_msg('/'))
153 bpfile.write('\n')
Justin Yunf073b742021-11-10 13:28:24 +0900154 bpfile.write(self._gen_license_package())
155 bpfile.write('\n')
156 bpfile.write(self._gen_license())
157 bpfile.write('\n')
Justin Yun1aad56c2020-11-30 10:24:58 +0900158 bpfile.write('\n'.join(prebuilt_buildrules))
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800159 bpfile.write('\n')
Jae Shinca625dd2017-11-30 15:58:00 +0900160
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800161 logging.info('Successfully generated {}'.format(self._root_bpfile))
Jae Shinaf0c0032018-06-21 11:54:05 +0900162
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800163 def generate_common_android_bp(self):
164 """Autogenerates common/Android.bp."""
165
166 logging.info('Generating common/Android.bp for snapshot v{}'.format(
167 self._vndk_version))
168 with open(self._common_bpfile, 'w') as bpfile:
169 bpfile.write(self._gen_autogen_msg('/'))
Justin Yunf073b742021-11-10 13:28:24 +0900170 bpfile.write('\n')
171 bpfile.write(self._gen_license_package())
Justin Yun9e48f542023-04-17 12:23:01 +0900172 if self._license_in_json:
173 for name in self._license_kinds_map:
174 bpfile.write('\n')
175 bpfile.write(self._gen_notice_license(name))
176 else:
177 for module in self._modules_with_notice:
178 bpfile.write('\n')
179 bpfile.write(self._gen_notice_license(module))
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800180
Jae Shinca625dd2017-11-30 15:58:00 +0900181 def generate_android_bp(self):
Jae Shinaf0c0032018-06-21 11:54:05 +0900182 """Autogenerates Android.bp."""
Jae Shinca625dd2017-11-30 15:58:00 +0900183
Jae Shinaf0c0032018-06-21 11:54:05 +0900184 def gen_for_variant(arch, is_binder32=False):
185 """Generates Android.bp file for specified VNDK snapshot variant.
186
187 A VNDK snapshot variant is defined by the TARGET_ARCH and binder
188 bitness. Example snapshot variants:
189 vndk_v{ver}_arm: {arch: arm, binder: 64-bit}
190 vndk_v{ver}_arm_binder32: {arch: arm, binder: 32-bit}
191
192 Args:
193 arch: string, VNDK snapshot arch (e.g. 'arm64')
194 is_binder32: bool, True if binder interface is 32-bit
195 """
196 binder32_suffix = '_{}'.format(
197 utils.BINDER32) if is_binder32 else ''
198 logging.info('Generating Android.bp for vndk_v{}_{}{}'.format(
199 self._vndk_version, arch, binder32_suffix))
200
Inseob Kim04c21ae2019-10-23 15:48:31 +0900201 src_root = os.path.join(self._install_dir, arch)
202 module_names_txt = os.path.join(
203 src_root, "configs", "module_names.txt")
204 module_names = dict()
205 try:
206 with open(module_names_txt, 'r') as f:
207 # Remove empty lines from module_names_txt
208 module_list = filter(None, f.read().split('\n'))
209 for module in module_list:
210 lib, name = module.split(' ')
211 module_names[lib] = name
212 except IOError:
213 # If module_names.txt doesn't exist, ignore it and parse
214 # module names out from .so filenames. (old snapshot)
215 pass
216
Jae Shinaf0c0032018-06-21 11:54:05 +0900217 variant_subpath = arch
Justin Yunef95d092020-11-30 10:19:43 +0900218 if is_binder32:
Jae Shinaf0c0032018-06-21 11:54:05 +0900219 variant_subpath = os.path.join(arch, utils.BINDER32)
Inseob Kim748307e2019-06-12 10:45:48 +0900220 variant_path = os.path.join(self._install_dir, variant_subpath)
221 bpfile_path = os.path.join(variant_path, 'Android.bp')
Jae Shinaf0c0032018-06-21 11:54:05 +0900222
Jae Shin4db81a52017-12-29 13:24:54 +0900223 vndk_core_buildrules = self._gen_vndk_shared_prebuilts(
Inseob Kim04c21ae2019-10-23 15:48:31 +0900224 self._vndk_core[arch],
225 arch,
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700226 is_llndk=False,
Inseob Kim04c21ae2019-10-23 15:48:31 +0900227 is_vndk_sp=False,
228 is_binder32=is_binder32,
229 module_names=module_names)
Jae Shin4db81a52017-12-29 13:24:54 +0900230 vndk_sp_buildrules = self._gen_vndk_shared_prebuilts(
Jae Shinaf0c0032018-06-21 11:54:05 +0900231 self._vndk_sp[arch],
232 arch,
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700233 is_llndk=False,
Jae Shinaf0c0032018-06-21 11:54:05 +0900234 is_vndk_sp=True,
Inseob Kim04c21ae2019-10-23 15:48:31 +0900235 is_binder32=is_binder32,
236 module_names=module_names)
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700237 include_llndk = self._vndk_version > 30
238 if include_llndk:
239 llndk_buildrules = self._gen_vndk_shared_prebuilts(
240 self._llndk[arch],
241 arch,
242 is_llndk=True,
243 is_vndk_sp=False,
244 is_binder32=is_binder32,
245 module_names=module_names)
Jae Shinca625dd2017-11-30 15:58:00 +0900246
Jae Shinaf0c0032018-06-21 11:54:05 +0900247 with open(bpfile_path, 'w') as bpfile:
Jae Shin4db81a52017-12-29 13:24:54 +0900248 bpfile.write(self._gen_autogen_msg('/'))
249 bpfile.write('\n')
Justin Yunf073b742021-11-10 13:28:24 +0900250 bpfile.write(self._gen_license_package())
251 bpfile.write('\n')
Jae Shin4db81a52017-12-29 13:24:54 +0900252 bpfile.write('\n'.join(vndk_core_buildrules))
Jae Shin2de352e2018-01-17 16:15:12 +0900253 bpfile.write('\n')
Jae Shin4db81a52017-12-29 13:24:54 +0900254 bpfile.write('\n'.join(vndk_sp_buildrules))
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700255 if include_llndk:
256 bpfile.write('\n')
257 bpfile.write('\n'.join(llndk_buildrules))
Jae Shinca625dd2017-11-30 15:58:00 +0900258
Inseob Kim748307e2019-06-12 10:45:48 +0900259 variant_include_path = os.path.join(variant_path, 'include')
260 include_path = os.path.join(self._install_dir, arch, 'include')
261 if os.path.isdir(include_path) and variant_include_path != include_path:
262 os.symlink(os.path.relpath(include_path, variant_path),
263 variant_include_path)
264
Jae Shinaf0c0032018-06-21 11:54:05 +0900265 logging.info('Successfully generated {}'.format(bpfile_path))
266
Jae Shinaf0c0032018-06-21 11:54:05 +0900267 for arch in self._snapshot_archs:
268 if os.path.isdir(
269 os.path.join(self._install_dir, arch, utils.BINDER32)):
270 gen_for_variant(arch, is_binder32=True)
271 gen_for_variant(arch)
272
Jae Shinca625dd2017-11-30 15:58:00 +0900273 def _gen_autogen_msg(self, comment_char):
274 return ('{0}{0} THIS FILE IS AUTOGENERATED BY '
275 'development/vndk/snapshot/gen_buildfiles.py\n'
276 '{0}{0} DO NOT EDIT\n'.format(comment_char))
277
Justin Yunf073b742021-11-10 13:28:24 +0900278 def _gen_license_package(self):
279 """ Generates license package for VNDK snapshot libs """
280 return ('package {{\n'
281 '{ind}default_applicable_licenses: ["prebuilts_vndk_v{version}_license"],\n'
282 '}}\n'.format(
283 ind=self.INDENT,
284 version=self._vndk_version))
285
Justin Yun9e48f542023-04-17 12:23:01 +0900286 def _get_license_kinds(self, module=''):
Justin Yun1bd0e292022-07-29 06:28:33 +0000287 """ Returns a set of license kinds
288
289 Args:
Justin Yun9e48f542023-04-17 12:23:01 +0900290 module: module name to find the license kind.
291 If empty, check all license files.
Justin Yun1bd0e292022-07-29 06:28:33 +0000292 """
Justin Yun9e48f542023-04-17 12:23:01 +0900293 if self._license_in_json:
294 license_kinds = set()
295 if module == '':
296 # collect all license kinds
297 for kinds in self._license_kinds_map.values():
298 license_kinds.update(kinds)
299 return license_kinds
300 else:
301 return self._license_kinds_map[module]
302
Justin Yun3e789772021-11-22 12:45:23 +0900303 license_collector = collect_licenses.LicenseCollector(self._install_dir)
Justin Yun9e48f542023-04-17 12:23:01 +0900304 license_collector.run(module)
Justin Yun3e789772021-11-22 12:45:23 +0900305 return license_collector.license_kinds
306
Justin Yun9e48f542023-04-17 12:23:01 +0900307 def _get_license_texts(self, module):
308 if self._license_in_json:
309 return {'{notice_dir}/{license_text}'.format(
310 notice_dir=utils.NOTICE_FILES_DIR_NAME,
311 license_text=license_text)
312 for license_text in self._license_texts_map[module]}
313 else:
314 return {'{notice_dir}/{module}.txt'.format(
315 notice_dir=utils.NOTICE_FILES_DIR_NAME,
316 module=module)}
317
Justin Yunf073b742021-11-10 13:28:24 +0900318 def _gen_license(self):
319 """ Generates license module.
320
321 It uses license files for all VNDK snapshot libraries in common/NOTICE_FILES directory.
322 """
Justin Yun3e789772021-11-22 12:45:23 +0900323 license_kinds = self._get_license_kinds()
324 license_kinds_string = ''
325 for license_kind in sorted(license_kinds):
326 license_kinds_string += '{ind}{ind}"{license_kind}",\n'.format(
327 ind=self.INDENT, license_kind=license_kind)
Justin Yunf073b742021-11-10 13:28:24 +0900328 return ('license {{\n'
329 '{ind}name: "prebuilts_vndk_v{version}_license",\n'
330 '{ind}visibility: [":__subpackages__"],\n'
Justin Yun3e789772021-11-22 12:45:23 +0900331 '{ind}license_kinds: [\n'
332 '{license_kinds}'
333 '{ind}],\n'
Justin Yunf073b742021-11-10 13:28:24 +0900334 '{ind}license_text: ["{notice_files}"],\n'
335 '}}\n'.format(
336 ind=self.INDENT,
337 version=self._vndk_version,
Justin Yun3e789772021-11-22 12:45:23 +0900338 license_kinds=license_kinds_string,
Justin Yun9e48f542023-04-17 12:23:01 +0900339 notice_files=os.path.join(utils.NOTICE_FILES_DIR_PATH, '**', '*')))
Justin Yunf073b742021-11-10 13:28:24 +0900340
Jae Shinaf0c0032018-06-21 11:54:05 +0900341 def _get_versioned_name(self,
342 prebuilt,
343 arch,
344 is_etc=False,
Inseob Kim04c21ae2019-10-23 15:48:31 +0900345 is_binder32=False,
346 module_names=None):
Jae Shinca625dd2017-11-30 15:58:00 +0900347 """Returns the VNDK version-specific module name for a given prebuilt.
348
349 The VNDK version-specific module name is defined as follows:
Jae Shin4db81a52017-12-29 13:24:54 +0900350 For a VNDK shared lib: 'libfoo.so'
Jae Shinaf0c0032018-06-21 11:54:05 +0900351 if binder is 32-bit:
352 'libfoo.vndk.{version}.{arch}.binder32.vendor'
353 else:
354 'libfoo.vndk.{version}.{arch}.vendor'
Jae Shin4db81a52017-12-29 13:24:54 +0900355 For an ETC module: 'foo.txt' -> 'foo.{version}.txt'
Jae Shinca625dd2017-11-30 15:58:00 +0900356
357 Args:
358 prebuilt: string, name of the prebuilt object
Jae Shinaf0c0032018-06-21 11:54:05 +0900359 arch: string, VNDK snapshot arch (e.g. 'arm64')
Jae Shinca625dd2017-11-30 15:58:00 +0900360 is_etc: bool, True if the LOCAL_MODULE_CLASS of prebuilt is 'ETC'
Jae Shinaf0c0032018-06-21 11:54:05 +0900361 is_binder32: bool, True if binder interface is 32-bit
Inseob Kim04c21ae2019-10-23 15:48:31 +0900362 module_names: dict, module names for given prebuilts
Jae Shinca625dd2017-11-30 15:58:00 +0900363 """
Jae Shinca625dd2017-11-30 15:58:00 +0900364 if is_etc:
Inseob Kim04c21ae2019-10-23 15:48:31 +0900365 name, ext = os.path.splitext(prebuilt)
Jae Shinca625dd2017-11-30 15:58:00 +0900366 versioned_name = '{}.{}{}'.format(name, self._vndk_version, ext)
367 else:
Inseob Kim04c21ae2019-10-23 15:48:31 +0900368 module_names = module_names or dict()
369 if prebuilt in module_names:
370 name = module_names[prebuilt]
371 else:
372 name = os.path.splitext(prebuilt)[0]
Jae Shinaf0c0032018-06-21 11:54:05 +0900373 binder_suffix = '.{}'.format(utils.BINDER32) if is_binder32 else ''
374 versioned_name = '{}.vndk.{}.{}{}.vendor'.format(
375 name, self._vndk_version, arch, binder_suffix)
Jae Shinca625dd2017-11-30 15:58:00 +0900376
377 return versioned_name
378
379 def _gen_etc_prebuilt(self, prebuilt):
380 """Generates build rule for an ETC prebuilt.
381
382 Args:
383 prebuilt: string, name of ETC prebuilt object
384 """
Jae Shin4db81a52017-12-29 13:24:54 +0900385 etc_path = self._etc_paths[prebuilt]
Jae Shinca625dd2017-11-30 15:58:00 +0900386 etc_sub_path = etc_path[etc_path.index('/') + 1:]
387
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800388 prebuilt_etc = ('prebuilt_etc {{\n'
389 '{ind}name: "{versioned_name}",\n'
390 '{ind}target: {{\n'.format(
391 ind=self.INDENT,
392 versioned_name=self._get_versioned_name(
393 prebuilt, None, is_etc=True)))
394 for arch in self._snapshot_archs:
395 prebuilt_etc += ('{ind}{ind}android_{arch}: {{\n'
396 '{ind}{ind}{ind}src: "{arch}/{etc_sub_path}",\n'
397 '{ind}{ind}}},\n'.format(
398 ind=self.INDENT,
399 arch=arch,
400 etc_sub_path=etc_sub_path))
401 prebuilt_etc += ('{ind}}},\n'
402 '}}\n'.format(ind=self.INDENT))
403 return prebuilt_etc
Jae Shinca625dd2017-11-30 15:58:00 +0900404
Justin Yun1aad56c2020-11-30 10:24:58 +0900405 def _gen_prebuilt_library_shared(self, prebuilt_lib_info):
406 """Generates cc_prebuilt_library_shared modules for the old vendor
407 compatibility.
408
409 Some vendor modules still require old version of libraries that is not
410 available from the current source tree. To provide the old copy of the
411 libraries, use the vndk snapshot.
412
413 Args:
414 prebuilt_lib_info: pair of (string, list of strings), name of the
415 prebuilt library and the list of shared libs for it.
416 """
417 lib_name = prebuilt_lib_info[0]
418 shared_libs = prebuilt_lib_info[1]
419
420 shared_libs_prop = ''
421 if shared_libs:
422 shared_libs_prop = ('{ind}shared_libs: [\n'.format(ind=self.INDENT))
423 for lib in shared_libs:
424 shared_libs_prop += ('{ind}{ind}"{lib}",\n'.format(
425 ind=self.INDENT, lib=lib))
426 shared_libs_prop += ('{ind}],\n'.format(ind=self.INDENT))
427
428 cc_prebuilt_libraries = ('cc_prebuilt_library_shared {{\n'
429 '{ind}name: "{name}-vendorcompat",\n'
430 '{ind}stem: "{name}",\n'
431 '{ind}vendor: true,\n'
432 '{ind}// These are already stripped, and '
433 'restripping them just issues diagnostics.\n'
434 '{ind}strip: {{\n'
435 '{ind}{ind}none: true,\n'
436 '{ind}}},\n'
437 '{shared_libs}'
438 '{ind}target: {{\n'.format(
439 ind=self.INDENT,
440 name=lib_name,
441 shared_libs=shared_libs_prop))
442 src_paths = utils.find(self._install_dir, [lib_name+'.so'])
443 for src in src_paths:
444 dirs = src.split(os.path.sep)
445 if len(dirs) < 3 or not dirs[1].startswith('arch-{}-'.format(dirs[0])):
446 continue
447 cc_prebuilt_libraries += ('{ind}{ind}android_{arch}: {{\n'
448 '{ind}{ind}{ind}srcs: ["{src}"],\n'
449 '{ind}{ind}}},\n'.format(
450 ind=self.INDENT, arch=dirs[0], src=src))
451 cc_prebuilt_libraries += ('{ind}}},\n'
452 '}}\n'.format(ind=self.INDENT))
453 return cc_prebuilt_libraries
454
Bob Badour46697882022-07-14 16:42:08 -0700455 def _gen_notice_license(self, module):
456 """Generates a notice license build rule for a given module.
Justin Yun9e48f542023-04-17 12:23:01 +0900457 When genererating each notice license, collect
458 modules_with_restricted_lic, the list of modules that are under the GPL.
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800459
460 Args:
Justin Yun9e48f542023-04-17 12:23:01 +0900461 module: string, module name
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800462 """
Justin Yun9e48f542023-04-17 12:23:01 +0900463 def has_restricted_license(license_kinds):
464 for lic in license_kinds:
465 if 'GPL' in lic:
466 return True
467 return False
468
469 license_kinds = self._get_license_kinds(module)
470 if has_restricted_license(license_kinds):
471 self.modules_with_restricted_lic.add(module)
Bob Badour46697882022-07-14 16:42:08 -0700472 license_kinds_string = ''
473 for license_kind in sorted(license_kinds):
474 license_kinds_string += '{ind}{ind}"{license_kind}",\n'.format(
475 ind=self.INDENT, license_kind=license_kind)
Justin Yun9e48f542023-04-17 12:23:01 +0900476 license_texts = self._get_license_texts(module)
477 license_texts_string = ''
478 for license_text in sorted(license_texts):
479 license_texts_string += '{ind}{ind}"{license_text}",\n'.format(
480 ind=self.INDENT, license_text=license_text)
Bob Badour46697882022-07-14 16:42:08 -0700481 return ('license {{\n'
482 '{ind}name: "{license_name}",\n'
483 '{ind}license_kinds: [\n'
484 '{license_kinds}'
485 '{ind}],\n'
Justin Yun9e48f542023-04-17 12:23:01 +0900486 '{ind}license_text: [\n'
487 '{license_texts}'
488 '{ind}],\n'
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800489 '}}\n'.format(
490 ind=self.INDENT,
Bob Badour46697882022-07-14 16:42:08 -0700491 license_name=self._get_notice_license_name(module),
492 license_kinds=license_kinds_string,
Justin Yun9e48f542023-04-17 12:23:01 +0900493 license_texts=license_texts_string))
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800494
Bob Badour46697882022-07-14 16:42:08 -0700495 def _get_notice_license_name(self, module):
496 """ Gets a notice license module name for a given module.
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800497
498 Args:
499 notice: string, module name.
500 """
Bob Badour46697882022-07-14 16:42:08 -0700501 return 'vndk-v{ver}-{module}-license'.format(
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800502 ver=self._vndk_version, module=module)
503
Jae Shinaf0c0032018-06-21 11:54:05 +0900504 def _gen_vndk_shared_prebuilts(self,
505 prebuilts,
506 arch,
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700507 is_llndk,
Inseob Kim04c21ae2019-10-23 15:48:31 +0900508 is_vndk_sp,
509 is_binder32,
510 module_names):
Jae Shinca625dd2017-11-30 15:58:00 +0900511 """Returns list of build rules for given prebuilts.
512
513 Args:
514 prebuilts: list of VNDK shared prebuilts
Jae Shinaf0c0032018-06-21 11:54:05 +0900515 arch: string, VNDK snapshot arch (e.g. 'arm64')
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700516 is_llndk: bool, True if the prebuilts are LLNDK stubs
Jae Shinca625dd2017-11-30 15:58:00 +0900517 is_vndk_sp: bool, True if prebuilts are VNDK_SP libs
Jae Shinaf0c0032018-06-21 11:54:05 +0900518 is_binder32: bool, True if binder interface is 32-bit
Inseob Kim04c21ae2019-10-23 15:48:31 +0900519 module_names: dict, module names for given prebuilts
Jae Shinca625dd2017-11-30 15:58:00 +0900520 """
Inseob Kim04c21ae2019-10-23 15:48:31 +0900521
Justin Yunfea111c2022-03-18 20:24:33 +0900522 module_prebuilts = dict()
Jae Shinca625dd2017-11-30 15:58:00 +0900523 for prebuilt in prebuilts:
Justin Yunfea111c2022-03-18 20:24:33 +0900524 if prebuilt in module_names:
525 name = module_names[prebuilt]
526 else:
527 name = os.path.splitext(prebuilt)[0]
528
529 if name not in module_prebuilts:
530 module_prebuilts[name] = list()
531 module_prebuilts[name].append(prebuilt)
532
533 build_rules = []
534 for name in module_prebuilts:
Inseob Kim8f99d6f2020-06-15 22:10:59 +0900535 bp_module = self._gen_vndk_shared_prebuilt(
Justin Yunfea111c2022-03-18 20:24:33 +0900536 name,
Inseob Kim8f99d6f2020-06-15 22:10:59 +0900537 arch,
Justin Yunfea111c2022-03-18 20:24:33 +0900538 srcs=module_prebuilts[name],
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700539 is_llndk=is_llndk,
Inseob Kim8f99d6f2020-06-15 22:10:59 +0900540 is_vndk_sp=is_vndk_sp,
Justin Yunfea111c2022-03-18 20:24:33 +0900541 is_binder32=is_binder32)
Inseob Kim8f99d6f2020-06-15 22:10:59 +0900542 if bp_module:
543 build_rules.append(bp_module)
Jae Shinca625dd2017-11-30 15:58:00 +0900544 return build_rules
545
Jae Shinaf0c0032018-06-21 11:54:05 +0900546 def _gen_vndk_shared_prebuilt(self,
Justin Yunfea111c2022-03-18 20:24:33 +0900547 name,
Jae Shinaf0c0032018-06-21 11:54:05 +0900548 arch,
Justin Yunfea111c2022-03-18 20:24:33 +0900549 srcs,
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700550 is_llndk,
Inseob Kim04c21ae2019-10-23 15:48:31 +0900551 is_vndk_sp,
Justin Yunfea111c2022-03-18 20:24:33 +0900552 is_binder32):
553 """Returns build rule for given prebuilt module, or an empty
554 string if the module is invalid (e.g. srcs doesn't exist).
Jae Shinca625dd2017-11-30 15:58:00 +0900555
556 Args:
Justin Yunfea111c2022-03-18 20:24:33 +0900557 name: string, name of prebuilt module
Jae Shinaf0c0032018-06-21 11:54:05 +0900558 arch: string, VNDK snapshot arch (e.g. 'arm64')
Justin Yunfea111c2022-03-18 20:24:33 +0900559 srcs: list, prebuilt source file names of this module
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700560 is_llndk: bool, True if prebuilt is a LLNDK stub
Jae Shinca625dd2017-11-30 15:58:00 +0900561 is_vndk_sp: bool, True if prebuilt is a VNDK_SP lib
Jae Shinaf0c0032018-06-21 11:54:05 +0900562 is_binder32: bool, True if binder interface is 32-bit
Jae Shinca625dd2017-11-30 15:58:00 +0900563 """
Jae Shin4db81a52017-12-29 13:24:54 +0900564
Justin Yunfea111c2022-03-18 20:24:33 +0900565 def is_prebuilts_in_list(prebuilts, vndk_list):
566 for prebuilt in prebuilts:
567 if prebuilt in vndk_list:
568 return True
569 return False
570
Justin Yun9e48f542023-04-17 12:23:01 +0900571 def get_license_prop(name):
572 """Returns the license prop build rule.
573
574 Args:
575 name: string, name of the module
576 """
577 if name in self._license_kinds_map:
578 return '{ind}licenses: ["{license}"],\n'.format(
579 ind=self.INDENT,
580 license=self._get_notice_license_name(name))
581 return ''
582
Justin Yunfea111c2022-03-18 20:24:33 +0900583 def get_notice_file(prebuilts):
Justin Yun1bd0e292022-07-29 06:28:33 +0000584 """Returns build rule for notice file (attribute 'licenses').
Jae Shinba7456d2017-12-15 20:03:20 +0900585
586 Args:
Justin Yunfea111c2022-03-18 20:24:33 +0900587 prebuilts: list, names of prebuilt objects
Jae Shinba7456d2017-12-15 20:03:20 +0900588 """
589 notice = ''
Justin Yunfea111c2022-03-18 20:24:33 +0900590 for prebuilt in prebuilts:
591 if prebuilt in self._modules_with_notice:
Bob Badour46697882022-07-14 16:42:08 -0700592 notice = '{ind}licenses: ["{notice_license}"],\n'.format(
Justin Yunfea111c2022-03-18 20:24:33 +0900593 ind=self.INDENT,
Bob Badour46697882022-07-14 16:42:08 -0700594 notice_license=self._get_notice_license_name(prebuilt))
Justin Yunfea111c2022-03-18 20:24:33 +0900595 break
Jae Shinba7456d2017-12-15 20:03:20 +0900596 return notice
597
Inseob Kim46628ff2023-04-18 11:31:25 +0900598 def get_arch_props(name, arch, srcs_props):
Jae Shinca625dd2017-11-30 15:58:00 +0900599 """Returns build rule for arch specific srcs.
600
601 e.g.,
Jae Shin4db81a52017-12-29 13:24:54 +0900602 arch: {
603 arm: {
Inseob Kim748307e2019-06-12 10:45:48 +0900604 export_include_dirs: ["..."],
605 export_system_include_dirs: ["..."],
606 export_flags: ["..."],
607 relative_install_path: "...",
Jae Shin4db81a52017-12-29 13:24:54 +0900608 srcs: ["..."]
609 },
610 arm64: {
Inseob Kim748307e2019-06-12 10:45:48 +0900611 export_include_dirs: ["..."],
612 export_system_include_dirs: ["..."],
613 export_flags: ["..."],
614 relative_install_path: "...",
Jae Shin4db81a52017-12-29 13:24:54 +0900615 srcs: ["..."]
616 },
617 }
Jae Shinca625dd2017-11-30 15:58:00 +0900618
619 Args:
Justin Yunfea111c2022-03-18 20:24:33 +0900620 name: string, name of prebuilt module
Jae Shinaf0c0032018-06-21 11:54:05 +0900621 arch: string, VNDK snapshot arch (e.g. 'arm64')
Inseob Kim46628ff2023-04-18 11:31:25 +0900622 srcs_props: dict, prebuilt source paths and corresponding flags
Jae Shinca625dd2017-11-30 15:58:00 +0900623 """
Inseob Kim748307e2019-06-12 10:45:48 +0900624 arch_props = '{ind}arch: {{\n'.format(ind=self.INDENT)
Jae Shinaf0c0032018-06-21 11:54:05 +0900625
Inseob Kim748307e2019-06-12 10:45:48 +0900626 def list_to_prop_value(l, name):
627 if len(l) == 0:
628 return ''
629 dirs=',\n{ind}{ind}{ind}{ind}'.format(
630 ind=self.INDENT).join(['"%s"' % d for d in l])
631 return ('{ind}{ind}{ind}{name}: [\n'
632 '{ind}{ind}{ind}{ind}{dirs},\n'
633 '{ind}{ind}{ind}],\n'.format(
634 ind=self.INDENT,
635 dirs=dirs,
636 name=name))
637
Inseob Kimdeb5beb2021-09-24 13:17:06 +0900638 def rename_generated_dirs(dirs):
Justin Yun9e48f542023-04-17 12:23:01 +0900639 # Rename out/soong/.intermediates to generated-headers for better readability.
Inseob Kimdeb5beb2021-09-24 13:17:06 +0900640 return [d.replace(utils.SOONG_INTERMEDIATES_DIR, utils.GENERATED_HEADERS_DIR, 1) for d in dirs]
641
Inseob Kim46628ff2023-04-18 11:31:25 +0900642 for src in sorted(srcs_props.keys()):
Inseob Kim748307e2019-06-12 10:45:48 +0900643 include_dirs = ''
644 system_include_dirs = ''
645 flags = ''
646 relative_install_path = ''
Inseob Kim46628ff2023-04-18 11:31:25 +0900647 props = srcs_props[src]
Inseob Kim748307e2019-06-12 10:45:48 +0900648 if 'ExportedDirs' in props:
Inseob Kimdeb5beb2021-09-24 13:17:06 +0900649 dirs = rename_generated_dirs(props['ExportedDirs'])
650 l = ['include/%s' % d for d in dirs]
Inseob Kim748307e2019-06-12 10:45:48 +0900651 include_dirs = list_to_prop_value(l, 'export_include_dirs')
652 if 'ExportedSystemDirs' in props:
Inseob Kimdeb5beb2021-09-24 13:17:06 +0900653 dirs = rename_generated_dirs(props['ExportedSystemDirs'])
654 l = ['include/%s' % d for d in dirs]
Inseob Kim748307e2019-06-12 10:45:48 +0900655 system_include_dirs = list_to_prop_value(l, 'export_system_include_dirs')
656 if 'ExportedFlags' in props:
657 flags = list_to_prop_value(props['ExportedFlags'], 'export_flags')
658 if 'RelativeInstallPath' in props:
659 relative_install_path = ('{ind}{ind}{ind}'
660 'relative_install_path: "{path}",\n').format(
661 ind=self.INDENT,
662 path=props['RelativeInstallPath'])
Justin Yun9e48f542023-04-17 12:23:01 +0900663 if 'LicenseKinds' in props:
664 self._license_kinds_map[name].update(props['LicenseKinds'])
665 if 'LicenseTexts' in props:
666 self._license_texts_map[name].update(props['LicenseTexts'])
Inseob Kim748307e2019-06-12 10:45:48 +0900667
668 arch_props += ('{ind}{ind}{arch}: {{\n'
669 '{include_dirs}'
670 '{system_include_dirs}'
671 '{flags}'
672 '{relative_install_path}'
673 '{ind}{ind}{ind}srcs: ["{src}"],\n'
674 '{ind}{ind}}},\n').format(
Jae Shin25d3abf2018-04-18 18:00:26 +0900675 ind=self.INDENT,
Jae Shinaf0c0032018-06-21 11:54:05 +0900676 arch=utils.prebuilt_arch_from_path(
677 os.path.join(arch, src)),
Inseob Kim748307e2019-06-12 10:45:48 +0900678 include_dirs=include_dirs,
679 system_include_dirs=system_include_dirs,
680 flags=flags,
681 relative_install_path=relative_install_path,
682 src=src)
683 arch_props += '{ind}}},\n'.format(ind=self.INDENT)
684 return arch_props
Jae Shinca625dd2017-11-30 15:58:00 +0900685
Jae Shinaf0c0032018-06-21 11:54:05 +0900686 src_root = os.path.join(self._install_dir, arch)
Justin Yunef95d092020-11-30 10:19:43 +0900687 if is_binder32:
Jae Shinaf0c0032018-06-21 11:54:05 +0900688 src_root = os.path.join(src_root, utils.BINDER32)
689
Justin Yunfea111c2022-03-18 20:24:33 +0900690 src_paths = utils.find(src_root, srcs)
Inseob Kim8f99d6f2020-06-15 22:10:59 +0900691 # filter out paths under 'binder32' subdirectory
692 src_paths = list(filter(lambda src: not src.startswith(utils.BINDER32),
693 src_paths))
Justin Yunfea111c2022-03-18 20:24:33 +0900694 # This module is invalid if no srcs are found.
Inseob Kim8f99d6f2020-06-15 22:10:59 +0900695 if not src_paths:
Justin Yunfea111c2022-03-18 20:24:33 +0900696 logging.info('No srcs found for {}; skipping'.format(name))
Inseob Kim8f99d6f2020-06-15 22:10:59 +0900697 return ""
698
Justin Yunba2a7e12020-11-27 20:14:28 +0900699 product_available = ''
700 # if vndkproduct.libraries.txt is empty, make the VNDKs available to product by default.
Justin Yunfea111c2022-03-18 20:24:33 +0900701 if is_llndk or not self._vndk_product[arch] or is_prebuilts_in_list(srcs, self._vndk_product[arch]):
Justin Yun70e152e2021-01-05 17:10:37 +0900702 product_available = '{ind}product_available: true,\n'.format(
703 ind=self.INDENT)
Jae Shinaf0c0032018-06-21 11:54:05 +0900704
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700705 vndk_props = ''
706 if not is_llndk:
707 vndk_sp = ''
708 if is_vndk_sp:
709 vndk_sp = '{ind}{ind}support_system_process: true,\n'.format(
710 ind=self.INDENT)
Jae Shinaf0c0032018-06-21 11:54:05 +0900711
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700712 vndk_private = ''
Justin Yunfea111c2022-03-18 20:24:33 +0900713 if is_prebuilts_in_list(srcs, self._vndk_private[arch]):
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700714 vndk_private = '{ind}{ind}private: true,\n'.format(
715 ind=self.INDENT)
716
717 vndk_props = ('{ind}vndk: {{\n'
718 '{ind}{ind}enabled: true,\n'
719 '{vndk_sp}'
720 '{vndk_private}'
721 '{ind}}},\n'.format(
722 ind=self.INDENT,
723 product_available=product_available,
724 vndk_sp=vndk_sp,
725 vndk_private=vndk_private))
Justin Yun70e152e2021-01-05 17:10:37 +0900726
Inseob Kim46628ff2023-04-18 11:31:25 +0900727 srcs_props = dict()
728 for src in src_paths:
729 props = dict()
730 prop_path = os.path.join(src_root, src+'.json')
731 try:
732 with open(prop_path, 'r') as f:
733 props = json.loads(f.read())
734 os.unlink(prop_path)
735 except:
736 # TODO(b/70312118): Parse from soong build system
737 if name == 'android.hidl.memory@1.0-impl':
738 props['RelativeInstallPath'] = 'hw'
739 srcs_props[src] = props
740 arch_props = get_arch_props(name, arch, srcs_props)
741
Justin Yun9e48f542023-04-17 12:23:01 +0900742 if self._license_in_json:
743 license = get_license_prop(name)
744 else:
745 license = get_notice_file(srcs)
Jae Shinaf0c0032018-06-21 11:54:05 +0900746
747 binder32bit = ''
748 if is_binder32:
749 binder32bit = '{ind}binder32bit: true,\n'.format(ind=self.INDENT)
Jae Shinca625dd2017-11-30 15:58:00 +0900750
Inseob Kim46628ff2023-04-18 11:31:25 +0900751 min_sdk_version = ''
752 for src, props in srcs_props.items():
753 if 'MinSdkVersion' in props:
754 min_sdk_version = '{ind}min_sdk_version: "{ver}",\n'.format(
755 ind=self.INDENT,
756 ver=props['MinSdkVersion'])
757 break
758
Jae Shinca625dd2017-11-30 15:58:00 +0900759 return ('vndk_prebuilt_shared {{\n'
760 '{ind}name: "{name}",\n'
761 '{ind}version: "{ver}",\n'
Jae Shin4db81a52017-12-29 13:24:54 +0900762 '{ind}target_arch: "{target_arch}",\n'
Jae Shinaf0c0032018-06-21 11:54:05 +0900763 '{binder32bit}'
Justin Yun70e152e2021-01-05 17:10:37 +0900764 '{ind}vendor_available: true,\n'
Justin Yunba2a7e12020-11-27 20:14:28 +0900765 '{product_available}'
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700766 '{vndk_props}'
Inseob Kim46628ff2023-04-18 11:31:25 +0900767 '{min_sdk_version}'
Justin Yun9e48f542023-04-17 12:23:01 +0900768 '{license}'
Inseob Kim748307e2019-06-12 10:45:48 +0900769 '{arch_props}'
Jae Shinca625dd2017-11-30 15:58:00 +0900770 '}}\n'.format(
771 ind=self.INDENT,
772 name=name,
773 ver=self._vndk_version,
Jae Shinaf0c0032018-06-21 11:54:05 +0900774 target_arch=arch,
775 binder32bit=binder32bit,
Justin Yunba2a7e12020-11-27 20:14:28 +0900776 product_available=product_available,
Bill Peckhamdba5e0f2021-05-12 17:21:17 -0700777 vndk_props=vndk_props,
Inseob Kim46628ff2023-04-18 11:31:25 +0900778 min_sdk_version=min_sdk_version,
Justin Yun9e48f542023-04-17 12:23:01 +0900779 license=license,
Inseob Kim748307e2019-06-12 10:45:48 +0900780 arch_props=arch_props))
Jae Shinca625dd2017-11-30 15:58:00 +0900781
782
Jae Shin94075212018-06-14 14:54:34 +0900783def get_args():
784 parser = argparse.ArgumentParser()
785 parser.add_argument(
786 'vndk_version',
Justin Yunef95d092020-11-30 10:19:43 +0900787 type=utils.vndk_version_int,
788 help='VNDK snapshot version to install, e.g. "{}".'.format(
789 utils.MINIMUM_VNDK_VERSION))
Jae Shin94075212018-06-14 14:54:34 +0900790 parser.add_argument(
791 '-v',
792 '--verbose',
793 action='count',
794 default=0,
795 help='Increase output verbosity, e.g. "-v", "-vv".')
796 return parser.parse_args()
797
798
Jae Shinca625dd2017-11-30 15:58:00 +0900799def main():
800 """For local testing purposes.
801
802 Note: VNDK snapshot must be already installed under
803 prebuilts/vndk/v{version}.
804 """
Jae Shin5233fe12017-12-18 22:29:48 +0900805 ANDROID_BUILD_TOP = utils.get_android_build_top()
Jae Shin4db81a52017-12-29 13:24:54 +0900806 PREBUILTS_VNDK_DIR = utils.join_realpath(ANDROID_BUILD_TOP,
807 'prebuilts/vndk')
Jae Shinca625dd2017-11-30 15:58:00 +0900808
Jae Shin94075212018-06-14 14:54:34 +0900809 args = get_args()
810 vndk_version = args.vndk_version
Jae Shinca625dd2017-11-30 15:58:00 +0900811 install_dir = os.path.join(PREBUILTS_VNDK_DIR, 'v{}'.format(vndk_version))
Jae Shin94075212018-06-14 14:54:34 +0900812 if not os.path.isdir(install_dir):
813 raise ValueError(
814 'Please provide valid VNDK version. {} does not exist.'
815 .format(install_dir))
816 utils.set_logging_config(args.verbose)
Jae Shinca625dd2017-11-30 15:58:00 +0900817
818 buildfile_generator = GenBuildFile(install_dir, vndk_version)
Justin Yun9e48f542023-04-17 12:23:01 +0900819 # To parse json information, read and generate arch android.bp using
820 # generate_android_bp() first.
821 buildfile_generator.generate_android_bp()
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800822 buildfile_generator.generate_root_android_bp()
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800823 buildfile_generator.generate_common_android_bp()
Jae Shinca625dd2017-11-30 15:58:00 +0900824
Jae Shinbd82ebb2018-06-21 14:13:46 +0900825 logging.info('Done.')
Jae Shin94075212018-06-14 14:54:34 +0900826
Jae Shinca625dd2017-11-30 15:58:00 +0900827
828if __name__ == '__main__':
829 main()