Skip to content

Commit f06493a

Browse files
add preprocess
1 parent dff48df commit f06493a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

runtime-compile/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ func main() {
2828
var testCaseOptions types.TestCaseOptions
2929
json.Unmarshal(testCaseJson, &testCaseOptions)
3030

31+
var prependCode *os.File
32+
var appendCode *os.File
33+
34+
if testCaseOptions.PreprocessOptions.AppendCodePath != "" {
35+
appendCode, _ = os.Open(filepath.Join(testCaseDir, testCaseOptions.PreprocessOptions.AppendCodePath))
36+
}
37+
38+
if testCaseOptions.PreprocessOptions.PrependCodePath != "" {
39+
prependCode, _ = os.Open(filepath.Join(testCaseDir, testCaseOptions.PreprocessOptions.PrependCodePath))
40+
}
41+
3142
args := append(testCaseOptions.CompilerOptions.Flags, "-o", "/dev/stdout", "-x", "c++", "-")
3243
compileCmd := exec.Command("g++", args...)
3344

@@ -47,7 +58,13 @@ func main() {
4758
}
4859

4960
go func() {
61+
if prependCode != nil {
62+
io.Copy(compileCmdStdin, prependCode)
63+
}
5064
io.Copy(compileCmdStdin, os.Stdin)
65+
if appendCode != nil {
66+
io.Copy(compileCmdStdin, appendCode)
67+
}
5168
compileCmdStdin.Close()
5269
}()
5370

0 commit comments

Comments
 (0)