Skip to content

Commit 15ec6a0

Browse files
Prepend './' to the executable's relative path when needed
This is needed when we want to run the executable from a shell, in case there is no path separator in its relative path (e.g: when there is no custom object directory). For eng/ide/ada_language_server#1305
1 parent b5526ba commit 15ec6a0

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

integration/vscode/ada/src/taskProviders.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as vscode from 'vscode';
2121
import { SymbolKind } from 'vscode';
2222
import { adaExtState } from './extension';
2323
import { AdaMain, getAdaMains, getProjectFile, getSymbols } from './helpers';
24+
import path from 'path';
2425

2526
export const ADA_TASK_TYPE = 'ada';
2627

@@ -691,8 +692,15 @@ async function buildFullCommandLine(
691692

692693
if (taskDef.configuration.kind == 'runMain') {
693694
if (adaMain) {
694-
// Append the run of the main executable
695-
cmd.push(adaMain.execRelPath());
695+
// Append the main executable's relative path, prepending './'
696+
// (or '.\\' on Windows) when needed, to make sure it's executable from
697+
// a shell.
698+
let execRelPath = adaMain.execRelPath();
699+
if (!execRelPath.includes(path.sep)) {
700+
execRelPath = '.' + path.sep + execRelPath;
701+
}
702+
703+
cmd.push(execRelPath);
696704
if (taskDef.configuration.mainArgs) {
697705
cmd = cmd.concat(taskDef.configuration.mainArgs);
698706
}

integration/vscode/ada/test/suite/general/tasks.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getSelectedRegion,
1212
} from '../../../src/taskProviders';
1313
import { activate } from '../utils';
14+
import path from 'path';
1415

1516
suite('GPR Tasks Provider', function () {
1617
let projectPath: string;
@@ -244,6 +245,34 @@ ada: Build and run main - src/test.adb - kind: buildAndRunMain`.trim();
244245
assert.equal(execStatus, 0);
245246
});
246247

248+
/**
249+
* Check that the 'buildAndRunMain' task works fine with projects that
250+
* do not explicitly define an object directory.
251+
*/
252+
test('buildAndRunMain task without object directory', async () => {
253+
// Load a custom project that does not define any object dir by
254+
// changing the 'ada.projectFile' setting.
255+
const initialProjectFile = vscode.workspace.getConfiguration().get('ada.projectFile');
256+
try {
257+
await vscode.workspace
258+
.getConfiguration()
259+
.update(
260+
'ada.projectFile',
261+
'default_without_obj_dir' + path.sep + 'default_without_obj_dir.gpr'
262+
);
263+
const adaTasks = await vscode.tasks.fetchTasks({ type: 'ada' });
264+
const task = adaTasks.find((v) => v.name == 'Build and run main - src/main1.adb');
265+
assert(task);
266+
267+
// Check that the executable has been ran correctly
268+
const execStatus: number | undefined = await runTaskAndGetResult(task);
269+
assert.equal(execStatus, 0);
270+
} finally {
271+
// Reset the 'ada.projectFile' setting.
272+
await vscode.workspace.getConfiguration().update('ada.projectFile', initialProjectFile);
273+
}
274+
});
275+
247276
/**
248277
* Test that buildAndRunMain fails when configured with non-existing tasks
249278
*/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project Default_Without_Obj_Dir is
2+
3+
Tools_Mains :=
4+
("main1.adb",
5+
"test.adb");
6+
7+
for Source_Dirs use ("../src/**");
8+
for Main use Tools_Mains;
9+
10+
package Builder is
11+
for Executable ("main1.adb") use "main1exec";
12+
end Builder;
13+
14+
package Compiler is
15+
for Default_Switches ("Ada") use ("-g", "-O0");
16+
end Compiler;
17+
18+
end Default_Without_Obj_Dir;

0 commit comments

Comments
 (0)