Skip to content

Commit

Permalink
Merge branch 'topic/relative_paths' into 'master'
Browse files Browse the repository at this point in the history
Prepend './' to the executable's relative path when needed

See merge request eng/ide/ada_language_server!1512
  • Loading branch information
AnthonyLeonardoGracio committed Mar 25, 2024
2 parents b5526ba + 15ec6a0 commit ce451f2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
12 changes: 10 additions & 2 deletions integration/vscode/ada/src/taskProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}
Expand Down
29 changes: 29 additions & 0 deletions integration/vscode/ada/test/suite/general/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ce451f2

Please sign in to comment.