|
| 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 SWBBuildSystem |
| 14 | +import SWBCore |
| 15 | +import SWBTaskExecution |
| 16 | +import SWBTestSupport |
| 17 | +import SWBUtil |
| 18 | +import Testing |
| 19 | + |
| 20 | +@Suite |
| 21 | +fileprivate struct CodeSigningBuildOperationTests: CoreBasedTests { |
| 22 | + @Test(.requireSDKs(.macOS)) |
| 23 | + func entitlementsModificationInvalidatesBuildDescription() async throws { |
| 24 | + try await withTemporaryDirectory { tmpDirPath in |
| 25 | + let testProject = TestProject( |
| 26 | + "aProject", |
| 27 | + sourceRoot: tmpDirPath, |
| 28 | + groupTree: TestGroup( |
| 29 | + "SomeFiles", path: "Sources", |
| 30 | + children: [ |
| 31 | + TestFile("AppSource.m"), |
| 32 | + ]), |
| 33 | + buildConfigurations: [ |
| 34 | + TestBuildConfiguration( "Debug", buildSettings: [ |
| 35 | + "COPY_PHASE_STRIP": "NO", |
| 36 | + "DEBUG_INFORMATION_FORMAT": "dwarf", |
| 37 | + "GENERATE_INFOPLIST_FILE": "YES", |
| 38 | + "PRODUCT_NAME": "$(TARGET_NAME)", |
| 39 | + "CODE_SIGN_IDENTITY": "-", |
| 40 | + "CODE_SIGN_ENTITLEMENTS": "Entitlements.entitlements", |
| 41 | + "SDKROOT": "macosx", |
| 42 | + "SUPPORTED_PLATFORMS": "macosx", |
| 43 | + ]), |
| 44 | + ], |
| 45 | + targets: [ |
| 46 | + TestStandardTarget( |
| 47 | + "AppTarget", |
| 48 | + type: .application, |
| 49 | + buildPhases: [ |
| 50 | + TestSourcesBuildPhase([ |
| 51 | + "AppSource.m", |
| 52 | + ]), |
| 53 | + ], |
| 54 | + ), |
| 55 | + ] |
| 56 | + ) |
| 57 | + |
| 58 | + let tester = try await BuildOperationTester(getCore(), testProject, simulated: false) |
| 59 | + let SRCROOT = tester.workspace.projects[0].sourceRoot.str |
| 60 | + |
| 61 | + try tester.fs.createDirectory(Path(SRCROOT).join("Sources"), recursive: true) |
| 62 | + try tester.fs.write(Path(SRCROOT).join("Sources/AppSource.m"), contents: "int main() { return 0; }") |
| 63 | + try await tester.fs.writePlist(Path(SRCROOT).join("Entitlements.entitlements"), .plDict([:])) |
| 64 | + |
| 65 | + try await tester.checkBuild(parameters: BuildParameters(configuration: "Debug"), runDestination: .macOS, persistent: true, signableTargets: ["AppTarget"]) { results in |
| 66 | + results.checkNoDiagnostics() |
| 67 | + } |
| 68 | + |
| 69 | + // Modify the entitlements in between builds, but make no other changes which would invalidate the build description. |
| 70 | + try tester.fs.touch(Path(SRCROOT).join("Entitlements.entitlements")) |
| 71 | + |
| 72 | + // A subsequent build should succeed, and should NOT diagnose entitlements modification during the build. |
| 73 | + try await tester.checkBuild(parameters: BuildParameters(configuration: "Debug"), runDestination: .macOS, persistent: true, signableTargets: ["AppTarget"]) { results in |
| 74 | + results.checkNoDiagnostics() |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
0 commit comments