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

Pass environment to the testing debugger #241

Merged
merged 1 commit into from
Jun 24, 2024
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
29 changes: 26 additions & 3 deletions src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import { ExecResult, exec, extensionConfiguration } from "./utils";
import { Tests } from "./types";
import { Tests, DebugEnvironmentConfiguration } from "./types";
import { getMesonTests, getMesonTargets } from "./introspection";
import { workspaceState } from "./extension";

Expand Down Expand Up @@ -128,16 +128,39 @@ export async function testDebugHandler(
let args = [...test.cmd];
args.shift();

let debugEnvironmentConfiguration: DebugEnvironmentConfiguration;
/* cppdbg uses 'environment' key, all others use 'env' key */
if (debugType == "cppdbg") {
const debugEnv = [];
if (test.env instanceof Object) {
/* convert from dict of key = value to array of {name: key, value: value} */
for (const [key, val] of Object.entries(test.env)) {
debugEnv.push({ name: key, value: val });
}
}
debugEnvironmentConfiguration = {
environment: debugEnv,
};
} else {
debugEnvironmentConfiguration = {
env: test.env,
};
}

let debugConfiguration = {
name: `meson-debug-${test.name}`,
type: debugType,
request: "launch",
cwd: test.workdir || sourceDir,
env: test.env,
program: test.cmd[0],
args: args,
};
await vscode.debug.startDebugging(undefined, { ...debugConfiguration, ...configDebugOptions });
const configuration = {
...debugConfiguration,
...debugEnvironmentConfiguration,
...configDebugOptions,
};
await vscode.debug.startDebugging(undefined, configuration);
}

run.end();
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ export interface Test {
depends: string[];
}

interface StdDebugEnvironmentConfiguration {
env: { [key: string]: string };
}
interface CppDebugEnvironmentConfiguration {
environment: { name: string; value: string }[];
}
export type DebugEnvironmentConfiguration = StdDebugEnvironmentConfiguration | CppDebugEnvironmentConfiguration;

export type Targets = Target[];
export type BuildOptions = BuildOption<any>[];
export type Dependencies = Dependency[];
Expand Down
Loading