-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling build targets from CMake Project Outline always builds default target if useTasks option is set #2780
Calling build targets from CMake Project Outline always builds default target if useTasks option is set #2780
Conversation
@elahehrashedi here is my proposal. Please take a look if it makes sense. I haven't squashed commits to clearly present how this solution evolved :) |
…t insted of default target
- proc.ExectionOptions.useBuildTask is not needed anymore (driver is now detecting if task should be used - rename taskFinder function and remove its parameter
428e90e
to
e9c2d54
Compare
src/drivers/cmakeDriver.ts
Outdated
@@ -1696,6 +1714,34 @@ export abstract class CMakeDriver implements vscode.Disposable { | |||
} | |||
} | |||
|
|||
private async _findBuildTask(): Promise<vscode.Task | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that _findBuildTask
is an implementation of vscode.commands.executeCommand("workbench.action.tasks.build");
, it fetches all of the tasks, choose the default is existed, otherwise shows a quickpick to choose from.
The only difference is that vscode.commands.executeCommand("workbench.action.tasks.build")
will show the template tasks besides the tasks defined in tasks.json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I also list only tasks which are 'cmake' tasks. I supose workbench.action.tasks.build will find also others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. However, it is still not delivering the results we want. Please read the later comments.
src/cmakeTaskProvider.ts
Outdated
const cmakeDriver: CMakeDriver | undefined = (await cmakeProject?.getCMakeDriverInstance()) || undefined; | ||
let cmakePath: string; | ||
if(cmakeDriver) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation doesn't seem to be a good practice. The task with a specific target is created, but the code is altering the targets during the execution time, without any warning. If the targets needs to be changed, it should be before the task is being executed.
Besides that, I don't think it is good idea to choose a defined task and then alter the targets. The _findBuildTask
could work like this:
- fetch all of the tasks in tasks.json
- find the task that has the targets matching the targets chosen from the project outline
- if there is no such task, show a quickpick of the template tasks to choose from.
- alter the targets if the template task to match the project outline target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is what do you call 'template' task. I supose you mean these which are added by default by cmake Task Provider.
In my case I add task to tasks.json which does not have targets defined as it is task dedicated for all executable targets ( I add custom problem matcher I also seen cases when one was using tasks to get output in terminal which na n contrary to Output log support colours). I supose in your definitione it is not template task.
Thus first condition to find tasks will never be met, second either as my taask is in tasks.json so wont appear on Quick pick list.
I agree that probably I could also eliminate in initial fetch all tasks which have target defined and it does not match the one requested.
PS. Please also note that target list is altered only when task is truggered as a result of 'BuildCommand'. When triggered by RunTask it will not get altered as target list in driver wont be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is what do you call 'template' task. I supose you mean these which are added by default by cmake Task Provider.
correct.
In my case I add task to tasks.json which does not have targets defined as it is task dedicated for all executable targets ( I add custom problem matcher I also seen cases when one was using tasks to get output in terminal which na n contrary to Output log support colours). I supose in your definitione it is not template task.
The user need to know what are the specifications of the task that is running. So it needs to be a custom task they defined in the tasks.json or the template task we provide.
Thus first condition to find tasks will never be met, second either as my taask is in tasks.json so wont appear on Quick pick list.
Would you please elaborate on this?
I agree that probably I could also eliminate in initial fetch all tasks which have target defined and it does not match the one requested.
Correct, quickpick should show the tasks with the same target, or template task for that target. And importantly, don't alter a selected task when running it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In template tasks, we only change the target, other characteristics stay the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elahehrashedi I reimplemented approach a little bit.
I list all cmake tasks.
Then I search for ones which target matches to requested one. If more than one found - I search for one with default flag. Else I let user to pick from list.
If no tasks with matching targets, then I do similar query among ones with no targets defined.
In task processing I use same "correctTargets" method which was already present. So all already implemented guards are in power. I added only a capability to query driver for "requested target".
By the way - I noticed that method runTestsTask and runConfigTasks also calls correctTargets but they ignore returned value. Does it make then sense to call them?
…eview) Task search algo is implemented: - among all cmake build tasks find ones with target matching requested target - if only one found use it, if more then try to find one with default flag, else show quick picker - if no target dedicated tasks find filter among one with no targets configured (same approach) -if above actions haven't provided tasks show all cmake tasks to user to pick one
I just published #2828 which should address the build from outline issues. It goes a little deeper than this PR does on that. If you're ok with that approach, we could repurpose this PR to cover the new feature being added to select the build task. Please also run |
src/cmakeBuildRunner.ts
Outdated
|
||
export class CMakeBuildRunner { | ||
|
||
private taskExecutor: vscode.TaskExecution | null = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use undefined
instead of null
(applies to the whole file). We will be trying to switch all null
usages to undefined
in the future. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do.
@elahehrashedi please let me know if I should do it or you prefer to take over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @elahehrashedi was planning to address some of your comments. She can fix this one too.
d47d27d
to
884edd2
Compare
piomis this change will consider the generic tasks with no target as well as the tasks defined for the specific target. |
return matchingTargetTasks[0]; | ||
} else { | ||
// Search for the matching default task. | ||
const defaultTask: CMakeTask[] = matchingTargetTasks.filter(task => task.group?.isDefault); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should change task => task.group?.isDefault
into task => task.isDefault
This is because in temporary task created in line 210 you do not add full group but only this one field
return defaultTask[0]; | ||
} else { | ||
// Search for the matching existing task. | ||
const existingTask: CMakeTask[] = matchingTargetTasks.filter(task => !task.isTemplate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I see isTemplate
property is not set for any task retuned in buildTasks
array. I guess you need to set this property in similar way like you set isDefault
By the way - I haven't found any place in code where isTemplate is set to true
?
@elahehrashedi thank you. I also added two comments - IMHO currently neither searching for default task nor filtering out template tasks will work. I am happy to push changes if you want. |
@elahehrashedi |
@elahehrashedi @bobbrow Should new Issues be reported and PRs created for these findings? |
piomis thank you for testing the PR. Would you please create a new report for the new issues? |
@elahehrashedi Done. For #2935 and for #2937 I've created pull-requests. |
This change fixes #2778
The following changes are proposed: