Skip to content

Commit 2e354d8

Browse files
author
chli
committed
支持patch(但目前会失败)
1 parent 837d885 commit 2e354d8

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

python/base/__init__.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ def __init__(self, repo_url, local_path, has_submodule=False):
2323
self.path_to_clone = local_path
2424
self.__repo = None
2525
self.__has_sub = has_submodule
26-
if not os.path.exists(self.path_to_clone):
27-
print(f"Directory {self.path_to_clone} does not exist, make it.")
28-
os.makedirs(self.path_to_clone)
26+
par_dir = os.path.dirname(self.path_to_clone)
27+
if not os.path.exists(par_dir):
28+
print(f"Directory {par_dir} does not exist, make it.")
29+
os.makedirs(par_dir)
2930

3031
def init(self):
32+
"""init repo
33+
init repo from an exsit repo or clone it.
34+
if repo has submodule, update it.
35+
"""
3136
if os.path.exists(self.path_to_clone):
3237
self.__repo = git.Repo(self.path_to_clone)
3338
else:
@@ -46,17 +51,28 @@ def create_local_branch_on_commit(self, branch_name, commit:str):
4651
branch.checkout()
4752

4853
def apply_patches(self, patch_dir):
49-
old_dir = os.curdir()
54+
# 修正 os.curdir() 为 os.getcwd()
55+
if not os.path.exists(patch_dir):
56+
print(f"Directory {patch_dir} does not exist, skip apply!")
57+
return
58+
patch_dir = os.path.abspath(patch_dir)
59+
old_dir = os.getcwd()
5060
os.chdir(self.get_repo_dir())
5161
res = os.system(f"git am --whitespace=fix --keep {patch_dir}/*.patch")
5262
os.chdir(old_dir)
5363
if res:
5464
raise InitError(f"Apply patches failed for {self.get_repo_dir()} within {patch_dir}")
5565

5666
def reset(self):
67+
"""abort rebase and fetch all tags
68+
"""
5769
if os.path.isdir(os.path.join(self.get_repo_dir(), '.git', 'rebase-apply')):
5870
self.__repo.git.am('--skip')
59-
71+
self.__repo.git.reset('--hard')
72+
# 使用 GitPython API 实现 git fetch --all --tags
73+
for remote in self.__repo.remotes:
74+
remote.fetch(tags=True, prune=True)
75+
6076
@dataclass
6177
class BuildConfigure(object):
6278
platform: str
@@ -240,12 +256,9 @@ def get_module_config(self) ->dict:
240256
def init_sample_repo(self, repo_url, repo_save):
241257
# TODO fix the spelling
242258
self.repo = Repo(repo_url, repo_save, self.module_config.get("has_submodule", False))
243-
if not os.path.exists(repo_save):
244-
self.repo.clone()
245-
return
246-
247-
# check if there is a patch
248-
print(f"Sample repo {repo_save} exists, skip cloing!")
259+
self.repo.init()
260+
self.repo.reset()
261+
self.repo.apply_patches(os.path.join(self.cfg.get_patch_dir(), self.module_config.get("patch_dir", "Not exist")))
249262

250263

251264
def copy_sample_to(self, target_dir):

python/module_ffmpeg/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
],
1717
"repo": "https://github.com/FFmpeg/FFmpeg.git",
1818
"repo_env": "REPO_FFMPEG",
19-
"repo_save_dir": "FFmpeg",
19+
"repo_save_dir": "ffmpeg7",
2020
"has_submodule": False,
21-
"patch_dir":"ffmpeg"
21+
"patch_dir":"ffmpeg-n7.1.1"
2222
}
2323

2424

python/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export ANDROID_NDK_HOME=/mnt/data/android-ndk-r27c
2+
python main.py -p android -a arm64 -w build --prefix install --action init --library ffmpeg7

0 commit comments

Comments
 (0)