Skip to content

Commit 0d8d6c3

Browse files
author
chli
committed
fix:code update
1 parent 2e7f054 commit 0d8d6c3

File tree

3 files changed

+136
-14
lines changed

3 files changed

+136
-14
lines changed

python/base/__init__.py

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ class BuildConfigure(object):
3737
workspace: str
3838
install_prefix: str
3939
action: str
40+
41+
def prepare(self):
42+
if not os.path.exists(self.workspace):
43+
os.makedirs(self.workspace)
44+
if not os.path.exists(self.install_prefix):
45+
os.makedirs(self.install_prefix)
46+
if not os.path.exists(self.get_arch_workspace()):
47+
os.makedirs(self.get_arch_workspace())
48+
if not os.path.exists(self.get_patch_dir()):
49+
os.makedirs(self.get_patch_dir())
50+
if not os.path.exists(self.get_samples_dir()):
51+
os.makedirs(self.get_samples_dir())
52+
53+
def get_arch_workspace(self):
54+
return os.path.join(self.workspace, self.arch)
55+
56+
def get_patch_dir(self):
57+
return os.path.join(self.workspace, "patches")
58+
59+
def get_samples_dir(self):
60+
return os.path.join(self.workspace, "samples")
61+
4062

4163
@dataclass
4264
class HostVars(object):
@@ -166,7 +188,7 @@ def get_platform_envs(cfg:BuildConfigure):
166188

167189

168190
class FFModule(ABC):
169-
def __init__(self, cfg: BuildConfigure, configs:dict = None):
191+
def __init__(self, cfg: BuildConfigure, toolchain:ToolchainVars, host:HostVars):
170192
"""_summary_
171193
172194
Args:
@@ -175,13 +197,18 @@ def __init__(self, cfg: BuildConfigure, configs:dict = None):
175197
"""
176198
self.cfg = cfg
177199
self.repo = None
178-
if configs:
179-
self.repo = Repo(configs["repo_url"], configs["repo_save_dir"])
180200

201+
@abstractmethod
202+
def get_module_config(self) ->dict:
203+
pass
181204

182-
def init_sample_repo(self):
205+
def init_sample_repo(self, repo_url, repo_save):
206+
self.repo = Repo(repo_url, repo_save)
183207
if self.repo:
184-
self.repo.clone()
208+
if not os.path.exists(repo_save):
209+
self.repo.clone()
210+
return
211+
print(f"Sample repo {repo_save} exists, skip cloing!")
185212
else:
186213
raise InitError("No repo, maybe not initialized?")
187214

@@ -202,21 +229,42 @@ def copy_sample_to_arch(self, parent_dir:str):
202229

203230
@abstractmethod
204231
def do_init():
232+
"""do the initialization
233+
1. clone the source code, or download the library
234+
2. prepare all the patches
235+
"""
205236
pass
206237

207238
@abstractmethod
208239
def do_install_prebuilt():
240+
"""install the prebuilt libraries
241+
if no prebuilt, an error will be raised.
242+
"""
209243
pass
210244

211245
@abstractmethod
212246
def prebuild(self):
247+
"""jobs before building
248+
1. copy to arch
249+
2. apply patches
250+
3. detect and setup third libraries
251+
4. prepare the directories
252+
"""
213253
pass
214254

215255
@abstractmethod
216-
def build(self, toolchain_vars: dict):
256+
def build(self, toolchain_vars: dict, host_vars: dict):
257+
"""do the build work
258+
259+
Args:
260+
toolchain_vars (dict): the detected toolchain variables
261+
host_vars: the detected host variables
262+
"""
217263
pass
218264

219265
@abstractmethod
220266
def postbuild(self):
267+
"""dirty works after build
268+
"""
221269
pass
222270

python/main.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import argparse
22
import logging
33
import base
4+
import os
5+
import module_ffmpeg
46

57
def setup_loggers(logger_path:str):
68
logger = logging.getLogger('build')
@@ -24,23 +26,45 @@ def setup_loggers(logger_path:str):
2426
logger.addHandler(console_handler)
2527
return logger
2628

