Skip to content

Commit

Permalink
Run Task: Use DevEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
CyborgPotato authored and David Crompton committed Aug 23, 2024
1 parent 0e2c1aa commit 5ad9198
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
12 changes: 5 additions & 7 deletions src/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as vscode from "vscode";
import { getMesonTargets, getMesonTests, getMesonBenchmarks } from "./introspection";
import { extensionConfiguration, getOutputChannel, getTargetName, getEnvDict } from "./utils";
import { extensionConfiguration, getOutputChannel, getTargetName } from "./utils";
import { Test, Target } from "./types";
import { checkMesonIsConfigured } from "./utils";
import { workspaceState } from "./extension";
import { mesonProgram } from "./utils";

interface MesonTaskDefinition extends vscode.TaskDefinition {
Expand Down Expand Up @@ -33,7 +32,7 @@ function createTestTask(meson: string, t: Test, buildDir: string, isBenchmark: b
return testTask;
}

function createRunTask(t: Target, targetName: string) {
function createRunTask(meson: string, t: Target, targetName: string, buildDir: string) {
const targetDisplayName = targetName.split(":")[0];
let runTask = new vscode.Task(
{
Expand All @@ -44,9 +43,8 @@ function createRunTask(t: Target, targetName: string) {
},
`Run ${targetDisplayName}`,
"Meson",
new vscode.ProcessExecution(t.filename[0], {
cwd: workspaceState.get<string>("mesonbuild.sourceDir")!,
env: getEnvDict(),
new vscode.ProcessExecution(meson, ["devenv", t.filename[0]], {
cwd: buildDir,
}),
);
runTask.group = vscode.TaskGroup.Test;
Expand Down Expand Up @@ -157,7 +155,7 @@ export async function getMesonTasks(buildDir: string, sourceDir: string) {
// Create run tasks for executables that are not tests,
// both installed and uninstalled (eg: examples)
if (!tests.some((test) => test.name === t.name)) {
return [buildTask, createRunTask(t, targetName)];
return [buildTask, createRunTask(meson, t, targetName, buildDir)];
}
}
return buildTask;
Expand Down
21 changes: 0 additions & 21 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ export function isThenable<T>(x: vscode.ProviderResult<T>): x is Thenable<T> {
return arrayIncludes(Object.getOwnPropertyNames(x), "then");
}

let _envDict: { [key: string]: string } | undefined = undefined;

export async function genEnvFile(buildDir: string) {
const envfile = path.join(buildDir, "meson-vscode.env");
try {
Expand All @@ -164,25 +162,6 @@ export async function genEnvFile(buildDir: string) {
// Ignore errors, Meson could be too old to support --dump-format.
return;
}

// Load into a dict because vscode.ProcessExecution() does not support envFile.
_envDict = {};
const data = await fs.promises.readFile(envfile);
for (const i of data
.toString()
.split(/\r?\n/)
.filter((i) => i)) {
// Poor man's i.split("=", 1), JS won't return part after first equal sign.
// Value is quoted, remove first and last " char and also possible \r ending.
const index = i.indexOf("=");
const key = i.substring(0, index);
const value = i.slice(index + 2, -1);
_envDict[key] = value;
}
}

export function getEnvDict() {
return _envDict;
}

// meson setup --reconfigure is needed if and only if coredata.dat exists.
Expand Down

0 comments on commit 5ad9198

Please sign in to comment.