adding buildPreset config to "debug" and "launch" target (#1977)

This commit is contained in:
Elaheh Rashedi 2021-07-09 16:46:10 -07:00 коммит произвёл GitHub
Родитель ebb4c09724
Коммит 721314b3c0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 32 добавлений и 9 удалений

Просмотреть файл

@ -1802,9 +1802,15 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI {
return null;
}
// add debug configuration from settings
// Add debug configuration from settings.
const user_config = this.workspaceContext.config.debugConfig;
Object.assign(debug_config, user_config);
// Add environment variables from buildPreset.
if (this.buildPreset?.environment) {
const build_preset_environment = await drv.getConfigureEnvironment();
debug_config.environment = debug_config.environment ? debug_config.environment.concat(util.splitEnvironmentVars(build_preset_environment)) : {};
}
log.debug(localize('starting.debugger.with', 'Starting debugger with following configuration.'), JSON.stringify({
workspace: this.folder.uri.toString(),
config: debug_config
@ -1846,6 +1852,12 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI {
return null;
}
const user_config = this.workspaceContext.config.debugConfig;
const drv = await this.getCMakeDriverInstance();
// Add environment variables from buildPreset.
if (drv && this.buildPreset?.environment) {
const build_preset_environment = await drv.getConfigureEnvironment();
user_config.environment = user_config.environment ? user_config.environment.concat(util.splitEnvironmentVars(build_preset_environment)) : {};
}
const termOptions: vscode.TerminalOptions = {
name: 'CMake/Launch',
cwd: (user_config && user_config.cwd) || path.dirname(executable.path)

Просмотреть файл

@ -207,15 +207,16 @@ export abstract class CMakeDriver implements vscode.Disposable {
* Get the environment variables that should be set at CMake-build time.
*/
async getCMakeBuildCommandEnvironment(in_env: proc.EnvironmentVariables): Promise<proc.EnvironmentVariables> {
let envs: proc.EnvironmentVariables;
if (this.useCMakePresets) {
return this._buildPreset?.environment as proc.EnvironmentVariables;
envs = util.mergeEnvironment(in_env, this._buildPreset?.environment as proc.EnvironmentVariables);
} else {
let envs = util.mergeEnvironment(in_env, getKitEnvironmentVariablesObject(this._kitEnvironmentVariables));
envs = util.mergeEnvironment(envs, await this.computeExpandedEnvironment(this.config.environment, envs));
envs = util.mergeEnvironment(envs, await this.computeExpandedEnvironment(this.config.buildEnvironment, envs));
envs = util.mergeEnvironment(envs, await this.computeExpandedEnvironment(this._variantEnv, envs));
return envs;
envs = util.mergeEnvironment(in_env, getKitEnvironmentVariablesObject(this._kitEnvironmentVariables));
}
envs = util.mergeEnvironment(envs, await this.computeExpandedEnvironment(this.config.environment, envs));
envs = util.mergeEnvironment(envs, await this.computeExpandedEnvironment(this.config.buildEnvironment, envs));
envs = util.mergeEnvironment(envs, await this.computeExpandedEnvironment(this._variantEnv, envs));
return envs;
}
/**
@ -223,7 +224,7 @@ export abstract class CMakeDriver implements vscode.Disposable {
*/
async getCTestCommandEnvironment(): Promise<proc.EnvironmentVariables> {
if (this.useCMakePresets) {
return this._testPreset?.environment as proc.EnvironmentVariables;
return (this._testPreset?.environment ? this._testPreset?.environment : {}) as proc.EnvironmentVariables;
} else {
let envs = getKitEnvironmentVariablesObject(this._kitEnvironmentVariables);
envs = util.mergeEnvironment(envs, await this.computeExpandedEnvironment(this.config.environment, envs));

Просмотреть файл

@ -34,7 +34,7 @@ export interface Preset {
environment?: { [key: string]: null | string };
vendor?: VendorType;
__expanded?: boolean; // Private field to indicate if we have already expanded thie preset.
__expanded?: boolean; // Private field to indicate if we have already expanded this preset.
}
export interface ValueStrategy {

Просмотреть файл

@ -359,6 +359,16 @@ export function* flatMap<In, Out>(rng: Iterable<In>, fn: (item: In) => Iterable<
}
}
export function splitEnvironmentVars(env: EnvironmentVariables): EnvironmentVariables[] {
const converted_env: EnvironmentVariables[] = Object.entries(env).map(
([key, value]) => ({
name: key,
value
})
);
return converted_env;
}
export function mergeEnvironment(...env: EnvironmentVariables[]): EnvironmentVariables {
return env.reduce((acc, vars) => {
if (process.platform === 'win32') {