(original_nso: Optional[Path])
| 111 | |
| 112 | |
| 113 | def prepare_executable(original_nso: Optional[Path]): |
| 114 | COMPRESSED_HASH = "63b7d29503400853c2cdb87a65d963cb9b5b934aea9d3d88b55764d33b13a722" |
| 115 | UNCOMPRESSED_HASH = "f408dbfb901ab191fbcb7b5994580ed91812bafa90ae164796ae8a254e4dcef8" |
| 116 | |
| 117 | target_hash = file_sha256(original_nso) |
| 118 | |
| 119 | if TARGET_PATH.is_file() and target_hash == COMPRESSED_HASH or target_hash == UNCOMPRESSED_HASH and TARGET_ELF_PATH.is_file(): |
| 120 | print(">>> NSO is already set up") |
| 121 | return |
| 122 | |
| 123 | if original_nso is None: |
| 124 | setup.fail("please pass a path to the NSO (refer to the readme for more details)") |
| 125 | |
| 126 | if not original_nso.is_file(): |
| 127 | setup.fail(f"{original_nso} is not a file") |
| 128 | |
| 129 | nso_hash = file_sha256(original_nso) |
| 130 | |
| 131 | if nso_hash == UNCOMPRESSED_HASH: |
| 132 | print(">>> found uncompressed NSO") |
| 133 | |
| 134 | elif nso_hash == COMPRESSED_HASH: |
| 135 | print(">>> found compressed NSO") |
| 136 | |
| 137 | else: |
| 138 | setup.fail(f"unknown executable: {nso_hash}") |
| 139 | |
| 140 | setup._convert_nso_to_elf(original_nso) |
| 141 | |
| 142 | converted_elf_path = original_nso.with_suffix(".elf") |
| 143 | |
| 144 | if not converted_elf_path.is_file(): |
| 145 | setup.fail("internal error while preparing executable (missing ELF); please report") |
| 146 | |
| 147 | shutil.move(converted_elf_path, TARGET_ELF_PATH) |
| 148 | |
| 149 | uncompressed_nso_path = original_nso.with_suffix(".uncompressed.nso") |
| 150 | shutil.move(uncompressed_nso_path, TARGET_UNCOMPRESSED_NSO_PATH) |
| 151 | |
| 152 | if not TARGET_UNCOMPRESSED_NSO_PATH.is_file() or file_sha256(TARGET_UNCOMPRESSED_NSO_PATH) != UNCOMPRESSED_HASH: |
| 153 | setup.fail("Internal error while exporting uncompressed NSO (uncompressed NSO either doesn't exist or has an incorrect hash); please report") |
| 154 | |
| 155 | def get_build_dir(): |
| 156 | return setup.ROOT / "build" |
no test coverage detected