1#!/usr/bin/python 2 3# This tool is used to generate the version scripts for libc and libm 4# for every architecture. 5 6import atexit 7import os.path 8import shutil 9import tempfile 10import sys 11 12 13all_arches = ["arm", "arm64", "mips", "mips64", "x86", "x86_64"] 14bionic_libc_root = os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libc") 15bionic_libm_root = os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libm") 16bionic_libdl_root = os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libdl") 17libc_script = os.path.join(bionic_libc_root, "libc.map.txt") 18libm_script = os.path.join(bionic_libm_root, "libm.map.txt") 19libdl_script = os.path.join(bionic_libdl_root, "libdl.map.txt") 20libstdcxx_script = os.path.join(bionic_libc_root, "libstdc++.map.txt") 21 22script_name = os.path.basename(sys.argv[0]) 23 24# TODO (dimity): generate architecture-specific version scripts as part of build 25 26# temp directory where we store all intermediate files 27bionic_temp = tempfile.mkdtemp(prefix="bionic_genversionscripts") 28# Make sure the directory is deleted when the script exits. 29atexit.register(shutil.rmtree, bionic_temp) 30 31bionic_libc_root = os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libc") 32 33warning = "Generated by %s. Do not edit." % script_name 34 35 36def has_arch_tags(tags): 37 for arch in all_arches: 38 if arch in tags: 39 return True 40 return False 41 42 43class VersionScriptGenerator(object): 44 45 def run(self): 46 for script in [libc_script, libstdcxx_script, libm_script, libdl_script]: 47 basename = os.path.basename(script) 48 dirname = os.path.dirname(script) 49 for arch in all_arches: 50 name = basename.split(".")[0] + "." + arch + ".map" 51 tmp_path = os.path.join(bionic_temp, name) 52 dest_path = os.path.join(dirname, name) 53 with open(tmp_path, "w") as fout: 54 with open(script, "r") as fin: 55 fout.write("# %s\n" % warning) 56 for line in fin: 57 index = line.find("#") 58 if index != -1: 59 tags = line[index+1:].split() 60 if arch not in tags and has_arch_tags(tags): 61 continue 62 fout.write(line) 63 shutil.copyfile(tmp_path, dest_path) 64 65 66generator = VersionScriptGenerator() 67generator.run() 68