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