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

Clang: Create kits for bundled LLVM in MSVC #930

Merged
merged 3 commits into from
Dec 27, 2019
Merged
Changes from 2 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
54 changes: 40 additions & 14 deletions src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,35 +806,61 @@ export async function scanForKits(opt?: KitScanOptions) {
location: vscode.ProgressLocation.Notification,
title: localize('scanning.for.kits', 'Scanning for kits'),
};

return vscode.window.withProgress(prog, async pr => {
const isWin32 = process.platform === 'win32';

pr.report({message: localize('scanning.for.cmake.kits', 'Scanning for CMake kits...')});
let scanPaths: string[] = [];
let scan_paths = [] as string[];

// Search directories on `PATH` for compiler binaries
const pathvar = process.env['PATH']!;
if (pathvar) {
if (process.env.hasOwnProperty('PATH')) {
const sep = isWin32 ? ';' : ':';
scanPaths = scanPaths.concat(pathvar.split(sep));
scan_paths = scan_paths.concat((process.env.PATH as string).split(sep));
bobbrow marked this conversation as resolved.
Show resolved Hide resolved
}

// Search them all in parallel
let prs = [] as Promise<Kit[]>[];
let kit_promises = [] as Promise<Kit[]>[];
if (isWin32 && kit_options.minGWSearchDirs) {
scanPaths = scanPaths.concat(convertMingwDirsToSearchPaths(kit_options.minGWSearchDirs));
scan_paths = scan_paths.concat(convertMingwDirsToSearchPaths(kit_options.minGWSearchDirs));
}
const compiler_kits = scanPaths.map(path_el => scanDirForCompilerKits(path_el, pr));
prs = prs.concat(compiler_kits);

const compiler_kits = scan_paths.map(path_el => scanDirForCompilerKits(path_el, pr));
kit_promises = kit_promises.concat(compiler_kits);

if (isWin32) {
const vs_kits = scanForVSKits(pr);
// Prepare clang-cl search paths
const clang_cl_paths = new Set<string>();

const clang_cl_path = ['C:\\Program Files (x86)\\LLVM\\bin', 'C:\\Program Files\\LLVM\\bin', ...scanPaths];
const clang_cl_kits = await scanForClangCLKits(clang_cl_path);
prs.push(vs_kits);
prs = prs.concat(clang_cl_kits);
// LLVM_ROOT environment variable location
if (process.env.hasOwnProperty('LLVM_ROOT')) {
const llvm_root = path.normalize(process.env.LLVM_ROOT as string + "\\bin");
clang_cl_paths.add(llvm_root);
}
// Default installation locations
clang_cl_paths.add('C:\\Program Files (x86)\\LLVM\\bin');
clang_cl_paths.add('C:\\Program Files\\LLVM\\bin');
// PATH environment variable locations
scan_paths.forEach(path_el => clang_cl_paths.add(path_el));
// LLVM bundled in VS locations
const vs_installs = await vsInstallations();
const bundled_clang_cl_paths = vs_installs.map(vs_install => {
return vs_install.installationPath + "\\VC\\Tools\\Llvm\\bin";
});
bundled_clang_cl_paths.forEach(path_ => {clang_cl_paths.add(path_);});

// Scan for kits
const vs_kits = scanForVSKits(pr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does changing the scanning order do? scanForVSKits used to be first. Is there a reason the order is changing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just grouped the scanFor... functions together as in that way it is easier for me to follow the process flow. It doesn't change the extension's behavior.

kit_promises.push(vs_kits);
const cl_paths = Array.from(clang_cl_paths);
const clang_cl_kits = await scanForClangCLKits(cl_paths);
kit_promises = kit_promises.concat(clang_cl_kits);
}
const arrays = await Promise.all(prs);

const arrays = await Promise.all(kit_promises);
const kits = ([] as Kit[]).concat(...arrays);
kits.map(k => log.info(localize('found.kit', 'Found Kit: {0}', k.name)));

return kits;
});
}
Expand Down