Skip to content

Commit

Permalink
Adopt new XCConfig resolution API
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jan 18, 2024
1 parent 55e4b04 commit d255ebe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 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" : "586308908873a212c17019163afea02847f782a3"
"revision" : "38fe6d21eaf34c36c3835cb4c5b81b4654de1abc"
}
},
{
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: "586308908873a212c17019163afea02847f782a3"),
.package(url: "https://github.com/mattmassicotte/XCConfig", revision: "38fe6d21eaf34c36c3835cb4c5b81b4654de1abc"),
.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
22 changes: 16 additions & 6 deletions Sources/XCLinting/Extensions/PBXProj+BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import Foundation
import XCConfig
import XcodeProj

extension Parser {
func parse(contentsOf url: URL) throws -> [Statement] {
let string = try String(contentsOf: url)

return parse(string)
}
}

extension PBXProj {
func enumerateBuildConfigurations(_ block: (String, XCConfigurationList) throws -> Void) rethrows {
for target in legacyTargets {
Expand All @@ -28,7 +36,7 @@ extension PBXProj {

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

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

let configStatements = try config.baseConfigurationStatements(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,
projConfigStatements ?? [],
projStatements,
configStatements,
configStatements ?? [],
statements
]

try block(proj, target, config, heirarchy)
try block(proj, target, config, heirarchy, configURL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ import XCConfig
import XcodeProj

extension XCBuildConfiguration {
func baseConfigurationContent(with sourceRoot: String) throws -> String? {
func baseConfigurationURL(with sourceRoot: String) throws -> URL? {
guard let fullPath = try baseConfiguration?.fullPath(sourceRoot: sourceRoot) else {
return nil
}

return try String(contentsOf: URL(fileURLWithPath: fullPath))
}

func baseConfigurationStatements(with sourceRoot: String) throws -> [Statement] {
guard let content = try baseConfigurationContent(with: sourceRoot) else {
return []
}

return Parser().parse(content)
return URL(fileURLWithPath: fullPath, isDirectory: false)
}

var buildSettingsStatements: [Statement] {
Expand Down
9 changes: 6 additions & 3 deletions Sources/XCLinting/Rules/ValidateBuildSettingsRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ struct ValidateBuildSettingsRule {
) throws {
let project = environment.project
let sourceRootURL = environment.projectRootURL.deletingLastPathComponent()
let evaluator = Evaluator(rootURL: sourceRootURL)
let evaluator = Evaluator()
let platformStatements: [Statement] = []

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

let settings = try evaluator.evaluate(heirarchy: heirarchy)
// 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 block(target, config, settings)
}
Expand Down

0 comments on commit d255ebe

Please sign in to comment.