Skip to content
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

Resolves mesonPath to program absolute path #206

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { extensionConfiguration, getOutputChannel, getTargetName, getEnvDict } f
import { Test, Target } from "./types";
import { checkMesonIsConfigured } from "./utils";
import { workspaceState } from "./extension";
import { mesonProgram } from "./utils";

interface MesonTaskDefinition extends vscode.TaskDefinition {
type: "meson";
Expand All @@ -12,7 +13,7 @@ interface MesonTaskDefinition extends vscode.TaskDefinition {
filename?: string;
}

function createTestTask(t: Test, buildDir: string, isBenchmark: boolean) {
function createTestTask(meson: string, t: Test, buildDir: string, isBenchmark: boolean) {
const project = t.suite[0].split(":")[0];
const name = `${project}:${t.name}`;
const mode = isBenchmark ? "benchmark" : "test";
Expand All @@ -23,7 +24,7 @@ function createTestTask(t: Test, buildDir: string, isBenchmark: boolean) {
{ type: "meson", mode, target: name },
`Test ${name}`,
"Meson",
new vscode.ShellExecution(extensionConfiguration("mesonPath"), args, {
new vscode.ProcessExecution(meson, args, {
cwd: buildDir,
}),
);
Expand All @@ -43,7 +44,7 @@ function createRunTask(t: Target, targetName: string) {
},
`Run ${targetDisplayName}`,
"Meson",
new vscode.ShellExecution(t.filename[0], {
new vscode.ProcessExecution(t.filename[0], {
cwd: workspaceState.get<string>("mesonbuild.sourceDir")!,
env: getEnvDict(),
}),
Expand All @@ -52,7 +53,7 @@ function createRunTask(t: Target, targetName: string) {
return runTask;
}

function createReconfigureTask(buildDir: string, sourceDir: string) {
function createReconfigureTask(meson: string, buildDir: string, sourceDir: string) {
const configureOpts = extensionConfiguration("configureOptions");
const setupOpts = extensionConfiguration("setupOptions");
const reconfigureOpts = checkMesonIsConfigured(buildDir) ? ["--reconfigure"] : [];
Expand All @@ -61,51 +62,46 @@ function createReconfigureTask(buildDir: string, sourceDir: string) {
{ type: "meson", mode: "reconfigure" },
"Reconfigure",
"Meson",
new vscode.ShellExecution(extensionConfiguration("mesonPath"), args),
new vscode.ProcessExecution(meson, args),
);
}

export async function getMesonTasks(buildDir: string, sourceDir: string) {
try {
const meson = mesonProgram();
const defaultBuildTask = new vscode.Task(
{ type: "meson", mode: "build" },
"Build all targets",
"Meson",
new vscode.ShellExecution(extensionConfiguration("mesonPath"), ["compile", "-C", buildDir]),
new vscode.ProcessExecution(meson, ["compile", "-C", buildDir]),
"$meson-gcc",
);
const defaultTestTask = new vscode.Task(
{ type: "meson", mode: "test" },
"Run all tests",
"Meson",
new vscode.ShellExecution(
extensionConfiguration("mesonPath"),
["test", ...extensionConfiguration("testOptions")],
{ cwd: buildDir },
),
new vscode.ProcessExecution(meson, ["test", ...extensionConfiguration("testOptions")], { cwd: buildDir }),
);
const defaultBenchmarkTask = new vscode.Task(
{ type: "meson", mode: "benchmark" },
"Run all benchmarks",
"Meson",
new vscode.ShellExecution(
extensionConfiguration("mesonPath"),
["test", "--benchmark", ...extensionConfiguration("benchmarkOptions")],
{ cwd: buildDir },
),
new vscode.ProcessExecution(meson, ["test", "--benchmark", ...extensionConfiguration("benchmarkOptions")], {
cwd: buildDir,
}),
);
const defaultReconfigureTask = createReconfigureTask(buildDir, sourceDir);
const defaultReconfigureTask = createReconfigureTask(meson, buildDir, sourceDir);
const defaultInstallTask = new vscode.Task(
{ type: "meson", mode: "install" },
"Run install",
"Meson",
new vscode.ShellExecution(extensionConfiguration("mesonPath"), ["install"], { cwd: buildDir }),
new vscode.ProcessExecution(meson, ["install"], { cwd: buildDir }),
);
const defaultCleanTask = new vscode.Task(
{ type: "meson", mode: "clean" },
"Clean",
"Meson",
new vscode.ShellExecution(extensionConfiguration("mesonPath"), ["compile", "--clean"], { cwd: buildDir }),
new vscode.ProcessExecution(meson, ["compile", "--clean"], { cwd: buildDir }),
);
defaultBuildTask.group = vscode.TaskGroup.Build;
defaultTestTask.group = vscode.TaskGroup.Test;
Expand Down Expand Up @@ -146,7 +142,7 @@ export async function getMesonTasks(buildDir: string, sourceDir: string) {
def,
`Build ${targetName}`,
"Meson",
new vscode.ShellExecution(extensionConfiguration("mesonPath"), ["compile", targetName], {
new vscode.ProcessExecution(meson, ["compile", targetName], {
cwd: buildDir,
}),
"$meson-gcc",
Expand All @@ -163,8 +159,8 @@ export async function getMesonTasks(buildDir: string, sourceDir: string) {
}),
)
).flat(1),
...tests.map((t) => createTestTask(t, buildDir, false)),
...benchmarks.map((b) => createTestTask(b, buildDir, true)),
...tests.map((t) => createTestTask(meson, t, buildDir, false)),
...benchmarks.map((b) => createTestTask(meson, b, buildDir, true)),
);
return tasks;
} catch (e: any) {
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as fs from "fs";
import * as path from "path";
import * as cp from "child_process";
import * as vscode from "vscode";
import * as which from "which";

import { createHash, BinaryLike } from "crypto";
import { ExtensionConfiguration, Target } from "./types";
import { getMesonBuildOptions } from "./introspection";
Expand Down Expand Up @@ -220,3 +222,7 @@ export function whenFileExists(ctx: vscode.ExtensionContext, file: string, liste
listener();
}
}

export function mesonProgram(): string {
return which.sync(extensionConfiguration("mesonPath"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a variable instead? Otherwise, we are calling this a lot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It calls it only once when creating tasks, but calls again if we refresh tasks in case the option changed.

}