def UpdateHalDirBuildRule(self, hal_list): """Updates build rules for vts drivers/profilers. Updates vts drivers/profilers for each pair of (hal_name, hal_version) in hal_list. Args: hal_list: list of tuple of strings. For example, [('vibrator', '1.3'), ('sensors', '1.7')] """ for target in hal_list: hal_name = target[0] hal_version = target[1] hal_dir = os.path.join(self._PROJECT_PATH, utils.HalNameDir(hal_name), utils.HalVerDir(hal_version)) file_path = os.path.join(hal_dir, 'Android.bp') utils.WriteBuildRule( file_path, utils.OnlySubdirsBpRule(self._warning_header, ['*'])) file_path = os.path.join(hal_dir, 'build', 'Android.bp') utils.WriteBuildRule( file_path, self._VtsBuildRuleFromTemplate(self._VTS_BUILD_TEMPLATE, hal_name, hal_version))
def UpdateSecondLevelBuildRule(self, hal_list): """Updates test/vts-testcase/hal/<hal_name>/Android.bp""" top_level_dirs = dict() for target in hal_list: hal_dir = os.path.join(utils.HalNameDir(target[0]), utils.HalVerDir(target[1])) top_dir = hal_dir.split('/', 1)[0] top_level_dirs.setdefault(top_dir, []).append( os.path.relpath(hal_dir, top_dir)) for k, v in top_level_dirs.items(): file_path = os.path.join(self._PROJECT_PATH, k, 'Android.bp') utils.WriteBuildRule( file_path, utils.OnlySubdirsBpRule(self._warning_header, v))
def VtsSpecNames(self, hal_name, hal_version): """Returns list of .vts file names for given hal name and version. hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' Returns: list of string, .vts files for given hal name and version, e.g. ['Vibrator.vts', 'types.vts'] """ self.GenerateVtsSpecs(hal_name, hal_version) vts_spec_dir = os.path.join(self._tmp_dir, 'android', 'hardware', utils.HalNameDir(hal_name), hal_version) vts_spec_names = filter(lambda x: x.endswith('.vts'), os.listdir(vts_spec_dir)) return sorted(vts_spec_names)
def GeneratedOutput(hal_name, hal_version, extension): """Formats list of vts spec names into a string. Formats list of vts spec name for given hal_name, hal_version into a string that can be inserted into build template. Args: hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' extension: string, extension of files e.g. '.cpp'. Returns: string, to be inserted into build template. """ result = [] vts_spec_names = self._vts_spec_parser.VtsSpecNames( hal_name, hal_version) for vts_spec in vts_spec_names: result.append('"android/hardware/%s/%s/%s%s",' % (utils.HalNameDir(hal_name), hal_version, vts_spec, extension)) return '\n '.join(result)
def VtsSpecProtos(self, hal_name, hal_version): """Returns list of .vts protos for given hal name and version. hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' Returns: list of ComponentSpecificationMessages """ self.GenerateVtsSpecs(hal_name, hal_version) vts_spec_dir = os.path.join(self._tmp_dir, 'android', 'hardware', utils.HalNameDir(hal_name), hal_version) vts_spec_protos = [] for vts_spec in self.VtsSpecNames(hal_name, hal_version): spec_proto = CompSpecMsg.ComponentSpecificationMessage() vts_spec_path = os.path.join(vts_spec_dir, vts_spec) with open(vts_spec_path, 'r') as spec_file: spec_string = spec_file.read() text_format.Merge(spec_string, spec_proto) vts_spec_protos.append(spec_proto) return vts_spec_protos
def UpdateHalDirBuildRule(self, hal_list, test_config_dir): """Updates build rules for vts drivers/profilers. Updates vts drivers/profilers for each pair of (hal_name, hal_version) in hal_list. Args: hal_list: list of tuple of strings. For example, [('vibrator', '1.3'), ('sensors', '1.7')] test_config_dir: string, directory storing the configurations. """ for target in hal_list: hal_name = target[0] hal_version = target[1] hal_dir = os.path.join( self._ANDROID_BUILD_TOP, test_config_dir, utils.HalNameDir(hal_name), utils.HalVerDir(hal_version)) file_path = os.path.join(hal_dir, 'build', 'Android.bp') utils.WriteBuildRule(file_path, self._VtsBuildRuleFromTemplate( self._VTS_BUILD_TEMPLATE, hal_name, hal_version))
def GeneratedOutput(hal_name, hal_version, extension): """Formats list of vts spec names into a string. Formats list of vts spec name for given hal_name, hal_version into a string that can be inserted into build template. Args: hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' extension: string, extension of files e.g. '.cpp'. Returns: string, to be inserted into build template. """ result = [] vts_spec_names = self._vts_spec_parser.VtsSpecNames(hal_name, hal_version) for vts_spec in vts_spec_names: result.append('%s/%s/%s/%s%s' % (package_root_dir, utils.HalNameDir(hal_name), hal_version, vts_spec, extension)) return ListToBuildString(result, 2)
def _FillOutBuildRuleTemplate(self, hal_name, hal_version, template): """Returns build rules in string form by filling out given template. Args: hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' template: string, build rule template to fill out. Returns: string, complete build rule in string form. """ def GeneratedOutput(hal_name, hal_version, extension): """Formats list of vts spec names into a string. Formats list of vts spec name for given hal_name, hal_version into a string that can be inserted into build template. Args: hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' extension: string, extension of files e.g. '.cpp'. Returns: string, to be inserted into build template. """ result = [] vts_spec_names = self._vts_spec_parser.VtsSpecNames( hal_name, hal_version) for vts_spec in vts_spec_names: result.append('"android/hardware/%s/%s/%s%s",' % (utils.HalNameDir(hal_name), hal_version, vts_spec, extension)) return '\n '.join(result) def ImportedPackages(vts_pkg_type, imported_packages): """Formats list of imported packages into a string. Formats list of imported packages for given hal_name, hal_version into a string that can be inserted into build template. Args: vts_pkg_type: string 'driver' or 'profiler' imported_packages: list of imported packages Returns: string, to be inserted into build template. """ result = [] for package in imported_packages: prefix = 'android.hardware.' if package.startswith(prefix): # TODO(b/36475863) result.append('"%s",' % package) vts_pkg_name = package + '-vts.' + vts_pkg_type result.append('"%s",' % vts_pkg_name) else: result.append('"%s",' % package) return '\n '.join(result) build_rule = self._warning_header + template build_rule = build_rule.replace('{HAL_NAME}', hal_name) build_rule = build_rule.replace('{HAL_NAME_DIR}', utils.HalNameDir(hal_name)) build_rule = build_rule.replace('{HAL_VERSION}', hal_version) build_rule = build_rule.replace( '{GENERATED_VTS_SPECS}', GeneratedOutput(hal_name, hal_version, '')) build_rule = build_rule.replace( '{GENERATED_SOURCES}', GeneratedOutput(hal_name, hal_version, '.cpp')) build_rule = build_rule.replace( '{GENERATED_HEADERS}', GeneratedOutput(hal_name, hal_version, '.h')) imported_packages = self._vts_spec_parser.ImportedPackagesList( hal_name, hal_version) build_rule = build_rule.replace( '{IMPORTED_DRIVER_PACKAGES}', ImportedPackages('driver', imported_packages)) build_rule = build_rule.replace( '{IMPORTED_PROFILER_PACKAGES}', ImportedPackages('profiler', imported_packages)) return build_rule
def _FillOutBuildRuleTemplate(self, hal_name, hal_version, template): """Returns build rules in string form by filling out given template. Args: hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' template: string, build rule template to fill out. Returns: string, complete build rule in string form. """ package_root_dir = self._package_root.replace(".", "/") def GeneratedOutput(hal_name, hal_version, extension): """Formats list of vts spec names into a string. Formats list of vts spec name for given hal_name, hal_version into a string that can be inserted into build template. Args: hal_name: string, name of the hal, e.g. 'vibrator'. hal_version: string, version of the hal, e.g '7.4' extension: string, extension of files e.g. '.cpp'. Returns: string, to be inserted into build template. """ result = [] vts_spec_names = self._vts_spec_parser.VtsSpecNames(hal_name, hal_version) for vts_spec in vts_spec_names: result.append('%s/%s/%s/%s%s' % (package_root_dir, utils.HalNameDir(hal_name), hal_version, vts_spec, extension)) return ListToBuildString(result, 2) def ImportedPackages(vts_pkg_type, imported_packages): """Formats list of imported packages into a string. Formats list of imported packages for given hal_name, hal_version into a string that can be inserted into build template. Args: vts_pkg_type: string 'driver' or 'profiler' imported_packages: list of imported packages Returns: string, to be inserted into build template. """ result = [] for package in imported_packages: if re.match(Constant.HAL_PACKAGE_NAME_PATTERN, package): vts_pkg_name = package + '-vts.' + vts_pkg_type result.append(vts_pkg_name) else: result.append(package) return ListToBuildString(result, 2) build_rule = self._warning_header + template build_rule = build_rule.replace('{HAL_NAME}', hal_name) build_rule = build_rule.replace('{HAL_NAME_DIR}', utils.HalNameDir(hal_name)) build_rule = build_rule.replace('{HAL_VERSION}', hal_version) build_rule = build_rule.replace('{PACKAGE_ROOT}', self._package_root) build_rule = build_rule.replace('{PACKAGE_ROOT_DIR}', package_root_dir) build_rule = build_rule.replace( '{HIDL_GEN_ARGS}', "-r %s:%s" % (self._package_root, self._path_root)) build_rule = build_rule.replace( '{GENERATED_VTS_SPECS}', GeneratedOutput(hal_name, hal_version, '')) build_rule = build_rule.replace( '{GENERATED_SOURCES}', GeneratedOutput(hal_name, hal_version, '.cpp')) build_rule = build_rule.replace( '{GENERATED_HEADERS}', GeneratedOutput(hal_name, hal_version, '.h')) imported_packages = self._vts_spec_parser.ImportedPackagesList( hal_name, hal_version) build_rule = build_rule.replace( '{IMPORTED_DRIVER_PACKAGES}', ImportedPackages('driver', imported_packages)) build_rule = build_rule.replace( '{IMPORTED_PROFILER_PACKAGES}', ImportedPackages('profiler', imported_packages)) this_package = '%s.%s@%s' % (self._package_root, hal_name, hal_version) imported_packages.append(this_package) hal_libs = sorted(imported_packages) build_rule = build_rule.replace( '{HAL_LIBS}', ListToBuildString(hal_libs, 2)) return build_rule