Skip to content

Commit aeb59ee

Browse files
committed
Assume the default build target is 'all'
'all' is a well-known name The default target must be explicitly named on the dry-run command line, because of [Remaking Makefiles](https://www.gnu.org/software/make/manual/html_node/Remaking-Makefiles.html) rule of GNU Make. In order to avoid remaking makefiles during a dry-run, the makefile must also be given as an explicit target. If the makefile were given as the only target, the dry-run would not mean 'dry-run the default target', but 'dry-run nothing'. Thus, if the makefile must be given as a target, the default target must be made explicit, and thus is must be defined. Also, previously 'all' was added to the make invokation for listing targets. This would prevent the .DEFAULT_GOAL to be correctly set as the Makefile declared, and instead be set to the value given on the command line. An explicit target is no longer given on the --print-data-base invocation, so the output .DEFAULT_GOAL will be the genuine default goal. This commit makes currentTarget always defined, with the default value 'all'; this is a reasonable, well-known default.
1 parent 7f27375 commit aeb59ee

3 files changed

Lines changed: 11 additions & 29 deletions

File tree

src/configuration.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -936,24 +936,22 @@ export async function readMakefileConfigurations(): Promise<void> {
936936
// Last target picked from the set of targets that are run by the makefiles
937937
// when building for the current configuration.
938938
// Saved into the settings storage. Also reflected in the configuration status bar button
939-
let currentTarget: string | undefined;
940-
export function getCurrentTarget(): string | undefined { return currentTarget; }
941-
export function setCurrentTarget(target: string | undefined): void { currentTarget = target; }
939+
// Assume the well-known "all" target for the default goal
940+
let currentTarget: string = "all";
941+
export function getCurrentTarget(): string { return currentTarget; }
942+
// Set the current target, or 'all' if none was given
943+
export function setCurrentTarget(target: string = "all"): void { currentTarget = target; }
942944

943945
// Read current target from workspace state, update status bar item
944946
function readCurrentTarget(): void {
945947
let buildTarget : string | undefined = extension.getState().buildTarget;
948+
setCurrentTarget(buildTarget);
946949
if (!buildTarget) {
947-
logger.message("No target defined in the workspace state. Assuming 'Default'.");
948-
statusBar.setTarget("Default");
949-
// If no particular target is defined in settings, use 'Default' for the button
950-
// but keep the variable empty, to not append it to the make command.
951-
currentTarget = "";
950+
logger.message(`No target defined in the workspace state. Assuming '${currentTarget}'.`);
952951
} else {
953-
currentTarget = buildTarget;
954952
logger.message(`Reading current build target "${currentTarget}" from the workspace state.`);
955-
statusBar.setTarget(currentTarget);
956953
}
954+
statusBar.setTarget(currentTarget);
957955
}
958956

959957
let configureOnOpen: boolean | undefined;

src/make.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,6 @@ export async function generateParseContent(progress: vscode.Progress<{}>,
446446
// Continue with the make dryrun invocation
447447
let makeArgs: string[] = [];
448448

449-
// Prepend the target to the arguments given in the makefile.configurations object,
450-
// unless we want to parse for the full set of available targets.
451-
if (forTargets) {
452-
makeArgs.push("all");
453-
} else {
454-
let currentTarget: string | undefined = configuration.getCurrentTarget();
455-
if (currentTarget) {
456-
makeArgs.push(currentTarget);
457-
}
458-
}
459-
460449
// Include all the make arguments defined in makefile.configurations.makeArgs
461450
makeArgs = makeArgs.concat(configuration.getConfigurationMakeArgs());
462451

@@ -492,6 +481,9 @@ export async function generateParseContent(progress: vscode.Progress<{}>,
492481
}
493482
});
494483

484+
// Append the target to the arguments given in the makefile.configurations object
485+
makeArgs.push(configuration.getCurrentTarget());
486+
495487
logger.messageNoCR(`Generating ${getConfigureIsInBackground() ? "in the background a new " : ""}configuration cache with command: `);
496488
}
497489

src/test/fakeSuite/extension.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ suite('Fake dryrun parsing', /*async*/() => {
6464
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
6565
configuration.setCurrentLaunchConfiguration(undefined);
6666
configuration.setCurrentMakefileConfiguration("Default");
67-
configuration.setCurrentTarget(undefined);
6867
configuration.initFromState();
6968
await configuration.initFromSettings();
7069

@@ -118,7 +117,6 @@ suite('Fake dryrun parsing', /*async*/() => {
118117
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
119118
configuration.setCurrentLaunchConfiguration(undefined);
120119
configuration.setCurrentMakefileConfiguration("Default");
121-
configuration.setCurrentTarget(undefined);
122120
configuration.initFromState();
123121
await configuration.initFromSettings();
124122

@@ -173,7 +171,6 @@ suite('Fake dryrun parsing', /*async*/() => {
173171
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
174172
configuration.setCurrentLaunchConfiguration(undefined);
175173
configuration.setCurrentMakefileConfiguration("Default");
176-
configuration.setCurrentTarget(undefined);
177174
configuration.initFromState();
178175
await configuration.initFromSettings();
179176

@@ -250,7 +247,6 @@ suite('Fake dryrun parsing', /*async*/() => {
250247
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
251248
configuration.setCurrentLaunchConfiguration(undefined);
252249
configuration.setCurrentMakefileConfiguration("Default");
253-
configuration.setCurrentTarget(undefined);
254250
configuration.initFromState();
255251
await configuration.initFromSettings();
256252

@@ -312,7 +308,6 @@ suite('Fake dryrun parsing', /*async*/() => {
312308
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
313309
configuration.setCurrentLaunchConfiguration(undefined);
314310
configuration.setCurrentMakefileConfiguration("Default");
315-
configuration.setCurrentTarget(undefined);
316311
configuration.initFromState();
317312
await configuration.initFromSettings();
318313

@@ -374,7 +369,6 @@ suite('Fake dryrun parsing', /*async*/() => {
374369
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
375370
configuration.setCurrentLaunchConfiguration(undefined);
376371
configuration.setCurrentMakefileConfiguration("Default");
377-
configuration.setCurrentTarget(undefined);
378372
configuration.initFromState();
379373
await configuration.initFromSettings();
380374

@@ -434,7 +428,6 @@ suite('Fake dryrun parsing', /*async*/() => {
434428
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
435429
configuration.setCurrentLaunchConfiguration(undefined);
436430
configuration.setCurrentMakefileConfiguration("Default");
437-
configuration.setCurrentTarget(undefined);
438431
configuration.initFromState();
439432
await configuration.initFromSettings();
440433

@@ -476,7 +469,6 @@ suite('Fake dryrun parsing', /*async*/() => {
476469
await vscode.workspace.getConfiguration("makefile").update("launchConfigurations", undefined);
477470
configuration.setCurrentLaunchConfiguration(undefined);
478471
configuration.setCurrentMakefileConfiguration("Default");
479-
configuration.setCurrentTarget(undefined);
480472
configuration.initFromState();
481473
await configuration.initFromSettings();
482474

0 commit comments

Comments
 (0)