diff --git a/src/api/CompileTools.ts b/src/api/CompileTools.ts index fabdb775a..6e7d427bd 100644 --- a/src/api/CompileTools.ts +++ b/src/api/CompileTools.ts @@ -17,6 +17,11 @@ import { Tools } from './Tools'; import { parseFSOptions } from '../filesystems/qsys/QSysFs'; import { instance } from '../instantiate'; +export interface ILELibrarySettings { + currentLibrary: string; + libraryList: string[]; +} + export namespace CompileTools { type Variables = Map @@ -167,21 +172,20 @@ export namespace CompileTools { return string; } - function getDefaultVariables(instance: Instance): Variables { + function getDefaultVariables(instance: Instance, librarySettings: ILELibrarySettings): Variables { const variables: Variables = new Map; const connection = instance.getConnection(); const config = instance.getConfig(); if (connection && config) { - variables.set(`&BUILDLIB`, config.currentLibrary); - variables.set(`&CURLIB`, config.currentLibrary); - variables.set(`\\*CURLIB`, config.currentLibrary); + variables.set(`&BUILDLIB`, librarySettings ? librarySettings.currentLibrary : config.currentLibrary); + variables.set(`&CURLIB`, librarySettings ? librarySettings.currentLibrary : config.currentLibrary); + variables.set(`\\*CURLIB`, librarySettings ? librarySettings.currentLibrary : config.currentLibrary); variables.set(`&USERNAME`, connection.currentUser); variables.set(`{usrprf}`, connection.currentUser); variables.set(`&HOME`, config.homeDirectory); - const libraryList = buildLibraryList(config); - variables.set(`&LIBLC`, libraryList.join(`,`)); + const libraryList = buildLibraryList(librarySettings); variables.set(`&LIBLS`, libraryList.join(` `)); for (const variable of config.customVariables) { @@ -517,9 +521,22 @@ export namespace CompileTools { if (config && connection) { const cwd = options.cwd; + let ileSetup: ILELibrarySettings = { + currentLibrary: config.currentLibrary, + libraryList: config.libraryList, + }; + + if (options.env) { + const libl: string|undefined = options.env[`&LIBL`]; + const curlib: string|undefined = options.env[`&CURLIB`]; + + if (libl) ileSetup.libraryList = libl.split(` `); + if (curlib) ileSetup.currentLibrary = curlib; + } + let commandString = replaceValues( options.command, - getDefaultVariables(instance) + getDefaultVariables(instance, ileSetup) ); if (commandString.startsWith(`?`)) { @@ -532,8 +549,8 @@ export namespace CompileTools { const commands = commandString.split(`\n`).filter(command => command.trim().length > 0); outputChannel.append(`\n\n`); - outputChannel.append(`Current library: ` + config.currentLibrary + `\n`); - outputChannel.append(`Library list: ` + config.libraryList.join(` `) + `\n`); + outputChannel.append(`Current library: ` + ileSetup.currentLibrary + `\n`); + outputChannel.append(`Library list: ` + ileSetup.libraryList.join(` `) + `\n`); outputChannel.append(`Commands:\n${commands.map(command => `\t\t${command}\n`).join(``)}\n`); const callbacks: StandardIO = { @@ -552,7 +569,7 @@ export namespace CompileTools { const paseVars: Variables = new Map; // Get default variable - getDefaultVariables(instance).forEach((value: string, key: string) => { + getDefaultVariables(instance, ileSetup).forEach((value: string, key: string) => { if ((/^[A-Za-z\&]/i).test(key)) { paseVars.set(key.startsWith('&') ? key.substring(1) : key, value); } @@ -576,7 +593,7 @@ export namespace CompileTools { case `qsh`: commandResult = await connection.sendQsh({ command: [ - ...buildLiblistCommands(connection, config), + ...buildLiblistCommands(connection, ileSetup), ...commands, ].join(` && `), directory: cwd, @@ -589,7 +606,7 @@ export namespace CompileTools { // escape $ and # in commands commandResult = await connection.sendQsh({ command: [ - ...buildLiblistCommands(connection, config), + ...buildLiblistCommands(connection, ileSetup), ...commands.map(command => `${`system ${GlobalConfiguration.get(`logCompileOutput`) ? `` : `-s`} "${command.replace(/[$]/g, `\\$&`)}"; if [[ $? -ne 0 ]]; then exit 1; fi`}` ), @@ -716,7 +733,7 @@ export namespace CompileTools { } } - function buildLibraryList(config: ConnectionConfiguration.Parameters): string[] { + function buildLibraryList(config: ILELibrarySettings): string[] { //We have to reverse it because `liblist -a` adds the next item to the top always return config.libraryList .map(library => { @@ -730,7 +747,7 @@ export namespace CompileTools { }).reverse(); } - function buildLiblistCommands(connection: IBMi, config: ConnectionConfiguration.Parameters): string[] { + function buildLiblistCommands(connection: IBMi, config: ILELibrarySettings): string[] { return [ `liblist -d ${connection.defaultUserLibraries.join(` `).replace(/\$/g, `\\$`)}`, `liblist -c ${config.currentLibrary.replace(/\$/g, `\\$`)}`,