fix(build): kernel.elf 链接命令改写做稳健化,避免误覆盖 kernel.bin
原改写用字面 replace("--oformat binary"/"kernel.bin"),若 .bat 里的写法是
"--oformat=binary" 或输出名大小写/路径不同就会匹配不中——那种情况下执行的
仍是原始命令,会把 kernel.bin 覆盖成非预期产物。现改为正则同时兜住
"--oformat binary"/"--oformat=binary"、"-o <path>"/"--output=<path>",
并加保护:改写后若不包含 kernel.elf 则直接跳过,绝不执行未改写的命令。
This commit is contained in:
1 parent
66eb70b131
commit
21f4a6aeca
1 file changed
+14
-5
@@ -1,5 +1,6 @@
|
||||
import shutil
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import threading
|
||||
@@ -39,11 +40,19 @@ if os.path.exists(p2c_bat):
|
||||
if "ld.lld" in low and (".bin" in low or "output" in low):
|
||||
link_line = line.rstrip("\r\n")
|
||||
if link_line is not None:
|
||||
elf_line = link_line.replace("--oformat binary", "").replace("--strip-all", "")
|
||||
elf_line = elf_line.replace("kernel.bin", "kernel.elf")
|
||||
print("[build] linking kernel.elf for analysis ...")
|
||||
if os.system(elf_line) != 0:
|
||||
print("[build] 警告: kernel.elf 链接失败(不影响 kernel.bin)")
|
||||
# 稳健改写:--oformat 可能是 "--oformat binary" 或 "--oformat=binary";输出可能是
|
||||
# "-o <path>" 或 "--output=<path>"。任一没匹配上就放弃(绝不去执行原样命令,否则会把
|
||||
# kernel.bin 覆盖成非预期产物)。
|
||||
elf_line = re.sub(r"--oformat[ =]binary", "", link_line)
|
||||
elf_line = re.sub(r"--strip-all", "", elf_line)
|
||||
elf_line = re.sub(r"(-o\s+)\S+", r"\1" + kernel_elf, elf_line)
|
||||
elf_line = re.sub(r"(--output=)\S+", r"\1" + kernel_elf, elf_line)
|
||||
if elf_line == link_line or kernel_elf not in elf_line:
|
||||
print("[build] 警告: 未能改写链接命令,跳过 kernel.elf(避免误覆盖 kernel.bin)")
|
||||
else:
|
||||
print("[build] linking kernel.elf for analysis ...")
|
||||
if os.system(elf_line) != 0:
|
||||
print("[build] 警告: kernel.elf 链接失败(不影响 kernel.bin)")
|
||||
else:
|
||||
print("[build] 警告: 未从 phase2command 取到链接命令,跳过 kernel.elf")
|
||||
|
||||
|
||||
Reference in new issue
Block a user