diff options
-rwxr-xr-x | scripts/gen-lockedsig-cache | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/scripts/gen-lockedsig-cache b/scripts/gen-lockedsig-cache index e3076e11a5..48cb67112f 100755 --- a/scripts/gen-lockedsig-cache +++ b/scripts/gen-lockedsig-cache | |||
@@ -5,9 +5,9 @@ | |||
5 | 5 | ||
6 | import os | 6 | import os |
7 | import sys | 7 | import sys |
8 | import glob | ||
9 | import shutil | 8 | import shutil |
10 | import errno | 9 | import errno |
10 | import time | ||
11 | 11 | ||
12 | def mkdir(d): | 12 | def mkdir(d): |
13 | try: | 13 | try: |
@@ -16,6 +16,36 @@ def mkdir(d): | |||
16 | if e.errno != errno.EEXIST: | 16 | if e.errno != errno.EEXIST: |
17 | raise e | 17 | raise e |
18 | 18 | ||
19 | # extract the hash from past the last colon to last underscore | ||
20 | def extract_sha(filename): | ||
21 | return filename.split(':')[7].split('_')[0] | ||
22 | |||
23 | # get all files in a directory, extract hash and make | ||
24 | # a map from hash to list of file with that hash | ||
25 | def map_sha_to_files(dir_, prefix, sha_map): | ||
26 | sstate_prefix_path = dir_ + '/' + prefix + '/' | ||
27 | sstate_files = os.listdir(sstate_prefix_path) | ||
28 | for f in sstate_files: | ||
29 | try: | ||
30 | sha = extract_sha(f) | ||
31 | if sha not in sha_map: | ||
32 | sha_map[sha] = [] | ||
33 | sha_map[sha].append(sstate_prefix_path + f) | ||
34 | except IndexError: | ||
35 | continue | ||
36 | |||
37 | # given a prefix build a map of hash to list of files | ||
38 | def build_sha_cache(prefix): | ||
39 | sha_map = {} | ||
40 | |||
41 | sstate_dir = sys.argv[2] | ||
42 | map_sha_to_files(sstate_dir, prefix, sha_map) | ||
43 | |||
44 | native_sstate_dir = sys.argv[2] + '/' + sys.argv[4] | ||
45 | map_sha_to_files(native_sstate_dir, prefix, sha_map) | ||
46 | |||
47 | return sha_map | ||
48 | |||
19 | if len(sys.argv) < 5: | 49 | if len(sys.argv) < 5: |
20 | print("Incorrect number of arguments specified") | 50 | print("Incorrect number of arguments specified") |
21 | print("syntax: gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir> <nativelsbstring> [filterfile]") | 51 | print("syntax: gen-lockedsig-cache <locked-sigs.inc> <input-cachedir> <output-cachedir> <nativelsbstring> [filterfile]") |
@@ -41,12 +71,19 @@ with open(sys.argv[1]) as f: | |||
41 | sigs.append(sig) | 71 | sigs.append(sig) |
42 | 72 | ||
43 | print('Gathering file list') | 73 | print('Gathering file list') |
74 | start_time = time.perf_counter() | ||
44 | files = set() | 75 | files = set() |
76 | sstate_content_cache = {} | ||
45 | for s in sigs: | 77 | for s in sigs: |
46 | p = sys.argv[2] + "/" + s[:2] + "/*" + s + "*" | 78 | prefix = s[:2] |
47 | files |= set(glob.glob(p)) | 79 | if prefix not in sstate_content_cache: |
48 | p = sys.argv[2] + "/%s/" % sys.argv[4] + s[:2] + "/*" + s + "*" | 80 | sstate_content_cache[prefix] = build_sha_cache(prefix) |
49 | files |= set(glob.glob(p)) | 81 | |
82 | for f in sstate_content_cache[prefix][s]: | ||
83 | files.add(f) | ||
84 | |||
85 | elapsed = time.perf_counter() - start_time | ||
86 | print("Gathering file list took %.1fs" % elapsed) | ||
50 | 87 | ||
51 | print('Processing files') | 88 | print('Processing files') |
52 | for f in files: | 89 | for f in files: |