Skip to content

Commit 1da2500

Browse files
committed
Move the instantiation of PackageBuilder into the diagnostics.with(location:) closure that sets the package location.
Without this, errors thrown for a package would be associated with a location, but regularly emitted diagnostics would not. The reason is that when the PackageBuilder is instantiated outside of the `diagnostics.with(location:)`, it keeps the unlocationed diagnostics engine as a property, and then uses that for all the diagnostics even though the `construct()` call happens inside of a with-location closure. This change allows all the diagnostics emitted by the PackageBuilder to be properly associated with the package.
1 parent a6daacf commit 1da2500

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Sources/PackageGraph/PackageGraphLoader.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -189,23 +189,22 @@ public struct PackageGraphLoader {
189189
// FIXME: Lift this out of the manifest.
190190
let packagePath = manifest.path.parentDirectory
191191

192-
// Create a package from the manifest and sources.
193-
let builder = PackageBuilder(
194-
manifest: manifest,
195-
productFilter: node.productFilter,
196-
path: packagePath,
197-
additionalFileRules: additionalFileRules,
198-
remoteArtifacts: remoteArtifacts,
199-
xcTestMinimumDeploymentTargets: xcTestMinimumDeploymentTargets,
200-
fileSystem: fileSystem,
201-
diagnostics: diagnostics,
202-
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
203-
createREPLProduct: manifest.packageKind == .root ? createREPLProduct : false
204-
)
205-
206192
let packageLocation = PackageLocation.Local(name: manifest.name, packagePath: packagePath)
207193
diagnostics.with(location: packageLocation) { diagnostics in
208194
diagnostics.wrap {
195+
// Create a package from the manifest and sources.
196+
let builder = PackageBuilder(
197+
manifest: manifest,
198+
productFilter: node.productFilter,
199+
path: packagePath,
200+
additionalFileRules: additionalFileRules,
201+
remoteArtifacts: remoteArtifacts,
202+
xcTestMinimumDeploymentTargets: xcTestMinimumDeploymentTargets,
203+
fileSystem: fileSystem,
204+
diagnostics: diagnostics,
205+
shouldCreateMultipleTestProducts: shouldCreateMultipleTestProducts,
206+
createREPLProduct: manifest.packageKind == .root ? createREPLProduct : false
207+
)
209208
let package = try builder.construct()
210209
manifestToPackage[manifest] = package
211210

Tests/PackageGraphTests/PackageGraphTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ class PackageGraphTests: XCTestCase {
529529
)
530530

531531
DiagnosticsEngineTester(diagnostics) { result in
532-
result.check(diagnostic: "Source files for target Bar should be located under /Bar/Sources/Bar", behavior: .warning)
532+
result.check(diagnostic: "Source files for target Bar should be located under /Bar/Sources/Bar", behavior: .warning, location: "'Bar' /Bar")
533533
result.check(diagnostic: "target 'Bar' referenced in product 'Bar' is empty", behavior: .error, location: "'Bar' /Bar")
534534
}
535535
}

0 commit comments

Comments
 (0)