-
Notifications
You must be signed in to change notification settings - Fork 461
/
Copy pathcmakeLegacyDriver.ts
210 lines (181 loc) · 6.72 KB
/
cmakeLegacyDriver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
* Module for the legacy driver. Talks to pre-CMake Server versions of CMake.
* Can also talk to newer versions of CMake via the command line.
*/ /** */
import { CMakeExecutable } from '@cmt/cmake/cmakeExecutable';
import * as vscode from 'vscode';
import * as api from '@cmt/api';
import { CMakeCache } from '@cmt/cache';
import { CMakeDriver, CMakePreconditionProblemSolver } from '@cmt/drivers/cmakeDriver';
import { Kit, CMakeGenerator } from '@cmt/kit';
import * as logging from '@cmt/logging';
import { fs } from '@cmt/pr';
import * as proc from '@cmt/proc';
import rollbar from '@cmt/rollbar';
import * as util from '@cmt/util';
import { ConfigurationReader } from '@cmt/config';
import * as nls from 'vscode-nls';
import { BuildPreset, ConfigurePreset, TestPreset } from '@cmt/preset';
import { CodeModelContent } from './codeModel';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
const log = logging.createLogger('legacy-driver');
/**
* The legacy driver.
*/
export class CMakeLegacyDriver extends CMakeDriver {
get isCacheConfigSupported(): boolean {
return false;
}
async doCacheConfigure(): Promise<number> {
throw new Error('Method not implemented.');
}
private constructor(cmake: CMakeExecutable, readonly config: ConfigurationReader, workspaceFolder: string | null, preconditionHandler: CMakePreconditionProblemSolver) {
super(cmake, config, workspaceFolder, preconditionHandler);
}
private _needsReconfigure = true;
doConfigureSettingsChange() {
this._needsReconfigure = true;
}
async checkNeedsReconfigure(): Promise<boolean> {
return this._needsReconfigure;
}
async doSetKit(need_clean: boolean, cb: () => Promise<void>): Promise<void> {
this._needsReconfigure = true;
if (need_clean) {
await this._cleanPriorConfiguration();
}
await cb();
}
async doSetConfigurePreset(need_clean: boolean, cb: () => Promise<void>): Promise<void> {
this._needsReconfigure = true;
if (need_clean) {
await this._cleanPriorConfiguration();
}
await cb();
}
doSetBuildPreset(cb: () => Promise<void>): Promise<void> {
return cb();
}
doSetTestPreset(cb: () => Promise<void>): Promise<void> {
return cb();
}
// Legacy disposal does nothing
async asyncDispose() {
this._cacheWatcher.dispose();
}
async doConfigure(args_: string[], outputConsumer?: proc.OutputConsumer, showCommandOnly?: boolean): Promise<number> {
// Ensure the binary directory exists
const binary_dir = this.binaryDir;
await fs.mkdir_p(binary_dir);
// Dup args so we can modify them
const args = Array.from(args_);
args.push(util.lightNormalizePath(this.sourceDir));
const gen = this.generator;
if (gen) {
args.push(`-G${gen.name}`);
if (gen.toolset) {
args.push(`-T${gen.toolset}`);
}
if (gen.platform) {
args.push(`-A${gen.platform}`);
}
}
const cmake = this.cmake.path;
if (showCommandOnly) {
log.showChannel();
log.info(proc.buildCmdStr(this.cmake.path, args));
return 0;
} else {
log.debug(localize('invoking.cmake.with.arguments', 'Invoking CMake {0} with arguments {1}', cmake, JSON.stringify(args)));
const res = await this.executeCommand(cmake, args, outputConsumer, {
environment: await this.getConfigureEnvironment(),
cwd: binary_dir
}).result;
log.trace(res.stderr);
log.trace(res.stdout);
if (res.retc === 0) {
this._needsReconfigure = false;
}
await this._reloadPostConfigure();
return res.retc === null ? -1 : res.retc;
}
}
protected async doPreCleanConfigure(): Promise<void> {
await this._cleanPriorConfiguration();
}
async doPostBuild(): Promise<boolean> {
await this._reloadPostConfigure();
return true;
}
async doInit() {
if (await fs.exists(this.cachePath)) {
await this._reloadPostConfigure();
}
this._cacheWatcher.onDidChange(() => {
log.debug(localize('reload.cmake.cache', 'Reload CMake cache: {0} changed', this.cachePath));
rollbar.invokeAsync(localize('reloading.cmake.cache', 'Reloading CMake Cache'), () => this._reloadPostConfigure());
});
}
static async create(cmake: CMakeExecutable,
config: ConfigurationReader,
useCMakePresets: boolean,
kit: Kit | null,
configurePreset: ConfigurePreset | null,
buildPreset: BuildPreset | null,
testPreset: TestPreset | null,
workspaceFolder: string | null,
preconditionHandler: CMakePreconditionProblemSolver,
preferredGenerators: CMakeGenerator[]): Promise<CMakeLegacyDriver> {
log.debug(localize('creating.instance.of', 'Creating instance of {0}', "LegacyCMakeDriver"));
return this.createDerived(new CMakeLegacyDriver(cmake, config, workspaceFolder, preconditionHandler),
useCMakePresets,
kit,
configurePreset,
buildPreset,
testPreset,
preferredGenerators);
}
get targets() {
return [];
}
get executableTargets() {
return [];
}
get uniqueTargets() {
return [];
}
/**
* Watcher for the CMake cache file on disk.
*/
private readonly _cacheWatcher = vscode.workspace.createFileSystemWatcher(this.cachePath);
get cmakeCache() {
return this._cmakeCache;
}
private _cmakeCache: CMakeCache | null = null;
private async _reloadPostConfigure() {
// Force await here so that any errors are thrown into rollbar
const new_cache = await CMakeCache.fromPath(this.cachePath);
this._cmakeCache = new_cache;
}
get cmakeCacheEntries() {
let ret = new Map<string, api.CacheEntryProperties>();
if (this.cmakeCache) {
ret = util.reduce(this.cmakeCache.allEntries, ret, (acc, entry) => acc.set(entry.key, entry));
}
return ret;
}
get generatorName(): string | null {
if (!this.cmakeCache) {
return null;
}
const gen = this.cmakeCache.get('CMAKE_GENERATOR');
return gen ? gen.as<string>() : null;
}
get codeModelContent(): CodeModelContent | null {
return null;
}
get onCodeModelChanged() {
return new vscode.EventEmitter<null>().event;
}
}