[sandbox] Create separate build dir for cpp

This commit is contained in:
orosmatthew 2024-02-17 15:12:54 -05:00
parent 79d48d3f8b
commit 722ff8c199
2 changed files with 18 additions and 11 deletions

View File

@ -1,7 +1,7 @@
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import fs from 'fs-extra'; import fs from 'fs-extra';
import urlJoin from 'url-join'; import urlJoin from 'url-join';
import { string, z } from 'zod'; import { z } from 'zod';
import os, { EOL } from 'os'; import os, { EOL } from 'os';
import { join } from 'path'; import { join } from 'path';
import { simpleGit, SimpleGit } from 'simple-git'; import { simpleGit, SimpleGit } from 'simple-git';
@ -90,12 +90,10 @@ async function cloneAndRun(submissionData: SubmissionGetData) {
return; return;
} }
const tmpDir = os.tmpdir(); const tmpDir = os.tmpdir();
const buildDir = join(tmpDir, 'bwcontest-build'); const repoDir = join(tmpDir, 'bwcontest-src');
if (fs.existsSync(buildDir)) { if (fs.existsSync(repoDir)) {
fs.removeSync(buildDir); fs.removeSync(repoDir);
} }
fs.mkdirSync(buildDir);
const repoDir = join(buildDir, 'src');
fs.mkdirSync(repoDir); fs.mkdirSync(repoDir);
const teamRepoUrl = urlJoin( const teamRepoUrl = urlJoin(
@ -114,7 +112,7 @@ async function cloneAndRun(submissionData: SubmissionGetData) {
try { try {
if (submissionData.submission.teamLanguage === 'Java') { if (submissionData.submission.teamLanguage === 'Java') {
let res = await runJava({ let res = await runJava({
srcDir: buildDir, srcDir: repoDir,
mainFile: join(repoDir, problemName, problemName + '.java'), mainFile: join(repoDir, problemName, problemName + '.java'),
mainClass: problemName, mainClass: problemName,
input: submissionData.submission.problem.realInput input: submissionData.submission.problem.realInput

View File

@ -4,6 +4,8 @@ import util from 'util';
import { RunResult, timeoutSeconds } from '../index.js'; import { RunResult, timeoutSeconds } from '../index.js';
import { IRunner, IRunnerParams, IRunnerReturn } from './types.js'; import { IRunner, IRunnerParams, IRunnerReturn } from './types.js';
import kill from 'tree-kill'; import kill from 'tree-kill';
import os from 'os';
import fs from 'fs-extra';
const execPromise = util.promisify(exec); const execPromise = util.promisify(exec);
@ -20,9 +22,16 @@ interface IRunnerParamsCpp extends IRunnerParams {
export const runCpp: IRunner<IRunnerParamsCpp> = async function ( export const runCpp: IRunner<IRunnerParamsCpp> = async function (
params: IRunnerParamsCpp params: IRunnerParamsCpp
): IRunnerReturn { ): IRunnerReturn {
const tmpDir = os.tmpdir();
const buildDir = join(tmpDir, 'bwcontest-cpp');
if (fs.existsSync(buildDir)) {
fs.removeSync(buildDir);
}
fs.mkdirSync(buildDir);
console.log(`- BUILD: ${params.problemName}`); console.log(`- BUILD: ${params.problemName}`);
const configureCommand = `cmake -S ${params.srcDir} -B ${join(params.srcDir, 'build')}`; const configureCommand = `cmake -S ${params.srcDir} -B ${buildDir}`;
try { try {
await execPromise(configureCommand); await execPromise(configureCommand);
} catch (e) { } catch (e) {
@ -34,7 +43,7 @@ export const runCpp: IRunner<IRunnerParamsCpp> = async function (
}; };
} }
const compileCommand = `cmake --build ${join(params.srcDir, 'build')} --target ${params.problemName}`; const compileCommand = `cmake --build ${buildDir} --target ${params.problemName}`;
try { try {
await execPromise(compileCommand); await execPromise(compileCommand);
} catch (e) { } catch (e) {
@ -50,9 +59,9 @@ export const runCpp: IRunner<IRunnerParamsCpp> = async function (
let runCommand = ''; let runCommand = '';
if (params.cppPlatform === 'VisualStudio') { if (params.cppPlatform === 'VisualStudio') {
runCommand = `${join(params.srcDir, 'build', 'Debug', `${params.problemName}.exe`)}`; runCommand = `${join(buildDir, 'Debug', `${params.problemName}.exe`)}`;
} else { } else {
runCommand = `${join(params.srcDir, 'build', params.problemName)}`; runCommand = `${join(buildDir, params.problemName)}`;
} }
try { try {
let outputBuffer = ''; let outputBuffer = '';