Skip to content

Don’t reload package manifest when a header is added #7691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/MockWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
46 changes: 46 additions & 0 deletions Tests/WorkspaceTests/WorkspaceReloadTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}