| 38 | |
| 39 | |
| 40 | def update_git_repo(): |
| 41 | try: |
| 42 | print("update third party repo...", flush=True) |
| 43 | original_dir = os.getcwd() |
| 44 | submodule_dir = os.path.dirname(os.path.abspath(__file__)) |
| 45 | third_party_path = os.path.join(submodule_dir, "third_party") |
| 46 | root_path = Path(third_party_path) |
| 47 | |
| 48 | # check if third_party is empty |
| 49 | update_third_party = False |
| 50 | for dirpath in root_path.iterdir(): |
| 51 | if dirpath.is_dir(): |
| 52 | has_content = any(dirpath.iterdir()) |
| 53 | if not has_content: |
| 54 | update_third_party = True |
| 55 | |
| 56 | if update_third_party: |
| 57 | os.chdir(submodule_dir) |
| 58 | subprocess.run( |
| 59 | "git submodule sync --recursive && git submodule update --init --recursive", |
| 60 | shell=True, |
| 61 | check=True, |
| 62 | text=True, |
| 63 | ) |
| 64 | else: |
| 65 | print( |
| 66 | "\033[33m[===WARNING===]third_party directory already exists, skip clone and update.\033[0m", |
| 67 | flush=True, |
| 68 | ) |
| 69 | |
| 70 | # apply deep gemm patch |
| 71 | deep_gemm_dir = "third_party/DeepGEMM" |
| 72 | dst_path = os.path.join(submodule_dir, deep_gemm_dir) |
| 73 | patch = "0001-DeepGEMM-95e81b3.patch" |
| 74 | patch_source = os.path.join(submodule_dir, patch) |
| 75 | patch_destination = os.path.join(dst_path, patch) |
| 76 | if not os.path.exists(patch_destination): |
| 77 | shutil.copy(patch_source, patch_destination) |
| 78 | apply_cmd = ["git", "apply", patch] |
| 79 | os.chdir(dst_path) |
| 80 | subprocess.run(apply_cmd, check=True) |
| 81 | os.chdir(original_dir) |
| 82 | except subprocess.CalledProcessError: |
| 83 | raise Exception("Git submodule update and apply patch failed. Maybe network connection is poor.") |
| 84 | |
| 85 | |
| 86 | ROOT_DIR = Path(__file__).parent.parent |