|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 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 | +import Testing |
| 14 | + |
| 15 | +import SWBCore |
| 16 | +import SWBTaskConstruction |
| 17 | +import SWBTestSupport |
| 18 | +import SWBUtil |
| 19 | + |
| 20 | +@Suite |
| 21 | +fileprivate struct DependencyVerificationTaskConstructionTests: CoreBasedTests { |
| 22 | + |
| 23 | + let project = "TestProject" |
| 24 | + let target = "TestTarget" |
| 25 | + let sourceBaseName = "TestSource" |
| 26 | + let source = "TestSource.m" |
| 27 | + |
| 28 | + func outputFile(_ srcroot: Path, _ filename: String) -> String { |
| 29 | + return "\(srcroot.str)/build/\(project).build/Debug/\(target).build/Objects-normal/x86_64/\(filename)" |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + func addsTraceArgsWhenDependenciesDeclared() async throws { |
| 34 | + try await testWith(dependencies: ["Foo"]) { tester, srcroot in |
| 35 | + await tester.checkBuild(runDestination: .macOS) { results in |
| 36 | + results.checkTask(.matchRuleType("Ld")) { task in |
| 37 | + task.checkCommandLineContains([ |
| 38 | + "-Xlinker", "-trace_file", |
| 39 | + "-Xlinker", outputFile(srcroot, "\(target)_trace.json"), |
| 40 | + ]) |
| 41 | + } |
| 42 | + results.checkTask(.compileC(target, fileName: source)) { task in |
| 43 | + task.checkCommandLineContains([ |
| 44 | + "-Xclang", "-header-include-file", |
| 45 | + "-Xclang", outputFile(srcroot, "\(sourceBaseName).o.trace.json"), |
| 46 | + "-Xclang", "-header-include-filtering=only-direct-system", |
| 47 | + "-Xclang", "-header-include-format=json" |
| 48 | + ]) |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + func noTraceArgsWhenDependenciesDeclared() async throws { |
| 56 | + try await testWith(dependencies: []) { tester, srcroot in |
| 57 | + await tester.checkBuild(runDestination: .macOS) { results in |
| 58 | + results.checkTask(.matchRuleType("Ld")) { task in |
| 59 | + task.checkCommandLineDoesNotContain("-trace_file") |
| 60 | + } |
| 61 | + results.checkTask(.compileC(target, fileName: source)) { task in |
| 62 | + task.checkCommandLineDoesNotContain("-header-include-file") |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private func testWith(dependencies: [String], _ assertions: (_ tester: TaskConstructionTester, _ srcroot: Path) async throws -> Void) async throws { |
| 69 | + let testProject = TestProject( |
| 70 | + project, |
| 71 | + groupTree: TestGroup( |
| 72 | + "TestGroup", |
| 73 | + children: [ |
| 74 | + TestFile(source) |
| 75 | + ]), |
| 76 | + buildConfigurations: [ |
| 77 | + TestBuildConfiguration( |
| 78 | + "Debug", |
| 79 | + buildSettings: [ |
| 80 | + "DEPENDENCIES": dependencies.joined(separator: " "), |
| 81 | + "PRODUCT_NAME": "$(TARGET_NAME)", |
| 82 | + "GENERATE_INFOPLIST_FILE": "YES", |
| 83 | + "CLANG_ENABLE_MODULES": "YES" |
| 84 | + ]) |
| 85 | + ], |
| 86 | + targets: [ |
| 87 | + TestStandardTarget( |
| 88 | + target, |
| 89 | + type: .framework, |
| 90 | + buildPhases: [ |
| 91 | + TestSourcesBuildPhase([TestBuildFile(source)]) |
| 92 | + ] |
| 93 | + ) |
| 94 | + ]) |
| 95 | + |
| 96 | + let core = try await getCore() |
| 97 | + let tester = try TaskConstructionTester(core, testProject) |
| 98 | + let SRCROOT = tester.workspace.projects[0].sourceRoot |
| 99 | + |
| 100 | + try await assertions(tester, SRCROOT) |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments