Skip to content

Commit

Permalink
Skip configuring when cache is present and according setting is ON (#…
Browse files Browse the repository at this point in the history
…1212)

* Skip configuring when cache is present and according setting is ON before various operations that require config change check. Configure on open remains unchanged.

* Add missing description for new setting

* Use camelCase naming for local variable

* Fixed typo mistake

Co-authored-by: Bob Brown <[email protected]>
  • Loading branch information
andreeis and bobbrow authored May 7, 2020
1 parent dd2aa65 commit ca4dcc5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,12 @@
"description": "%cmake-tools.configuration.cmake.configureOnOpen.description%",
"scope": "resource"
},
"cmake.skipConfigureIfCachePresent": {
"type": "boolean",
"default": null,
"description": "%cmake-tools.configuration.cmake.skipConfigureIfCachePresent.description%",
"scope": "resource"
},
"cmake.cmakeCommunicationMode": {
"type": "string",
"default": "automatic",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"cmake-tools.configuration.cmake.emscriptenSearchDirs.description": "Directories where Emscripten may be installed.",
"cmake-tools.configuration.cmake.copyCompileCommands.description": "Copy compile_commands.json to this location after a successful configure.",
"cmake-tools.configuration.cmake.configureOnOpen.description": "Automatically configure CMake project directories when they are opened.",
"cmake-tools.configuration.cmake.skipConfigureIfCachePresent.description": "Skip over the configure process if cache is present.",
"cmake-tools.configuration.cmake.cmakeCommunicationMode": "The protocol used to communicate between the extension and CMake",
"cmake-tools.configuration.cmake.ignoreKitEnv.description": "Do not use the kit environment variables when running CMake commands.",
"cmake-tools.configuration.cmake.buildTask.description": "Build using tasks.json instead of internal process.",
Expand Down
17 changes: 14 additions & 3 deletions src/cmake-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,22 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI {
*/
private async _needsReconfigure(): Promise<boolean> {
const drv = await this.getCMakeDriverInstance();
if (!drv || await drv.checkNeedsReconfigure()) {
if (!drv) {
return true;
} else {
}

const needsReconfigure: boolean = await drv.checkNeedsReconfigure();

const skipConfigureIfCachePresent = this.workspaceContext.config.skipConfigureIfCachePresent;
if (skipConfigureIfCachePresent && needsReconfigure && await fs.exists(drv.cachePath)) {
log.info(localize('warn.skip.configure.when.cache.present',
'The extension determined that a configuration is needed at this moment \
but we are skipping because the setting cmake.skipConfigureWhenCachePresent is ON. \
Make sure the CMake cache is in sync with the latest configuration changes.'));
return false;
}

return needsReconfigure;
}

async ensureConfigured(): Promise<number|null> {
Expand All @@ -748,7 +759,7 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI {
if (!await this.maybeAutoSaveAll()) {
return -1;
}
if (await drv.checkNeedsReconfigure()) {
if (await this._needsReconfigure()) {
return this.configure();
} else {
return 0;
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface ExtensionConfigurationSettings {
emscriptenSearchDirs: string[];
copyCompileCommands: string|null;
configureOnOpen: boolean|null;
skipConfigureIfCachePresent: boolean|null;
useCMakeServer: boolean;
cmakeCommunicationMode: CMakeCommunicationMode;
ignoreKitEnv: boolean;
Expand Down Expand Up @@ -199,6 +200,8 @@ export class ConfigurationReader implements vscode.Disposable {

get configureOnOpen() { return this.configData.configureOnOpen; }

get skipConfigureIfCachePresent() { return this.configData.skipConfigureIfCachePresent; }

get useCMakeServer(): boolean { return this.configData.useCMakeServer; }

get cmakeCommunicationMode(): CMakeCommunicationMode {
Expand Down Expand Up @@ -279,6 +282,7 @@ export class ConfigurationReader implements vscode.Disposable {
emscriptenSearchDirs: new vscode.EventEmitter<string[]>(),
copyCompileCommands: new vscode.EventEmitter<string|null>(),
configureOnOpen: new vscode.EventEmitter<boolean|null>(),
skipConfigureIfCachePresent: new vscode.EventEmitter<boolean|null>(),
useCMakeServer: new vscode.EventEmitter<boolean>(),
cmakeCommunicationMode: new vscode.EventEmitter<CMakeCommunicationMode>(),
ignoreKitEnv: new vscode.EventEmitter<boolean>(),
Expand Down
1 change: 1 addition & 0 deletions test/unit-tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
emscriptenSearchDirs: [],
copyCompileCommands: null,
configureOnOpen: null,
skipConfigureIfCachePresent: null,
useCMakeServer: true,
cmakeCommunicationMode: 'automatic',
ignoreKitEnv: false,
Expand Down

0 comments on commit ca4dcc5

Please sign in to comment.