in src/preset.ts [652:759]
export async function expandConfigurePreset(folder: string,
name: string,
workspaceFolder: string,
sourceDir: string,
preferredGeneratorName: string | undefined,
allowUserPreset: boolean = false): Promise<ConfigurePreset | null> {
const refs = referencedConfigurePresets.get(folder);
if (!refs) {
referencedConfigurePresets.set(folder, new Set());
} else {
refs.clear();
}
const preset = await expandConfigurePresetImpl(folder, name, workspaceFolder, sourceDir, allowUserPreset);
if (!preset) {
return null;
}
// Expand strings under the context of current preset
const expandedPreset: ConfigurePreset = { name };
const expansionOpts: ExpansionOptions = await getExpansionOptions(folder, workspaceFolder, sourceDir, preset);
// Expand environment vars first since other fields may refer to them
if (preset.environment) {
expandedPreset.environment = EnvironmentUtils.createPreserveNull();
for (const key in preset.environment) {
if (preset.environment[key]) {
expandedPreset.environment[key] = await expandString(preset.environment[key]!, expansionOpts);
}
}
}
expansionOpts.envOverride = expandedPreset.environment;
const presetsFile = getPresetsFile(folder);
if (presetsFile && presetsFile.version >= 3) {
// For presets v3+ binaryDir and generator are optional, but cmake-tools needs a value. Default to something reasonable.
if (!preset.binaryDir) {
const defaultValue = '${sourceDir}/out/build/${presetName}';
log.debug(localize('binaryDir.undefined', 'Configure preset {0}: No binaryDir specified, using default value {1}', preset.name, `"${defaultValue}"`));
preset.binaryDir = defaultValue;
}
if (!preset.generator) {
const defaultValue = preferredGeneratorName ?? 'Ninja';
log.debug(localize('generator.undefined', 'Configure preset {0}: No generator specified, using default value {1}', preset.name, `"${defaultValue}"`));
preset.generator = defaultValue;
}
} else {
// toolchainFile and installDir added in presets v3
if (preset.toolchainFile) {
log.error(localize('property.unsupported.v2', 'Configure preset {0}: Property {1} is unsupported in presets v2', preset.name, '"toolchainFile"'));
return null;
}
if (preset.installDir) {
log.error(localize('property.unsupported.v2', 'Configure preset {0}: Property {1} is unsupported in presets v2', preset.name, '"installDir"'));
return null;
}
}
// Expand other fields
if (preset.binaryDir) {
expandedPreset.binaryDir = util.lightNormalizePath(await expandString(preset.binaryDir, expansionOpts));
if (!path.isAbsolute(expandedPreset.binaryDir)) {
expandedPreset.binaryDir = util.resolvePath(expandedPreset.binaryDir, sourceDir);
}
}
if (preset.cmakeExecutable) {
expandedPreset.cmakeExecutable = util.lightNormalizePath(await expandString(preset.cmakeExecutable, expansionOpts));
}
if (preset.installDir) {
expandedPreset.installDir = util.lightNormalizePath(await expandString(preset.installDir, expansionOpts));
}
if (preset.toolchainFile) {
expandedPreset.toolchainFile = util.lightNormalizePath(await expandString(preset.toolchainFile, expansionOpts));
}
if (preset.cacheVariables) {
expandedPreset.cacheVariables = {};
for (const cacheVarName in preset.cacheVariables) {
const cacheVar = preset.cacheVariables[cacheVarName];
if (typeof cacheVar === 'boolean') {
expandedPreset.cacheVariables[cacheVarName] = cacheVar;
} else if (cacheVar) {
if (util.isString(cacheVar)) {
expandedPreset.cacheVariables[cacheVarName] = await expandString(cacheVar, expansionOpts);
} else if (util.isString(cacheVar.value)) {
expandedPreset.cacheVariables[cacheVarName] = { type: cacheVar.type, value: await expandString(cacheVar.value, expansionOpts) };
} else {
expandedPreset.cacheVariables[cacheVarName] = { type: cacheVar.type, value: cacheVar.value };
}
}
}
}
if (preset.condition) {
expandedPreset.condition = await expandCondition(expandedPreset.condition, expansionOpts);
}
// Other fields can be copied by reference for simplicity
merge(expandedPreset, preset);
return expandedPreset;
}