Skip to content

Commit

Permalink
Fix Erlang compiler & convert it to typescript (#4124)
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenRBS committed Oct 10, 2022
1 parent 72a19da commit b543993
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 44 deletions.
2 changes: 1 addition & 1 deletion etc/config/erlang.defaults.properties
@@ -1,7 +1,7 @@
# Default settings for Erlang
compilers=&erlang
compilerType=erlang
versionFlag=
versionFlag=-noshell -eval io:fwrite("~s~n", [erlang:system_info(otp_release)]), halt().
objdumper=
instructionSet=beam

Expand Down
68 changes: 25 additions & 43 deletions lib/compilers/erlang.js → lib/compilers/erlang.ts
Expand Up @@ -24,8 +24,8 @@

import path from 'path';

import {ParseFilters} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';
import {logger} from '../logger';

import {ErlangParser} from './argument-parsers';

Expand All @@ -34,8 +34,7 @@ export class ErlangCompiler extends BaseCompiler {
return 'erlang';
}

/* eslint-disable no-unused-vars */
optionsForFilter(filters, outputFilename) {
override optionsForFilter(filters: ParseFilters, outputFilename: string): string[] {
return [
'-noshell',
'-eval',
Expand All @@ -47,52 +46,35 @@ export class ErlangCompiler extends BaseCompiler {
'halt().',
];
}
/* eslint-enable no-unused-vars */

async runCompiler(compiler, options, inputFilename, execOptions) {
if (!execOptions) {
execOptions = this.getDefaultExecOptions();
}

if (!execOptions.customCwd) {
execOptions.customCwd = path.dirname(inputFilename);
}

const result = await this.exec(compiler, options.concat(['-input', inputFilename]), execOptions);
result.inputFilename = inputFilename;
const transformedInput = result.filenameTransform(inputFilename);
this.parseCompilationOutput(result, transformedInput);
return result;
}

getVersion() {
logger.info(`Gathering ${this.compiler.id} version information on ${this.compiler.exe}...`);
if (this.compiler.explicitVersion) {
logger.debug(`${this.compiler.id} has forced version output: ${this.compiler.explicitVersion}`);
return {stdout: [this.compiler.explicitVersion], stderr: [], code: 0};
}
const execOptions = this.getDefaultExecOptions();
const versionCmd = this.compilerProps(`compiler.${this.compiler.id}.runtime`);
execOptions.timeoutMs = 0; // No timeout for --version. A sort of workaround for slow EFS/NFS on the prod site
execOptions.ldPath = this.getSharedLibraryPathsAsLdLibraryPaths([]);

try {
return this.execCompilerCached(
versionCmd,
['-noshell', '-eval', 'io:fwrite("~s~n", [erlang:system_info(otp_release)]), halt().'],
execOptions,
);
} catch (err) {
logger.error(`Unable to get version for compiler '${this.compiler.exe}' - ${err}`);
return null;
}
override orderArguments(
options: string[],
inputFilename: string,
libIncludes: string[],
libOptions: string[],
libPaths: string[],
libLinks: string[],
userOptions: string[],
staticLibLinks: string[],
): string[] {
options.push('-input', inputFilename);
return super.orderArguments(
options,
inputFilename,
libIncludes,
libOptions,
libPaths,
libLinks,
userOptions,
staticLibLinks,
);
}

getOutputFilename(dirPath, outputFilebase) {
override getOutputFilename(dirPath: string, outputFilebase: string): string {
return path.join(dirPath, `${outputFilebase}.S`);
}

getArgumentParser() {
override getArgumentParser() {
return ErlangParser;
}
}

0 comments on commit b543993

Please sign in to comment.