diff --git a/package.json b/package.json index 3e1ed6964..df9c15452 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/package.nls.json b/package.nls.json index acf0a4a00..25b78fc96 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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.", diff --git a/src/cmake-tools.ts b/src/cmake-tools.ts index 76aeabcab..439182b2f 100644 --- a/src/cmake-tools.ts +++ b/src/cmake-tools.ts @@ -732,11 +732,22 @@ export class CMakeTools implements vscode.Disposable, api.CMakeToolsAPI { */ private async _needsReconfigure(): Promise { 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 { @@ -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; diff --git a/src/config.ts b/src/config.ts index 23853aafe..7d42c7d15 100644 --- a/src/config.ts +++ b/src/config.ts @@ -57,6 +57,7 @@ export interface ExtensionConfigurationSettings { emscriptenSearchDirs: string[]; copyCompileCommands: string|null; configureOnOpen: boolean|null; + skipConfigureIfCachePresent: boolean|null; useCMakeServer: boolean; cmakeCommunicationMode: CMakeCommunicationMode; ignoreKitEnv: boolean; @@ -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 { @@ -279,6 +282,7 @@ export class ConfigurationReader implements vscode.Disposable { emscriptenSearchDirs: new vscode.EventEmitter(), copyCompileCommands: new vscode.EventEmitter(), configureOnOpen: new vscode.EventEmitter(), + skipConfigureIfCachePresent: new vscode.EventEmitter(), useCMakeServer: new vscode.EventEmitter(), cmakeCommunicationMode: new vscode.EventEmitter(), ignoreKitEnv: new vscode.EventEmitter(), diff --git a/test/unit-tests/config.test.ts b/test/unit-tests/config.test.ts index 71fd43f86..d6ae571db 100644 --- a/test/unit-tests/config.test.ts +++ b/test/unit-tests/config.test.ts @@ -39,6 +39,7 @@ function createConfig(conf: Partial): Configurat emscriptenSearchDirs: [], copyCompileCommands: null, configureOnOpen: null, + skipConfigureIfCachePresent: null, useCMakeServer: true, cmakeCommunicationMode: 'automatic', ignoreKitEnv: false,