修正了一些错误
This commit is contained in:
@@ -14,8 +14,38 @@ from lib.Projectrans.Phase1Generator import Phase1Generator
|
||||
from lib.Projectrans.Phase2Translator import Phase2Translator
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 全局 SHA1 映射内存存储器
|
||||
#
|
||||
# Phase1 生成 sha1_map 后写入此处(save_sha1_map),
|
||||
# Phase2 从此处读取(Load_sha1_map / Phase2Translator._LoadSha1Map)。
|
||||
# _sha1_map.txt 文件仅作为人类可读输出,不再作为机器分析数据源。
|
||||
# ============================================================
|
||||
_g_sha1_map_store: dict[str, str] = {}
|
||||
|
||||
|
||||
def get_sha1_map_store() -> dict[str, str]:
|
||||
"""返回全局 SHA1 映射内存存储器(供 Phase2Translator 直接访问)"""
|
||||
return _g_sha1_map_store
|
||||
|
||||
|
||||
def clear_sha1_map_store() -> None:
|
||||
"""清空全局 SHA1 映射内存存储器"""
|
||||
_g_sha1_map_store.clear()
|
||||
|
||||
|
||||
def save_sha1_map(temp_dir: str, sha1_map: dict[str, str]) -> None:
|
||||
"""将 SHA1 映射表保存到文件"""
|
||||
"""将 SHA1 映射表保存到内存存储器,并输出人类可读的 _sha1_map.txt
|
||||
|
||||
机器分析使用内存存储器(_g_sha1_map_store),
|
||||
_sha1_map.txt 仅作为人类可读输出,不再被机器读取。
|
||||
"""
|
||||
# 写入内存存储器(机器分析数据源)
|
||||
_g_sha1_map_store.clear()
|
||||
for sha1, rel in sha1_map.items():
|
||||
_g_sha1_map_store[sha1] = rel
|
||||
|
||||
# 写入文件(仅人类可读输出)
|
||||
map_path: str = os.path.join(temp_dir, '_sha1_map.txt')
|
||||
with open(map_path, 'w', encoding='utf-8') as f:
|
||||
for sha1, rel in sorted(sha1_map.items()):
|
||||
@@ -23,18 +53,14 @@ def save_sha1_map(temp_dir: str, sha1_map: dict[str, str]) -> None:
|
||||
|
||||
|
||||
def Load_sha1_map(temp_dir: str) -> dict[str, str]:
|
||||
"""从文件加载 SHA1 映射表"""
|
||||
map_path: str = os.path.join(temp_dir, '_sha1_map.txt')
|
||||
"""从内存存储器加载 SHA1 映射表
|
||||
|
||||
temp_dir 参数保留用于签名兼容性,但不再读取文件。
|
||||
机器分析使用内存存储器(_g_sha1_map_store)。
|
||||
"""
|
||||
result: dict[str, str] = {}
|
||||
if os.path.exists(map_path):
|
||||
with open(map_path, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
line: str = line.strip()
|
||||
if ':' in line:
|
||||
sha1: str
|
||||
rel: str
|
||||
sha1, rel = line.split(':', 1)
|
||||
result[sha1] = rel
|
||||
for sha1, rel in _g_sha1_map_store.items():
|
||||
result[sha1] = rel
|
||||
return result
|
||||
|
||||
|
||||
@@ -69,17 +95,9 @@ def resolve_paths(config: dict[str, Any], project_file: str) -> dict[str, Any]:
|
||||
resolved_sources.append(resolve(src))
|
||||
result['sources'] = [s for s in resolved_sources if os.path.isfile(s)]
|
||||
|
||||
# build_dir: 统一构建目录(默认 ./.tpv_build),temp 和 output 作为其子目录
|
||||
# 不再单独读取 temp_dir/output_dir,由 build_dir 自动计算
|
||||
build_dir: str = config.get('build_dir', './.tpv_build')
|
||||
build_dir = resolve(build_dir)
|
||||
result['build_dir'] = build_dir
|
||||
if build_dir is not None:
|
||||
result['temp_dir'] = os.path.join(build_dir, 'temp')
|
||||
result['output_dir'] = os.path.join(build_dir, 'output')
|
||||
else:
|
||||
result['temp_dir'] = None
|
||||
result['output_dir'] = None
|
||||
# 直接使用 output_dir / temp_dir(与新版本 TPV 一致,不再支持 build_dir)
|
||||
result['temp_dir'] = resolve(config.get('temp_dir', './temp'))
|
||||
result['output_dir'] = resolve(config.get('output_dir', './output'))
|
||||
|
||||
if 'includes' in result:
|
||||
result['includes'] = [resolve(inc) for inc in result['includes']]
|
||||
|
||||
Reference in New Issue
Block a user