Skip to content

Commit

Permalink
Added option to specify objdump executable
Browse files Browse the repository at this point in the history
  • Loading branch information
bneumann committed Apr 14, 2024
1 parent 49303c3 commit 5fa997e
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 301 deletions.
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

12 changes: 0 additions & 12 deletions .vscodeignore

This file was deleted.

16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"rimraf": "^3.0.2",
"ts-mockito": "^2.6.1",
"ts-node": "^10.9.2",
"typescript": "^4.9.5",
"typescript": "^5.4.5",
"vsce": "^2.7.0"
},
"engines": {
Expand All @@ -64,7 +64,7 @@
"hbenl.vscode-test-explorer"
],
"activationEvents": [
"*"
"onStartupFinished"
],
"contributes": {
"configuration": {
Expand Down Expand Up @@ -116,6 +116,12 @@
"default": "",
"type": "string",
"scope": "resource"
},
"cpputestTestAdapter.objDumpExecutable": {
"description": "The path to the objdump executable",
"default": "objdump",
"type": "string",
"scope": "resource"
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/Infrastructure/ExecutableRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,31 @@ export class RunResult {
}
}

export interface ExecutableRunnerOptions {
workingDirectory?: string;
objDumpExecutable?: string;
}

export default class ExecutableRunner {
private readonly exec: Function;
private readonly execFile: Function;
private readonly kill: Function;
private readonly command: string;
private readonly workingDirectory: string;
private readonly objDumpExecutable: string;
private readonly tempFile: string;
public readonly Name: string;
private dumpCached: boolean;
private tryGetLocation: boolean;
private log: Log;

constructor(processExecuter: ProcessExecuter, command: string, log: Log, workingDirectory: string = dirname(command)) {
constructor(processExecuter: ProcessExecuter, command: string, log: Log, options?: ExecutableRunnerOptions) {
this.exec = processExecuter.Exec;
this.execFile = processExecuter.ExecFile;
this.kill = processExecuter.KillProcess;
this.command = command;
this.workingDirectory = workingDirectory;
this.workingDirectory = options?.workingDirectory ?? dirname(command);
this.objDumpExecutable = options?.objDumpExecutable ?? "objdump";
this.Name = basename(command);
this.tempFile = `${this.Name}.dump`
this.dumpCached = false;
Expand All @@ -54,7 +61,7 @@ export default class ExecutableRunner {
return this.GetTestListWithLocation(true);
case TestLocationFetchMode.Auto:
if (this.tryGetLocation) {
return this.GetTestListWithLocation(false).catch( () => {
return this.GetTestListWithLocation(false).catch(() => {
this.tryGetLocation = false;
return this.GetTestListGroupAndNames();
});
Expand Down Expand Up @@ -111,7 +118,7 @@ export default class ExecutableRunner {
private DumpSymbols(): Promise<void> {
if (this.dumpCached) { return Promise.resolve(); }
// Linux:
const sourceGrep = `objdump -lSd ${this.command} > ${this.tempFile}`;
const sourceGrep = `${this.objDumpExecutable} -lSd ${this.command} > ${this.tempFile}`;
// Windows:
// const sourceGrep = `windObjDumpOrWhatEver ${command} | findstr TEST_${group}_${test}`
return new Promise<void>((resolve, reject) => {
Expand Down
1 change: 1 addition & 0 deletions src/Infrastructure/SettingsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum TestLocationFetchMode {
}

export interface SettingsProvider {
GetObjDumpPath(): string;
GetTestRunners(): string[];
GetTestPath(): string;
get TestLocationFetchMode(): TestLocationFetchMode;
Expand Down
3 changes: 3 additions & 0 deletions src/Infrastructure/VscodeSettingsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default class VscodeSettingsProvider implements SettingsProvider {
}
})
}
GetObjDumpPath(): string {
return this.ResolveSettingsVariable(this.config.objDumpExecutable);
}

GetWorkspaceFolders(): readonly vscode.WorkspaceFolder[] | undefined {
return vscode.workspace.workspaceFolders;
Expand Down
10 changes: 8 additions & 2 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TestResult } from './Domain/TestResult';
import { CppUTest } from './Domain/CppUTest';
import { RegexResultParser } from "./Domain/RegexResultParser";
import VscodeSettingsProvider from "./Infrastructure/VscodeSettingsProvider";
import ExecutableRunner from "./Infrastructure/ExecutableRunner";
import ExecutableRunner, { ExecutableRunnerOptions } from "./Infrastructure/ExecutableRunner";
import { NodeProcessExecuter } from './Application/NodeProcessExecuter';
import { VscodeAdapterImplementation } from "./Application/VscodeAdapterImplementation";
import { SettingsProvider } from "./Infrastructure/SettingsProvider";
Expand Down Expand Up @@ -101,11 +101,17 @@ export class CppUTestAdapter implements TestAdapter {

private async updateTests(): Promise<void> {
this.root.ClearTests();
const runners = this.settingsProvider.GetTestRunners().map(runner => new ExecutableRunner(this.processExecuter, runner, this.log));
const runners = this.settingsProvider.GetTestRunners().map(runner => new ExecutableRunner(this.processExecuter, runner, this.log, this.GetExecutionOptions()));
const loadedTests = await this.root.LoadTests(runners);
this.mainSuite.children = loadedTests;
this.testsEmitter.fire(<TestLoadFinishedEvent>{ type: 'finished', suite: this.mainSuite });
}
private GetExecutionOptions(): ExecutableRunnerOptions | undefined {
return {
objDumpExecutable: this.settingsProvider.GetObjDumpPath(),
workingDirectory: undefined // this is calculated inside the ExecutableRunner, not really good style
}
}

private handleTestStarted(test: CppUTest): void {
const event = this.mapTestResultToTestEvent(test);
Expand Down
Loading

0 comments on commit 5fa997e

Please sign in to comment.