-
Notifications
You must be signed in to change notification settings - Fork 461
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
Expand targets names while searching for matching build task #3009
Changes from 4 commits
b39c24c
aa13845
6b5cc74
a89030a
ae9308c
61bec6f
407217f
b414191
d6091f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import * as preset from '@cmt/preset'; | |
import { UseCMakePresets } from './config'; | ||
import * as telemetry from '@cmt/telemetry'; | ||
import * as util from '@cmt/util'; | ||
import * as expand from '@cmt/expand'; | ||
|
||
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); | ||
const localize: nls.LocalizeFunc = nls.loadMessageBundle(); | ||
|
@@ -186,18 +187,30 @@ export class CMakeTaskProvider implements vscode.TaskProvider { | |
return task; | ||
} | ||
|
||
public static async findBuildTask(presetName?: string, targets?: string[]): Promise<CMakeTask | undefined> { | ||
public static async findBuildTask(presetName?: string, targets?: string[], expansionOptions?: expand.ExpansionOptions): Promise<CMakeTask | undefined> { | ||
// Fetch all CMake task from `tasks.json` files. | ||
const allTasks: vscode.Task[] = await vscode.tasks.fetchTasks({ type: CMakeTaskProvider.CMakeScriptType }); | ||
const tasks: (CMakeTask | undefined)[] = allTasks.map((task: any) => { | ||
|
||
const tasks: (CMakeTask | undefined)[] = await Promise.all(allTasks.map(async (task: any) => { | ||
if (!task.definition.label || !task.group || (task.group && task.group.id !== vscode.TaskGroup.Build.id)) { | ||
return undefined; | ||
} | ||
|
||
let taskTargets: string[]; | ||
if (expansionOptions) { | ||
taskTargets = await expand.expandStrings(task.definition.targets, expansionOptions); | ||
if (task.definition.options?.cwd){ | ||
task.definition.options.cwd = await expand.expandString(task.definition.options.cwd, expansionOptions); | ||
} | ||
} else { | ||
taskTargets = task.definition.targets; | ||
} | ||
|
||
const definition: CMakeTaskDefinition = { | ||
type: task.definition.type, | ||
label: task.definition.label, | ||
command: task.definition.command, | ||
targets: task.definition.targets || targets, | ||
targets: taskTargets || targets, | ||
preset: task.definition.preset, | ||
options: task.definition.options | ||
}; | ||
|
@@ -208,7 +221,7 @@ export class CMakeTaskProvider implements vscode.TaskProvider { | |
buildTask.isDefault = true; | ||
} | ||
return buildTask; | ||
}); | ||
})); | ||
|
||
const buildTasks: CMakeTask[] = tasks.filter((task) => task !== undefined) as CMakeTask[]; | ||
|
||
|
@@ -237,12 +250,12 @@ export class CMakeTaskProvider implements vscode.TaskProvider { | |
} else { | ||
// Search for the matching default task. | ||
const defaultTask: CMakeTask[] = matchingTargetTasks.filter(task => task.isDefault); | ||
if (defaultTask.length === 1) { | ||
if (defaultTask.length >= 1) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elahehrashedi There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. INstead of using If you need help implementing this let me know and I will modify your branch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elahehrashedi By the way I found one comment from maintainers of VS code which suggests not to use ad hock tasks (microsoft/vscode#59337 (comment)) maybe an Original proposal with 'target' retrieval during task execution (instead of having target set by default when task is created). Potentially this could also allownto use 'shell' task type. By the way I have just discovered that ProblemMatchers stopped working. And this is also related to fact that it is not possible to programicaly define non standard problem matcher in Task constructor. |
||
if (existingTask.length === 1) { | ||
if (existingTask.length >= 1) { | ||
return existingTask[0]; | ||
} | ||
} | ||
|
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 added
cwd
to be expanded too