Download a platform-appropriate clang-format binary if one doesn't already exist at the expected location and verify that it is the right binary by checking its SHA1 hash against the expected hash.
()
| 47 | |
| 48 | |
| 49 | def get_and_check_clang_format(): |
| 50 | """ |
| 51 | Download a platform-appropriate clang-format binary if one doesn't already exist at the expected location and verify |
| 52 | that it is the right binary by checking its SHA1 hash against the expected hash. |
| 53 | """ |
| 54 | # If the host platform is not in PLATFORM_TO_HASH, it is unsupported. |
| 55 | if HOST_PLATFORM not in PLATFORM_TO_HASH: |
| 56 | print(f"Unsupported platform: {HOST_PLATFORM}") |
| 57 | return False |
| 58 | if HOST_PLATFORM not in PLATFORM_TO_CF_URL: |
| 59 | print(f"Unsupported platform: {HOST_PLATFORM}") |
| 60 | return False |
| 61 | |
| 62 | try: |
| 63 | download_url( |
| 64 | PLATFORM_TO_CF_URL[HOST_PLATFORM], CLANG_FORMAT_PATH, PLATFORM_TO_HASH[HOST_PLATFORM], hash_type="sha256" |
| 65 | ) |
| 66 | except Exception as e: |
| 67 | print(f"Download {CLANG_FORMAT_PATH} failed: {e}") |
| 68 | print(f"Please remove {CLANG_FORMAT_PATH} and retry.") |
| 69 | return False |
| 70 | |
| 71 | # Make sure the binary is executable. |
| 72 | mode = os.stat(CLANG_FORMAT_PATH).st_mode |
| 73 | mode |= stat.S_IXUSR |
| 74 | os.chmod(CLANG_FORMAT_PATH, mode) |
| 75 | print(f"Using clang-format located at {CLANG_FORMAT_PATH}") |
| 76 | |
| 77 | return True |
| 78 | |
| 79 | |
| 80 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…