blob: f504f552ee7bab7aa58b244431baf9ff5f63db38 [file] [log] [blame]
Jae Shinca625dd2017-11-30 15:58:00 +09001#!/usr/bin/env python
2#
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
Jae Shin9bc4fd02017-12-26 13:07:18 +090019import glob
Jae Shin94075212018-06-14 14:54:34 +090020import logging
Jae Shinca625dd2017-11-30 15:58:00 +090021import os
22import sys
23
Jae Shin5233fe12017-12-18 22:29:48 +090024import utils
25
Jae Shinca625dd2017-11-30 15:58:00 +090026
27class GenBuildFile(object):
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -080028 """Generates Android.bp for VNDK snapshot.
Jae Shinca625dd2017-11-30 15:58:00 +090029
Jae Shin4db81a52017-12-29 13:24:54 +090030 VNDK snapshot directory structure under prebuilts/vndk/v{version}:
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -080031 Android.bp
Jae Shinaf0c0032018-06-21 11:54:05 +090032 {SNAPSHOT_ARCH}/
Jae Shin4db81a52017-12-29 13:24:54 +090033 Android.bp
34 arch-{TARGET_ARCH}-{TARGET_ARCH_VARIANT}/
35 shared/
36 vndk-core/
37 (VNDK-core libraries, e.g. libbinder.so)
38 vndk-sp/
39 (VNDK-SP libraries, e.g. libc++.so)
40 arch-{TARGET_2ND_ARCH}-{TARGET_2ND_ARCH_VARIANT}/
41 shared/
42 vndk-core/
43 (VNDK-core libraries, e.g. libbinder.so)
44 vndk-sp/
45 (VNDK-SP libraries, e.g. libc++.so)
Jae Shinaf0c0032018-06-21 11:54:05 +090046 binder32/
47 (This directory is newly introduced in v28 (Android P) to hold
48 prebuilts built for 32-bit binder interface.)
49 Android.bp
50 arch-{TARGET_ARCH}-{TARGE_ARCH_VARIANT}/
51 ...
Jae Shin4db81a52017-12-29 13:24:54 +090052 configs/
53 (various *.txt configuration files, e.g. ld.config.*.txt)
Jae Shinaf0c0032018-06-21 11:54:05 +090054 ... (other {SNAPSHOT_ARCH}/ directories)
Jae Shin4db81a52017-12-29 13:24:54 +090055 common/
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -080056 Android.bp
Jae Shin4db81a52017-12-29 13:24:54 +090057 NOTICE_FILES/
58 (license files, e.g. libfoo.so.txt)
59 """
Jae Shinca625dd2017-11-30 15:58:00 +090060 INDENT = ' '
Jae Shin4db81a52017-12-29 13:24:54 +090061 ETC_MODULES = [
62 'ld.config.txt', 'llndk.libraries.txt', 'vndksp.libraries.txt'
63 ]
Jae Shinca625dd2017-11-30 15:58:00 +090064
65 # TODO(b/70312118): Parse from soong build system
Jae Shin4db81a52017-12-29 13:24:54 +090066 RELATIVE_INSTALL_PATHS = {'android.hidl.memory@1.0-impl.so': 'hw'}
Jae Shinca625dd2017-11-30 15:58:00 +090067
68 def __init__(self, install_dir, vndk_version):
69 """GenBuildFile constructor.
70
71 Args:
72 install_dir: string, absolute path to the prebuilts/vndk/v{version}
73 directory where the build files will be generated.
74 vndk_version: int, VNDK snapshot version (e.g., 27, 28)
75 """
76 self._install_dir = install_dir
77 self._vndk_version = vndk_version
Jae Shin4db81a52017-12-29 13:24:54 +090078 self._etc_paths = self._get_etc_paths()
Jae Shinaf0c0032018-06-21 11:54:05 +090079 self._snapshot_archs = utils.get_snapshot_archs(install_dir)
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -080080 self._root_bpfile = os.path.join(install_dir, utils.ROOT_BP_PATH)
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -080081 self._common_bpfile = os.path.join(install_dir, utils.COMMON_BP_PATH)
Jae Shinca625dd2017-11-30 15:58:00 +090082 self._vndk_core = self._parse_lib_list('vndkcore.libraries.txt')
Jae Shin4db81a52017-12-29 13:24:54 +090083 self._vndk_sp = self._parse_lib_list(
84 os.path.basename(self._etc_paths['vndksp.libraries.txt']))
Jae Shinca625dd2017-11-30 15:58:00 +090085 self._vndk_private = self._parse_lib_list('vndkprivate.libraries.txt')
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -080086 self._modules_with_notice = self._get_modules_with_notice()
Jae Shinca625dd2017-11-30 15:58:00 +090087
Jae Shin4db81a52017-12-29 13:24:54 +090088 def _get_etc_paths(self):
89 """Returns a map of relative file paths for each ETC module."""
90
91 etc_paths = dict()
92 for etc_module in self.ETC_MODULES:
93 etc_pattern = '{}*'.format(os.path.splitext(etc_module)[0])
94 etc_path = glob.glob(
95 os.path.join(self._install_dir, utils.CONFIG_DIR_PATH_PATTERN,
96 etc_pattern))[0]
97 rel_etc_path = etc_path.replace(self._install_dir, '')[1:]
98 etc_paths[etc_module] = rel_etc_path
99 return etc_paths
100
Jae Shinca625dd2017-11-30 15:58:00 +0900101 def _parse_lib_list(self, txt_filename):
Jae Shinaf0c0032018-06-21 11:54:05 +0900102 """Returns a map of VNDK library lists per VNDK snapshot arch.
Jae Shinca625dd2017-11-30 15:58:00 +0900103
104 Args:
Jae Shin4db81a52017-12-29 13:24:54 +0900105 txt_filename: string, name of snapshot config file
Jae Shinca625dd2017-11-30 15:58:00 +0900106
Jae Shin4db81a52017-12-29 13:24:54 +0900107 Returns:
108 dict, e.g. {'arm64': ['libfoo.so', 'libbar.so', ...], ...}
109 """
110 lib_map = dict()
111 for txt_path in utils.find(self._install_dir, [txt_filename]):
Jae Shinaf0c0032018-06-21 11:54:05 +0900112 arch = utils.snapshot_arch_from_path(txt_path)
Jae Shin4db81a52017-12-29 13:24:54 +0900113 abs_path_of_txt = os.path.join(self._install_dir, txt_path)
114 with open(abs_path_of_txt, 'r') as f:
Jae Shinaf0c0032018-06-21 11:54:05 +0900115 lib_map[arch] = f.read().strip().split('\n')
Jae Shin4db81a52017-12-29 13:24:54 +0900116 return lib_map
Jae Shinca625dd2017-11-30 15:58:00 +0900117
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800118 def _get_modules_with_notice(self):
119 """Returns a list of modules that have associated notice files. """
120 notice_paths = glob.glob(
121 os.path.join(self._install_dir, utils.NOTICE_FILES_DIR_PATH,
122 '*.txt'))
123 return [os.path.splitext(os.path.basename(p))[0] for p in notice_paths]
124
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800125 def generate_root_android_bp(self):
126 """Autogenerates Android.bp."""
Jae Shinca625dd2017-11-30 15:58:00 +0900127
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800128 logging.info('Generating Android.bp for snapshot v{}'.format(
Jae Shinaf0c0032018-06-21 11:54:05 +0900129 self._vndk_version))
Jae Shinca625dd2017-11-30 15:58:00 +0900130 etc_buildrules = []
Jae Shin4db81a52017-12-29 13:24:54 +0900131 for prebuilt in self.ETC_MODULES:
Justin Yunb59da8f2019-01-23 19:25:05 +0900132 # ld.config.VER.txt is not installed as a prebuilt but is built and
133 # installed from thesource tree at the time the VNDK snapshot is
134 # installed to the system.img.
135 if prebuilt == 'ld.config.txt':
Jae Shin124ef782018-08-06 18:33:20 +0900136 continue
Jae Shinca625dd2017-11-30 15:58:00 +0900137 etc_buildrules.append(self._gen_etc_prebuilt(prebuilt))
138
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800139 with open(self._root_bpfile, 'w') as bpfile:
140 bpfile.write(self._gen_autogen_msg('/'))
141 bpfile.write('\n')
142 bpfile.write('\n'.join(etc_buildrules))
143 bpfile.write('\n')
Jae Shinca625dd2017-11-30 15:58:00 +0900144
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800145 logging.info('Successfully generated {}'.format(self._root_bpfile))
Jae Shinaf0c0032018-06-21 11:54:05 +0900146
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800147 def generate_common_android_bp(self):
148 """Autogenerates common/Android.bp."""
149
150 logging.info('Generating common/Android.bp for snapshot v{}'.format(
151 self._vndk_version))
152 with open(self._common_bpfile, 'w') as bpfile:
153 bpfile.write(self._gen_autogen_msg('/'))
154 for module in self._modules_with_notice:
155 bpfile.write('\n')
156 bpfile.write(self._gen_notice_filegroup(module))
157
Jae Shinca625dd2017-11-30 15:58:00 +0900158 def generate_android_bp(self):
Jae Shinaf0c0032018-06-21 11:54:05 +0900159 """Autogenerates Android.bp."""
Jae Shinca625dd2017-11-30 15:58:00 +0900160
Jae Shinaf0c0032018-06-21 11:54:05 +0900161 def gen_for_variant(arch, is_binder32=False):
162 """Generates Android.bp file for specified VNDK snapshot variant.
163
164 A VNDK snapshot variant is defined by the TARGET_ARCH and binder
165 bitness. Example snapshot variants:
166 vndk_v{ver}_arm: {arch: arm, binder: 64-bit}
167 vndk_v{ver}_arm_binder32: {arch: arm, binder: 32-bit}
168
169 Args:
170 arch: string, VNDK snapshot arch (e.g. 'arm64')
171 is_binder32: bool, True if binder interface is 32-bit
172 """
173 binder32_suffix = '_{}'.format(
174 utils.BINDER32) if is_binder32 else ''
175 logging.info('Generating Android.bp for vndk_v{}_{}{}'.format(
176 self._vndk_version, arch, binder32_suffix))
177
178 variant_subpath = arch
179 # For O-MR1 snapshot (v27), 32-bit binder prebuilts are not
180 # isolated in separate 'binder32' subdirectory.
181 if is_binder32 and self._vndk_version >= 28:
182 variant_subpath = os.path.join(arch, utils.BINDER32)
183 bpfile_path = os.path.join(self._install_dir, variant_subpath,
184 'Android.bp')
185
Jae Shin4db81a52017-12-29 13:24:54 +0900186 vndk_core_buildrules = self._gen_vndk_shared_prebuilts(
Jae Shinaf0c0032018-06-21 11:54:05 +0900187 self._vndk_core[arch], arch, is_binder32=is_binder32)
Jae Shin4db81a52017-12-29 13:24:54 +0900188 vndk_sp_buildrules = self._gen_vndk_shared_prebuilts(
Jae Shinaf0c0032018-06-21 11:54:05 +0900189 self._vndk_sp[arch],
190 arch,
191 is_vndk_sp=True,
192 is_binder32=is_binder32)
Jae Shinca625dd2017-11-30 15:58:00 +0900193
Jae Shinaf0c0032018-06-21 11:54:05 +0900194 with open(bpfile_path, 'w') as bpfile:
Jae Shin4db81a52017-12-29 13:24:54 +0900195 bpfile.write(self._gen_autogen_msg('/'))
196 bpfile.write('\n')
Jae Shinaf0c0032018-06-21 11:54:05 +0900197 bpfile.write(self._gen_bp_phony(arch, is_binder32))
Jae Shin4db81a52017-12-29 13:24:54 +0900198 bpfile.write('\n')
199 bpfile.write('\n'.join(vndk_core_buildrules))
Jae Shin2de352e2018-01-17 16:15:12 +0900200 bpfile.write('\n')
Jae Shin4db81a52017-12-29 13:24:54 +0900201 bpfile.write('\n'.join(vndk_sp_buildrules))
Jae Shinca625dd2017-11-30 15:58:00 +0900202
Jae Shinaf0c0032018-06-21 11:54:05 +0900203 logging.info('Successfully generated {}'.format(bpfile_path))
204
205 if self._vndk_version == 27:
206 # For O-MR1 snapshot (v27), 32-bit binder prebuilts are not
207 # isolated in separate 'binder32' subdirectory.
208 for arch in self._snapshot_archs:
209 if arch in ('arm', 'x86'):
210 gen_for_variant(arch, is_binder32=True)
211 else:
212 gen_for_variant(arch)
213 return
214
215 for arch in self._snapshot_archs:
216 if os.path.isdir(
217 os.path.join(self._install_dir, arch, utils.BINDER32)):
218 gen_for_variant(arch, is_binder32=True)
219 gen_for_variant(arch)
220
Jae Shinca625dd2017-11-30 15:58:00 +0900221 def _gen_autogen_msg(self, comment_char):
222 return ('{0}{0} THIS FILE IS AUTOGENERATED BY '
223 'development/vndk/snapshot/gen_buildfiles.py\n'
224 '{0}{0} DO NOT EDIT\n'.format(comment_char))
225
Jae Shinaf0c0032018-06-21 11:54:05 +0900226 def _get_versioned_name(self,
227 prebuilt,
228 arch,
229 is_etc=False,
230 is_binder32=False):
Jae Shinca625dd2017-11-30 15:58:00 +0900231 """Returns the VNDK version-specific module name for a given prebuilt.
232
233 The VNDK version-specific module name is defined as follows:
Jae Shin4db81a52017-12-29 13:24:54 +0900234 For a VNDK shared lib: 'libfoo.so'
Jae Shinaf0c0032018-06-21 11:54:05 +0900235 if binder is 32-bit:
236 'libfoo.vndk.{version}.{arch}.binder32.vendor'
237 else:
238 'libfoo.vndk.{version}.{arch}.vendor'
Jae Shin4db81a52017-12-29 13:24:54 +0900239 For an ETC module: 'foo.txt' -> 'foo.{version}.txt'
Jae Shinca625dd2017-11-30 15:58:00 +0900240
241 Args:
242 prebuilt: string, name of the prebuilt object
Jae Shinaf0c0032018-06-21 11:54:05 +0900243 arch: string, VNDK snapshot arch (e.g. 'arm64')
Jae Shinca625dd2017-11-30 15:58:00 +0900244 is_etc: bool, True if the LOCAL_MODULE_CLASS of prebuilt is 'ETC'
Jae Shinaf0c0032018-06-21 11:54:05 +0900245 is_binder32: bool, True if binder interface is 32-bit
Jae Shinca625dd2017-11-30 15:58:00 +0900246 """
247 name, ext = os.path.splitext(prebuilt)
248 if is_etc:
249 versioned_name = '{}.{}{}'.format(name, self._vndk_version, ext)
250 else:
Jae Shinaf0c0032018-06-21 11:54:05 +0900251 binder_suffix = '.{}'.format(utils.BINDER32) if is_binder32 else ''
252 versioned_name = '{}.vndk.{}.{}{}.vendor'.format(
253 name, self._vndk_version, arch, binder_suffix)
Jae Shinca625dd2017-11-30 15:58:00 +0900254
255 return versioned_name
256
257 def _gen_etc_prebuilt(self, prebuilt):
258 """Generates build rule for an ETC prebuilt.
259
260 Args:
261 prebuilt: string, name of ETC prebuilt object
262 """
Jae Shin4db81a52017-12-29 13:24:54 +0900263 etc_path = self._etc_paths[prebuilt]
Jae Shinca625dd2017-11-30 15:58:00 +0900264 etc_sub_path = etc_path[etc_path.index('/') + 1:]
265
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800266 prebuilt_etc = ('prebuilt_etc {{\n'
267 '{ind}name: "{versioned_name}",\n'
268 '{ind}target: {{\n'.format(
269 ind=self.INDENT,
270 versioned_name=self._get_versioned_name(
271 prebuilt, None, is_etc=True)))
272 for arch in self._snapshot_archs:
273 prebuilt_etc += ('{ind}{ind}android_{arch}: {{\n'
274 '{ind}{ind}{ind}src: "{arch}/{etc_sub_path}",\n'
275 '{ind}{ind}}},\n'.format(
276 ind=self.INDENT,
277 arch=arch,
278 etc_sub_path=etc_sub_path))
279 prebuilt_etc += ('{ind}}},\n'
280 '}}\n'.format(ind=self.INDENT))
281 return prebuilt_etc
Jae Shinca625dd2017-11-30 15:58:00 +0900282
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800283 def _gen_notice_filegroup(self, module):
284 """Generates a notice filegroup build rule for a given module.
285
286 Args:
287 notice: string, module name
288 """
289 return ('filegroup {{\n'
290 '{ind}name: "{filegroup_name}",\n'
291 '{ind}srcs: ["{notice_dir}/{module}.txt"],\n'
292 '}}\n'.format(
293 ind=self.INDENT,
294 filegroup_name=self._get_notice_filegroup_name(module),
295 module=module,
296 notice_dir=utils.NOTICE_FILES_DIR_NAME))
297
298 def _get_notice_filegroup_name(self, module):
299 """ Gets a notice filegroup module name for a given module.
300
301 Args:
302 notice: string, module name.
303 """
304 return 'vndk-v{ver}-{module}-notice'.format(
305 ver=self._vndk_version, module=module)
306
Jae Shinaf0c0032018-06-21 11:54:05 +0900307 def _gen_bp_phony(self, arch, is_binder32=False):
308 """Generates build rule for phony package 'vndk_v{ver}_{arch}'.
Jae Shinca625dd2017-11-30 15:58:00 +0900309
Jae Shin4db81a52017-12-29 13:24:54 +0900310 Args:
Jae Shinaf0c0032018-06-21 11:54:05 +0900311 arch: string, VNDK snapshot arch (e.g. 'arm64')
312 is_binder32: bool, True if binder interface is 32-bit
Jae Shin4db81a52017-12-29 13:24:54 +0900313 """
Jae Shinca625dd2017-11-30 15:58:00 +0900314 required = []
Jae Shinaf0c0032018-06-21 11:54:05 +0900315 for prebuilts in (self._vndk_core[arch], self._vndk_sp[arch]):
Jae Shin4db81a52017-12-29 13:24:54 +0900316 for prebuilt in prebuilts:
317 required.append(
Jae Shinaf0c0032018-06-21 11:54:05 +0900318 self._get_versioned_name(
319 prebuilt, arch, is_binder32=is_binder32))
Jae Shinca625dd2017-11-30 15:58:00 +0900320
Jae Shin4db81a52017-12-29 13:24:54 +0900321 for prebuilt in self.ETC_MODULES:
Jae Shinaf0c0032018-06-21 11:54:05 +0900322 required.append(
323 self._get_versioned_name(
324 prebuilt, None, is_etc=True, is_binder32=is_binder32))
Jae Shinca625dd2017-11-30 15:58:00 +0900325
326 required_str = ['"{}",'.format(prebuilt) for prebuilt in required]
327 required_formatted = '\n{ind}{ind}'.format(
328 ind=self.INDENT).join(required_str)
329 required_buildrule = ('{ind}required: [\n'
330 '{ind}{ind}{required_formatted}\n'
331 '{ind}],\n'.format(
332 ind=self.INDENT,
333 required_formatted=required_formatted))
Jae Shinaf0c0032018-06-21 11:54:05 +0900334 binder_suffix = '_{}'.format(utils.BINDER32) if is_binder32 else ''
Jae Shinca625dd2017-11-30 15:58:00 +0900335
336 return ('phony {{\n'
Jae Shinaf0c0032018-06-21 11:54:05 +0900337 '{ind}name: "vndk_v{ver}_{arch}{binder_suffix}",\n'
Jae Shinca625dd2017-11-30 15:58:00 +0900338 '{required_buildrule}'
339 '}}\n'.format(
340 ind=self.INDENT,
341 ver=self._vndk_version,
Jae Shinaf0c0032018-06-21 11:54:05 +0900342 arch=arch,
343 binder_suffix=binder_suffix,
Jae Shinca625dd2017-11-30 15:58:00 +0900344 required_buildrule=required_buildrule))
345
Jae Shinaf0c0032018-06-21 11:54:05 +0900346 def _gen_vndk_shared_prebuilts(self,
347 prebuilts,
348 arch,
349 is_vndk_sp=False,
350 is_binder32=False):
Jae Shinca625dd2017-11-30 15:58:00 +0900351 """Returns list of build rules for given prebuilts.
352
353 Args:
354 prebuilts: list of VNDK shared prebuilts
Jae Shinaf0c0032018-06-21 11:54:05 +0900355 arch: string, VNDK snapshot arch (e.g. 'arm64')
Jae Shinca625dd2017-11-30 15:58:00 +0900356 is_vndk_sp: bool, True if prebuilts are VNDK_SP libs
Jae Shinaf0c0032018-06-21 11:54:05 +0900357 is_binder32: bool, True if binder interface is 32-bit
Jae Shinca625dd2017-11-30 15:58:00 +0900358 """
359 build_rules = []
360 for prebuilt in prebuilts:
361 build_rules.append(
Jae Shinaf0c0032018-06-21 11:54:05 +0900362 self._gen_vndk_shared_prebuilt(
363 prebuilt,
364 arch,
365 is_vndk_sp=is_vndk_sp,
366 is_binder32=is_binder32))
Jae Shinca625dd2017-11-30 15:58:00 +0900367 return build_rules
368
Jae Shinaf0c0032018-06-21 11:54:05 +0900369 def _gen_vndk_shared_prebuilt(self,
370 prebuilt,
371 arch,
372 is_vndk_sp=False,
373 is_binder32=False):
Jae Shinca625dd2017-11-30 15:58:00 +0900374 """Returns build rule for given prebuilt.
375
376 Args:
377 prebuilt: string, name of prebuilt object
Jae Shinaf0c0032018-06-21 11:54:05 +0900378 arch: string, VNDK snapshot arch (e.g. 'arm64')
Jae Shinca625dd2017-11-30 15:58:00 +0900379 is_vndk_sp: bool, True if prebuilt is a VNDK_SP lib
Jae Shinaf0c0032018-06-21 11:54:05 +0900380 is_binder32: bool, True if binder interface is 32-bit
Jae Shinca625dd2017-11-30 15:58:00 +0900381 """
Jae Shin4db81a52017-12-29 13:24:54 +0900382
Jae Shinba7456d2017-12-15 20:03:20 +0900383 def get_notice_file(prebuilt):
384 """Returns build rule for notice file (attribute 'notice').
385
386 Args:
387 prebuilt: string, name of prebuilt object
388 """
389 notice = ''
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800390 if prebuilt in self._modules_with_notice:
391 notice = '{ind}notice: ":{notice_filegroup}",\n'.format(
Jae Shinba7456d2017-12-15 20:03:20 +0900392 ind=self.INDENT,
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800393 notice_filegroup=self._get_notice_filegroup_name(prebuilt))
Jae Shinba7456d2017-12-15 20:03:20 +0900394 return notice
395
396 def get_rel_install_path(prebuilt):
397 """Returns build rule for 'relative_install_path'.
398
399 Args:
400 prebuilt: string, name of prebuilt object
401 """
402 rel_install_path = ''
403 if prebuilt in self.RELATIVE_INSTALL_PATHS:
404 path = self.RELATIVE_INSTALL_PATHS[prebuilt]
405 rel_install_path += ('{ind}relative_install_path: "{path}",\n'
406 .format(ind=self.INDENT, path=path))
407 return rel_install_path
408
Jae Shinaf0c0032018-06-21 11:54:05 +0900409 def get_arch_srcs(prebuilt, arch):
Jae Shinca625dd2017-11-30 15:58:00 +0900410 """Returns build rule for arch specific srcs.
411
412 e.g.,
Jae Shin4db81a52017-12-29 13:24:54 +0900413 arch: {
414 arm: {
415 srcs: ["..."]
416 },
417 arm64: {
418 srcs: ["..."]
419 },
420 }
Jae Shinca625dd2017-11-30 15:58:00 +0900421
422 Args:
423 prebuilt: string, name of prebuilt object
Jae Shinaf0c0032018-06-21 11:54:05 +0900424 arch: string, VNDK snapshot arch (e.g. 'arm64')
Jae Shinca625dd2017-11-30 15:58:00 +0900425 """
426 arch_srcs = '{ind}arch: {{\n'.format(ind=self.INDENT)
Jae Shinaf0c0032018-06-21 11:54:05 +0900427 src_paths = utils.find(src_root, [prebuilt])
428 # filter out paths under 'binder32' subdirectory
429 src_paths = filter(lambda src: not src.startswith(utils.BINDER32),
430 src_paths)
431
Jae Shinca625dd2017-11-30 15:58:00 +0900432 for src in sorted(src_paths):
Jae Shin25d3abf2018-04-18 18:00:26 +0900433 arch_srcs += ('{ind}{ind}{arch}: {{\n'
434 '{ind}{ind}{ind}srcs: ["{src}"],\n'
435 '{ind}{ind}}},\n'.format(
436 ind=self.INDENT,
Jae Shinaf0c0032018-06-21 11:54:05 +0900437 arch=utils.prebuilt_arch_from_path(
438 os.path.join(arch, src)),
Jae Shin25d3abf2018-04-18 18:00:26 +0900439 src=src))
Jae Shinca625dd2017-11-30 15:58:00 +0900440 arch_srcs += '{ind}}},\n'.format(ind=self.INDENT)
441 return arch_srcs
442
Jae Shinaf0c0032018-06-21 11:54:05 +0900443 src_root = os.path.join(self._install_dir, arch)
444 # For O-MR1 snapshot (v27), 32-bit binder prebuilts are not
445 # isolated in separate 'binder32' subdirectory.
446 if is_binder32 and self._vndk_version >= 28:
447 src_root = os.path.join(src_root, utils.BINDER32)
448
Jae Shinca625dd2017-11-30 15:58:00 +0900449 name = os.path.splitext(prebuilt)[0]
Jae Shin4db81a52017-12-29 13:24:54 +0900450 vendor_available = str(
Jae Shinaf0c0032018-06-21 11:54:05 +0900451 prebuilt not in self._vndk_private[arch]).lower()
452
453 vndk_sp = ''
Jae Shinca625dd2017-11-30 15:58:00 +0900454 if is_vndk_sp:
455 vndk_sp = '{ind}{ind}support_system_process: true,\n'.format(
456 ind=self.INDENT)
Jae Shinaf0c0032018-06-21 11:54:05 +0900457
Jae Shinba7456d2017-12-15 20:03:20 +0900458 notice = get_notice_file(prebuilt)
Jae Shinca625dd2017-11-30 15:58:00 +0900459 rel_install_path = get_rel_install_path(prebuilt)
Jae Shinaf0c0032018-06-21 11:54:05 +0900460 arch_srcs = get_arch_srcs(prebuilt, arch)
461
462 binder32bit = ''
463 if is_binder32:
464 binder32bit = '{ind}binder32bit: true,\n'.format(ind=self.INDENT)
Jae Shinca625dd2017-11-30 15:58:00 +0900465
466 return ('vndk_prebuilt_shared {{\n'
467 '{ind}name: "{name}",\n'
468 '{ind}version: "{ver}",\n'
Jae Shin4db81a52017-12-29 13:24:54 +0900469 '{ind}target_arch: "{target_arch}",\n'
Jae Shinaf0c0032018-06-21 11:54:05 +0900470 '{binder32bit}'
Jae Shinca625dd2017-11-30 15:58:00 +0900471 '{ind}vendor_available: {vendor_available},\n'
472 '{ind}vndk: {{\n'
473 '{ind}{ind}enabled: true,\n'
474 '{vndk_sp}'
475 '{ind}}},\n'
Jae Shinba7456d2017-12-15 20:03:20 +0900476 '{notice}'
Jae Shinca625dd2017-11-30 15:58:00 +0900477 '{rel_install_path}'
478 '{arch_srcs}'
479 '}}\n'.format(
480 ind=self.INDENT,
481 name=name,
482 ver=self._vndk_version,
Jae Shinaf0c0032018-06-21 11:54:05 +0900483 target_arch=arch,
484 binder32bit=binder32bit,
Jae Shinca625dd2017-11-30 15:58:00 +0900485 vendor_available=vendor_available,
486 vndk_sp=vndk_sp,
Jae Shinba7456d2017-12-15 20:03:20 +0900487 notice=notice,
Jae Shinca625dd2017-11-30 15:58:00 +0900488 rel_install_path=rel_install_path,
489 arch_srcs=arch_srcs))
490
491
Jae Shin94075212018-06-14 14:54:34 +0900492def get_args():
493 parser = argparse.ArgumentParser()
494 parser.add_argument(
495 'vndk_version',
496 type=int,
497 help='VNDK snapshot version to install, e.g. "27".')
498 parser.add_argument(
499 '-v',
500 '--verbose',
501 action='count',
502 default=0,
503 help='Increase output verbosity, e.g. "-v", "-vv".')
504 return parser.parse_args()
505
506
Jae Shinca625dd2017-11-30 15:58:00 +0900507def main():
508 """For local testing purposes.
509
510 Note: VNDK snapshot must be already installed under
511 prebuilts/vndk/v{version}.
512 """
Jae Shin5233fe12017-12-18 22:29:48 +0900513 ANDROID_BUILD_TOP = utils.get_android_build_top()
Jae Shin4db81a52017-12-29 13:24:54 +0900514 PREBUILTS_VNDK_DIR = utils.join_realpath(ANDROID_BUILD_TOP,
515 'prebuilts/vndk')
Jae Shinca625dd2017-11-30 15:58:00 +0900516
Jae Shin94075212018-06-14 14:54:34 +0900517 args = get_args()
518 vndk_version = args.vndk_version
Jae Shinca625dd2017-11-30 15:58:00 +0900519 install_dir = os.path.join(PREBUILTS_VNDK_DIR, 'v{}'.format(vndk_version))
Jae Shin94075212018-06-14 14:54:34 +0900520 if not os.path.isdir(install_dir):
521 raise ValueError(
522 'Please provide valid VNDK version. {} does not exist.'
523 .format(install_dir))
524 utils.set_logging_config(args.verbose)
Jae Shinca625dd2017-11-30 15:58:00 +0900525
526 buildfile_generator = GenBuildFile(install_dir, vndk_version)
Jaewoong Jung6a5aaca2019-01-17 15:41:06 -0800527 buildfile_generator.generate_root_android_bp()
Jaewoong Jung6fbb9d22018-11-28 09:25:22 -0800528 buildfile_generator.generate_common_android_bp()
Jae Shinca625dd2017-11-30 15:58:00 +0900529 buildfile_generator.generate_android_bp()
530
Jae Shinbd82ebb2018-06-21 14:13:46 +0900531 logging.info('Done.')
Jae Shin94075212018-06-14 14:54:34 +0900532
Jae Shinca625dd2017-11-30 15:58:00 +0900533
534if __name__ == '__main__':
535 main()