Skip to content

Add HashEncoder and QueryEngineTests #7435

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 14 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
87 changes: 56 additions & 31 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,34 @@
//
//===----------------------------------------------------------------------===//

import PackageDescription
import class Foundation.ProcessInfo
import PackageDescription

// When building the toolchain on the CI for ELF platforms, remove the CI's
// stdlib absolute runpath and add ELF's $ORIGIN relative paths before installing.
let swiftpmLinkSettings : [LinkerSetting]
let packageLibraryLinkSettings : [LinkerSetting]
let swiftpmLinkSettings: [LinkerSetting]
let packageLibraryLinkSettings: [LinkerSetting]
if let resourceDirPath = ProcessInfo.processInfo.environment["SWIFTCI_INSTALL_RPATH_OS"] {
swiftpmLinkSettings = [ .unsafeFlags(["-no-toolchain-stdlib-rpath", "-Xlinker", "-rpath", "-Xlinker", "$ORIGIN/../lib/swift/\(resourceDirPath)"]) ]
packageLibraryLinkSettings = [ .unsafeFlags(["-no-toolchain-stdlib-rpath", "-Xlinker", "-rpath", "-Xlinker", "$ORIGIN/../../\(resourceDirPath)"]) ]
swiftpmLinkSettings = [.unsafeFlags([
"-no-toolchain-stdlib-rpath",
"-Xlinker", "-rpath",
"-Xlinker", "$ORIGIN/../lib/swift/\(resourceDirPath)",
])]
packageLibraryLinkSettings = [.unsafeFlags([
"-no-toolchain-stdlib-rpath",
"-Xlinker", "-rpath",
"-Xlinker", "$ORIGIN/../../\(resourceDirPath)",
])]
} else {
swiftpmLinkSettings = []
packageLibraryLinkSettings = []
swiftpmLinkSettings = []
packageLibraryLinkSettings = []
}

