From 27136f3e1dc2913fa4d9d48c85bc540d5209b59a Mon Sep 17 00:00:00 2001 From: Patrick Quist Date: Sat, 4 Sep 2021 20:55:49 +0200 Subject: [PATCH] Clean trunk and execution (#2916) --- etc/config/clean.amazon.properties | 10 ++- etc/config/clean.defaults.properties | 2 + lib/compilers/clean.js | 123 +++++++++++++++++++++------ 3 files changed, 108 insertions(+), 27 deletions(-) diff --git a/etc/config/clean.amazon.properties b/etc/config/clean.amazon.properties index 0cc744f61..45a64b0f3 100644 --- a/etc/config/clean.amazon.properties +++ b/etc/config/clean.amazon.properties @@ -1,7 +1,9 @@ compilers=&clean64:&clean32 defaultCompiler=clean30_64 +demangler=/opt/compiler-explorer/gcc-11.2.0/bin/c++filt +objdumper=/opt/compiler-explorer/gcc-11.2.0/bin/objdump -group.clean64.compilers=clean24_64:clean30_64 +group.clean64.compilers=clean24_64:clean30_64:clean_trunk group.clean64.isSemVer=true group.clean64.baseName=x86-64 clean @@ -17,6 +19,12 @@ compiler.clean30_64.exe=/opt/compiler-explorer/clean64-3.0/bin/clm compiler.clean30_64.semver=3.0 compiler.clean30_64.libPath=/opt/compiler-explorer/clean64-3.0/StdEnv:/opt/compiler-explorer/clean64-3.0/data/StdLib:/opt/compiler-explorer/clean64-3.0/data/ArgEnv:/opt/compiler-explorer/clean64-3.0/data/Directory:/opt/compiler-explorer/clean64-3.0/data/Dynamics:/opt/compiler-explorer/clean64-3.0/data/Generics:/opt/compiler-explorer/clean64-3.0/data/MersenneTwister:/opt/compiler-explorer/clean64-3.0/data/TCPIP +compiler.clean_trunk.exe=/opt/compiler-explorer/clean-trunk/bin/clm +compiler.clean_trunk.semver=(trunk) +compiler.clean_trunk.libPath=/opt/compiler-explorer/clean-trunk/lib/StdEnv:/opt/compiler-explorer/clean-trunk/lib/StdLib:/opt/compiler-explorer/clean-trunk/lib/ArgEnv:/opt/compiler-explorer/clean-trunk/lib/Directory:/opt/compiler-explorer/clean-trunk/lib/Dynamics:/opt/compiler-explorer/clean-trunk/lib/Generics:/opt/compiler-explorer/clean-trunk/lib/MersenneTwister:/opt/compiler-explorer/clean-trunk/lib/TCPIP +compiler.clean_trunk.supportsBinary=true +compiler.clean_trunk.supportsExecute=true + compiler.clean24_32.exe=/opt/compiler-explorer/clean32-2.4/bin/clm compiler.clean24_32.semver=2.4 compiler.clean24_32.libPath=/opt/compiler-explorer/clean32-2.4/StdEnv:/opt/compiler-explorer/clean32-2.4/data/StdLib:/opt/compiler-explorer/clean32-2.4/data/ArgEnv:/opt/compiler-explorer/clean32-2.4/data/Directory:/opt/compiler-explorer/clean32-2.4/data/Dynamics:/opt/compiler-explorer/clean32-2.4/data/Generics:/opt/compiler-explorer/clean32-2.4/data/MersenneTwister:/opt/compiler-explorer/clean32-2.4/data/TCPIP diff --git a/etc/config/clean.defaults.properties b/etc/config/clean.defaults.properties index 8c86c5d54..26ad846f2 100644 --- a/etc/config/clean.defaults.properties +++ b/etc/config/clean.defaults.properties @@ -1,4 +1,6 @@ supportsBinary=false +supportsExecute=false compilerType=clean demangler= objdumper=objdump +versionFlag=-V diff --git a/lib/compilers/clean.js b/lib/compilers/clean.js index 88a7d0a2d..572b91829 100644 --- a/lib/compilers/clean.js +++ b/lib/compilers/clean.js @@ -1,3 +1,6 @@ +/** + * @prettier + */ // Copyright (c) 2018, Compiler Explorer Authors // All rights reserved. // @@ -26,11 +29,20 @@ import path from 'path'; import fs from 'fs-extra'; -import { BaseCompiler } from '../base-compiler'; +import {BaseCompiler} from '../base-compiler'; +import {propsFor} from '../properties'; import * as utils from '../utils'; export class CleanCompiler extends BaseCompiler { - static get key() { return 'clean'; } + static get key() { + return 'clean'; + } + + constructor(compiler, env) { + super(compiler, env); + const execProps = propsFor('execution'); + this.executionType = execProps('executionType', 'none'); + } optionsForFilter(filters) { if (filters.binary) { @@ -44,52 +56,111 @@ export class CleanCompiler extends BaseCompiler { return path.join(dirPath, 'Clean System Files/example.s'); } + getExecutableFilename(dirPath) { + return path.join(dirPath, 'a.out'); + } + + getSharedLibraryPathsAsArguments() { + return []; + } + preprocessOutput(output) { const errorRegex = /^error \[.*,(\d*),(.*)]:\s?(.*)/i; const errorLineRegex = /^error \[.*,(\d*)]:\s?(.*)/i; const parseerrorRegex = /^parse error \[.*,(\d*);(\d*),(.*)]:\s?(.*)/i; const typeeerrorRegex = /^type error \[.*,(\d*),(.*)]:\s?(.*)/i; - return utils.splitLines(output).map(line => { - let matches = line.match(errorRegex); - if (!matches) matches = line.match(typeeerrorRegex); + return utils + .splitLines(output) + .map(line => { + let matches = line.match(errorRegex); + if (!matches) matches = line.match(typeeerrorRegex); - if (matches) { - return ':' + matches[1] + ',0: error: (' + matches[2] + ') ' + matches[3]; - } - - matches = line.match(errorLineRegex); - if (matches) { - return ':' + matches[1] + ',0: error: ' + matches[2]; - } - - matches = line.match(parseerrorRegex); - if (matches) { - if (matches[3] === '') { - return ':' + matches[1] + ',' + matches[2] + ': error: ' + matches[4]; - } else { - return ':' + matches[1] + ',' + matches[2] + ': error: (' + matches[3] + ') ' + matches[4]; + if (matches) { + return ( + ':' + + matches[1] + + ',0: error: (' + + matches[2] + + ') ' + + matches[3] + ); } - } - return line; - }).join('\n'); + matches = line.match(errorLineRegex); + if (matches) { + return ( + ':' + matches[1] + ',0: error: ' + matches[2] + ); + } + + matches = line.match(parseerrorRegex); + if (matches) { + if (matches[3] === '') { + return ( + ':' + + matches[1] + + ',' + + matches[2] + + ': error: ' + + matches[4] + ); + } else { + return ( + ':' + + matches[1] + + ',' + + matches[2] + + ': error: (' + + matches[3] + + ') ' + + matches[4] + ); + } + } + + return line; + }) + .join('\n'); } async runCompiler(compiler, options, inputFilename, execOptions) { const tmpDir = path.dirname(inputFilename); const moduleName = path.basename(inputFilename, '.icl'); const compilerPath = path.dirname(compiler); + execOptions = this.getDefaultExecOptions(); execOptions.customCwd = tmpDir; - execOptions.env.CLEANLIB = path.join(compilerPath, '../exe'); + if (await utils.dirExists(path.join(compilerPath, '../exe'))) { + execOptions.env.CLEANLIB = path.join(compilerPath, '../exe'); + } else if ( + await utils.dirExists(path.join(compilerPath, '../lib/exe')) + ) { + execOptions.env.CLEANLIB = path.join(compilerPath, '../lib/exe'); + } execOptions.env.CLEANPATH = this.compiler.libPath.join(':'); + execOptions.env.CLEANABCPATH = tmpDir + '/Clean System Files'; + execOptions.env.CLEANOPATH = tmpDir + '/obj'; options.pop(); options.push(moduleName); + await fs.mkdir(execOptions.env.CLEANABCPATH); + await fs.mkdir(execOptions.env.CLEANOPATH); + + if (this.executionType === 'nsjail') { + execOptions.env.CLEANABCPATH = '/app/Clean System Files'; + execOptions.env.CLEANOPATH = '/app/obj'; + } + const result = await this.exec(compiler, options, execOptions); result.inputFilename = inputFilename; - result.stdout = utils.parseOutput(this.preprocessOutput(result.stdout), inputFilename); - result.stderr = utils.parseOutput(this.preprocessOutput(result.stderr), inputFilename); + result.stdout = utils.parseOutput( + this.preprocessOutput(result.stdout), + inputFilename, + ); + result.stderr = utils.parseOutput( + this.preprocessOutput(result.stderr), + inputFilename, + ); if (!options.includes('-S')) { const aOut = path.join(tmpDir, 'a.out');