Skip to content

Commit 6db2dfa

Browse files
committed
fix: use createTempPath in Cpp grammar
1 parent 49d62d3 commit 6db2dfa

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/grammars/c.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ const Cpp = {
9494
args(context) {
9595
const code = context.getCode()
9696
const tmpFile = GrammarUtils.createTempFileWithCode(code, ".cpp")
97+
const tempOutFile = GrammarUtils.createTempPath("cpp-", ".out")
9798
let cmdArgs = ""
98-
9999
switch (os) {
100100
case "darwin":
101-
cmdArgs = `xcrun clang++ -std=c++14 ${options} -fcolor-diagnostics -include iostream ${tmpFile} -o /tmp/cpp.out && /tmp/cpp.out`
101+
cmdArgs = `xcrun clang++ -std=c++14 ${options} -fcolor-diagnostics -include iostream ${tmpFile} -o ${tempOutFile} && ${tempOutFile}`
102102
break
103103
case "linux":
104-
cmdArgs = `g++ ${options} -std=c++14 -include iostream ${tmpFile} -o /tmp/cpp.out && /tmp/cpp.out`
104+
cmdArgs = `g++ ${options} -std=c++14 -include iostream ${tmpFile} -o ${tempOutFile} && ${tempOutFile}`
105105
break
106106
default: {
107107
atom.notifications.addError(`Not support on ${os}`)
@@ -114,13 +114,14 @@ const Cpp = {
114114
"File Based": {
115115
command,
116116
args({ filepath }) {
117+
const tempOutFile = GrammarUtils.createTempPath("cpp-", ".out")
117118
let cmdArgs = ""
118119
switch (os) {
119120
case "darwin":
120-
cmdArgs = `xcrun clang++ -std=c++14 ${options} -fcolor-diagnostics -include iostream '${filepath}' -o /tmp/cpp.out && /tmp/cpp.out`
121+
cmdArgs = `xcrun clang++ -std=c++14 ${options} -fcolor-diagnostics -include iostream '${filepath}' -o ${tempOutFile} && ${tempOutFile}`
121122
break
122123
case "linux":
123-
cmdArgs = `g++ -std=c++14 ${options} -include iostream '${filepath}' -o /tmp/cpp.out && /tmp/cpp.out`
124+
cmdArgs = `g++ -std=c++14 ${options} -include iostream '${filepath}' -o ${tempOutFile} && ${tempOutFile}`
124125
break
125126
case "win32":
126127
if (
@@ -131,7 +132,7 @@ const Cpp = {
131132
filepath = path.posix
132133
.join(...[filepath.split(path.win32.sep)[0].toLowerCase(), ...filepath.split(path.win32.sep).slice(1)])
133134
.replace(":", "")
134-
cmdArgs = `g++ -std=c++14 ${options} -include iostream /mnt/${filepath} -o /tmp/cpp.out && /tmp/cpp.out`
135+
cmdArgs = `g++ -std=c++14 ${options} -include iostream /mnt/${filepath} -o ${tempOutFile} && ${tempOutFile}`
135136
}
136137
break
137138
default: {

0 commit comments

Comments
 (0)