Skip to content

Commit

Permalink
fix: use createTempPath in C grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Mar 22, 2021
1 parent ccea0bf commit 49d62d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/grammar-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ temp.track()
const GrammarUtils = {
tempFilesDir: path.join(os.tmpdir(), "atom_script_tempfiles"),

// Public: Create a temporary path
//
// Returns the {String} filepath of the new file
createTempPath(prefix = "", extension = "") {
return temp.path({ dir: this.tempFilesDir, prefix, suffix: extension })
},

// Public: Create a temporary file with the provided code
//
// * `code` A {String} containing some code
Expand Down
5 changes: 3 additions & 2 deletions lib/grammars/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const options = "-Wall -include stdio.h"

// TODO add windows support
function CArgs({ filepath }) {
const tempOutFile = GrammarUtils.createTempPath("c-", ".out")
let cmdArgs = ""
switch (os) {
case "darwin":
cmdArgs = `xcrun clang ${options} -fcolor-diagnostics '${filepath}' -o /tmp/c.out && /tmp/c.out`
cmdArgs = `xcrun clang ${options} -fcolor-diagnostics '${filepath}' -o ${tempOutFile} && ${tempOutFile}`
break
case "linux":
cmdArgs = `cc ${options} '${filepath}' -o /tmp/c.out && /tmp/c.out`
cmdArgs = `cc ${options} '${filepath}' -o ${tempOutFile} && ${tempOutFile}`
break
default: {
atom.notifications.addError(`Not support on ${os}`)
Expand Down

0 comments on commit 49d62d3

Please sign in to comment.