|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See http://swift.org/LICENSE.txt for license information |
| 9 | +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +@testable |
| 14 | +import Build |
| 15 | + |
| 16 | +import class Basics.ObservabilitySystem |
| 17 | +import class TSCBasic.InMemoryFileSystem |
| 18 | + |
| 19 | +import class PackageModel.Manifest |
| 20 | +import struct PackageModel.TargetDescription |
| 21 | + |
| 22 | +@testable |
| 23 | +import struct PackageGraph.ResolvedProduct |
| 24 | + |
| 25 | +import func SPMTestSupport.loadPackageGraph |
| 26 | +import func SPMTestSupport.mockBuildParameters |
| 27 | +import func SPMTestSupport.XCTAssertNoDiagnostics |
| 28 | +import XCTest |
| 29 | + |
| 30 | +final class ProductBuildDescriptionTests: XCTestCase { |
| 31 | + func testEmbeddedProducts() throws { |
| 32 | + let fs = InMemoryFileSystem( |
| 33 | + emptyFiles: |
| 34 | + "/Pkg/Sources/exe/main.swift" |
| 35 | + ) |
| 36 | + |
| 37 | + let observability = ObservabilitySystem.makeForTesting() |
| 38 | + let graph = try loadPackageGraph( |
| 39 | + fileSystem: fs, |
| 40 | + manifests: [ |
| 41 | + Manifest.createRootManifest( |
| 42 | + displayName: "Pkg", |
| 43 | + path: "/Pkg", |
| 44 | + targets: [ |
| 45 | + TargetDescription( |
| 46 | + name: "exe", |
| 47 | + settings: [.init(tool: .swift, kind: .enableExperimentalFeature("Embedded"))] |
| 48 | + ), |
| 49 | + ] |
| 50 | + ), |
| 51 | + ], |
| 52 | + observabilityScope: observability.topScope |
| 53 | + ) |
| 54 | + XCTAssertNoDiagnostics(observability.diagnostics) |
| 55 | + |
| 56 | + let id = ResolvedProduct.ID(targetName: "exe", packageIdentity: .plain("pkg"), buildTriple: .destination) |
| 57 | + let package = try XCTUnwrap(graph.rootPackages.first) |
| 58 | + let product = try XCTUnwrap(graph.allProducts[id]) |
| 59 | + |
| 60 | + let buildDescription = try ProductBuildDescription( |
| 61 | + package: package, |
| 62 | + product: product, |
| 63 | + toolsVersion: .v5_9, |
| 64 | + buildParameters: mockBuildParameters(environment: .init(platform: .macOS)), |
| 65 | + fileSystem: fs, |
| 66 | + observabilityScope: observability.topScope |
| 67 | + ) |
| 68 | + |
| 69 | + XCTAssertTrue( |
| 70 | + try buildDescription.linkArguments() |
| 71 | + .joined(separator: " ") |
| 72 | + .contains("-enable-experimental-feature Embedded") |
| 73 | + ) |
| 74 | + } |
| 75 | +} |
0 commit comments