Skip to content

Commit 363fadf

Browse files
authored
[Prepare] Don't skip non-exportable-decls when enable-testing (#7675)
1 parent 075005b commit 363fadf

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,13 @@ public final class SwiftTargetBuildDescription {
539539
}
540540

541541
if self.buildParameters.prepareForIndexing {
542+
if !args.contains("-enable-testing") {
543+
// enable-testing needs the non-exportable-decls
544+
args += ["-Xfrontend", "-experimental-skip-non-exportable-decls"]
545+
}
542546
args += [
543547
"-Xfrontend", "-experimental-skip-all-function-bodies",
544548
"-Xfrontend", "-experimental-lazy-typecheck",
545-
"-Xfrontend", "-experimental-skip-non-exportable-decls",
546549
"-Xfrontend", "-experimental-allow-module-with-compiler-errors",
547550
"-Xfrontend", "-empty-abi-descriptor"
548551
]

Tests/BuildTests/PrepareForIndexTests.swift

+77-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
import Build
1414
import Foundation
1515
import LLBuildManifest
16-
@_spi(SwiftPMInternal)
17-
import SPMTestSupport
1816
import TSCBasic
1917
import XCTest
18+
@_spi(SwiftPMInternal)
19+
import SPMTestSupport
20+
import class Basics.ObservabilitySystem
21+
@_spi(DontAdoptOutsideOfSwiftPMExposedForBenchmarksAndTestsOnly)
22+
import func PackageGraph.loadModulesGraph
23+
import class PackageModel.Manifest
24+
import struct PackageModel.TargetDescription
2025

2126
class PrepareForIndexTests: XCTestCase {
2227
func testPrepare() throws {
@@ -82,4 +87,74 @@ class PrepareForIndexTests: XCTestCase {
8287
let name = lib.getLLBuildTargetName(buildParameters: plan.destinationBuildParameters)
8388
XCTAssertTrue(manifest.targets.keys.contains(name))
8489
}
90+
91+
// enable-testing requires the non-exportable-decls, make sure they aren't skipped.
92+
func testEnableTesting() throws {
93+
let fs = InMemoryFileSystem(
94+
emptyFiles:
95+
"/Pkg/Sources/lib/lib.swift",
96+
"/Pkg/Tests/test/TestCase.swift"
97+
)
98+
99+
let observability = ObservabilitySystem.makeForTesting()
100+
let scope = observability.topScope
101+
102+
let graph = try loadModulesGraph(
103+
fileSystem: fs,
104+
manifests: [
105+
Manifest.createRootManifest(
106+
displayName: "Pkg",
107+
path: "/Pkg",
108+
targets: [
109+
TargetDescription(name: "lib", dependencies: []),
110+
TargetDescription(name: "test", dependencies: ["lib"], type: .test),
111+
]
112+
),
113+
],
114+
observabilityScope: scope
115+
)
116+
XCTAssertNoDiagnostics(observability.diagnostics)
117+
118+
// Under debug, enable-testing is turned on by default. Make sure the flag is not added.
119+
let debugPlan = try BuildPlan(
120+
destinationBuildParameters: mockBuildParameters(destination: .target, config: .debug, prepareForIndexing: true),
121+
toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false),
122+
graph: graph,
123+
fileSystem: fs,
124+
observabilityScope: observability.topScope
125+
)
126+
let debugBuilder = LLBuildManifestBuilder(debugPlan, fileSystem: fs, observabilityScope: scope)
127+
let debugManifest = try debugBuilder.generatePrepareManifest(at: "/manifest")
128+
129+
XCTAssertNil(debugManifest.commands.values.first(where: {
130+
guard let swiftCommand = $0.tool as? SwiftCompilerTool,
131+
swiftCommand.outputs.contains(where: { $0.name.hasSuffix("/lib.swiftmodule")})
132+
else {
133+
return false
134+
}
135+
return swiftCommand.otherArguments.contains("-experimental-skip-non-exportable-decls")
136+
&& !swiftCommand.otherArguments.contains("-enable-testing")
137+
}))
138+
139+
// Under release, enable-testing is turned off by default so we should see our flag
140+
let releasePlan = try BuildPlan(
141+
destinationBuildParameters: mockBuildParameters(destination: .target, config: .release, prepareForIndexing: true),
142+
toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false),
143+
graph: graph,
144+
fileSystem: fs,
145+
observabilityScope: observability.topScope
146+
)
147+
let releaseBuilder = LLBuildManifestBuilder(releasePlan, fileSystem: fs, observabilityScope: scope)
148+
let releaseManifest = try releaseBuilder.generatePrepareManifest(at: "/manifest")
149+
150+
XCTAssertEqual(releaseManifest.commands.values.filter({
151+
guard let swiftCommand = $0.tool as? SwiftCompilerTool,
152+
swiftCommand.outputs.contains(where: { $0.name.hasSuffix("/lib.swiftmodule")})
153+
else {
154+
return false
155+
}
156+
return swiftCommand.otherArguments.contains("-experimental-skip-non-exportable-decls")
157+
&& !swiftCommand.otherArguments.contains("-enable-testing")
158+
}).count, 1)
159+
}
85160
}

0 commit comments

Comments
 (0)