2018-03-26 01:44:50 +03:00
|
|
|
import {CMakeTools} from '@cmt/cmake-tools';
|
2018-06-10 11:04:05 +03:00
|
|
|
import {Kit, scanForKits, kitsForWorkspaceDirectory} from '@cmt/kit';
|
2018-03-26 01:44:50 +03:00
|
|
|
import paths from '@cmt/paths';
|
|
|
|
import {fs} from '@cmt/pr';
|
|
|
|
import * as chai from 'chai';
|
|
|
|
import {expect} from 'chai';
|
|
|
|
import * as chaiAsPromised from 'chai-as-promised';
|
2018-02-28 19:17:20 +03:00
|
|
|
import * as path from 'path';
|
2018-03-03 16:09:12 +03:00
|
|
|
import * as vscode from 'vscode';
|
2018-02-28 19:17:20 +03:00
|
|
|
|
2018-03-26 01:44:50 +03:00
|
|
|
// re-exports:
|
|
|
|
export {DefaultEnvironment} from './helpers/test/default-environment';
|
|
|
|
|
|
|
|
chai.use(chaiAsPromised);
|
2018-03-03 16:09:12 +03:00
|
|
|
|
2018-03-26 01:44:50 +03:00
|
|
|
export {expect};
|
2018-02-28 19:17:20 +03:00
|
|
|
|
2018-03-03 23:37:06 +03:00
|
|
|
export async function clearExistingKitConfigurationFile() {
|
2018-03-04 00:39:32 +03:00
|
|
|
await fs.writeFile(path.join(paths.dataDir, 'cmake-kits.json'), '[]');
|
2018-03-03 23:37:06 +03:00
|
|
|
}
|
2018-02-28 19:17:20 +03:00
|
|
|
|
|
|
|
export async function getExtension() {
|
2019-10-22 22:39:32 +03:00
|
|
|
const cmt = vscode.extensions.getExtension<CMakeTools>('ms-vscode.cmake-tools');
|
2018-03-03 16:09:12 +03:00
|
|
|
if (!cmt) {
|
2018-03-04 00:39:32 +03:00
|
|
|
throw new Error('Extension doesn\'t exist');
|
2018-03-03 16:09:12 +03:00
|
|
|
}
|
|
|
|
return cmt.isActive ? Promise.resolve(cmt.exports) : cmt.activate();
|
2018-03-26 01:44:50 +03:00
|
|
|
}
|
2018-05-11 10:03:47 +03:00
|
|
|
|
|
|
|
let AVAIL_KITS: Promise<Kit[]> | null = null;
|
|
|
|
|
|
|
|
export async function getSystemKits(): Promise<Kit[]> {
|
|
|
|
if (AVAIL_KITS === null) {
|
|
|
|
AVAIL_KITS = scanForKits();
|
|
|
|
}
|
2020-01-17 00:31:31 +03:00
|
|
|
return AVAIL_KITS;
|
2018-05-11 10:03:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getFirstSystemKit(): Promise<Kit> {
|
|
|
|
const kits = await getSystemKits();
|
|
|
|
console.assert(kits.length >= 1, 'No kits found for testing');
|
|
|
|
return kits[0];
|
2018-06-10 11:04:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getMatchingSystemKit(re: RegExp): Promise<Kit> {
|
|
|
|
const kits = await getSystemKits();
|
|
|
|
return getMatchingKit(kits, re);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getMatchingProjectKit(re: RegExp, dir: string): Promise<Kit> {
|
|
|
|
const kits = await kitsForWorkspaceDirectory(dir);
|
|
|
|
return getMatchingKit(kits, re);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMatchingKit(kits: Kit[], re: RegExp): Kit {
|
|
|
|
const kit = kits.find(k => re.test(k.name));
|
|
|
|
if (!kit) {
|
|
|
|
throw new Error(`No kit matching expression: ${re}`);
|
|
|
|
}
|
|
|
|
return kit;
|
2018-05-11 10:03:47 +03:00
|
|
|
}
|