Skip to content

Commit 21017f1

Browse files
committed
translate to english
1 parent 1251bcd commit 21017f1

3 files changed

Lines changed: 138 additions & 138 deletions

File tree

fuzz/build_oss_fuzz.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"""
55
build_oss_fuzz.py
66
7-
并行构建 OSS-Fuzz 项目(Docker 镜像和 Fuzzer 编译)。
8-
使用 multiprocessing.Pool 将项目分发到多个 CPU 核心同时处理。
7+
Parallel build of OSS-Fuzz projects (Docker images and Fuzzer compilation).
8+
Uses multiprocessing.Pool to distribute projects across multiple CPU cores for concurrent processing.
99
10-
用法: python3 build_oss_fuzz.py [项目列表文件] [--sanitizer 类型] [--workers N]
11-
示例: python3 fuzz/build_oss_fuzz.py data/valid_projects.txt \
10+
Usage: python3 build_oss_fuzz.py [project_list_file] [--sanitizer type] [--workers N]
11+
Example: python3 fuzz/build_oss_fuzz.py data/valid_projects.txt \
1212
--sanitizer address \
1313
--workers 8
1414
"""
@@ -22,19 +22,19 @@
2222
from typing import List, Optional, Tuple
2323
from multiprocessing import Pool, cpu_count
2424

25-
# --- 全局配置 ---
25+
# --- Global configuration ---
2626
HOME_DIR = Path.home()
2727
OSS_FUZZ_DIR = HOME_DIR / "FuzzAug" / "fuzz" / "oss-fuzz"
2828
LOG_DIR = OSS_FUZZ_DIR / "build_logs"
2929

3030
def setup_logging(project_name: str) -> Path:
31-
"""为单个项目创建带时间戳的日志文件"""
31+
"""Create a timestamped log file for a single project"""
3232
LOG_DIR.mkdir(parents=True, exist_ok=True)
3333
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
3434
return LOG_DIR / f"build_{project_name}_{timestamp}.log"
3535

3636
def log_and_print(message: str, log_file: Path, to_stdout: bool = True):
37-
"""将消息写入日志并打印到控制台"""
37+
"""Write message to log and print to console"""
3838
if to_stdout:
3939
print(f"[PID:{os.getpid()}] {message}")
4040
with open(log_file, "a", encoding="utf-8") as f:
@@ -46,14 +46,14 @@ def run_command(
4646
log_file: Path,
4747
allowed_exit_codes: Optional[List[int]] = None
4848
) -> bool:
49-
"""执行 shell 命令并实时记录输出"""
49+
"""Execute a shell command and stream output to log in real-time"""
5050
allowed_exit_codes = allowed_exit_codes or []
5151
log_and_print(f"▶️ {log_msg}...", log_file, to_stdout=False)
5252
log_and_print(f" $ {cmd}", log_file, to_stdout=False)
5353

5454
try:
5555
process = subprocess.Popen(
56-
f"yes | {cmd}", # 自动确认所有提示
56+
f"yes | {cmd}", # Auto-confirm all prompts
5757
shell=True,
5858
stdout=subprocess.PIPE,
5959
stderr=subprocess.STDOUT,
@@ -67,67 +67,67 @@ def run_command(
6767
process.wait()
6868
exit_code = process.returncode
6969
if exit_code in [0, *allowed_exit_codes]:
70-
log_and_print(f"✅ 命令成功完成", log_file, to_stdout=False)
70+
log_and_print(f"✅ Command completed successfully", log_file, to_stdout=False)
7171
return True
72-
log_and_print(f"❌ 命令失败 (退出码: {exit_code})", log_file)
72+
log_and_print(f"❌ Command failed (exit code: {exit_code})", log_file)
7373
return False
7474
except Exception as e:
75-
log_and_print(f"💥 执行异常: {e}", log_file)
75+
log_and_print(f"💥 Execution exception: {e}", log_file)
7676
return False
7777

7878
def build_project(project_name: str, sanitizer: str) -> Tuple[bool, str]:
79-
"""单个项目的构建工作流"""
79+
"""Build workflow for a single project"""
8080
log_file = setup_logging(project_name)
8181
os.chdir(OSS_FUZZ_DIR)
8282

8383
log_and_print("="*60, log_file)
84-
log_and_print(f"🔨 开始构建项目: {project_name}", log_file)
85-
log_and_print(f"📝 日志路径: {log_file}", log_file)
84+
log_and_print(f"🔨 Starting build for project: {project_name}", log_file)
85+
log_and_print(f"📝 Log path: {log_file}", log_file)
8686
log_and_print("="*60, log_file)
8787

88-
# 1. 构建 Docker 镜像
88+
# 1. Build Docker image
8989
if not run_command(
9090
f"python3 infra/helper.py build_image {project_name}",
91-
"步骤1/2: 构建 Docker 镜像",
91+
"Step 1/2: Building Docker image",
9292
log_file
9393
):
9494
return (False, project_name)
9595

96-
# 2. 编译 Fuzzer
96+
# 2. Compile Fuzzers
9797
if not run_command(
9898
f"python3 infra/helper.py build_fuzzers --sanitizer {sanitizer} {project_name}",
99-
f"步骤2/2: 编译 Fuzzer (sanitizer={sanitizer})",
99+
f"Step 2/2: Compiling Fuzzers (sanitizer={sanitizer})",
100100
log_file
101101
):
102102
return (False, project_name)
103103

104-
log_and_print(f"✅ 项目 {project_name} 构建完成", log_file)
104+
log_and_print(f"✅ Project {project_name} build completed", log_file)
105105
return (True, project_name)
106106

107107
def main():
108-
parser = argparse.ArgumentParser(description="OSS-Fuzz 并行构建工具")
109-
parser.add_argument("project_list", help="项目列表文件路径")
108+
parser = argparse.ArgumentParser(description="OSS-Fuzz Parallel Build Tool")
109+
parser.add_argument("project_list", help="Project list file path")
110110
parser.add_argument("--sanitizer", default="address", choices=["address", "memory", "undefined"])
111111
parser.add_argument("--workers", type=int, default=cpu_count())
112112
args = parser.parse_args()
113113

114-
# 读取项目列表
114+
# Read project list
115115
try:
116116
with open(args.project_list, "r") as f:
117117
projects = [line.strip() for line in f if line.strip()]
118118
except Exception as e:
119-
print(f"❌ 读取项目列表失败: {e}")
119+
print(f"❌ Failed to read project list: {e}")
120120
sys.exit(1)
121121

122-
# 并行构建
122+
# Parallel build
123123
with Pool(args.workers) as pool:
124124
results = pool.starmap(build_project, [(p, args.sanitizer) for p in projects])
125125

126-
# 输出结果
126+
# Output results
127127
failed = [p for success, p in results if not success]
128-
print(f"\n📊 构建完成: 成功 {len(projects)-len(failed)}/{len(projects)}")
128+
print(f"\n📊 Build completed: Success {len(projects)-len(failed)}/{len(projects)}")
129129
if failed:
130-
print("❌ 失败项目: " + ", ".join(failed))
130+
print("❌ Failed projects: " + ", ".join(failed))
131131

132132
if __name__ == "__main__":
133133
main()

0 commit comments

Comments
 (0)