Skip to content

Use '@_implementationOnly' when importing 'Foundation.Bundle' in generated resource bundle accessor #5728

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 3 commits into from
Sep 28, 2022
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
17 changes: 17 additions & 0 deletions Fixtures/Resources/FoundationlessClient/AppPkg/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// swift-tools-version:999.0
import PackageDescription

let package = Package(
name: "AppPkg",
dependencies: [
.package(path: "../UtilsPkg"),
],
targets: [
.executableTarget(
name: "App",
dependencies: [
.product(name: "Utils", package: "UtilsPkg")
],
path: "./Sources/App"),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Utils
// Note the lack of 'import Foundation'.
// The purpose of this fixture is to test that the following line of code
// expectedly *doesn't* compile:
print(FooUtils.foo.trimmingCharacters(in: .whitespaces))
14 changes: 14 additions & 0 deletions Fixtures/Resources/FoundationlessClient/UtilsPkg/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version:999.0
import PackageDescription

let package = Package(
name: "UtilsPkg",
products: [
.library(name: "Utils", targets: ["Utils"]),
],
targets: [
.target(name: "Utils", dependencies: [], resources: [
.copy("foo.txt"),
]),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@frozen
public enum FooUtils { }

extension FooUtils {
public static let foo: String = "Hello, World!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
2 changes: 1 addition & 1 deletion Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public final class SwiftTargetBuildDescription {

let stream = BufferedOutputByteStream()
stream <<< """
import class Foundation.Bundle
\(toolsVersion < .vNext ? "import" : "@_implementationOnly import") class Foundation.Bundle

extension Foundation.Bundle {
static var module: Bundle = {
Expand Down
14 changes: 14 additions & 0 deletions Tests/FunctionalTests/ResourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,18 @@ class ResourcesTests: XCTestCase {
}
}
}

func testFoundationlessClient() throws {
try fixture(name: "Resources/FoundationlessClient") { fixturePath in
#if os(Linux) && swift(>=5.8)
let pkgPath = fixturePath.appending(components: "AppPkg")
guard let failure = XCTAssertBuildFails(pkgPath) else {
XCTFail("missing expected command execution error")
return
}
// Check that the following code expectedly doesn't compile for lack of 'import Foundation'
XCTAssertMatch(failure.stdout, .contains("print(FooUtils.foo.trimmingCharacters(in: .whitespaces))"))
#endif
}
}
}