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

Use build description to check for unified testing binary #1004

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
4 changes: 0 additions & 4 deletions src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ export class TestRunner {
fifoPipePath,
this.testKind,
this.testArgs.swiftTestArgs,
new Date(),
true
);

Expand Down Expand Up @@ -700,8 +699,6 @@ export class TestRunner {
});
subscriptions.push(buildTask);

const buildStartTime = new Date();

// Perform a build all before the tests are run. We want to avoid the "Debug Anyway" dialog
// since choosing that with no prior build, when debugging swift-testing tests, will cause
// the extension to start listening to the fifo pipe when no results will be produced,
Expand Down Expand Up @@ -729,7 +726,6 @@ export class TestRunner {
fifoPipePath,
this.testKind,
this.testArgs.swiftTestArgs,
buildStartTime,
true
);

Expand Down
31 changes: 18 additions & 13 deletions src/debugger/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class TestingDebugConfigurationFactory {
fifoPipePath: string,
testKind: TestKind,
testList: string[],
buildStartTime: Date,
expandEnvVariables = false
): Promise<vscode.DebugConfiguration | null> {
return new TestingDebugConfigurationFactory(
Expand All @@ -47,7 +46,6 @@ export class TestingDebugConfigurationFactory {
testKind,
TestLibrary.swiftTesting,
testList,
buildStartTime,
expandEnvVariables
).build();
}
Expand All @@ -64,7 +62,6 @@ export class TestingDebugConfigurationFactory {
testKind,
TestLibrary.xctest,
testList,
null,
expandEnvVariables
).build();
}
Expand All @@ -80,7 +77,6 @@ export class TestingDebugConfigurationFactory {
testKind,
testLibrary,
[],
null,
true
).testExecutableOutputPath();
}
Expand All @@ -91,7 +87,6 @@ export class TestingDebugConfigurationFactory {
private testKind: TestKind,
private testLibrary: TestLibrary,
private testList: string[],
private buildStartTime: Date | null,
private expandEnvVariables = false
) {}

Expand Down Expand Up @@ -454,23 +449,33 @@ export class TestingDebugConfigurationFactory {
);
}

private buildDescriptionPath(): string {
return path.join(this.buildDirectory, this.artifactFolderForTestKind, "description.json");
}

private async isUnifiedTestingBinary(): Promise<boolean> {
// Toolchains that contain https://github.com/swiftlang/swift-package-manager/commit/844bd137070dcd18d0f46dd95885ef7907ea0697
// no longer produce a .swift-testing binary, instead we want to use `unifiedTestingOutputPath`.
// In order to determine if we're working with a unified binary we need to check if the .swift-testing
// binary _doesn't_ exist, and if it does exist we need to check that it wasn't built by an old toolchain
// and is still in the .build directory. We do this by checking its mtime and seeing if it is after
// the `buildStartTime`.
// binary was produced by the latest build. If it was then we are not using a unified binary.

// TODO: When Swift 6 is released and enough time has passed that we're sure no one is building the .swift-testing
plemarquand marked this conversation as resolved.
Show resolved Hide resolved
// binary anymore this fs.stat workaround can be removed and `swiftTestingPath` can be returned. The
// `buildStartTime` argument can be removed and the build config generation can be made synchronous again.
// binary anymore this workaround can be removed and `swiftTestingPath` can be returned, and the build config
// generation can be made synchronous again.

try {
const stat = await fs.stat(this.swiftTestingOutputPath());
return !this.buildStartTime || stat.mtime.getTime() < this.buildStartTime.getTime();
const buildDescriptionStr = await fs.readFile(this.buildDescriptionPath(), "utf-8");
const buildDescription = JSON.parse(buildDescriptionStr);
const testProducts = buildDescription.builtTestProducts as { binaryPath: string }[];
if (!testProducts) {
return false;
}
const testBinaryPaths = testProducts.map(({ binaryPath }) => binaryPath);
const swiftTestingBinaryRealPath = await fs.realpath(this.swiftTestingOutputPath());
return !testBinaryPaths.includes(swiftTestingBinaryRealPath);
} catch {
// If the .swift-testing binary doesn't exist then swift-testing tests are in the unified binary.
// If the .swift-testing binary wasn't produced by the latest build then we assume the
// swift-testing tests are in the unified binary.
return true;
}
}
Expand Down