From 4132e7888c411f8dd389a4f10c49c6ab6a0cfe59 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 28 Nov 2023 16:38:34 -0500 Subject: [PATCH] Resolves mesonPath to program absolute path ProcessExecution() does not lookup into PATH. Fixes: #181 --- src/tasks.ts | 38 +++++++++++++++++--------------------- src/utils.ts | 6 ++++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/tasks.ts b/src/tasks.ts index f5bff597..a4bad047 100644 --- a/src/tasks.ts +++ b/src/tasks.ts @@ -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"; @@ -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"; @@ -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, }), ); @@ -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"] : []; @@ -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; @@ -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", @@ -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) { diff --git a/src/utils.ts b/src/utils.ts index 348045d1..7620a0e3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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"; @@ -220,3 +222,7 @@ export function whenFileExists(ctx: vscode.ExtensionContext, file: string, liste listener(); } } + +export function mesonProgram(): string { + return which.sync(extensionConfiguration("mesonPath")); +}