Skip to content

Commit c5aa4f8

Browse files
committed
Move all the compiling/running parts to tracers repository
1 parent 7530898 commit c5aa4f8

File tree

4 files changed

+14
-57
lines changed

4 files changed

+14
-57
lines changed

bin/temporary_action.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

bin/www

100644100755
File mode changed.

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
"version": "2.0.0",
44
"description": "Algorithm Visualizer",
55
"scripts": {
6-
"postinstall": "docker pull openjdk:8 && docker pull gcc:8.1",
7-
"dev": "NODE_ENV=development node bin/www",
8-
"start": "NODE_ENV=production node bin/www",
6+
"dev": "NODE_ENV=development ./bin/www",
7+
"start": "NODE_ENV=production ./bin/www",
98
"build": "npm run build:frontend && npm run build:backend",
109
"build:frontend": "NODE_ENV=production node ./node_modules/webpack/bin/webpack --bail --progress --config webpack.frontend.config.js",
1110
"build:backend": "NODE_ENV=production node ./node_modules/webpack/bin/webpack --bail --progress --config webpack.backend.config.js",
12-
"lint": "./node_modules/.bin/eslint --fix src",
13-
"publish": "npm run lint && npm run build && git add . && git commit && git push"
11+
"lint": "./node_modules/.bin/eslint --fix src"
1412
},
1513
"repository": {
1614
"type": "git",

src/backend/controllers/tracers.js

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,71 +9,46 @@ import { CompileError, RuntimeError } from '/common/error';
99
const router = express.Router();
1010

1111
const repoPath = path.resolve(__dirname, '..', 'public', 'tracers');
12-
const getLibsPath = (...args) => path.resolve(repoPath, 'libs', ...args);
1312
const getCodesPath = (...args) => path.resolve(__dirname, '..', 'public', 'codes', ...args);
1413

1514
const buildRelease = release => (
1615
fs.pathExistsSync(repoPath) ?
1716
execute(`git fetch && ! git diff-index --quiet ${release.target_commitish}`, repoPath) :
1817
execute(`git clone git@github.com:algorithm-visualizer/tracers ${repoPath}`, __dirname)
19-
).then(() => execute(`git reset --hard ${release.target_commitish} && npm install && npm run build`, repoPath));
18+
).then(() => execute(`git reset --hard ${release.target_commitish} && npm install && npm run build && ./bin/build`, repoPath));
2019

2120
GitHubApi.getLatestRelease('algorithm-visualizer', 'tracers').then(buildRelease);
2221
// TODO: build release when webhooked
2322

2423
const getJsWorker = (req, res, next) => {
25-
res.sendFile(getLibsPath('js', 'tracers.js'));
24+
res.sendFile(path.resolve(repoPath, 'src', 'languages', 'js', 'tracers', 'build', 'tracers.js'));
2625
};
2726

28-
const executeInDocker = (imageId, ext, srcPath, command) => {
29-
// TODO: memory limit + time limit + space limit?
30-
const libsPath = getLibsPath(ext);
31-
const dockerCommand = [
32-
`docker run --rm`,
33-
'-w=/usr/judge',
34-
`-v=${libsPath}:/usr/bin/tracers:ro`,
35-
`-v=${srcPath}:/usr/judge:rw`,
36-
`-e MAX_TRACES=${1e6} -e MAX_TRACERS=${1e2}`,
37-
imageId,
38-
].join(' ');
39-
return execute(`${dockerCommand} ${command}`, repoPath, { stdout: null, stderr: null });
40-
};
41-
42-
const trace = ({ ext, imageId, compileCommand, runCommand }) => (req, res, next) => {
27+
const trace = lang => (req, res, next) => {
4328
const { code } = req.body;
44-
const srcPath = getCodesPath(uuid.v4());
45-
fs.outputFile(path.resolve(srcPath, `Main.${ext}`), code)
46-
.then(() => executeInDocker(imageId, ext, srcPath, compileCommand)
29+
const tempPath = getCodesPath(uuid.v4());
30+
fs.outputFile(path.resolve(tempPath, `Main.${lang}`), code)
31+
.then(() => execute(`LANG=${lang} TEMP_PATH=${tempPath} ./bin/compile`, repoPath, { stdout: null, stderr: null })
4732
.catch(error => {
4833
throw new CompileError(error);
4934
}))
50-
.then(() => executeInDocker(imageId, ext, srcPath, runCommand)
35+
.then(() => execute(`LANG=${lang} TEMP_PATH=${tempPath} ./bin/run`, repoPath, { stdout: null, stderr: null })
5136
.catch(error => {
5237
throw new RuntimeError(error);
5338
}))
54-
.then(() => res.sendFile(path.resolve(srcPath, 'traces.json')))
39+
.then(() => res.sendFile(path.resolve(tempPath, 'traces.json')))
5540
.catch(next)
56-
.finally(() => fs.remove(srcPath));
41+
.finally(() => fs.remove(tempPath));
5742
};
5843

5944

6045
router.route('/js')
6146
.get(getJsWorker);
6247

6348
router.route('/java')
64-
.post(trace({
65-
ext: 'java',
66-
imageId: 'openjdk:8',
67-
compileCommand: 'javac -cp /usr/bin/tracers/tracers.jar Main.java',
68-
runCommand: 'java -cp /usr/bin/tracers/tracers.jar:. Main',
69-
}));
49+
.post(trace('java'));
7050

7151
router.route('/cpp')
72-
.post(trace({
73-
ext: 'cpp',
74-
imageId: 'gcc:8.1',
75-
compileCommand: 'g++ Main.cpp -o Main -O2 -std=c++11 -L/usr/bin/tracers/lib -l:tracers.a -I/usr/bin/tracers/include',
76-
runCommand: './Main',
77-
}));
52+
.post(trace('cpp'));
7853

7954
export default router;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy