Skip to content

Commit 81832fd

Browse files
committed
Merge branch 'dev'
2 parents ac11d55 + 3e3a975 commit 81832fd

File tree

12 files changed

+39
-19
lines changed

12 files changed

+39
-19
lines changed

lib/c/compile-file.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { execute } from "../execute-command";
1313
export async function compileC(filePath: string, options?: Options): Promise<string> {
1414
let compileTimeout = options && options.compileTimeout || 3000;
1515
let executableExt = getExecutableExt();
16+
const compilationPath: string = options && options.compilationPath || 'gcc';
1617
let cPath = path.join(tmpPath, 'c');
1718
checkExistsAndMakeDir(cPath);
1819
let executableName = getFileName(executableExt);
1920
let executablePath = path.join(cPath, executableName);
20-
let res = await execute('gcc', [filePath, '-o', executablePath], { timeout: compileTimeout });
21+
let res = await execute(compilationPath, [filePath, '-o', executablePath], { timeout: compileTimeout });
2122
if (res.exitCode !== 0) {
22-
res.errorType ='compile-time';
23+
res.errorType = 'compile-time';
2324
throw res;
2425
}
2526
return executablePath;

lib/cpp/compile-file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import { execute } from "../execute-command";
1313
export async function compileCpp(filePath: string, options?: Options): Promise<string> {
1414
let compileTimeout = options && options.compileTimeout || 3000;
1515
let executableExt = getExecutableExt();
16+
const compilationPath: string = options && options.compilationPath || 'gcc';
1617
let cppPath = path.join(tmpPath, 'cpp');
1718
checkExistsAndMakeDir(cppPath);
1819
let executableName = getFileName(executableExt);
1920
let executablePath = path.join(cppPath, executableName);
20-
let res = await execute('gcc', [filePath, '-o', executablePath, '-lstdc++'], { timeout: compileTimeout });
21+
let res = await execute(compilationPath, [filePath, '-o', executablePath, '-lstdc++'], { timeout: compileTimeout });
2122
if (res.exitCode !== 0) {
2223
res.errorType = 'compile-time';
2324
throw res;

lib/init/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ export function checkExistsAndMakeDir(path: string) {
3737
catch (err) {
3838
handleError(err);
3939
}
40-
}
40+
}

lib/java/compile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import path from 'path';
99
*/
1010
export async function compileJava(filePath: string, options?: Options): Promise<string> {
1111
filePath = path.resolve(filePath);
12-
let res = await execute('javac', [filePath], {
12+
const compilationPath: string = options && options.compilationPath || 'javac';
13+
let res = await execute(compilationPath, [filePath], {
1314
timeout: options && options.compileTimeout || 3000
1415
});
1516

lib/java/run-file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export async function runJavaFileAndReturnPromise(filePath: string, options?: Op
3535
let classFilePath = await compileJavaFile(filePath, options);
3636
let classPath = path.dirname(classFilePath);
3737
let [className] = path.basename(classFilePath).split('.');
38-
let res = await execute('java', ['-classpath', classPath, className], options);
38+
const executionPath = options && options.executionPath || 'java';
39+
let res = await execute(executionPath, ['-classpath', classPath, className], options);
3940
if (res.stderr) {
4041
res.errorType = 'run-time';
4142
}

lib/java/run-source.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export async function runJavaSourceAndReturnPromise(filePath: string, options?:
3535
let classFilePath = await compileJavaSource(filePath, options);
3636
let classPath = path.dirname(classFilePath);
3737
let [className] = path.basename(classFilePath).split('.');
38-
let res = await execute('java', ['-classpath', classPath, className], options);
38+
const executionPath = options && options.executionPath || 'java';
39+
let res = await execute(executionPath, ['-classpath', classPath, className], options);
3940
if (res.stderr) {
4041
res.errorType = 'run-time';
4142
}

lib/node/run-file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export async function runNodeFile(filePath: string, ...args: any[]): Promise<Res
3737
async function runNodeFileAndReturnPromise(filePath: string, options?: Options): Promise<Result> {
3838
//Make the path absolute
3939
filePath = path.resolve(filePath);
40-
let res = await execute('node', [filePath], options);
40+
const executionPath = options && options.executionPath || 'node';
41+
let res = await execute(executionPath, [filePath], options);
4142
if (res.exitCode != 0) {
4243
res.errorType = 'run-time';
4344
}

lib/python/run-file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export async function runPythonFile(filePath: string, ...args: any[]): Promise<R
4040
async function runPythonFileAndReturnPromise(filePath: string, options?: Options): Promise<Result> {
4141
//Make the path absolute
4242
filePath = path.resolve(filePath);
43-
let res = await execute('python', [filePath], options);
43+
const executionPath = options && options.executionPath || 'python';
44+
let res = await execute(executionPath, [filePath], options);
4445
if (res.exitCode != 0) {
4546
res.errorType = 'run-time';
4647
}

lib/types/interfaces/options.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,17 @@ export interface Options {
22
timeout?: number;
33
stdin?: string;
44
compileTimeout?: number;
5+
/**
6+
* Path to the compiler like for java=>javac'path, cpp,c=>gcc's path
7+
*
8+
* can be a path like string to the compiler or custom command name whose path is already set
9+
*/
10+
compilationPath?: string;
11+
/**
12+
* Path to the execution Command like for python,node,java
13+
*
14+
* Can be a path like string to the compiler or custom command name whose path is already set
15+
* like some people use python3 for python v3.6 and python for python v2.7
16+
*/
17+
executionPath?: string;
518
}

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)