Skip to content

Commit 6045cd0

Browse files
Dependencies: propagate actual xcconfig final line/column number to fixits instead of using .max (rdar://159783939)
1 parent c859a24 commit 6045cd0

File tree

4 files changed

+39
-42
lines changed

4 files changed

+39
-42
lines changed

Sources/SWBCore/CapturedBuildInfo.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ public struct CapturedBuildInfo: PropertyListItemConvertible, Sendable {
9797
let settings = settingsPerTarget[configuredTarget]
9898
let targetConstructionComponents = settings?.constructionComponents
9999
let projectXcconfigSettings: CapturedBuildSettingsTableInfo = {
100-
let settings = targetConstructionComponents?.projectXcconfigSettings?.capturedRepresentation ?? [:]
101-
return CapturedBuildSettingsTableInfo(name: CapturedBuildSettingsTableInfo.Name.projectXcconfig, path: targetConstructionComponents?.projectXcconfigPath, settings: settings)
100+
let settings = targetConstructionComponents?.projectXcconfig?.settings.capturedRepresentation ?? [:]
101+
return CapturedBuildSettingsTableInfo(name: CapturedBuildSettingsTableInfo.Name.projectXcconfig, path: targetConstructionComponents?.projectXcconfig?.path, settings: settings)
102102
}()
103103
let projectSettings: CapturedBuildSettingsTableInfo = {
104104
let settings = targetConstructionComponents?.projectSettings?.capturedRepresentation ?? [:]
105105
return CapturedBuildSettingsTableInfo(name: CapturedBuildSettingsTableInfo.Name.project, path: nil, settings: settings)
106106
}()
107107
let targetXcconfigSettings: CapturedBuildSettingsTableInfo = {
108-
let settings = targetConstructionComponents?.targetXcconfigSettings?.capturedRepresentation ?? [:]
109-
return CapturedBuildSettingsTableInfo(name: CapturedBuildSettingsTableInfo.Name.targetXcconfig, path: targetConstructionComponents?.targetXcconfigPath, settings: settings)
108+
let settings = targetConstructionComponents?.targetXcconfig?.settings.capturedRepresentation ?? [:]
109+
return CapturedBuildSettingsTableInfo(name: CapturedBuildSettingsTableInfo.Name.targetXcconfig, path: targetConstructionComponents?.targetXcconfig?.path, settings: settings)
110110
}()
111111
let targetSettings: CapturedBuildSettingsTableInfo = {
112112
let settings = targetConstructionComponents?.targetSettings?.capturedRepresentation ?? [:]

Sources/SWBCore/Dependencies.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ public struct ModuleDependenciesContext: Sendable, SerializableCodable {
196196
{
197197
self.init(sourceRange: .init(path: location.path, startLine: location.endLine, startColumn: location.endColumn, endLine: location.endLine, endColumn: location.endColumn), modificationStyle: .appendToExistingAssignment)
198198
}
199-
else if let path = settings.constructionComponents.targetXcconfigPath {
200-
self.init(sourceRange: .init(path: path, startLine: .max, startColumn: .max, endLine: .max, endColumn: .max), modificationStyle: .insertNewAssignment(targetNameCondition: nil))
199+
else if let xcconfig = settings.constructionComponents.targetXcconfig {
200+
self.init(sourceRange: .init(path: xcconfig.path, startLine: xcconfig.finalLineNumber, startColumn: xcconfig.finalColumnNumber, endLine: xcconfig.finalLineNumber, endColumn: xcconfig.finalColumnNumber), modificationStyle: .insertNewAssignment(targetNameCondition: nil))
201201
}
202-
else if let path = settings.constructionComponents.projectXcconfigPath {
203-
self.init(sourceRange: .init(path: path, startLine: .max, startColumn: .max, endLine: .max, endColumn: .max), modificationStyle: .insertNewAssignment(targetNameCondition: target.name))
202+
else if let xcconfig = settings.constructionComponents.projectXcconfig {
203+
self.init(sourceRange: .init(path: xcconfig.path, startLine: xcconfig.finalLineNumber, startColumn: xcconfig.finalColumnNumber, endLine: xcconfig.finalLineNumber, endColumn: xcconfig.finalColumnNumber), modificationStyle: .insertNewAssignment(targetNameCondition: target.name))
204204
}
205205
else {
206206
return nil
@@ -357,11 +357,11 @@ public struct HeaderDependenciesContext: Sendable, SerializableCodable {
357357
{
358358
self.init(sourceRange: .init(path: location.path, startLine: location.endLine, startColumn: location.endColumn, endLine: location.endLine, endColumn: location.endColumn), modificationStyle: .appendToExistingAssignment)
359359
}
360-
else if let path = settings.constructionComponents.targetXcconfigPath {
361-
self.init(sourceRange: .init(path: path, startLine: .max, startColumn: .max, endLine: .max, endColumn: .max), modificationStyle: .insertNewAssignment(targetNameCondition: nil))
360+
else if let xcconfig = settings.constructionComponents.targetXcconfig {
361+
self.init(sourceRange: .init(path: xcconfig.path, startLine: xcconfig.finalLineNumber, startColumn: xcconfig.finalColumnNumber, endLine: xcconfig.finalLineNumber, endColumn: xcconfig.finalColumnNumber), modificationStyle: .insertNewAssignment(targetNameCondition: nil))
362362
}
363-
else if let path = settings.constructionComponents.projectXcconfigPath {
364-
self.init(sourceRange: .init(path: path, startLine: .max, startColumn: .max, endLine: .max, endColumn: .max), modificationStyle: .insertNewAssignment(targetNameCondition: target.name))
363+
else if let xcconfig = settings.constructionComponents.projectXcconfig {
364+
self.init(sourceRange: .init(path: xcconfig.path, startLine: xcconfig.finalLineNumber, startColumn: xcconfig.finalColumnNumber, endLine: xcconfig.finalLineNumber, endColumn: xcconfig.finalColumnNumber), modificationStyle: .insertNewAssignment(targetNameCondition: target.name))
365365
}
366366
else {
367367
return nil

Sources/SWBCore/Settings/Settings.swift

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -786,19 +786,16 @@ public final class Settings: PlatformBuildContext, Sendable {
786786
///
787787
/// - remark: The overhead of this object should be very small, because the majority of the actual data are the linked lists of macro definitions, which are shared with the main table in the `Settings` object.
788788
public struct ConstructionComponents: Sendable {
789-
// These properties are the individual tables (and info about them) of specific levels which contributed to the Settings.
789+
struct XcconfigInfo: Sendable {
790+
var path: Path
791+
var settings: MacroValueAssignmentTable
792+
var finalLineNumber: Int
793+
var finalColumnNumber: Int
794+
}
790795

791-
/// The path to the project-level xcconfig file.
792-
let projectXcconfigPath: Path?
793-
/// The project-level xcconfig settings table.
794-
let projectXcconfigSettings: MacroValueAssignmentTable?
795-
/// The project-level settings table.
796+
let projectXcconfig: XcconfigInfo?
796797
let projectSettings: MacroValueAssignmentTable?
797-
/// The path to the target-level xcconfig file.
798-
let targetXcconfigPath: Path?
799-
/// The target-level xcconfig settings table.
800-
let targetXcconfigSettings: MacroValueAssignmentTable?
801-
/// The target-level settings table.
798+
let targetXcconfig: XcconfigInfo?
802799
let targetSettings: MacroValueAssignmentTable?
803800

804801
// These properties are the actual tables of settings up to a certain point, which are used to compute the resolved values of settings at that level in the build settings editor (e.g., in the Levels view).
@@ -966,9 +963,9 @@ public final class Settings: PlatformBuildContext, Sendable {
966963
return BuildSettingsEditorInfoPayload(
967964
// Assigned values
968965
targetSettingAssignments: assignedValues(for: constructionComponents.targetSettings),
969-
targetXcconfigSettingAssignments: assignedValues(for: constructionComponents.targetXcconfigSettings),
966+
targetXcconfigSettingAssignments: assignedValues(for: constructionComponents.targetXcconfig?.settings),
970967
projectSettingAssignments: assignedValues(for: constructionComponents.projectSettings),
971-
projectXcconfigSettingAssignments: assignedValues(for: constructionComponents.projectXcconfigSettings),
968+
projectXcconfigSettingAssignments: assignedValues(for: constructionComponents.projectXcconfig?.settings),
972969

973970
// Resolved values
974971
targetResolvedSettingsValues: resolvedValues(for: constructionComponents.upToTargetSettings),
@@ -1322,18 +1319,16 @@ private class SettingsBuilder {
13221319
return core.coreSettings
13231320
}
13241321

1325-
private var projectXcconfigPath: Path? = nil
1326-
private var projectXcconfigSettings: MacroValueAssignmentTable? = nil
1322+
private var projectXcconfig: Settings.ConstructionComponents.XcconfigInfo? = nil
13271323
private var projectSettings: MacroValueAssignmentTable? = nil
1328-
private var targetXcconfigPath: Path? = nil
1329-
private var targetXcconfigSettings: MacroValueAssignmentTable? = nil
1324+
private var targetXcconfig: Settings.ConstructionComponents.XcconfigInfo? = nil
13301325
private var targetSettings: MacroValueAssignmentTable? = nil
13311326
/// Convenient array for iterating over all defined settings tables in the project for this target, from lowest to highest.
13321327
private var allProjectSettingsLevels: [(table: MacroValueAssignmentTable?, path: Path?, level: String)] {
13331328
return [
1334-
(projectXcconfigSettings, projectXcconfigPath, "project-xcconfig"),
1329+
(projectXcconfig?.settings, projectXcconfig?.path, "project-xcconfig"),
13351330
(projectSettings, nil, "project"),
1336-
(targetXcconfigSettings, targetXcconfigPath, "target-xcconfig"),
1331+
(targetXcconfig?.settings, targetXcconfig?.path, "target-xcconfig"),
13371332
(targetSettings, nil, "target"),
13381333
]
13391334
}
@@ -1347,11 +1342,9 @@ private class SettingsBuilder {
13471342
/// The project model components which were used to construct the settings made by this builder.
13481343
var constructionComponents: Settings.ConstructionComponents {
13491344
return Settings.ConstructionComponents(
1350-
projectXcconfigPath: self.projectXcconfigPath,
1351-
projectXcconfigSettings: self.projectXcconfigSettings,
1345+
projectXcconfig: self.projectXcconfig,
13521346
projectSettings: self.projectSettings,
1353-
targetXcconfigPath: self.targetXcconfigPath,
1354-
targetXcconfigSettings: self.targetXcconfigSettings,
1347+
targetXcconfig: self.targetXcconfig,
13551348
targetSettings: self.targetSettings,
13561349
upToDefaultsSettings: self.upToDefaultsSettings,
13571350
upToProjectXcconfigSettings: upToProjectXcconfigSettings,
@@ -2807,8 +2800,7 @@ private class SettingsBuilder {
28072800
}
28082801

28092802
// Save the settings table as part of the construction components.
2810-
self.projectXcconfigPath = path
2811-
self.projectXcconfigSettings = info.table
2803+
self.projectXcconfig = .init(path: path, settings: info.table, finalLineNumber: info.finalLineNumber, finalColumnNumber: info.finalColumnNumber)
28122804

28132805
// Also save the table we've constructed so far.
28142806
self.upToProjectXcconfigSettings = MacroValueAssignmentTable(copying: _table)
@@ -3015,8 +3007,7 @@ private class SettingsBuilder {
30153007
}
30163008

30173009
// Save the settings table as part of the construction components.
3018-
self.targetXcconfigPath = path
3019-
self.targetXcconfigSettings = info.table
3010+
self.targetXcconfig = .init(path: path, settings: info.table, finalLineNumber: info.finalLineNumber, finalColumnNumber: info.finalColumnNumber)
30203011

30213012
// Save the table we've constructed so far.
30223013
self.upToTargetXcconfigSettings = MacroValueAssignmentTable(copying: _table)

Tests/SWBBuildSystemTests/DependencyValidationTests.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Foundation
1314
import SWBCore
1415
import SWBTestSupport
1516
import SWBUtil
@@ -412,6 +413,11 @@ fileprivate struct DependencyValidationTests: CoreBasedTests {
412413
"""
413414
}
414415

416+
let projectXCConfigContents = try #require(tester.fs.read(projectXCConfigPath).stringValue)
417+
let projectXCConfigLines = projectXCConfigContents.components(separatedBy: .newlines)
418+
let projectXCConfigFinalLineNumber = projectXCConfigLines.count
419+
let projectXCConfigFinalColumnNumber = (projectXCConfigLines.last?.count ?? 0) + 1
420+
415421
let expectedDiagsByTarget: [String: [Diagnostic]] = [
416422
"TargetA": [
417423
Diagnostic(
@@ -437,11 +443,11 @@ fileprivate struct DependencyValidationTests: CoreBasedTests {
437443
"TargetB": [
438444
Diagnostic(
439445
behavior: .error,
440-
location: Diagnostic.Location.path(projectXCConfigPath, line: .max, column: .max),
446+
location: Diagnostic.Location.path(projectXCConfigPath, line: projectXCConfigFinalLineNumber, column: projectXCConfigFinalColumnNumber),
441447
data: DiagnosticData("Missing entries in MODULE_DEPENDENCIES: Foundation"),
442448
fixIts: [
443449
Diagnostic.FixIt(
444-
sourceRange: Diagnostic.SourceRange(path: projectXCConfigPath, startLine: .max, startColumn: .max, endLine: .max, endColumn: .max),
450+
sourceRange: Diagnostic.SourceRange(path: projectXCConfigPath, startLine: projectXCConfigFinalLineNumber, startColumn: projectXCConfigFinalColumnNumber, endLine: projectXCConfigFinalLineNumber, endColumn: projectXCConfigFinalColumnNumber),
445451
newText: "\nMODULE_DEPENDENCIES[target=TargetB] = $(inherited) \\\n Foundation\n"),
446452
],
447453
childDiagnostics: [
@@ -450,7 +456,7 @@ fileprivate struct DependencyValidationTests: CoreBasedTests {
450456
location: Diagnostic.Location.path(swiftSourcePath, line: 1, column: 8),
451457
data: DiagnosticData("Missing entry in MODULE_DEPENDENCIES: Foundation"),
452458
fixIts: [Diagnostic.FixIt(
453-
sourceRange: Diagnostic.SourceRange(path: projectXCConfigPath, startLine: .max, startColumn: .max, endLine: .max, endColumn: .max),
459+
sourceRange: Diagnostic.SourceRange(path: projectXCConfigPath, startLine: projectXCConfigFinalLineNumber, startColumn: projectXCConfigFinalColumnNumber, endLine: projectXCConfigFinalLineNumber, endColumn: projectXCConfigFinalColumnNumber),
454460
newText: "\nMODULE_DEPENDENCIES[target=TargetB] = $(inherited) \\\n Foundation\n")],
455461
),
456462
]),

0 commit comments

Comments
 (0)