From 4d6e9a89e99404d918c34dd486d5660205f1b92e Mon Sep 17 00:00:00 2001 From: blackandred <22807686+blackandred@users.noreply.github.com> Date: Thu, 24 Mar 2022 08:31:30 +0100 Subject: [PATCH] fix: ldd was not always found --- assets/extraction.go | 4 ++++ hack/get-binary-with-libs.py | 26 ++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/assets/extraction.go b/assets/extraction.go index 7d3295e..b594ed8 100644 --- a/assets/extraction.go +++ b/assets/extraction.go @@ -15,6 +15,10 @@ import ( func UnpackAll(targetDir string) (bool, error) { var hasAtLeastOneError bool + if err := os.RemoveAll(targetDir); err != nil { + return false, errors.Wrapf(err, "Cannot delete temporary directory at path: '%s'", targetDir) + } + if err := os.MkdirAll(targetDir, 0755); err != nil { return false, errors.Wrapf(err, "Cannot create directory '%s'", targetDir) } diff --git a/hack/get-binary-with-libs.py b/hack/get-binary-with-libs.py index 2d78db1..c5f06a9 100755 --- a/hack/get-binary-with-libs.py +++ b/hack/get-binary-with-libs.py @@ -28,16 +28,24 @@ def copy_dependencies_for_path(bin_path: str, target_dir: str, depth: int = 0): print(ldd) for line in ldd: - if not line.strip() or "=>" not in line: + is_static_ld = "=>" not in line and "ld-" in line + + if not line.strip() or ("=>" not in line and not is_static_ld): continue - try: - parsed = re.findall('=>\s*([/A-Za-z\-_.0-9]+)\ ', line) - orig_name = re.findall('\s*([A-Za-z\-_.0-9]+)\s*=>', line) - finally: - print(">> Line caused error: ", line) + if is_static_ld: + parsed = re.findall('\s*([\/A-Za-z\-_.0-9]+)\ ', line) + orig_name = os.path.basename(parsed[0]) + else: + try: + parsed = re.findall('=>\s*([\/A-Za-z\-_.0-9]+)\ ', line) + orig_name = re.findall('\s*([A-Za-z\-_.0-9]+)\s*=>', line) + except Exception as e: + print(">> Line caused error: ", line) + print(" Exception: ", e) + raise - orig_name = orig_name[0] + orig_name = orig_name[0] if parsed[0] == "ldd": # ['\tldd (0x7f5a18c9c000)', '\tlibc.musl-x86_64.so.1 => ldd (0x7f5a18c9c000)', ''] @@ -46,7 +54,9 @@ def copy_dependencies_for_path(bin_path: str, target_dir: str, depth: int = 0): real_path = subprocess.check_output(['readlink', '-f', parsed[0]]).decode('utf-8').strip() print((" " * depth * 2) + f">> Copying {real_path} -> {orig_name}") subprocess.check_call(['cp', real_path, target_dir + "/" + orig_name]) - copy_dependencies_for_path(real_path, target_dir, depth + 1) + + if not is_static_ld: + copy_dependencies_for_path(real_path, target_dir, depth + 1) ALREADY_COPIED.append(bin_path)