Skip to content

Commit 19627d6

Browse files
committed
Merge branch 'main' of github.com:apple/swift-package-manager into maxd/packagegraph-value-types
# Conflicts: # Sources/PackageGraph/PackageGraph+Loading.swift # Sources/PackageGraph/Resolution/PlatformVersionProvider.swift # Sources/PackageGraph/Resolution/ResolvedPackage.swift # Sources/PackageGraph/Resolution/ResolvedProduct.swift # Sources/PackageGraph/Resolution/ResolvedTarget.swift # Sources/XCBuildSupport/PIFBuilder.swift # Tests/PackageGraphTests/TargetTests.swift
2 parents 57ff0a4 + 10be62b commit 19627d6

File tree

73 files changed

+1497
-892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1497
-892
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/SwiftPM-Package.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,16 @@
839839
ReferencedContainer = "container:">
840840
</BuildableReference>
841841
</TestableReference>
842+
<TestableReference
843+
skipped = "NO">
844+
<BuildableReference
845+
BuildableIdentifier = "primary"
846+
BlueprintIdentifier = "SourceKitLSPAPITests"
847+
BuildableName = "SourceKitLSPAPITests"
848+
BlueprintName = "SourceKitLSPAPITests"
849+
ReferencedContainer = "container:">
850+
</BuildableReference>
851+
</TestableReference>
842852
</Testables>
843853
</TestAction>
844854
<LaunchAction

CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
3030
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
3131
set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
3232

33-
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} Windows CMAKE_INSTALL_DEFAULT)
34-
option(USE_CMAKE_INSTALL
35-
"Install build products using cmake's install() instead of the bootstrap script's install()"
36-
${CMAKE_INSTALL_DEFAULT})
37-
38-
add_compile_options(-DUSE_IMPL_ONLY_IMPORTS)
39-
4033
if(FIND_PM_DEPS)
4134
find_package(SwiftSystem CONFIG REQUIRED)
4235
find_package(TSC CONFIG REQUIRED)

Package.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ let swiftPMDataModelProduct = (
4242
"PackageMetadata",
4343
"PackageModel",
4444
"SourceControl",
45+
"SourceKitLSPAPI",
4546
"Workspace",
4647
]
4748
)
@@ -148,6 +149,14 @@ let package = Package(
148149
linkerSettings: packageLibraryLinkSettings
149150
),
150151

152+
.target(
153+
name: "SourceKitLSPAPI",
154+
dependencies: [
155+
"Build",
156+
"SPMBuildCore"
157+
]
158+
),
159+
151160
// MARK: SwiftPM specific support libraries
152161

