Skip to content

Commit

Permalink
Add an option to deal with warning of gcc (#354)
Browse files Browse the repository at this point in the history
* Add a optional choice to deal with waring of gcc

* rename import

* lint fix

---------

Co-authored-by: tesla59 <nishant@heim.id>
  • Loading branch information
llx07 and tesla59 authored Aug 10, 2023
1 parent 7bdbba6 commit 7f2d272
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
"default": 3000,
"description": "The time in ms for which a testcase is run before it is killed ( timed-out )."
},
"cph.general.zeroExitCodeIsWarning": {
"type": "boolean",
"default": false,
"description": "If enabled, zero exit code when compilation will be considered as warning and will not cause the compilation to fail."
},
"cph.general.ignoreSTDERROR": {
"type": "boolean",
"default": false,
Expand Down
17 changes: 15 additions & 2 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { getLanguage, ocHide, ocShow, ocWrite } from './utils';
import { Language } from './types';
import { spawn } from 'child_process';
import path from 'path';
import { getSaveLocationPref } from './preferences';
import {
getSaveLocationPref,
getZeroExitCodeIsWarningPref,
} from './preferences';
import * as vscode from 'vscode';
import { getJudgeViewProvider } from './extension';
export let onlineJudgeEnv = false;
Expand Down Expand Up @@ -161,7 +164,10 @@ export const compileFile = async (srcPath: string): Promise<boolean> => {
});

compiler.on('exit', (exitcode) => {
if (exitcode === 1 || error !== '') {
if (
(!getZeroExitCodeIsWarningPref() || exitcode !== 0) &&
(exitcode === 1 || error !== '')
) {
ocWrite('Errors while compiling:\n' + error);
ocShow();
console.error('Compilation failed');
Expand All @@ -173,6 +179,13 @@ export const compileFile = async (srcPath: string): Promise<boolean> => {
command: 'not-running',
});
return;
} else if (
getZeroExitCodeIsWarningPref() &&
exitcode === 0 &&
error !== ''
) {
ocWrite('Warnings while compiling:\n' + error);
ocShow();
}
console.log('Compilation passed');
getJudgeViewProvider().extensionToJudgeViewMessage({
Expand Down
3 changes: 3 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const getSaveLocationPref = (): string => {
return pref;
};

export const getZeroExitCodeIsWarningPref = (): string =>
getPreference('general.zeroExitCodeIsWarning');

export const getIgnoreSTDERRORPref = (): string =>
getPreference('general.ignoreSTDERROR');

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type prefSection =
| 'general.saveLocation'
| 'general.defaultLanguage'
| 'general.timeOut'
| 'general.zeroExitCodeIsWarning'
| 'general.ignoreSTDERROR'
| 'general.firstTime'
| 'general.useShortCodeForcesName'
Expand Down

0 comments on commit 7f2d272

Please sign in to comment.