Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8f6bfe8
Fix `package` access modifier in XCBuild support
MaxDesiatov Jan 16, 2024
582cd2b
Fix formatting, remove excessive `print`, reduce the diff
MaxDesiatov Jan 16, 2024
9b9d0ed
Enable `testPackageNameFlagXCBuild` only on macOS
MaxDesiatov Jan 16, 2024
796c1b1
Fix CMake build
MaxDesiatov Jan 16, 2024
82a22b3
Address PR feedback
MaxDesiatov Jan 16, 2024
2f60251
Add missing `SwiftDriver` dependency to `XCBuildSupport`
MaxDesiatov Jan 16, 2024
427b518
Update BuildParameters.swift
MaxDesiatov Jan 16, 2024
eea30f4
Merge branch 'main' into maxd/fix-xcbuild-package-name
MaxDesiatov Jan 17, 2024
46d01e5
Replace `package` modifier with `@testable` at place of use
MaxDesiatov Jan 19, 2024
bb2f876
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Jan 19, 2024
6e49171
Replace `package` with `@_spi(SwiftPMInternal)`
MaxDesiatov Jan 19, 2024
42c868a
Fix remaining use of `package var`
MaxDesiatov Jan 19, 2024
6bbf6e2
Fix use of `package func`
MaxDesiatov Jan 19, 2024
031ead4
Add required `@_spi(SwiftPMInternal)` on imports
MaxDesiatov Jan 19, 2024
44d7267
Update `SourceKitLSPAPI/CMakeLists.txt`
MaxDesiatov Jan 22, 2024
4d4a8f4
Update `XCBuildSupport/CMakeLists.txt`
MaxDesiatov Jan 22, 2024
e23f9c7
Update `swift-bootstrap/CMakeLists.txt`
MaxDesiatov Jan 22, 2024
553f559
Update `SwiftSDKTool/CMakeLists.txt`
MaxDesiatov Jan 23, 2024
95ff5da
Update `swift-experimental-sdk/CMakeLists.txt`
MaxDesiatov Jan 24, 2024
e83dc69
Update `swift-build/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
35d949b
Update `swift-package/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
3be01c3
Update `swift-run/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
1565886
Update `swift-test/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
e293b7e
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Feb 16, 2024
c57d3f5
Clean up `DriverSupport` imports
MaxDesiatov Feb 16, 2024
398dd3e
More cleanups
MaxDesiatov Feb 16, 2024
7749bab
Add `DriverSupport` missing in `swift-bootstrap` CMake
MaxDesiatov Feb 16, 2024
df2daf5
Add `SwiftDriver` as `PRIVATE` requirement to `target_link_libraries`
MaxDesiatov Feb 17, 2024
888e657
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Feb 21, 2024
8124f79
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Feb 23, 2024
f9b7f1a
Reduce diff to `main`
MaxDesiatov Feb 23, 2024
af4e9e6
Add `@_spi(SwiftPMInternal)` on `isPackageNameSupported`
MaxDesiatov Feb 23, 2024
3d7fab2
Reduce diff to `main`
MaxDesiatov Feb 23, 2024
2f7e094
Add missing `SwiftDriver` requirement to `swift-bootstrap/CMakeLists.…
MaxDesiatov Feb 23, 2024
7ca0f81
Define `DISABLE_XCBUILD_SUPPORT` in `swift-bootstrap/CMakeLists.txt`
MaxDesiatov Feb 23, 2024
79f68c3
Remove unused imports
MaxDesiatov Feb 23, 2024
b13d173
Merge branch 'main' into maxd/fix-xcbuild-package-name
MaxDesiatov Feb 23, 2024
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ find_package(dispatch QUIET)
find_package(Foundation QUIET)
find_package(SQLite3 REQUIRED)

# Enable `package` modifier for the whole package.
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:-package-name;SwiftPM>")

add_subdirectory(Sources)
add_subdirectory(cmake/modules)
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -461,6 +461,7 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"Basics",
"Build",
"DriverSupport",
"PackageGraph",
"PackageLoading",
"PackageModel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public final class SwiftTargetBuildDescription {
private func packageNameArgumentIfSupported(with pkg: ResolvedPackage, packageAccess: Bool) -> [String] {
let flag = "-package-name"
if pkg.manifest.usePackageNameFlag,
DriverSupport.checkToolchainDriverFlags(flags: [flag], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem) {
DriverSupport.isPackageNameSupported(toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem) {
if packageAccess {
let pkgID = pkg.identity.description.spm_mangledToC99ExtendedIdentifier()
return [flag, pkgID]
Expand Down
8 changes: 6 additions & 2 deletions Sources/CoreCommands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -721,7 +721,11 @@ public final class SwiftTool {
enableParseableModuleInterfaces: options.build.shouldEnableParseableModuleInterfaces,
explicitTargetDependencyImportCheckingMode: options.build.explicitTargetDependencyImportCheck.modeParameter,
useIntegratedSwiftDriver: options.build.useIntegratedSwiftDriver,
useExplicitModuleBuild: options.build.useExplicitModuleBuild
useExplicitModuleBuild: options.build.useExplicitModuleBuild,
isPackageAccessModifierSupported: DriverSupport.isPackageNameSupported(
toolchain: toolchain,
fileSystem: self.fileSystem
)
),
linkingParameters: .init(
linkerDeadStrip: options.linker.linkerDeadStrip,
Expand Down
12 changes: 8 additions & 4 deletions Sources/DriverSupport/DriverSupportUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -17,11 +17,11 @@ import class TSCBasic.Process
import enum TSCBasic.ProcessEnv
import struct TSCBasic.ProcessResult

public enum DriverSupport {
package enum DriverSupport {
private static var flagsMap = ThreadSafeBox<[String: Set<String>]>()

// This checks _frontend_ supported flags, which are not necessarily supported in the driver.
public static func checkSupportedFrontendFlags(
package static func checkSupportedFrontendFlags(
flags: Set<String>,
toolchain: PackageModel.Toolchain,
fileSystem: FileSystem
Expand Down Expand Up @@ -54,7 +54,7 @@ public enum DriverSupport {
// This checks if given flags are supported in the built-in toolchain driver. Currently
// there's no good way to get the supported flags from it, so run `swiftc -h` directly
// to get the flags and cache the result.
public static func checkToolchainDriverFlags(
static func checkToolchainDriverFlags(
flags: Set<String>,
toolchain: PackageModel.Toolchain,
fileSystem: FileSystem
Expand Down Expand Up @@ -83,4 +83,8 @@ public enum DriverSupport {
return false
}
}

package static func isPackageNameSupported(toolchain: PackageModel.Toolchain, fileSystem: FileSystem) -> Bool {
DriverSupport.checkToolchainDriverFlags(flags: ["-package-name"], toolchain: toolchain, fileSystem: fileSystem)
}
}
2 changes: 1 addition & 1 deletion Sources/PackageGraph/Resolution/ResolvedTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageModel/Target/SwiftTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -25,13 +25,15 @@ extension BuildParameters {
enableParseableModuleInterfaces: Bool = false,
explicitTargetDependencyImportCheckingMode: TargetDependencyImportCheckingMode = .none,
useIntegratedSwiftDriver: Bool = false,
useExplicitModuleBuild: Bool = false
useExplicitModuleBuild: Bool = false,
isPackageAccessModifierSupported: Bool = false
) {
self.canRenameEntrypointFunctionName = canRenameEntrypointFunctionName
self.enableParseableModuleInterfaces = enableParseableModuleInterfaces
self.explicitTargetDependencyImportCheckingMode = explicitTargetDependencyImportCheckingMode
self.useIntegratedSwiftDriver = useIntegratedSwiftDriver
self.useExplicitModuleBuild = useExplicitModuleBuild
self.isPackageAccessModifierSupported = isPackageAccessModifierSupported
}

/// Whether to enable the entry-point-function-name feature.
Expand All @@ -45,11 +47,15 @@ extension BuildParameters {
/// `.swiftmodule`s.
public var enableParseableModuleInterfaces: Bool

/// Whether to use the integrated Swift driver rather than shelling out
/// Whether to use the integrated Swift Driver rather than shelling out
/// to a separate process.
public var useIntegratedSwiftDriver: Bool

/// Whether to use the explicit module build flow (with the integrated driver).
public var useExplicitModuleBuild: Bool

/// Whether the version of Swift Driver used in the currently selected toolchain
/// supports `-package-name` options.
package var isPackageAccessModifierSupported: Bool
}
}
4 changes: 2 additions & 2 deletions Sources/SPMBuildCore/BuildParameters/BuildParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -132,7 +132,7 @@ public struct BuildParameters: Encodable {
isXcodeBuildSystemEnabled: Bool = false,
shouldSkipBuilding: Bool = false,
debuggingParameters: Debugging? = nil,
driverParameters: Driver = .init(),
driverParameters: Driver,
linkingParameters: Linking = .init(),
outputParameters: Output = .init(),
testingParameters: Testing? = nil
Expand Down
1 change: 1 addition & 0 deletions Sources/SPMBuildCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_library(SPMBuildCore
Plugins/PluginMessages.swift
Plugins/PluginScriptRunner.swift
PrebuildCommandResult.swift
ResolvedPackage+Extensions.swift
Triple+Extensions.swift
XCFrameworkMetadata.swift)
# NOTE(compnerd) workaround for CMake not setting up include flags yet
Expand Down
24 changes: 24 additions & 0 deletions Sources/SPMBuildCore/ResolvedPackage+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import struct PackageGraph.ResolvedPackage
import struct PackageGraph.ResolvedTarget

extension ResolvedPackage {
package func packageNameArgument(target: ResolvedTarget, isPackageNameSupported: Bool) -> [String] {
if self.manifest.usePackageNameFlag, target.packageAccess {
["-package-name", self.identity.description.spm_mangledToC99ExtendedIdentifier()]
} else {
[]
}
}
}
82 changes: 68 additions & 14 deletions Sources/SPMTestSupport/PIFTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2020 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -32,7 +32,12 @@ public final class PIFWorkspaceTester {
targetMap = Dictionary(uniqueKeysWithValues: targetsByGUID)
}

public func checkProject(_ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, body: (PIFProjectTester) -> Void) throws {
public func checkProject(
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
body: (PIFProjectTester) -> Void
) throws {
guard let project = projectMap[guid] else {
return XCTFail("project \(guid) not found", file: file, line: line)
}
Expand All @@ -55,10 +60,20 @@ public final class PIFProjectTester {
fileprivate init(project: PIF.Project, targetMap: [PIF.GUID: PIF.BaseTarget]) throws {
self.project = project
self.targetMap = targetMap
self.fileMap = try collectFiles(from: project.groupTree, parentPath: project.path, projectPath: project.path, builtProductsPath: project.path)
self.fileMap = try collectFiles(
from: project.groupTree,
parentPath: project.path,
projectPath: project.path,
builtProductsPath: project.path
)
}

public func checkTarget(_ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, body: ((PIFTargetTester) -> Void)? = nil) {
public func checkTarget(
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
body: ((PIFTargetTester) -> Void)? = nil
) {
guard let baseTarget = baseTarget(withGUID: guid) else {
let guids = project.targets.map { $0.guid }.joined(separator: ", ")
return XCTFail("target \(guid) not found among \(guids)", file: file, line: line)
Expand All @@ -71,13 +86,23 @@ public final class PIFProjectTester {
body?(PIFTargetTester(target: target, targetMap: targetMap, fileMap: fileMap))
}

public func checkNoTarget(_ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, body: ((PIFTargetTester) -> Void)? = nil) {
public func checkNoTarget(
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
body: ((PIFTargetTester) -> Void)? = nil
) {
if baseTarget(withGUID: guid) != nil {
XCTFail("target \(guid) found", file: file, line: line)
}
}

public func checkAggregateTarget(_ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, body: ((PIFAggregateTargetTester) -> Void)? = nil) {
public func checkAggregateTarget(
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
body: ((PIFAggregateTargetTester) -> Void)? = nil
) {
guard let baseTarget = baseTarget(withGUID: guid) else {
let guids = project.targets.map { $0.guid }.joined(separator: ", ")
return XCTFail("target \(guid) not found among \(guids)", file: file, line: line)
Expand All @@ -90,7 +115,12 @@ public final class PIFProjectTester {
body?(PIFAggregateTargetTester(target: target, targetMap: targetMap, fileMap: fileMap))
}

public func checkBuildConfiguration(_ name: String, file: StaticString = #file, line: UInt = #line, body: (PIFBuildConfigurationTester) -> Void) {
public func checkBuildConfiguration(
_ name: String,
file: StaticString = #file,
line: UInt = #line,
body: (PIFBuildConfigurationTester) -> Void
) {
guard let configuration = buildConfiguration(withName: name) else {
let names = project.buildConfigurations.map { $0.name }.joined(separator: ", ")
return XCTFail("build configuration \(name) not found among \(names)", file: file, line: line)
Expand Down Expand Up @@ -151,7 +181,12 @@ public class PIFBaseTargetTester {
})
}

public func checkBuildConfiguration(_ name: String, file: StaticString = #file, line: UInt = #line, body: (PIFBuildConfigurationTester) -> Void) {
public func checkBuildConfiguration(
_ name: String,
file: StaticString = #file,
line: UInt = #line,
body: (PIFBuildConfigurationTester) -> Void
) {
guard let configuration = buildConfiguration(withName: name) else {
return XCTFail("build configuration \(name) not found", file: file, line: line)
}
Expand All @@ -163,19 +198,33 @@ public class PIFBaseTargetTester {
return baseTarget.buildConfigurations.first { $0.name == name }
}

public func checkImpartedBuildSettings(file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void) {
let buildSettingsTester = PIFBuildSettingsTester(buildSettings: baseTarget.buildConfigurations.first!.impartedBuildProperties.buildSettings)
public func checkImpartedBuildSettings(
file: StaticString = #file,
line: UInt = #line,
_ body: (PIFBuildSettingsTester) -> Void
) {
let buildSettingsTester = PIFBuildSettingsTester(
buildSettings: baseTarget.buildConfigurations.first!.impartedBuildProperties.buildSettings
)
body(buildSettingsTester)
}

public func checkAllImpartedBuildSettings(file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void) {
let buildSettingsTester = PIFBuildSettingsTester(buildSettings: baseTarget.buildConfigurations.first!.impartedBuildProperties.buildSettings)
public func checkAllImpartedBuildSettings(
file: StaticString = #file,
line: UInt = #line,
_ body: (PIFBuildSettingsTester) -> Void
) {
let buildSettingsTester = PIFBuildSettingsTester(
buildSettings: baseTarget.buildConfigurations.first!.impartedBuildProperties.buildSettings
)
body(buildSettingsTester)
buildSettingsTester.checkUncheckedSettings(file: file, line: line)
}

public func checkNoImpartedBuildSettings(file: StaticString = #file, line: UInt = #line) {
let buildSettingsTester = PIFBuildSettingsTester(buildSettings: baseTarget.buildConfigurations.first!.impartedBuildProperties.buildSettings)
let buildSettingsTester = PIFBuildSettingsTester(
buildSettings: baseTarget.buildConfigurations.first!.impartedBuildProperties.buildSettings
)
buildSettingsTester.checkUncheckedSettings(file: file, line: line)
}
}
Expand Down Expand Up @@ -313,7 +362,12 @@ private func collectFiles(
files[reference.guid] = referencePath.pathString
} else if let group = reference as? PIF.Group {
for child in group.children {
let childFiles = try collectFiles(from: child, parentPath: referencePath, projectPath: projectPath, builtProductsPath: builtProductsPath)
let childFiles = try collectFiles(
from: child,
parentPath: referencePath,
projectPath: projectPath,
builtProductsPath: builtProductsPath
)
files.merge(childFiles, uniquingKeysWith: { _, _ in fatalError("non-unique GUID") })
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/SwiftPMProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ extension SwiftPM {
completeArgs += ["--package-path", packagePath.pathString]
}
completeArgs += args

return try Process.popen(arguments: completeArgs, environment: environment)
}
}
Expand Down
Loading