153162
.systemLibrary(name: "SPMSQLite3", pkgConfig: systemSQLitePkgConfig),
@@ -518,6 +527,7 @@ let package = Package(
518527
name: "SPMTestSupport",
519528
dependencies: [
520529
"Basics",
530+
"Build",
521531
"PackageFingerprint",
522532
"PackageGraph",
523533
"PackageLoading",
@@ -537,6 +547,14 @@ let package = Package(
537547

538548
// MARK: SwiftPM tests
539549

550+
.testTarget(
551+
name: "SourceKitLSPAPITests",
552+
dependencies: [
553+
"SourceKitLSPAPI",
554+
"SPMTestSupport",
555+
]
556+
),
557+
540558
.testTarget(
541559
name: "BasicsTests",
542560
dependencies: ["Basics", "SPMTestSupport", "tsan_utils"],

Sources/Basics/Archiver/Archiver.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,43 @@ public protocol Archiver {
5656
}
5757

5858
extension Archiver {
59+
/// Asynchronously extracts the contents of an archive to a destination folder.
60+
///
61+
/// - Parameters:
62+
/// - archivePath: The `AbsolutePath` to the archive to extract.
63+
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
5964
public func extract(
6065
from archivePath: AbsolutePath,
6166
to destinationPath: AbsolutePath
6267
) async throws {
63-
try await safe_async {
64-
self.extract(from: archivePath, to: destinationPath, completion: $0)
68+
try await withCheckedThrowingContinuation {
69+
self.extract(from: archivePath, to: destinationPath, completion: $0.resume(with:))
6570
}
6671
}
6772

73+
/// Asynchronously compresses the contents of a directory to a destination archive.
74+
///
75+
/// - Parameters:
76+
/// - directory: The `AbsolutePath` to the archive to extract.
77+
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
6878
public func compress(
6979
directory: AbsolutePath,
70-
to: AbsolutePath
80+
to destinationPath: AbsolutePath
7181
) async throws {
72-
try await safe_async {
73-
self.compress(directory: directory, to: to, completion: $0)
82+
try await withCheckedThrowingContinuation {
83+
self.compress(directory: directory, to: destinationPath, completion: $0.resume(with:))
7484
}
7585
}
7686

87+
/// Asynchronously validates if a file is an archive.
88+
///
89+
/// - Parameters:
90+
/// - path: The `AbsolutePath` to the archive to validate.
7791
public func validate(
7892
path: AbsolutePath
7993
) async throws -> Bool {
80-
try await safe_async {
81-
self.validate(path: path, completion: $0)
94+
try await withCheckedThrowingContinuation {
95+
self.validate(path: path, completion: $0.resume(with:))
8296
}
8397
}
8498
}

Sources/Basics/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ set_target_properties(Basics PROPERTIES
7676
target_link_options(Basics PRIVATE
7777
"$<$<PLATFORM_ID:Darwin>:SHELL:-Xlinker -framework -Xlinker Security>")
7878

79-
if(USE_CMAKE_INSTALL)
8079
install(TARGETS Basics
8180
ARCHIVE DESTINATION lib
8281
LIBRARY DESTINATION lib
8382
RUNTIME DESTINATION bin)
84-
endif()
8583
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS Basics)

Sources/Basics/Concurrency/ConcurrencyHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public func temp_await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
4141

4242
extension DispatchQueue {
4343
// a shared concurrent queue for running concurrent asynchronous operations
44-
public static var sharedConcurrent = DispatchQueue(
44+
public static let sharedConcurrent = DispatchQueue(
4545
label: "swift.org.swiftpm.shared.concurrent",
4646
attributes: .concurrent
4747
)

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,42 @@ public final class ClangTargetBuildDescription {
320320
return args
321321
}
322322

323+
public func emitCommandLine(for filePath: AbsolutePath) throws -> [String] {
324+
let standards = [
325+
(clangTarget.cxxLanguageStandard, SupportedLanguageExtension.cppExtensions),
326+
(clangTarget.cLanguageStandard, SupportedLanguageExtension.cExtensions),
327+
]
328+
329+
guard let path = try self.compilePaths().first(where: { $0.source == filePath }) else {
330+
throw BuildDescriptionError.requestedFileNotPartOfTarget(
331+
targetName: self.target.name,
332+
requestedFilePath: filePath
333+
)
334+
}
335+
336+
let isCXX = path.source.extension.map { SupportedLanguageExtension.cppExtensions.contains($0) } ?? false
337+
let isC = path.source.extension.map { $0 == SupportedLanguageExtension.c.rawValue } ?? false
338+
339+
var args = try basicArguments(isCXX: isCXX, isC: isC)
340+
341+
args += ["-MD", "-MT", "dependencies", "-MF", path.deps.pathString]
342+
343+
// Add language standard flag if needed.
344+
if let ext = path.source.extension {
345+
for (standard, validExtensions) in standards {
346+
if let standard, validExtensions.contains(ext) {
347+
args += ["-std=\(standard)"]
348+
}
349+
}
350+
}
351+
352+
args += ["-c", path.source.pathString, "-o", path.object.pathString]
353+
354+
let clangCompiler = try buildParameters.toolchain.getClangCompiler().pathString
355+
args.insert(clangCompiler, at: 0)
356+
return args
357+
}
358+
323359
/// Returns the build flags from the declared build settings.
324360
private func buildSettingsFlags() throws -> [String] {
325361
let scope = buildParameters.createScope(for: target)

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ public final class SwiftTargetBuildDescription {
240240
/// Whether or not to generate code for test observation.
241241
private let shouldGenerateTestObservation: Bool
242242

243+
/// Whether to disable sandboxing (e.g. for macros).
244+
private let disableSandbox: Bool
245+
243246
/// Create a new target description with target and build parameters.
244247
init(
245248
package: ResolvedPackage,
@@ -252,6 +255,7 @@ public final class SwiftTargetBuildDescription {
252255
requiredMacroProducts: [ResolvedProduct] = [],
253256
testTargetRole: TestTargetRole? = nil,
254257
shouldGenerateTestObservation: Bool = false,
258+
disableSandbox: Bool,
255259
fileSystem: FileSystem,
256260
observabilityScope: ObservabilityScope
257261
) throws {
@@ -279,6 +283,7 @@ public final class SwiftTargetBuildDescription {
279283
self.prebuildCommandResults = prebuildCommandResults
280284
self.requiredMacroProducts = requiredMacroProducts
281285
self.shouldGenerateTestObservation = shouldGenerateTestObservation
286+
self.disableSandbox = disableSandbox
282287
self.fileSystem = fileSystem
283288
self.observabilityScope = observabilityScope
284289

@@ -456,6 +461,18 @@ public final class SwiftTargetBuildDescription {
456461
args += ["-Xfrontend", "-external-plugin-path", "-Xfrontend", "\(localPluginPath)#\(pluginServer.pathString)"]
457462
}
458463

464+
if self.disableSandbox {
465+
let toolchainSupportsDisablingSandbox = DriverSupport.checkSupportedFrontendFlags(flags: ["-disable-sandbox"], toolchain: self.buildParameters.toolchain, fileSystem: fileSystem)
466+
if toolchainSupportsDisablingSandbox {
467+
args += ["-disable-sandbox"]
468+
} else {
469+
// If there's at least one macro being used, we warn about our inability to disable sandboxing.
470+
if !self.requiredMacroProducts.isEmpty {
471+
observabilityScope.emit(warning: "cannot disable sandboxing for Swift compilation because the selected toolchain does not support it")
472+
}
473+
}
474+
}
475+
459476
return args
460477
}
461478

@@ -541,6 +558,27 @@ public final class SwiftTargetBuildDescription {
541558
args += ["-color-diagnostics"]
542559
}
543560

561+
// If this is a generated test discovery target, it might import a test
562+
// target that is built with C++ interop enabled. In that case, the test
563+
// discovery target must enable C++ interop as well
564+
switch testTargetRole {
565+
case .discovery:
566+
for dependency in try self.target.recursiveTargetDependencies() {
567+
let dependencyScope = self.buildParameters.createScope(for: dependency)
568+
let dependencySwiftFlags = dependencyScope.evaluate(.OTHER_SWIFT_FLAGS)
569+
if let interopModeFlag = dependencySwiftFlags.first(where: { $0.hasPrefix("-cxx-interoperability-mode=") }) {
570+
args += [interopModeFlag]
571+
if interopModeFlag != "-cxx-interoperability-mode=off" {
572+
if let cxxStandard = self.package.manifest.cxxLanguageStandard {
573+
args += ["-Xcc", "-std=\(cxxStandard)"]
574+
}
575+
}
576+
break
577+
}
578+
}
579+
default: break
580+
}
581+
544582
// Add arguments from declared build settings.
545583
args += try self.buildSettingsFlags()
546584

Sources/Build/BuildDescription/TargetBuildDescription.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import struct PackageModel.Resource
1616
import struct SPMBuildCore.BuildToolPluginInvocationResult
1717
import struct SPMBuildCore.BuildParameters
1818

19+
public enum BuildDescriptionError: Swift.Error {
20+
case requestedFileNotPartOfTarget(targetName: String, requestedFilePath: AbsolutePath)
21+
}
22+
1923
/// A target description which can either be for a Swift or Clang target.
2024
public enum TargetBuildDescription {
2125
/// Swift target description.

Sources/Build/BuildManifest/LLBuildManifestBuilder+Clang.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ extension LLBuildManifestBuilder {
2121
func createClangCompileCommand(
2222
_ target: ClangTargetBuildDescription
2323
) throws {
24-
let standards = [
25-
(target.clangTarget.cxxLanguageStandard, SupportedLanguageExtension.cppExtensions),
26-
(target.clangTarget.cLanguageStandard, SupportedLanguageExtension.cExtensions),
27-
]
28-
2924
var inputs: [Node] = []
3025

3126
// Add resources node as the input to the target. This isn't great because we
@@ -79,26 +74,7 @@ extension LLBuildManifestBuilder {
7974
var objectFileNodes: [Node] = []
8075

8176
for path in try target.compilePaths() {
82-
let isCXX = path.source.extension.map { SupportedLanguageExtension.cppExtensions.contains($0) } ?? false
83-
let isC = path.source.extension.map { $0 == SupportedLanguageExtension.c.rawValue } ?? false
84-
85-
var args = try target.basicArguments(isCXX: isCXX, isC: isC)
86-
87-
args += ["-MD", "-MT", "dependencies", "-MF", path.deps.pathString]
88-
89-
// Add language standard flag if needed.
90-
if let ext = path.source.extension {
91-
for (standard, validExtensions) in standards {
92-
if let standard, validExtensions.contains(ext) {
93-
args += ["-std=\(standard)"]
94-
}
95-
}
96-
}
97-
98-
args += ["-c", path.source.pathString, "-o", path.object.pathString]
99-
100-
let clangCompiler = try target.buildParameters.toolchain.getClangCompiler().pathString
101-
args.insert(clangCompiler, at: 0)
77+
let args = try target.emitCommandLine(for: path.source)
10278

10379
let objectFileNode: Node = .file(path.object)
10480
objectFileNodes.append(objectFileNode)

Sources/Build/BuildOperation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
545545
additionalFileRules: additionalFileRules,
546546
buildToolPluginInvocationResults: buildToolPluginInvocationResults,
547547
prebuildCommandResults: prebuildCommandResults,
548+
disableSandbox: self.pluginConfiguration?.disableSandbox ?? false,
548549
fileSystem: self.fileSystem,
549550
observabilityScope: self.observabilityScope
550551
)

Sources/Build/BuildPlan/BuildPlan+Test.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extension BuildPlan {
2828
static func makeDerivedTestTargets(
2929
_ buildParameters: BuildParameters,
3030
_ graph: PackageGraph,
31+
_ disableSandbox: Bool,
3132
_ fileSystem: FileSystem,
3233
_ observabilityScope: ObservabilityScope
3334
) throws -> [(product: ResolvedProduct, discoveryTargetBuildDescription: SwiftTargetBuildDescription?, entryPointTargetBuildDescription: SwiftTargetBuildDescription)] {
@@ -96,6 +97,7 @@ extension BuildPlan {
9697
toolsVersion: toolsVersion,
9798
buildParameters: buildParameters,
9899
testTargetRole: .discovery,
100+
disableSandbox: disableSandbox,
99101
fileSystem: fileSystem,
100102
observabilityScope: observabilityScope
101103
)
@@ -134,6 +136,7 @@ extension BuildPlan {
134136
toolsVersion: toolsVersion,
135137
buildParameters: buildParameters,
136138
testTargetRole: .entryPoint(isSynthesized: true),
139+
disableSandbox: disableSandbox,
137140
fileSystem: fileSystem,
138141
observabilityScope: observabilityScope
139142
)
@@ -177,6 +180,7 @@ extension BuildPlan {
177180
toolsVersion: toolsVersion,
178181
buildParameters: buildParameters,
179182
testTargetRole: .entryPoint(isSynthesized: false),
183+
disableSandbox: disableSandbox,
180184
fileSystem: fileSystem,
181185
observabilityScope: observabilityScope
182186
)
@@ -198,6 +202,7 @@ extension BuildPlan {
198202
toolsVersion: toolsVersion,
199203
buildParameters: buildParameters,
200204
testTargetRole: .entryPoint(isSynthesized: false),
205+
disableSandbox: disableSandbox,
201206
fileSystem: fileSystem,
202207
observabilityScope: observabilityScope
203208
)

0 commit comments

Comments
 (0)