Skip to content

Commit

Permalink
Add output argument for C/C++ compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
yaner-here committed Nov 12, 2024
1 parent 45597ce commit 1b5613c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@
"cph.language.c.Command": {
"type": "string",
"default": "gcc",
"description": "Command used to compile .c files. Example 'gcc', 'gcc-10', 'clang', etc."
"description": "Command used to compile .c files. Example 'gcc', 'gcc-10', 'clang', 'msvc', etc."
},
"cph.language.c.OutputArg": {
"type": "string",
"default": "-o",
"enum": [
"-o",
"/Fe:"
],
"description": "C compiler's argument that specifies the output files."
},
"cph.language.cpp.Args": {
"title": "Compilation flags for .cpp files",
Expand Down Expand Up @@ -131,6 +140,15 @@
"default": "g++",
"description": "Command used to compile .cpp files. Example 'g++', 'g++-10', 'clang++', etc."
},
"cph.language.cpp.OutputArg": {
"type": "string",
"default": "-o",
"enum": [
"-o",
"/Fe:"
],
"description": "C++ compiler's argument that specifies the output files."
},
"cph.language.python.Args": {
"title": "Compilation flags for Python",
"type": "string",
Expand Down
11 changes: 9 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Language } from './types';
import { spawn } from 'child_process';
import path from 'path';
import {
getCOutputArgPref,
getCppOutputArgPref,
getSaveLocationPref,
getHideStderrorWhenCompiledOK,
} from './preferences';
Expand Down Expand Up @@ -56,7 +58,7 @@ const getFlags = (language: Language, srcPath: string): string[] => {
case 'cpp': {
ret = [
srcPath,
'-o',
getCppOutputArgPref(),
getBinSaveLocation(srcPath),
...args,
'-D',
Expand All @@ -72,7 +74,12 @@ const getFlags = (language: Language, srcPath: string): string[] => {
}
case 'c': {
{
ret = [srcPath, '-o', getBinSaveLocation(srcPath), ...args];
ret = [
srcPath,
getCOutputArgPref(),
getBinSaveLocation(srcPath),
...args,
];
if (onlineJudgeEnv) {
ret.push('-D');
ret.push('ONLINE_JUDGE');
Expand Down
10 changes: 8 additions & 2 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ export const getTimeOutPref = (): number =>
export const getRetainWebviewContextPref = (): boolean =>
getPreference('general.retainWebviewContext');

export const getCArgsPref = (): string[] =>
getPreference('language.c.Args').split(' ') || [];

export const getCOutputArgPref = (): string =>
getPreference('language.c.OutputArg');

export const getCppArgsPref = (): string[] =>
getPreference('language.cpp.Args').split(' ') || [];

export const getCArgsPref = (): string[] =>
getPreference('language.c.Args').split(' ') || [];
export const getCppOutputArgPref = (): string =>
getPreference('language.cpp.OutputArg');

export const getPythonArgsPref = (): string[] =>
getPreference('language.python.Args').split(' ') || [];
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export type prefSection =
| 'language.c.Args'
| 'language.c.SubmissionCompiler'
| 'language.c.Command'
| 'language.c.OutputArg'
| 'language.cpp.Args'
| 'language.cpp.SubmissionCompiler'
| 'language.cpp.Command'
| 'language.cpp.OutputArg'
| 'language.go.Args'
| 'language.go.SubmissionCompiler'
| 'language.go.Command'
Expand Down

0 comments on commit 1b5613c

Please sign in to comment.