Skip to content

Commit

Permalink
Fix module loading in Hook compiler (#4639)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosvm committed Jan 28, 2023
1 parent 784393b commit b3a4d27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/compilers/hook.ts
Expand Up @@ -41,14 +41,19 @@ export class HookCompiler extends BaseCompiler {
return path.join(dirPath, 'example.out');
}

override getDefaultExecOptions(): ExecutionOptions {
const execOptions = super.getDefaultExecOptions();
const compilerPath = path.dirname(this.compiler.exe);
execOptions.env.HOOK_HOME = path.join(compilerPath, '..');
return execOptions;
}

override async runCompiler(
compiler: string,
options: string[],
inputFilename: string,
execOptions: ExecutionOptions,
): Promise<CompilationResult> {
const compilerPath = path.dirname(compiler);
execOptions.env.HOOK_HOME = path.join(compilerPath, '..');
const dirPath = path.dirname(inputFilename);
const outputFilename = this.getOutputFilename(dirPath);
options.push(outputFilename);
Expand Down
11 changes: 10 additions & 1 deletion test/compilers/hook-tests.js
Expand Up @@ -32,7 +32,11 @@ describe('Hook compiler', () => {
HookCompiler.key.should.equal('hook');
});

const info = {remote: true, lang: 'hook'};
const info = {
exe: '/opt/hook/bin/hook',
remote: true,
lang: 'hook',
};
const languages = {hook: {id: 'hook'}};
const hook = new HookCompiler(info, makeCompilationEnvironment({languages}));

Expand All @@ -45,6 +49,11 @@ describe('Hook compiler', () => {
hook.getOutputFilename(dirPath).should.equal('/tmp/example.out');
});

it('should return correct default exec options', () => {
const execOptions = hook.getDefaultExecOptions();
execOptions.env.HOOK_HOME.should.equal('/opt/hook');
});

it('should process and return correct bytecode result', () => {
const asm =
'; main in /app/example.hk at 0x56554a556550\n' +
Expand Down

0 comments on commit b3a4d27

Please sign in to comment.