Refactor compare_images
* Drop unused import * Simplify filename globbing logic Test: Manually test noop Change-Id: Ib1e491a47b2fd4fa76884571259f8c6764dbb547
This commit is contained in:
@@ -18,7 +18,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from operator import itemgetter
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import argparse
|
import argparse
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -42,7 +41,9 @@ def sha1sum_without_signing_key(filepath):
|
|||||||
|
|
||||||
def strip_and_sha1sum(filepath):
|
def strip_and_sha1sum(filepath):
|
||||||
tmp_filepath = filepath + '.tmp.no-build-id'
|
tmp_filepath = filepath + '.tmp.no-build-id'
|
||||||
strip_all_and_remove_build_id = lambda: silent_call(["llvm-strip", "--strip-all", "--keep-section=.ARM.attributes", "--remove-section=.note.gnu.build-id", filepath, "-o", tmp_filepath])
|
strip_all_and_remove_build_id = lambda: silent_call(
|
||||||
|
["llvm-strip", "--strip-all", "--keep-section=.ARM.attributes",
|
||||||
|
"--remove-section=.note.gnu.build-id", filepath, "-o", tmp_filepath])
|
||||||
try:
|
try:
|
||||||
if strip_all_and_remove_build_id():
|
if strip_all_and_remove_build_id():
|
||||||
return sha1sum(tmp_filepath)
|
return sha1sum(tmp_filepath)
|
||||||
@@ -58,27 +59,26 @@ def strip_and_sha1sum(filepath):
|
|||||||
def main(all_targets, search_paths, ignore_signing_key=False):
|
def main(all_targets, search_paths, ignore_signing_key=False):
|
||||||
def get_target_name(path):
|
def get_target_name(path):
|
||||||
return os.path.basename(os.path.normpath(path))
|
return os.path.basename(os.path.normpath(path))
|
||||||
|
|
||||||
|
def run(path):
|
||||||
|
is_native_component = silent_call(["llvm-objdump", "-a", path])
|
||||||
|
is_apk = path.endswith('.apk')
|
||||||
|
if is_native_component:
|
||||||
|
return strip_and_sha1sum(path)
|
||||||
|
elif is_apk and ignore_signing_key:
|
||||||
|
return sha1sum_without_signing_key(path)
|
||||||
|
else:
|
||||||
|
return sha1sum(path)
|
||||||
|
|
||||||
artifact_target_map = defaultdict(list)
|
artifact_target_map = defaultdict(list)
|
||||||
for target in all_targets:
|
for target in all_targets:
|
||||||
def valid_path(p):
|
paths = []
|
||||||
if os.path.isdir(p) or not os.path.exists(p):
|
for search_path in search_paths:
|
||||||
return False
|
for path in Path(target, search_path).glob('**/*'):
|
||||||
for s in search_paths:
|
if path.exists() and not path.is_dir():
|
||||||
if os.path.join(target, s).lower() + os.path.sep in p.lower():
|
paths.append((str(path), str(path.relative_to(target))))
|
||||||
return True
|
|
||||||
return False
|
|
||||||
paths = [str(path) for path in Path(target).glob('**/*') if valid_path(str(path))]
|
|
||||||
|
|
||||||
def run(path):
|
results = [(run(path), filename) for path, filename in paths]
|
||||||
is_native_component = silent_call(["llvm-objdump", "-a", path])
|
|
||||||
is_apk = path.endswith('.apk')
|
|
||||||
if is_native_component:
|
|
||||||
return strip_and_sha1sum(path), path[len(target):]
|
|
||||||
elif is_apk and ignore_signing_key:
|
|
||||||
return sha1sum_without_signing_key(path), path[len(target):]
|
|
||||||
else:
|
|
||||||
return sha1sum(path), path[len(target):]
|
|
||||||
results = [run(p) for p in paths]
|
|
||||||
|
|
||||||
for sha1, filename in results:
|
for sha1, filename in results:
|
||||||
artifact_target_map[(sha1, filename)].append(get_target_name(target))
|
artifact_target_map[(sha1, filename)].append(get_target_name(target))
|
||||||
|
|||||||
Reference in New Issue
Block a user