feat(cbuild): 添加SCC编译器支持并更新构建脚本
添加了新的SccCompiler类以支持SCC编译器,包括编译和链接功能。 更新了justfile中的构建任务,添加了clean、build、build-install和test-scc等新任务。 同时修复了异常处理语法错误并将wc.py工具文件移除。
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""cbuild.py - 优化的轻量C构建系统"""
|
||||
"""cbuild.py - 优化的轻量C构建系统""" # pylint: disable=too-many-lines
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
import tomllib
|
||||
@@ -517,7 +517,7 @@ class BuildCache:
|
||||
with open(self.cache_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
self.cache = {k: CacheEntry(**v) for k, v in data.items()}
|
||||
except OSError, json.JSONDecodeError, TypeError:
|
||||
except (OSError, json.JSONDecodeError, TypeError):
|
||||
self.cache = {}
|
||||
|
||||
def save(self):
|
||||
@@ -679,6 +679,24 @@ class ClangCompiler(Compiler):
|
||||
self.run(cmd)
|
||||
|
||||
|
||||
class SccCompiler(Compiler):
|
||||
"""SCC编译器"""
|
||||
|
||||
def get_flags(self, mode: BuildMode) -> list[str]:
|
||||
return []
|
||||
|
||||
def compile(
|
||||
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]
|
||||
self.run(cmd)
|
||||
|
||||
def link(self, objects: list[Path], output: Path, flags: list[str]):
|
||||
pass
|
||||
|
||||
|
||||
class DummyCompiler(Compiler):
|
||||
"""虚拟编译器(用于测试)"""
|
||||
|
||||
@@ -1023,7 +1041,11 @@ def create_parser():
|
||||
|
||||
def add_common_args(subparser):
|
||||
subparser.add_argument(
|
||||
"--compiler", "-c", choices=["gcc", "clang"], default="gcc", help="编译器"
|
||||
"--compiler",
|
||||
"-c",
|
||||
choices=["gcc", "clang", "scc"],
|
||||
default="gcc",
|
||||
help="编译器",
|
||||
)
|
||||
subparser.add_argument("--record", "-r", action="store_true", help="记录命令")
|
||||
subparser.add_argument(
|
||||
@@ -1102,6 +1124,7 @@ def create_parser():
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
# print("current cwd: " + os.getcwd())
|
||||
parser = create_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -1117,6 +1140,7 @@ def main():
|
||||
compiler_map = {
|
||||
"gcc": GccCompiler(),
|
||||
"clang": ClangCompiler(),
|
||||
"scc": SccCompiler(),
|
||||
}
|
||||
compiler = compiler_map.get(args.compiler, GccCompiler())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user