Skip to content

[Prepare] Don't skip non-exportable-decls when enable-testing #7675

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

Merged
merged 1 commit into from
Jun 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,13 @@ public final class SwiftTargetBuildDescription {
}

if self.buildParameters.prepareForIndexing {
if !args.contains("-enable-testing") {
// enable-testing needs the non-exportable-decls
args += ["-Xfrontend", "-experimental-skip-non-exportable-decls"]
}
args += [
"-Xfrontend", "-experimental-skip-all-function-bodies",
"-Xfrontend", "-experimental-lazy-typecheck",
"-Xfrontend", "-experimental-skip-non-exportable-decls",
"-Xfrontend", "-experimental-allow-module-with-compiler-errors",
"-Xfrontend", "-empty-abi-descriptor"
]
Expand Down
79 changes: 77 additions & 2 deletions Tests/BuildTests/PrepareForIndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
import Build
import Foundation
import LLBuildManifest
@_spi(SwiftPMInternal)
import SPMTestSupport
import TSCBasic
import XCTest
@_spi(SwiftPMInternal)
import SPMTestSupport
import class Basics.ObservabilitySystem
@_spi(DontAdoptOutsideOfSwiftPMExposedForBenchmarksAndTestsOnly)
import func PackageGraph.loadModulesGraph
import class PackageModel.Manifest
import struct PackageModel.TargetDescription

class PrepareForIndexTests: XCTestCase {
func testPrepare() throws {
Expand Down Expand Up @@ -82,4 +87,74 @@ class PrepareForIndexTests: XCTestCase {
let name = lib.getLLBuildTargetName(buildParameters: plan.destinationBuildParameters)
XCTAssertTrue(manifest.targets.keys.contains(name))
}

// enable-testing requires the non-exportable-decls, make sure they aren't skipped.
func testEnableTesting() throws {
let fs = InMemoryFileSystem(
emptyFiles:
"/Pkg/Sources/lib/lib.swift",
"/Pkg/Tests/test/TestCase.swift"
)

let observability = ObservabilitySystem.makeForTesting()
let scope = observability.topScope

let graph = try loadModulesGraph(
fileSystem: fs,
manifests: [
Manifest.createRootManifest(
displayName: "Pkg",
path: "/Pkg",
targets: [
TargetDescription(name: "lib", dependencies: []),
TargetDescription(name: "test", dependencies: ["lib"], type: .test),
]
),
],
observabilityScope: scope
)
XCTAssertNoDiagnostics(observability.diagnostics)

// Under debug, enable-testing is turned on by default. Make sure the flag is not added.
let debugPlan = try BuildPlan(
destinationBuildParameters: mockBuildParameters(destination: .target, config: .debug, prepareForIndexing: true),
toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false),
graph: graph,
fileSystem: fs,
observabilityScope: observability.topScope
)
let debugBuilder = LLBuildManifestBuilder(debugPlan, fileSystem: fs, observabilityScope: scope)
let debugManifest = try debugBuilder.generatePrepareManifest(at: "/manifest")

XCTAssertNil(debugManifest.commands.values.first(where: {
guard let swiftCommand = $0.tool as? SwiftCompilerTool,
swiftCommand.outputs.contains(where: { $0.name.hasSuffix("/lib.swiftmodule")})
else {
return false
}
return swiftCommand.otherArguments.contains("-experimental-skip-non-exportable-decls")
&& !swiftCommand.otherArguments.contains("-enable-testing")
}))

// Under release, enable-testing is turned off by default so we should see our flag
let releasePlan = try BuildPlan(
destinationBuildParameters: mockBuildParameters(destination: .target, config: .release, prepareForIndexing: true),
toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false),
graph: graph,
fileSystem: fs,
observabilityScope: observability.topScope
)
let releaseBuilder = LLBuildManifestBuilder(releasePlan, fileSystem: fs, observabilityScope: scope)
let releaseManifest = try releaseBuilder.generatePrepareManifest(at: "/manifest")

XCTAssertEqual(releaseManifest.commands.values.filter({
guard let swiftCommand = $0.tool as? SwiftCompilerTool,
swiftCommand.outputs.contains(where: { $0.name.hasSuffix("/lib.swiftmodule")})
else {
return false
}
return swiftCommand.otherArguments.contains("-experimental-skip-non-exportable-decls")
&& !swiftCommand.otherArguments.contains("-enable-testing")
}).count, 1)
}
}