diff --git a/CMakeLists.txt b/CMakeLists.txt index db4c32af6a7..a94930d523e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ if(FIND_PM_DEPS) endif() find_package(ArgumentParser CONFIG REQUIRED) + find_package(swift-collections CONFIG REQUIRED) find_package(SwiftCrypto CONFIG REQUIRED) find_package(SwiftDriver CONFIG REQUIRED) endif() diff --git a/Documentation/Contributing.md b/Documentation/Contributing.md index c051b507de4..af5d88d8651 100644 --- a/Documentation/Contributing.md +++ b/Documentation/Contributing.md @@ -129,39 +129,45 @@ The bootstrap script requires having [CMake](https://cmake.org/) and [Ninja](htt Please refer to the [_Get Started_ guide](https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#installing-dependencies) on the Swift project repository for installation instructions. 1. Clone [llbuild](https://github.com/apple/swift-llbuild) beside the SwiftPM directory. - -```bash -$> git clone https://github.com/apple/swift-llbuild llbuild -``` - -Note: Make sure the directory for llbuild is called "llbuild" and not - "swift-llbuild". + + ```bash + $> git clone https://github.com/apple/swift-llbuild llbuild + ``` + + > **Note**: Make sure the directory for llbuild is called "llbuild" and not "swift-llbuild". 2. Clone [Yams](https://github.com/jpsim/yams) beside the SwiftPM directory. - -```bash -$> git clone https://github.com/jpsim/yams -``` + + ```bash + $> git clone https://github.com/jpsim/yams + ``` 3. Clone [swift-driver](https://github.com/apple/swift-driver) beside the SwiftPM directory. - -```bash -$> git clone https://github.com/apple/swift-driver -``` + + ```bash + $> git clone https://github.com/apple/swift-driver + ``` 4. Clone [swift-argument-parser](https://github.com/apple/swift-argument-parser) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-argument-parser/tags). - -For example, if the latest tag is 0.3.1: -```bash -$> git clone https://github.com/apple/swift-argument-parser --branch 0.3.1 -``` - -5. Clone [swift-crypto](https://github.com/apple/swift-crypto) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags). - -For example, if the latest tag is 1.1.3: -```bash -$> git clone https://github.com/apple/swift-crypto --branch 1.1.3 -``` + + For example, if the latest tag is 0.4.3: + ```sh + $> git clone https://github.com/apple/swift-argument-parser --branch 0.4.3 + ``` + +5. Clone [swift-collections](https://github.com/apple/swift-collections) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-collections/tags). + + For example, if the latest tag is 0.0.3: + ```sh + $> git clone https://github.com/apple/swift-collections --branch 0.0.3 + ``` + +6. Clone [swift-crypto](https://github.com/apple/swift-crypto) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags). + + For example, if the latest tag is 1.1.4: + ```sh + $> git clone https://github.com/apple/swift-crypto --branch 1.1.4 + ``` #### Building diff --git a/Package.swift b/Package.swift index 668f5fbf063..7636746be75 100644 --- a/Package.swift +++ b/Package.swift @@ -157,14 +157,29 @@ let package = Package( .target( /** Package model conventions and loading support */ name: "PackageLoading", - dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageModel", "SourceControl"]), + dependencies: [ + "SwiftToolsSupport-auto", + "Basics", + "OrderedCollections", + "PackageModel", + "SourceControl", + ] + ), // MARK: Package Dependency Resolution .target( /** Data structures and support for complete package graphs */ name: "PackageGraph", - dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageLoading", "PackageModel", "SourceControl"]), + dependencies: [ + "SwiftToolsSupport-auto", + "Basics", + "OrderedCollections", + "PackageLoading", + "PackageModel", + "SourceControl", + ] + ), // MARK: Package Collections @@ -199,7 +214,17 @@ let package = Package( .target( /** Builds Modules and Products */ name: "Build", - dependencies: ["SwiftToolsSupport-auto", "Basics", "SPMBuildCore", "PackageGraph", "LLBuildManifest", "SwiftDriver", "SPMLLBuild"]), + dependencies: [ + "SwiftToolsSupport-auto", + "Basics", + "OrderedCollections", + "SPMBuildCore", + "PackageGraph", + "LLBuildManifest", + "SwiftDriver", + "SPMLLBuild", + ] + ), .target( /** Support for building using Xcode's build system */ name: "XCBuildSupport", @@ -360,14 +385,16 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { // used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate // dependency version changes here with those projects. .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")), - .package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)), + .package(url: "https://github.com/apple/swift-collections.git", .exact("0.0.3")), .package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "1.1.4")), + .package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)), ] } else { package.dependencies += [ .package(path: "../swift-tools-support-core"), .package(path: "../swift-argument-parser"), - .package(path: "../swift-driver"), + .package(path: "../swift-collections"), .package(path: "../swift-crypto"), + .package(path: "../swift-driver"), ] } diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index 78072f5b17d..0729ef52f17 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -9,14 +9,15 @@ */ import Basics -import TSCBasic -import TSCUtility +import Foundation +import OrderedCollections import PackageModel import PackageGraph import PackageLoading -import Foundation import SPMBuildCore @_implementationOnly import SwiftDriver +import TSCBasic +import TSCUtility extension String { fileprivate var asSwiftStringLiteralConstant: String { diff --git a/Sources/Build/CMakeLists.txt b/Sources/Build/CMakeLists.txt index cc020d06b68..a37855139ce 100644 --- a/Sources/Build/CMakeLists.txt +++ b/Sources/Build/CMakeLists.txt @@ -16,6 +16,7 @@ add_library(Build target_link_libraries(Build PUBLIC TSCBasic Basics + OrderedCollections PackageGraph LLBuildManifest SPMBuildCore diff --git a/Sources/PackageGraph/CMakeLists.txt b/Sources/PackageGraph/CMakeLists.txt index b966477075c..d7d9fefa668 100644 --- a/Sources/PackageGraph/CMakeLists.txt +++ b/Sources/PackageGraph/CMakeLists.txt @@ -36,6 +36,7 @@ add_library(PackageGraph target_link_libraries(PackageGraph PUBLIC TSCBasic Basics + OrderedCollections PackageLoading PackageModel SourceControl diff --git a/Sources/PackageGraph/PackageGraph+Loading.swift b/Sources/PackageGraph/PackageGraph+Loading.swift index 8698aa9660e..624f4359365 100644 --- a/Sources/PackageGraph/PackageGraph+Loading.swift +++ b/Sources/PackageGraph/PackageGraph+Loading.swift @@ -9,6 +9,7 @@ */ import Basics +import OrderedCollections import PackageLoading import PackageModel import SourceControl @@ -612,7 +613,7 @@ fileprivate func findCycle( _ successors: (GraphLoadingNode) throws -> [GraphLoadingNode] ) rethrows -> (path: [Manifest], cycle: [Manifest])? { // If this node is already in the current path then we have found a cycle. - if !path.append(node.manifest) { + if !path.append(node.manifest).inserted { let index = path.firstIndex(of: node.manifest)! // forced unwrap safe return (Array(path[path.startIndex.. 0, "An incompatibility must contain at least one term after normalization.") self.init(terms: OrderedSet(normalizedTerms), cause: cause) diff --git a/Sources/PackageGraph/Pubgrub/PartialSolution.swift b/Sources/PackageGraph/Pubgrub/PartialSolution.swift index 044a1694dfa..61a5f40fa03 100644 --- a/Sources/PackageGraph/Pubgrub/PartialSolution.swift +++ b/Sources/PackageGraph/Pubgrub/PartialSolution.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2019 Apple Inc. and the Swift project authors + Copyright (c) 2019 - 2021 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 @@ -9,6 +9,7 @@ */ import Basics +import OrderedCollections import TSCBasic import struct TSCUtility.Version diff --git a/Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift b/Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift index 57478dd4e1b..1f06d4c92fa 100644 --- a/Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift +++ b/Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2019 Apple Inc. and the Swift project authors + Copyright (c) 2019 - 2021 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 @@ -10,6 +10,7 @@ import Basics import Dispatch +import OrderedCollections import PackageModel import TSCBasic import TSCUtility diff --git a/Sources/PackageLoading/CMakeLists.txt b/Sources/PackageLoading/CMakeLists.txt index 92a32450cdd..edd9c0280c1 100644 --- a/Sources/PackageLoading/CMakeLists.txt +++ b/Sources/PackageLoading/CMakeLists.txt @@ -22,6 +22,7 @@ add_library(PackageLoading target_link_libraries(PackageLoading PUBLIC TSCBasic Basics + OrderedCollections PackageModel SourceControl TSCUtility) diff --git a/Sources/PackageLoading/PackageBuilder.swift b/Sources/PackageLoading/PackageBuilder.swift index 702c67c60bd..434bba31d08 100644 --- a/Sources/PackageLoading/PackageBuilder.swift +++ b/Sources/PackageLoading/PackageBuilder.swift @@ -10,6 +10,7 @@ import Basics import Dispatch +import OrderedCollections import PackageModel import TSCBasic import TSCUtility @@ -1192,8 +1193,7 @@ public final class PackageBuilder { /// Helper method to append to products array. func append(_ product: Product) { - let inserted = products.append(KeyedPair(product, key: product.name)) - if !inserted { + if !products.append(KeyedPair(product, key: product.name)).inserted { diagnostics.emit( .duplicateProduct(product: product), location: self.diagnosticLocation diff --git a/Tests/PackageGraphTests/PubgrubTests.swift b/Tests/PackageGraphTests/PubgrubTests.swift index e4c83ee87a2..b69e411e292 100644 --- a/Tests/PackageGraphTests/PubgrubTests.swift +++ b/Tests/PackageGraphTests/PubgrubTests.swift @@ -11,6 +11,7 @@ import XCTest import TSCBasic +import OrderedCollections import PackageLoading @testable import PackageModel @testable import PackageGraph diff --git a/Utilities/bootstrap b/Utilities/bootstrap index d1802dbada1..74aaad51d56 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -166,14 +166,16 @@ def add_test_args(parser): def parse_global_args(args): """Parses and cleans arguments necessary for all actions.""" - args.build_dir = os.path.abspath(args.build_dir) - args.project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - args.tsc_source_dir = os.path.join(args.project_root, "..", "swift-tools-support-core") - args.yams_source_dir = os.path.join(args.project_root, "..", "yams") + args.build_dir = os.path.abspath(args.build_dir) + args.project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + args.source_root = os.path.join(args.project_root, "Sources") args.swift_argument_parser_source_dir = os.path.join(args.project_root, "..", "swift-argument-parser") - args.swift_driver_source_dir = os.path.join(args.project_root, "..", "swift-driver") - args.swift_crypto_source_dir = os.path.join(args.project_root, "..", "swift-crypto") - args.source_root = os.path.join(args.project_root, "Sources") + args.swift_collections_source_dir = os.path.join(args.project_root, "..", "swift-collections") + args.swift_crypto_source_dir = os.path.join(args.project_root, "..", "swift-crypto") + args.swift_driver_source_dir = os.path.join(args.project_root, "..", "swift-driver") + args.tsc_source_dir = os.path.join(args.project_root, "..", "swift-tools-support-core") + args.yams_source_dir = os.path.join(args.project_root, "..", "yams") + if platform.system() == 'Darwin': args.sysroot = call_output(["xcrun", "--sdk", "macosx", "--show-sdk-path"], verbose=args.verbose) @@ -305,11 +307,12 @@ def build(args): build_llbuild(args) if args.bootstrap: - build_tsc(args) - build_yams(args) build_swift_argument_parser(args) - build_swift_driver(args) + build_swift_collections(args) build_swift_crypto(args) + build_swift_driver(args) + build_tsc(args) + build_yams(args) build_swiftpm_with_cmake(args) build_swiftpm_with_swiftpm(args,integrated_swift_driver=False) @@ -531,17 +534,6 @@ def build_llbuild(args): llbuild_source_dir = get_llbuild_source_path(args) build_with_cmake(args, flags, llbuild_source_dir, args.llbuild_build_dir) -def build_tsc(args): - note("Building TSC") - args.tsc_build_dir = os.path.join(args.target_dir, "tsc") - - cmake_flags = [] - if platform.system() == 'Darwin': - cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target)) - cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) - - build_with_cmake(args, cmake_flags, args.tsc_source_dir, args.tsc_build_dir) - def build_swift_argument_parser(args): note("Building swift-argument-parser") args.swift_argument_parser_build_dir = os.path.join(args.target_dir, "swift-argument-parser") @@ -555,19 +547,27 @@ def build_swift_argument_parser(args): cmake_flags.append("-DBUILD_EXAMPLES=NO") build_with_cmake(args, cmake_flags, args.swift_argument_parser_source_dir, args.swift_argument_parser_build_dir) -def build_yams(args): - note("Building Yams") - args.yams_build_dir = os.path.join(args.target_dir, "yams") +def build_swift_collections(args): + note("Building swift-collections") + args.swift_collections_build_dir = os.path.join(args.target_dir, "swift-collections") cmake_flags = [] if platform.system() == 'Darwin': cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target)) cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) - else: - if args.foundation_build_dir: - cmake_flags.append(get_foundation_cmake_arg(args)) + + build_with_cmake(args, cmake_flags, args.swift_collections_source_dir, args.swift_collections_build_dir) - build_with_cmake(args, cmake_flags, args.yams_source_dir, args.yams_build_dir) +def build_swift_crypto(args): + note("Building SwiftCrypto") + args.swift_crypto_build_dir = os.path.join(args.target_dir, "swift-crypto") + + cmake_flags = [] + if platform.system() == 'Darwin': + cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target)) + cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) + + build_with_cmake(args, cmake_flags, args.swift_crypto_source_dir, args.swift_crypto_build_dir) def build_swift_driver(args): note("Building SwiftDriver") @@ -584,17 +584,31 @@ def build_swift_driver(args): cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) build_with_cmake(args, cmake_flags, args.swift_driver_source_dir, args.swift_driver_build_dir) - -def build_swift_crypto(args): - note("Building SwiftCrypto") - args.swift_crypto_build_dir = os.path.join(args.target_dir, "swift-crypto") + +def build_tsc(args): + note("Building TSC") + args.tsc_build_dir = os.path.join(args.target_dir, "tsc") cmake_flags = [] if platform.system() == 'Darwin': cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target)) cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) - build_with_cmake(args, cmake_flags, args.swift_crypto_source_dir, args.swift_crypto_build_dir) + build_with_cmake(args, cmake_flags, args.tsc_source_dir, args.tsc_build_dir) + +def build_yams(args): + note("Building Yams") + args.yams_build_dir = os.path.join(args.target_dir, "yams") + + cmake_flags = [] + if platform.system() == 'Darwin': + cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target)) + cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) + else: + if args.foundation_build_dir: + cmake_flags.append(get_foundation_cmake_arg(args)) + + build_with_cmake(args, cmake_flags, args.yams_source_dir, args.yams_build_dir) def add_rpath_for_cmake_build(args, rpath): "Adds the given rpath to the CMake-built swift-build" @@ -610,11 +624,12 @@ def build_swiftpm_with_cmake(args): if args.bootstrap: cmake_flags = [ get_llbuild_cmake_arg(args), - "-DTSC_DIR=" + os.path.join(args.tsc_build_dir, "cmake/modules"), - "-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"), - "-DArgumentParser_DIR=" + os.path.join(args.swift_argument_parser_build_dir, "cmake/modules"), - "-DSwiftDriver_DIR=" + os.path.join(args.swift_driver_build_dir, "cmake/modules"), - "-DSwiftCrypto_DIR=" + os.path.join(args.swift_crypto_build_dir, "cmake/modules"), + "-DArgumentParser_DIR=" + os.path.join(args.swift_argument_parser_build_dir, "cmake/modules"), + "-DSwiftCollections_DIR=" + os.path.join(args.swift_collections_build_dir, "cmake/modules"), + "-DSwiftCrypto_DIR=" + os.path.join(args.swift_crypto_build_dir, "cmake/modules"), + "-DSwiftDriver_DIR=" + os.path.join(args.swift_driver_build_dir, "cmake/modules"), + "-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"), + "-DTSC_DIR=" + os.path.join(args.tsc_build_dir, "cmake/modules"), "-DFIND_PM_DEPS:BOOL=YES", ] else: @@ -632,10 +647,11 @@ def build_swiftpm_with_cmake(args): add_rpath_for_cmake_build(args, args.llbuild_build_dir) if platform.system() == "Darwin": - add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "lib")) add_rpath_for_cmake_build(args, os.path.join(args.swift_argument_parser_build_dir, "lib")) - add_rpath_for_cmake_build(args, os.path.join(args.swift_driver_build_dir, "lib")) - add_rpath_for_cmake_build(args, os.path.join(args.swift_crypto_build_dir, "lib")) + add_rpath_for_cmake_build(args, os.path.join(args.swift_collections_build_dir, "lib")) + add_rpath_for_cmake_build(args, os.path.join(args.swift_crypto_build_dir, "lib")) + add_rpath_for_cmake_build(args, os.path.join(args.swift_driver_build_dir, "lib")) + add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "lib")) def build_swiftpm_with_swiftpm(args, integrated_swift_driver): """Builds SwiftPM using the version of SwiftPM built with CMake.""" @@ -728,12 +744,13 @@ def get_swiftpm_env_cmd(args): if args.bootstrap: libs_joined = ":".join([ os.path.join(args.bootstrap_dir, "lib"), - os.path.join(args.tsc_build_dir, "lib"), os.path.join(args.llbuild_build_dir, "lib"), - os.path.join(args.yams_build_dir, "lib"), os.path.join(args.swift_argument_parser_build_dir, "lib"), - os.path.join(args.swift_driver_build_dir, "lib"), + os.path.join(args.swift_collections_build_dir, "lib"), os.path.join(args.swift_crypto_build_dir, "lib"), + os.path.join(args.swift_driver_build_dir, "lib"), + os.path.join(args.tsc_build_dir, "lib"), + os.path.join(args.yams_build_dir, "lib"), ] + args.target_info["paths"]["runtimeLibraryPaths"]) if platform.system() == 'Darwin':