Skip to content

Commit

Permalink
Update XCConfig again for include fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jan 19, 2024
1 parent d255ebe commit f4b81dd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattmassicotte/XCConfig",
"state" : {
"revision" : "38fe6d21eaf34c36c3835cb4c5b81b4654de1abc"
"revision" : "6375b3d7ac16e5c4103c3cbe7b633411bee47d37"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/tuist/XcodeProj", from: "8.15.0"),
.package(url: "https://github.com/mattmassicotte/XCConfig", revision: "38fe6d21eaf34c36c3835cb4c5b81b4654de1abc"),
.package(url: "https://github.com/mattmassicotte/XCConfig", revision: "6375b3d7ac16e5c4103c3cbe7b633411bee47d37"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.3"),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.0"),
],
Expand Down
34 changes: 20 additions & 14 deletions Sources/XCLinting/Extensions/PBXProj+BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension PBXProj {

func enumerateBuildSettingStatements(
rootURL: URL,
_ block: (PBXProject, PBXTarget, XCBuildConfiguration, [[Statement]], URL?) throws -> Void
_ block: (PBXProject, PBXTarget, XCBuildConfiguration, [BuildSetting: String]) throws -> Void
) throws {
let sourceRootPath = rootURL.path

Expand All @@ -46,22 +46,28 @@ extension PBXProj {
for target in proj.targets {
for config in target.buildConfigurationList?.buildConfigurations ?? [] {
let projConfig = projConfigList?.configuration(name: config.name)
let baseConfigURL = try projConfig?.baseConfigurationURL(with: sourceRootPath)
let projConfigStatements = try baseConfigURL.map { try Parser().parse(contentsOf: $0) }
let projStatements = projConfig?.buildSettingsStatements ?? []

let projConfigURL = try projConfig?.baseConfigurationURL(with: sourceRootPath)
let configURL = try config.baseConfigurationURL(with: sourceRootPath)
let configStatements = try configURL.map {try Parser().parse(contentsOf: $0) }
let statements = config.buildSettingsStatements

let heirarchy = [
projConfigStatements ?? [],
projStatements,
configStatements ?? [],
statements
]
let heirarchy = BuildSettingsHeirarchy(
projectRootURL: rootURL,
platformDefaults: [],
projectConfigURL: projConfigURL,
project: projConfig?.buildSettingsAssignments ?? [],
configURL: configURL,
target: config.buildSettingsAssignments
)

let settings: [BuildSetting: String]

do {
settings = try Evaluator().evaluate(heirarchy)
} catch {
print("XCConfig failed to evaluate settings heirarchy:", error)
settings = [:]
}

try block(proj, target, config, heirarchy, configURL)
try block(proj, target, config, settings)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ extension XCBuildConfiguration {
return URL(fileURLWithPath: fullPath, isDirectory: false)
}

var buildSettingsStatements: [Statement] {
buildSettings.compactMap { (key, value) -> Statement? in
var buildSettingsAssignments: [Assignment] {
buildSettings.compactMap { (key, value) -> Assignment? in
guard let value = value as? String else { return nil }

return Statement.assignment(Assignment(key: key, value: value))
return Assignment(key: key, value: value)
}
}
}
11 changes: 1 addition & 10 deletions Sources/XCLinting/Rules/ValidateBuildSettingsRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,8 @@ struct ValidateBuildSettingsRule {
) throws {
let project = environment.project
let sourceRootURL = environment.projectRootURL.deletingLastPathComponent()
let evaluator = Evaluator()
let platformStatements: [Statement] = []

try project.pbxproj.enumerateBuildSettingStatements(rootURL: sourceRootURL) { proj, target, config, statementsList, url in
let heirarchy = [platformStatements] + statementsList

// This is bogus. But the only solution I can come up with is to change how evaluation works, and that's complex.
let effectiveURL = url ?? sourceRootURL

let settings = try evaluator.evaluate(heirarchy: heirarchy, for: effectiveURL)

try project.pbxproj.enumerateBuildSettingStatements(rootURL: sourceRootURL) { proj, target, config, settings in
try block(target, config, settings)
}
}
Expand Down

0 comments on commit f4b81dd

Please sign in to comment.