Skip to content

Commit f8500c3

Browse files
committed
Support customizing the instrumentation and build commands of test execution
1 parent 86c86b5 commit f8500c3

File tree

1 file changed

+81
-45
lines changed

1 file changed

+81
-45
lines changed

integration/vscode/ada/src/gnattest.ts

Lines changed: 81 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -738,52 +738,88 @@ async function buildTestDriverAndReportErrors(
738738

739739
const buildTasks = [];
740740
if (coverage) {
741-
const adaTP = adaExtState.getAdaTaskProvider()!;
741+
const adaTP = adaExtState.getAdaTaskProvider();
742+
assert(adaTP);
742743

743-
const instTaskDef: SimpleTaskDef = {
744-
type: TASK_TYPE_ADA,
745-
command: 'gnatcov',
746-
args: ['instrument', '--level=stmt', '-P', await getGnatTestDriverProjectPath()].concat(
747-
getScenarioArgs(),
748-
),
749-
};
750-
const instTask = (await adaTP.resolveTask(
751-
new vscode.Task(
752-
instTaskDef,
753-
vscode.TaskScope.Workspace,
754-
`GNATcoverage - Generate instrumented sources for coverage analysis`,
755-
TASK_TYPE_ADA,
756-
undefined,
757-
DEFAULT_PROBLEM_MATCHER,
758-
),
759-
))!;
760-
instTask.presentationOptions.reveal = vscode.TaskRevealKind.Never;
761-
762-
const buildTaskDef: SimpleTaskDef = {
763-
type: TASK_TYPE_ADA,
764-
command: 'gprbuild',
765-
args: [
766-
'-m',
767-
'-s',
768-
'--src-subdirs=gnatcov-instr',
769-
'--implicit-with=gnatcov_rts.gpr',
770-
'-P',
771-
await getGnatTestDriverProjectPath(),
772-
]
773-
.concat(getScenarioArgs())
774-
.concat(['-cargs', '-g', '-fdump-scos', '-fpreserve-control-flow']),
775-
};
776-
const buildTask = (await adaTP.resolveTask(
777-
new vscode.Task(
778-
buildTaskDef,
779-
vscode.TaskScope.Workspace,
780-
`GNATcoverage - Build GNATtest harness project in coverage mode`,
781-
TASK_TYPE_ADA,
782-
undefined,
783-
DEFAULT_PROBLEM_MATCHER,
784-
),
785-
))!;
786-
buildTask.presentationOptions.reveal = vscode.TaskRevealKind.Never;
744+
const instTaskName = `GNATcoverage - Generate instrumented sources for coverage analysis`;
745+
/**
746+
* First try to fetch an existing task of the corresponding name. The
747+
* User may have defined a homonym in tasks.json to customize this
748+
* step.
749+
*/
750+
const instExistingTask = await findTaskByName(`${TASK_TYPE_ADA}: ${instTaskName}`).then(
751+
undefined,
752+
/**
753+
* Return undefined in case of errors when searching for the task.
754+
*/
755+
() => undefined,
756+
);
757+
let instTask;
758+
if (instExistingTask) {
759+
instTask = instExistingTask;
760+
} else {
761+
/**
762+
* If there's no existing task of that name, create one on the fly.
763+
*/
764+
const instTaskDef: SimpleTaskDef = {
765+
type: TASK_TYPE_ADA,
766+
command: 'gnatcov',
767+
args: [
768+
'instrument',
769+
'--level=stmt',
770+
'-P',
771+
await getGnatTestDriverProjectPath(),
772+
].concat(getScenarioArgs()),
773+
};
774+
instTask = (await adaTP.resolveTask(
775+
new vscode.Task(
776+
instTaskDef,
777+
vscode.TaskScope.Workspace,
778+
instTaskName,
779+
TASK_TYPE_ADA,
780+
undefined,
781+
DEFAULT_PROBLEM_MATCHER,
782+
),
783+
))!;
784+
instTask.presentationOptions.reveal =
785+
instTask.presentationOptions.reveal ?? vscode.TaskRevealKind.Never;
786+
}
787+
788+
const buildTaskName = `GNATcoverage - Build GNATtest harness project in coverage mode`;
789+
const buildExistingTask = await findTaskByName(`${TASK_TYPE_ADA}: ${buildTaskName}`).then(
790+
undefined,
791+
() => undefined,
792+
);
793+
let buildTask;
794+
if (buildExistingTask) {
795+
buildTask = buildExistingTask;
796+
} else {
797+
const buildTaskDef: SimpleTaskDef = {
798+
type: TASK_TYPE_ADA,
799+
command: 'gprbuild',
800+
args: [
801+
'-m',
802+
'-s',
803+
'--src-subdirs=gnatcov-instr',
804+
'--implicit-with=gnatcov_rts.gpr',
805+
'-P',
806+
await getGnatTestDriverProjectPath(),
807+
]
808+
.concat(getScenarioArgs())
809+
.concat(['-cargs', '-g', '-fdump-scos', '-fpreserve-control-flow']),
810+
};
811+
buildTask = (await adaTP.resolveTask(
812+
new vscode.Task(
813+
buildTaskDef,
814+
vscode.TaskScope.Workspace,
815+
buildTaskName,
816+
TASK_TYPE_ADA,
817+
undefined,
818+
DEFAULT_PROBLEM_MATCHER,
819+
),
820+
))!;
821+
buildTask.presentationOptions.reveal = vscode.TaskRevealKind.Never;
822+
}
787823

788824
buildTasks.push(instTask, buildTask);
789825
} else {

0 commit comments

Comments
 (0)