diff --git a/Sources/SPMTestSupport/MockWorkspace.swift b/Sources/SPMTestSupport/MockWorkspace.swift index 4e53ec634e9..8a5049c2586 100644 --- a/Sources/SPMTestSupport/MockWorkspace.swift +++ b/Sources/SPMTestSupport/MockWorkspace.swift @@ -479,7 +479,7 @@ public final class MockWorkspace { public func checkPackageGraph( roots: [String] = [], deps: [MockDependency], - _ result: (ModulesGraph, [Basics.Diagnostic]) -> Void + _ result: (ModulesGraph, [Basics.Diagnostic]) throws -> Void ) throws { let dependencies = try deps.map { try $0.convert(baseURL: packagesDir, identityResolver: self.identityResolver) } try self.checkPackageGraph(roots: roots, dependencies: dependencies, result) diff --git a/Sources/Workspace/Workspace.swift b/Sources/Workspace/Workspace.swift index b3a39688140..9783717303c 100644 --- a/Sources/Workspace/Workspace.swift +++ b/Sources/Workspace/Workspace.swift @@ -1204,7 +1204,7 @@ extension Workspace { /// generated by SwiftPM. public func fileAffectsSwiftOrClangBuildSettings(filePath: AbsolutePath, packageGraph: ModulesGraph) -> Bool { // TODO: Implement a more sophisticated check that also verifies if the file is in the sources directories of the passed in `packageGraph`. - FileRuleDescription.builtinRules.contains { fileRuleDescription in + !FileRuleDescription.header.match(path: filePath, toolsVersion: self.currentToolsVersion) && FileRuleDescription.builtinRules.contains { fileRuleDescription in fileRuleDescription.match(path: filePath, toolsVersion: self.currentToolsVersion) } } diff --git a/Tests/WorkspaceTests/WorkspaceReloadTests.swift b/Tests/WorkspaceTests/WorkspaceReloadTests.swift new file mode 100644 index 00000000000..2a6baa99a06 --- /dev/null +++ b/Tests/WorkspaceTests/WorkspaceReloadTests.swift @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift open source project +// +// Copyright (c) 2014-2024 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 +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import Basics +import SPMTestSupport +import Workspace +import XCTest + +final class WorkspaceReloadTests: XCTestCase { + func testHeaderReloading() throws { + let sandbox = AbsolutePath("/tmp/ws/") + let fs = InMemoryFileSystem() + + let workspace = try MockWorkspace( + sandbox: sandbox, + fileSystem: fs, + roots: [ + MockPackage( + name: "Foo", + targets: [ + MockTarget(name: "Foo", dependencies: []), + ] + ), + ] + ) + + try workspace.checkPackageGraph(roots: ["Foo"], deps: []) { graph, diagnostics in + try XCTAssertFalse( + workspace.getOrCreateWorkspace().fileAffectsSwiftOrClangBuildSettings( + filePath: "/tmp/ws/.build/header.h", + packageGraph: graph + ) + ) + XCTAssertNoDiagnostics(diagnostics) + } + } +}