/** SwiftPMDataModel is the subset of SwiftPM product that includes just its data model.
This allows some clients (such as IDEs) that use SwiftPM's data model but not its build system
to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here,
though that could break some clients.
*/
This allows some clients (such as IDEs) that use SwiftPM's data model but not its build system
to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here,
though that could break some clients.
*/
let swiftPMDataModelProduct = (
name: "SwiftPMDataModel",
targets: [
Expand All @@ -51,7 +59,7 @@ let swiftPMDataModelProduct = (
command line tools, while `libSwiftPMDataModel` includes only the data model.

NOTE: This API is *unstable* and may change at any time.
*/
*/
let swiftPMProduct = (
name: "SwiftPM",
targets: swiftPMDataModelProduct.targets + [
Expand All @@ -69,8 +77,8 @@ let systemSQLitePkgConfig: String? = "sqlite3"
#endif

/** An array of products which have two versions listed: one dynamically linked, the other with the
automatic linking type with `-auto` suffix appended to product's name.
*/
automatic linking type with `-auto` suffix appended to product's name.
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]


Expand All @@ -90,11 +98,11 @@ let package = Package(
name: "SwiftPM",
platforms: [
.macOS(.v13),
.iOS(.v16)
.iOS(.v16),
],
products:
autoProducts.flatMap {
[
autoProducts.flatMap {
[
.library(
name: $0.name,
type: .dynamic,
Expand All @@ -103,9 +111,9 @@ let package = Package(
.library(
name: "\($0.name)-auto",
targets: $0.targets
)
]
} + [
),
]
} + [
.library(
name: "XCBuildSupport",
targets: ["XCBuildSupport"]
Expand Down Expand Up @@ -166,7 +174,7 @@ let package = Package(
name: "SourceKitLSPAPI",
dependencies: [
"Build",
"SPMBuildCore"
"SPMBuildCore",
],
exclude: ["CMakeLists.txt"],
swiftSettings: [.enableExperimentalFeature("AccessLevelOnImport")]
Expand Down Expand Up @@ -213,7 +221,7 @@ let package = Package(
name: "SourceControl",
dependencies: [
"Basics",
"PackageModel"
"PackageModel",
],
exclude: ["CMakeLists.txt"]
),
Expand Down Expand Up @@ -255,7 +263,7 @@ let package = Package(
dependencies: [
"Basics",
"PackageLoading",
"PackageModel"
"PackageModel",
],
exclude: ["CMakeLists.txt", "README.md"]
),
Expand All @@ -267,7 +275,7 @@ let package = Package(
name: "PackageCollectionsModel",
dependencies: [],
exclude: [
"Formats/v1.md"
"Formats/v1.md",
]
),

Expand Down Expand Up @@ -301,7 +309,7 @@ let package = Package(
],
exclude: ["CMakeLists.txt"]
),

.target(
name: "PackageSigning",
dependencies: [
Expand All @@ -320,7 +328,7 @@ let package = Package(
name: "SPMBuildCore",
dependencies: [
"Basics",
"PackageGraph"
"PackageGraph",
],
exclude: ["CMakeLists.txt"]
),
Expand Down Expand Up @@ -460,6 +468,17 @@ let package = Package(
]
),

.target(
name: "QueryEngine",
dependencies: [
"Basics",
.product(name: "Crypto", package: "swift-crypto"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
]
),

.executableTarget(
/** The main executable provided by SwiftPM */
name: "swift-package",
Expand Down Expand Up @@ -517,7 +536,7 @@ let package = Package(
"Commands",
"SwiftSDKCommand",
"PackageCollectionsCommand",
"PackageRegistryCommand"
"PackageRegistryCommand",
],
linkerSettings: swiftpmLinkSettings
),
Expand Down Expand Up @@ -562,7 +581,8 @@ let package = Package(
.target(
/** Test for thread-santizer. */
name: "tsan_utils",
dependencies: []),
dependencies: []
),

// MARK: SwiftPM tests

Expand Down Expand Up @@ -655,6 +675,10 @@ let package = Package(
name: "PackageSigningTests",
dependencies: ["SPMTestSupport", "PackageSigning"]
),
.testTarget(
name: "QueryEngineTests",
dependencies: ["QueryEngine", "SPMTestSupport"]
),
.testTarget(
name: "SourceControlTests",
dependencies: ["SourceControl", "SPMTestSupport"],
Expand All @@ -670,7 +694,7 @@ let package = Package(
name: "package-info",
dependencies: ["Workspace"],
path: "Examples/package-info/Sources/package-info"
)
),
],
swiftLanguageVersions: [.v5]
)
Expand All @@ -688,15 +712,16 @@ package.targets.append(contentsOf: [
),
])

// rdar://101868275 "error: cannot find 'XCTAssertEqual' in scope" can affect almost any functional test, so we flat out disable them all until we know what is going on
// rdar://101868275 "error: cannot find 'XCTAssertEqual' in scope" can affect almost any functional test, so we flat out
// disable them all until we know what is going on
if ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] == nil {
package.targets.append(contentsOf: [
.testTarget(
name: "FunctionalTests",
dependencies: [
"swift-package-manager",
"PackageModel",
"SPMTestSupport"
"SPMTestSupport",
]
),

Expand Down
59 changes: 59 additions & 0 deletions Sources/Basics/Concurrency/ThrowingDefer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// Runs a cleanup closure (`deferred`) after a given `work` closure,
/// making sure `deferred` is run also when `work` throws an error.
/// - Parameters:
/// - work: The work that should be performed. Will always be executed.
/// - deferred: The cleanup that needs to be done in any case.
/// - Throws: Any error thrown by `deferred` or `work` (in that order).
/// - Returns: The result of `work`.
/// - Note: If `work` **and** `deferred` throw an error,
/// the one thrown by `deferred` is thrown from this function.
/// - SeeAlso: ``withAsyncThrowing(do:defer:)``
public func withThrowing<T>(
do work: () throws -> T,
defer deferred: () throws -> Void
) throws -> T {
do {
let result = try work()
try deferred()
return result
} catch {
try deferred()
throw error
}
}

/// Runs an async cleanup closure (`deferred`) after a given async `work` closure,
/// making sure `deferred` is run also when `work` throws an error.
/// - Parameters:
/// - work: The work that should be performed. Will always be executed.
/// - deferred: The cleanup that needs to be done in any case.
/// - Throws: Any error thrown by `deferred` or `work` (in that order).
/// - Returns: The result of `work`.
/// - Note: If `work` **and** `deferred` throw an error,
/// the one thrown by `deferred` is thrown from this function.
/// - SeeAlso: ``withThrowing(do:defer:)``
public func withAsyncThrowing<T: Sendable>(
do work: @Sendable () async throws -> T,
defer deferred: @Sendable () async throws -> Void
) async throws -> T {
do {
let result = try await work()
try await deferred()
return result
} catch {
try await deferred()
throw error
}
}
Loading