29+
2730
def parse_args():
2831
parser = argparse.ArgumentParser()
2932
parser.add_argument('-p', '--platform', type=str, default='android', choices=['apple', 'android', 'ios', 'tvos', 'macos', 'all'], help='platform must be: [apple|android|ios|tvos|macos|all]')
3033
# only avalibale for apple
3134
parser.add_argument('-a', '--arch', type=str, default='arm64', choices=['arm64', 'arm64-simulator','x86_64', 'x86_64-simulator', 'all'], help='arch must be: [arm64|arm64-simulator|x86_64|x86_64-simulator|all], only avaliable for apple')
3235
parser.add_argument('-w', '--workspace', type=str, default='build', help='specify workspace')
3336
parser.add_argument('--prefix', type=str, help='install the library')
34-
parser.add_argument('--install', action='store_true', help='install the library')
35-
parser.add_argument('--init', action='store_true', help='initialize the library')
36-
parser.add_argument('--build', action='store_true', help='build the library')
37+
parser.add_argument('--action', type=str, default='init', choices=['init', 'build', 'install'], help='action must be: [init|build|install]')
38+
parser.add_argument('--library', type=str, default="", help='specify the library name')
39+
# parser.add_argument('--install', action='store_true', help='install the library')
40+
# # prepare the repo, clone the sample code, and don't build it.
41+
# parser.add_argument('--init', action='store_true', help='initialize the library')
42+
# parser.add_argument('--build', action='store_true', help='build the library')
3743

3844
args = parser.parse_args()
3945
return args
4046

47+
def preapre_workspaces(bcfg:base.BuildConfigure):
48+
if not bcfg.action == "init":
49+
logger.info("Not initialize the library, skip checking workspace!")
50+
return
51+
bcfg.prepare()
52+
4153
if __name__ == "__main__":
4254
args = parse_args()
4355
logger = setup_loggers("build.log")
44-
args = base.BuildConfigure(args.platform, args.arch, args.workspace, args.prefix, args.build)
45-
print(base.get_platform_envs(args))
56+
build_cfg = base.BuildConfigure(args.platform, args.arch, args.workspace, args.prefix, args.action)
57+
toolchain_vars, host_vars = base.get_platform_envs(build_cfg)
58+
preapre_workspaces(build_cfg)
59+
60+
ffmpeg_module = module_ffmpeg.FFMpegModule(build_cfg, toolchain_vars, host_vars)
61+
# "repo": "https://github.com/FFmpeg/FFmpeg.git",
62+
# "repo_env": "REPO_FFMPEG",
63+
# "repo_save_dir": "FFmpeg"
64+
ffconfig=ffmpeg_module.get_module_config()
65+
repo = os.environ.get(ffconfig["repo_env"], ffconfig['repo'])
66+
repo_save_dir= os.path.join(build_cfg.get_samples_dir(), ffconfig['repo_save_dir'])
67+
ffmpeg_module.init_sample_repo(repo, repo_save_dir)
68+
69+
# print(base.get_platform_envs(args))
4670
pass

python/module_ffmpeg/__init__.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22
import subprocess
3-
import config
3+
# import config
4+
from .config import *
5+
from base import *
6+
47
MODULE_CONFIG = {
58
"name": "ffmpeg",
69
"libraries": [
@@ -16,6 +19,8 @@
1619
"repo_save_dir": "FFmpeg"
1720
}
1821

22+
23+
1924
def wait_proc(proc:subprocess.Popen):
2025
sto, ste = proc.communicate()
2126
if proc.returncode != 0 :
@@ -39,7 +44,7 @@ def build_repo_android(source_path: str, install_prefix: str, toolchain_vars: di
3944
env.update(toolchain_vars)
4045
if not os.path.exists("config.h") or force_re_compile:
4146
# 构建命令参数
42-
cfg_flags = config.configs
47+
cfg_flags = configs
4348
triple_cc = env.get('TRIPLE_CC', '')
4449
ar = env.get('AR', '')
4550
nm = env.get('NM', '')
@@ -86,4 +91,49 @@ def build_repo_android(source_path: str, install_prefix: str, toolchain_vars: di
8691
finally:
8792
os.chdir(old_wk_dir)
8893

89-
# after build
94+
# after build
95+
96+
class FFMpegModule(FFModule):
97+
def __init__(self, cfg: BuildConfigure,toolchain:ToolchainVars, host:HostVars):
98+
super().__init__(cfg, toolchain, host)
99+
100+
def get_module_config(self):
101+
return MODULE_CONFIG
102+
103+
104+
def do_init():
105+
"""do the initialization
106+
1. clone the source code, or download the library
107+
2. prepare all the patches
108+
"""
109+
pass
110+
111+
def do_install_prebuilt():
112+
"""install the prebuilt libraries
113+
if no prebuilt, an error will be raised.
114+
"""
115+
pass
116+
117+
def prebuild(self):
118+
"""jobs before building
119+
1. copy to arch
120+
2. apply patches
121+
3. detect and setup third libraries
122+
4. prepare the directories
123+
"""
124+
pass
125+
126+
def build(self, toolchain_vars: dict, host_vars: dict):
127+
"""do the build work
128+
129+
Args:
130+
toolchain_vars (dict): the detected toolchain variables
131+
host_vars: the detected host variables
132+
"""
133+
pass
134+
135+
def postbuild(self):
136+
"""dirty works after build
137+
"""
138+
pass
139+

0 commit comments

Comments
 (0)