feat(pproc): 改进宏处理器以支持括号嵌套和GNU扩展
- 实现了括号深度跟踪来正确分割带括号的宏参数 - 添加了对 GNU 扩展中 `##` 操作符逗号删除的支持 - 新增辅助函数 `got_left_non_blank` 和 `got_right_non_blank` 来优化查找非空白 token 的逻辑 - 改进了错误消息以显示预期但得到的实际值类型 fix(pproc): 修复条件编译和包含文件路径的错误消息 - 在 `scc_pproc_parse_if_condition` 中改进错误消息格式 - 修复 `switch_file_stack` 函数中的日志字符串格式问题 test(pproc): 添加宏处理相关的单元测试 - 增加了连接操作符、嵌套宏、括号处理等测试用例 - 添加了 C99 标准示例和 GNU 变参宏删除逗号的测试 - 包含了复杂的宏展开场景测试 chore(justfile): 更新构建脚本添加调试目标 - 为 `test-scc` 目标添加了 `debug-scc` 调试版本 - 更新构建命令以支持开发模式 feat(cbuild): 添加 dry-run 模式和改进编译器参数 - 为编译器类添加 dry-run 功能,只打印命令不执行 - 改进 scc 编译器的包含路径处理逻辑 - 为命令行解析器添加 dry-run 参数选项 refactor(log): 重命名 static_assert 为 StaticAssert 避免冲突 - 为了避免与标准库冲突,将自定义 static_assert 重命名为 StaticAssert style(scc_core): 移除未使用的预定义宏定义 - 删除了不再需要的基础类型前缀宏定义 fix(scc_core): 初始化 ring 测试中的未初始化变量 - 为测试函数中的字符变量添加初始化值避免未定义行为
This commit is contained in:
@@ -564,6 +564,7 @@ class Compiler(ABC):
|
||||
def __init__(self):
|
||||
self.recorded = []
|
||||
self.recording = False
|
||||
self.dry_run = False
|
||||
|
||||
def enable_recording(self, enable=True):
|
||||
"""启用命令记录"""
|
||||
@@ -580,6 +581,8 @@ class Compiler(ABC):
|
||||
"""运行命令"""
|
||||
self.record(cmd)
|
||||
logger.debug("执行命令: %s", cmd)
|
||||
if self.dry_run:
|
||||
return # 只打印,不执行
|
||||
try:
|
||||
subprocess.run(cmd, check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
@@ -689,8 +692,9 @@ class SccCompiler(Compiler):
|
||||
self, source: Path, output: Path, includes: list[Path], flags: list[str]
|
||||
):
|
||||
# cmd = ["clang"] + flags + ["-c", str(source), "-o", str(output)]
|
||||
cmd = ["scc", "--emit-pp", "-o", str(output), str(source)]
|
||||
cmd += [f"-I{inc}" for inc in includes]
|
||||
cmd = ["scc", "--emit-pp", "-o", str(output), str(source), "-I", "scc_libs"]
|
||||
for inc in includes:
|
||||
cmd += ["-I", f"{inc}"]
|
||||
self.run(cmd)
|
||||
|
||||
def link(self, objects: list[Path], output: Path, flags: list[str]):
|
||||
@@ -1036,7 +1040,6 @@ def create_parser():
|
||||
parser = argparse.ArgumentParser(description="轻量C构建系统", prog="cbuild")
|
||||
parser.add_argument("--verbose", "-v", action="store_true", help="详细输出")
|
||||
parser.add_argument("--path", "-p", default=".", help="项目路径")
|
||||
|
||||
subparsers = parser.add_subparsers(dest="command", required=True, metavar="COMMAND")
|
||||
|
||||
def add_common_args(subparser):
|
||||
@@ -1047,6 +1050,9 @@ def create_parser():
|
||||
default="gcc",
|
||||
help="编译器",
|
||||
)
|
||||
subparser.add_argument(
|
||||
"--dry-run", "-d", action="store_true", help="仅打印命令,不实际执行"
|
||||
)
|
||||
subparser.add_argument("--record", "-r", action="store_true", help="记录命令")
|
||||
subparser.add_argument(
|
||||
"--jobs", "-j", type=int, default=0, help="并行编译任务数 (0=自动检测)"
|
||||
@@ -1144,6 +1150,8 @@ def main():
|
||||
}
|
||||
compiler = compiler_map.get(args.compiler, GccCompiler())
|
||||
|
||||
if hasattr(args, "dry_run") and args.dry_run:
|
||||
compiler.dry_run = True
|
||||
if hasattr(args, "record") and args.record:
|
||||
compiler.enable_recording()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user