1 | #!/usr/bin/python
|
---|
2 |
|
---|
3 | import glob
|
---|
4 | import os
|
---|
5 | import subprocess
|
---|
6 | import sys
|
---|
7 | from sets import Set
|
---|
8 | from operator import itemgetter
|
---|
9 |
|
---|
10 |
|
---|
11 | current_arch = sys.argv[1]
|
---|
12 |
|
---|
13 | print("Building Index Table")
|
---|
14 |
|
---|
15 | if current_arch not in ("x86_64", "arm64"):
|
---|
16 | sys.exit()
|
---|
17 |
|
---|
18 | bitcode_file_original_directory = os.path.join(os.getenv("TARGET_TEMP_DIR"), "Objects-" + os.getenv("CURRENT_VARIANT"), current_arch)
|
---|
19 |
|
---|
20 | if not os.path.isdir(bitcode_file_original_directory):
|
---|
21 | print("Failed to build index table at " + bitcode_file_original_directory)
|
---|
22 | sys.exit()
|
---|
23 |
|
---|
24 | framework_directory = os.path.join(os.getenv("BUILT_PRODUCTS_DIR"), os.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch)
|
---|
25 |
|
---|
26 |
|
---|
27 | symbol_table_location = os.path.join(framework_directory, "Runtime.symtbl")
|
---|
28 |
|
---|
29 | symbol_table = {}
|
---|
30 |
|
---|
31 | symbol_table_is_out_of_date = False
|
---|
32 |
|
---|
33 | symbol_table_modification_time = 0
|
---|
34 |
|
---|
35 | if os.path.isfile(symbol_table_location):
|
---|
36 | symbol_table_modification_time = os.path.getmtime(symbol_table_location)
|
---|
37 |
|
---|
38 | file_suffix = "bc"
|
---|
39 | file_suffix_length = len(file_suffix)
|
---|
40 |
|
---|
41 | tested_symbols_location = "./tested-symbols.symlst"
|
---|
42 | include_symbol_table_location = os.path.join(os.getenv("SHARED_DERIVED_FILE_DIR"), "JavaScriptCore/InlineRuntimeSymbolTable.h")
|
---|
43 |
|
---|
44 | tested_symbols = Set([])
|
---|
45 |
|
---|
46 | if os.path.isfile(tested_symbols_location):
|
---|
47 | with open(tested_symbols_location, 'r') as file:
|
---|
48 | print("Loading tested symbols")
|
---|
49 | for line in file:
|
---|
50 | tested_symbols.add(line[:-1])
|
---|
51 |
|
---|
52 | print ("Original directory: " + bitcode_file_original_directory)
|
---|
53 |
|
---|
54 | for bitcode_file in glob.iglob(os.path.join(framework_directory, "*." + file_suffix)):
|
---|
55 | bitcode_basename = os.path.basename(bitcode_file)
|
---|
56 | bitcode_file_original = os.path.join(bitcode_file_original_directory, bitcode_basename[:-file_suffix_length] + "o")
|
---|
57 | if os.path.getmtime(bitcode_file_original) < symbol_table_modification_time:
|
---|
58 | continue
|
---|
59 |
|
---|
60 | symbol_table_is_out_of_date = True
|
---|
61 |
|
---|
62 | print("Appending symbols from " + bitcode_basename)
|
---|
63 | lines = subprocess.check_output(["nm", "-U", "-j", bitcode_file]).splitlines()
|
---|
64 |
|
---|
65 | for symbol in lines:
|
---|
66 | if symbol[:2] == "__" and symbol[-3:] != ".eh" and symbol in tested_symbols:
|
---|
67 | symbol_table[symbol[1:]] = bitcode_basename
|
---|
68 |
|
---|
69 | if not symbol_table_is_out_of_date:
|
---|
70 | sys.exit()
|
---|
71 |
|
---|
72 | if os.path.isfile(symbol_table_location):
|
---|
73 | with open(symbol_table_location, 'r') as file:
|
---|
74 | print("Loading symbol table")
|
---|
75 | for line in file:
|
---|
76 | symbol, _, location = line[:-1].partition(" ")
|
---|
77 | # don't overwrite new symbols with old locations
|
---|
78 | if not symbol in symbol_table:
|
---|
79 | symbol_table[symbol] = location
|
---|
80 |
|
---|
81 | symbol_list = symbol_table.items()
|
---|
82 |
|
---|
83 | print("Writing symbol table: " + symbol_table_location)
|
---|
84 | print("Writing inline file: " + include_symbol_table_location)
|
---|
85 |
|
---|
86 | with open(symbol_table_location, "w") as symbol_file:
|
---|
87 | with open(include_symbol_table_location, "w") as include_file:
|
---|
88 | include_file.write("#define FOR_EACH_LIBRARY_SYMBOL(macro)")
|
---|
89 | for symbol, location in symbol_list:
|
---|
90 | symbol_file.write("{} {}\n".format(symbol, location))
|
---|
91 | include_file.write(" \\\nmacro(\"{}\", \"{}\")".format(symbol, location))
|
---|
92 | include_file.write("\n")
|
---|
93 | print("Done")
|
---|