diff --git a/lib/compilers/hook.ts b/lib/compilers/hook.ts index 26ebc42fe8c..63cf6f8fce5 100644 --- a/lib/compilers/hook.ts +++ b/lib/compilers/hook.ts @@ -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 { - 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); diff --git a/test/compilers/hook-tests.js b/test/compilers/hook-tests.js index 7bda70c7829..b10c48cc85a 100644 --- a/test/compilers/hook-tests.js +++ b/test/compilers/hook-tests.js @@ -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})); @@ -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' +