diff --git a/integration/vscode/ada/src/taskProviders.ts b/integration/vscode/ada/src/taskProviders.ts index 4154f2b03..68edd44b9 100644 --- a/integration/vscode/ada/src/taskProviders.ts +++ b/integration/vscode/ada/src/taskProviders.ts @@ -21,6 +21,7 @@ import * as vscode from 'vscode'; import { SymbolKind } from 'vscode'; import { adaExtState } from './extension'; import { AdaMain, getAdaMains, getProjectFile, getSymbols } from './helpers'; +import path from 'path'; export const ADA_TASK_TYPE = 'ada'; @@ -691,8 +692,15 @@ async function buildFullCommandLine( if (taskDef.configuration.kind == 'runMain') { if (adaMain) { - // Append the run of the main executable - cmd.push(adaMain.execRelPath()); + // Append the main executable's relative path, prepending './' + // (or '.\\' on Windows) when needed, to make sure it's executable from + // a shell. + let execRelPath = adaMain.execRelPath(); + if (!execRelPath.includes(path.sep)) { + execRelPath = '.' + path.sep + execRelPath; + } + + cmd.push(execRelPath); if (taskDef.configuration.mainArgs) { cmd = cmd.concat(taskDef.configuration.mainArgs); } diff --git a/integration/vscode/ada/test/suite/general/tasks.test.ts b/integration/vscode/ada/test/suite/general/tasks.test.ts index eb02c1976..8206f608a 100644 --- a/integration/vscode/ada/test/suite/general/tasks.test.ts +++ b/integration/vscode/ada/test/suite/general/tasks.test.ts @@ -11,6 +11,7 @@ import { getSelectedRegion, } from '../../../src/taskProviders'; import { activate } from '../utils'; +import path from 'path'; suite('GPR Tasks Provider', function () { let projectPath: string; @@ -244,6 +245,34 @@ ada: Build and run main - src/test.adb - kind: buildAndRunMain`.trim(); assert.equal(execStatus, 0); }); + /** + * Check that the 'buildAndRunMain' task works fine with projects that + * do not explicitly define an object directory. + */ + test('buildAndRunMain task without object directory', async () => { + // Load a custom project that does not define any object dir by + // changing the 'ada.projectFile' setting. + const initialProjectFile = vscode.workspace.getConfiguration().get('ada.projectFile'); + try { + await vscode.workspace + .getConfiguration() + .update( + 'ada.projectFile', + 'default_without_obj_dir' + path.sep + 'default_without_obj_dir.gpr' + ); + const adaTasks = await vscode.tasks.fetchTasks({ type: 'ada' }); + const task = adaTasks.find((v) => v.name == 'Build and run main - src/main1.adb'); + assert(task); + + // Check that the executable has been ran correctly + const execStatus: number | undefined = await runTaskAndGetResult(task); + assert.equal(execStatus, 0); + } finally { + // Reset the 'ada.projectFile' setting. + await vscode.workspace.getConfiguration().update('ada.projectFile', initialProjectFile); + } + }); + /** * Test that buildAndRunMain fails when configured with non-existing tasks */ diff --git a/integration/vscode/ada/test/workspaces/general/default_without_obj_dir/default_without_obj_dir.gpr b/integration/vscode/ada/test/workspaces/general/default_without_obj_dir/default_without_obj_dir.gpr new file mode 100644 index 000000000..607f6e091 --- /dev/null +++ b/integration/vscode/ada/test/workspaces/general/default_without_obj_dir/default_without_obj_dir.gpr @@ -0,0 +1,18 @@ +project Default_Without_Obj_Dir is + + Tools_Mains := + ("main1.adb", + "test.adb"); + + for Source_Dirs use ("../src/**"); + for Main use Tools_Mains; + + package Builder is + for Executable ("main1.adb") use "main1exec"; + end Builder; + + package Compiler is + for Default_Switches ("Ada") use ("-g", "-O0"); + end Compiler; + +end Default_Without_Obj_Dir;