()
| 101 | |
| 102 | |
| 103 | def main(): |
| 104 | ap = argparse.ArgumentParser(description='Prepare LIEF third-party and configured headers for checked-in sources') |
| 105 | ap.add_argument('--source-dir', required=True, help='Path to the unzipped LIEF source directory (e.g. /tmp/LIEF-<ver>/)') |
| 106 | ap.add_argument('--lief-dir', required=True, help='Target path to deps/LIEF (the vendored destination in this repo)') |
| 107 | ap.add_argument('--version', help='LIEF version (X.Y.Z). If omitted, try to infer a fallback (0.17.0).') |
| 108 | ap.add_argument('--commit', default='', help='Commit hash to embed into version.h (optional)') |
| 109 | ap.add_argument('--tag', default='', help='Git tag to embed into version.h (optional)') |
| 110 | args = ap.parse_args() |
| 111 | |
| 112 | source_dir = Path(args.source_dir).resolve() |
| 113 | lief_dir = Path(args.lief_dir).resolve() |
| 114 | if not source_dir.exists(): |
| 115 | print(f"source-dir does not exist: {source_dir}", file=sys.stderr) |
| 116 | return 1 |
| 117 | if not lief_dir.exists(): |
| 118 | ensure_dir(lief_dir) |
| 119 | |
| 120 | # 1) Copy only the relevant files from source_dir to lief_dir |
| 121 | included_dirs = ['src', 'include', 'config', 'README.md', 'LICENSE'] |
| 122 | for item in included_dirs: |
| 123 | src = source_dir / item |
| 124 | dst = lief_dir / item |
| 125 | if not src.exists(): |
| 126 | print(f"Warning: expected item missing: {src}", file=sys.stderr) |
| 127 | continue |
| 128 | print(f"Copying {src} -> {dst}") |
| 129 | if src.is_dir(): |
| 130 | if dst.exists(): |
| 131 | shutil.rmtree(dst) |
| 132 | shutil.copytree(src, dst) |
| 133 | else: |
| 134 | shutil.copy2(src, dst) |
| 135 | |
| 136 | # 2) Extract selected third-party zips into third-party/<base> |
| 137 | # Keep this generic via a small allowlist so we can extend later if needed. |
| 138 | # For now, we only extract 'mbedtls'. |
| 139 | src_third_party = source_dir / 'third-party' |
| 140 | dst_third_party = lief_dir / 'third-party' |
| 141 | ensure_dir(dst_third_party) |
| 142 | |
| 143 | # Use a temporary third party directory, then move needed files to lief_dir |
| 144 | tmp_third_party = Path(tempfile.mkdtemp()) |
| 145 | # For example, src_third_party/mbedtls-<ver>.zip contains mbedtls-<ver>/, |
| 146 | # we extract that to tmp_third_party/mbedtls, and in the extracted directory, we |
| 147 | # only want to copy the 'library' folder, so tmp_third_party/mbedtls/library -> |
| 148 | # dst_third_party/mbedtls/library. Any other files under the extracted mbedtls |
| 149 | # directory will be ignored. |
| 150 | libs_to_extract = { |
| 151 | 'mbedtls': ['library', 'include', 'README.md', 'LICENSE'], # #include "mbedtls/private_access.h" |
| 152 | 'spdlog': ['include', 'src', 'LICENSE', 'README.md'], # #include "spdlog/fmt/..." |
| 153 | 'frozen': ['include', 'LICENSE', 'README.rst'], # #include <frozen/map.h> |
| 154 | 'expected': ['include', 'README.md', 'COPYING'], # #include <LIEF/third-party/internal/expected.hpp> |
| 155 | 'utfcpp': ['source', 'README.md', 'LICENSE'], # #include <internal/utfcpp/utf8/unchecked.h> | #include "utf8/unchecked.h" |
| 156 | 'tcb-span': ['span.hpp'], # #include <LIEF/third-party/internal/span.hpp> |
| 157 | } |
| 158 | extracted_libs = [] |
| 159 | with tempfile.TemporaryDirectory() as _tmp_dir: |
| 160 | tmp_third_party = Path(_tmp_dir) |
no test coverage detected
searching dependent graphs…