Skip to content

Commit

Permalink
Resolves mesonPath to program absolute path
Browse files Browse the repository at this point in the history
ProcessExecution() does not lookup into PATH.

Fixes: #181
  • Loading branch information
xclaesse authored and tristan957 committed Nov 29, 2023
1 parent 8ed5b45 commit 4132e78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
38 changes: 17 additions & 21 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.ProcessExecution(extensionConfiguration("mesonPath"), args, {
new vscode.ProcessExecution(meson, args, {
cwd: buildDir,
}),
);
Expand Down Expand Up @@ -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.ProcessExecution(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.ProcessExecution(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.ProcessExecution(
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.ProcessExecution(
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.ProcessExecution(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.ProcessExecution(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.ProcessExecution(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"));
}

0 comments on commit 4132e78

Please sign in to comment.