Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

${workspaceFolder} is not working for "environmentSetupScript" option… #1406

Merged
merged 5 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
effectiveKitEnvironment,
scanForKitsIfNeeded,
} from '@cmt/kit';
import {KitsController} from '@cmt/kitsController';
import {KitsController, KitsReadMode} from '@cmt/kitsController';
import * as logging from '@cmt/logging';
import {fs} from '@cmt/pr';
import {FireNow, FireLate} from '@cmt/prop';
Expand Down Expand Up @@ -639,6 +639,9 @@ class ExtensionManager implements vscode.Disposable {
async scanForKits() {
KitsController.minGWSearchDirs = this._getMinGWDirs();
const duplicateRemoved = await KitsController.scanForKits();

await this._folders.activeFolder?.kitsController.readKits(KitsReadMode.folderKits);
andreeis marked this conversation as resolved.
Show resolved Hide resolved

if (duplicateRemoved) {
// Check each folder. If there is an active kit set and if it is of the old definition,
// unset the kit
Expand Down
14 changes: 10 additions & 4 deletions src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ async function collectDevBatVars(devbat: string, args: string[], major_version:
* Gets the environment variables set by a shell script.
* @param kit The kit to get the environment variables for
*/
export async function getShellScriptEnvironment(kit: Kit): Promise<Map<string, string>|undefined> {
export async function getShellScriptEnvironment(kit: Kit, opts?: expand.ExpansionOptions): Promise<Map<string, string>|undefined> {
console.assert(kit.environmentSetupScript);
const filename = Math.random().toString() + (process.platform == 'win32' ? '.bat' : '.sh');
const script_filename = `vs-cmt-${filename}`;
Expand All @@ -588,12 +588,18 @@ export async function getShellScriptEnvironment(kit: Kit): Promise<Map<string, s

let script = '';
let run_command = '';

let environmentSetupScript = kit.environmentSetupScript;
if (opts) {
environmentSetupScript = await expand.expandString(environmentSetupScript!, opts);
}

if (process.platform == 'win32') { // windows
script += `call "${kit.environmentSetupScript}"\r\n`; // call the user batch script
script += `call "${environmentSetupScript}"\r\n`; // call the user batch script
script += `set >> ${environment_path}`; // write env vars to temp file
run_command = `call ${script_path}`;
} else { // non-windows
script += `source "${kit.environmentSetupScript}"\n`; // run the user shell script
script += `source "${environmentSetupScript}"\n`; // run the user shell script
script +=`printenv >> ${environment_path}`; // write env vars to temp file
run_command = `/bin/bash -c "source ${script_path}"`; // run script in bash to enable bash-builtin commands like 'source'
}
Expand Down Expand Up @@ -864,7 +870,7 @@ export async function effectiveKitEnvironment(kit: Kit, opts?: expand.ExpansionO
}
}
if (kit.environmentSetupScript) {
const shell_vars = await getShellScriptEnvironment(kit);
const shell_vars = await getShellScriptEnvironment(kit, opts);
if (shell_vars) {
host_env = util.map(shell_vars, ([k, v]): [string, string] => [k.toLocaleUpperCase(), v]) as [string, string][];
}
Expand Down