command
Version:
v0.0.0-...-57e7b7e
Opens a new window with list of versions in this module.
Published: May 20, 2026
License: GPL-3.0
Opens a new window with license information.
Imports: 12
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
cmd/compiler
该目录实现编译阶段的独立入口,职责是读取 compile.json、限制编译资源、执行实际编译器,并以 JSON 输出编译是否成功。
文件说明
main.go:总入口,负责加载配置、初始化日志、执行编译流程并输出 JSON。
cfg.go:CompileConfig 定义,描述 compile.json 的字段和默认值。
compiler_linux.go:Linux 实现,负责 fork、setrlimit、输出重定向、exec 真正的编译器。
compiler_darwin.go:macOS 占位实现,仅用于跨平台开发时保持可编译。
makefile:本地 smoke 用法示例。
tests/:编译期 fixture,不同语言或极端场景的 compile.json 与样例源码。
常见检索入口
- 想改默认编译命令或参数:
cfg.go
- 想改编译资源限制:
compiler_linux.go 中的 setrLimits
- 想改编译输出文件名:
compiler_linux.go 中的 doCompile
- 想看最终返回结构:
main.go 中的 RunResult
compile.json 参数约定
-
推荐使用 Command + Args 数组,例如:
{
"command": "g++",
"args": ["main.cpp", "-o", "main", "-O2", "--static"]
}
-
Args 明确给出时,优先级高于对 Command 的拆分。
-
为兼容旧配置,args 仍接受历史上的字符串写法,内部统一按 shell 风格拆分。
-
通过环境变量或 flag 覆盖 args 时,也遵循同一套 shell 风格字符串规则。
-
如果未提供 Args,compiler 会像 runner 一样尝试对 Command 做 shlex 拆分。
日志输出
LogPath 默认值为空字符串,此时日志写到 stderr,适合容器和判题 worker 由外部平台统一采集。
- 如需写入文件,请在
compile.json 中显式配置 LogPath,并确保目录已存在且运行用户有写权限。
- 例如使用
/var/log/runner/compiler.log 时,部署脚本或镜像构建流程应提前创建 /var/log/runner 并设置正确的 owner/permission。
关键标识符
CompileConfig
loadConfig
setrLimits
doCompile
handle
相关目录
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.