From b51305662afc1a89f1214bb0b4d023ad4e4454eb Mon Sep 17 00:00:00 2001 From: Alex Maimescu Date: Thu, 1 May 2025 15:46:18 +0100 Subject: [PATCH 1/2] Add support for variable InfoPlist file paths --- Sources/XcodeGraph/Models/Plist.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/XcodeGraph/Models/Plist.swift b/Sources/XcodeGraph/Models/Plist.swift index 30e95550..da027531 100644 --- a/Sources/XcodeGraph/Models/Plist.swift +++ b/Sources/XcodeGraph/Models/Plist.swift @@ -103,6 +103,9 @@ public enum InfoPlist: Equatable, Codable, Sendable { // User defined dictionary of keys/values for an info.plist file. case dictionary([String: Plist.Value], configuration: BuildConfiguration? = nil) + // A user defined xcconfig variable map to .entitlements file + case variable(String, configuration: BuildConfiguration? = nil) + // User defined dictionary of keys/values for an info.plist file extending the default set of keys/values // for the target type. case extendingDefault(with: [String: Plist.Value], configuration: BuildConfiguration? = nil) @@ -123,7 +126,12 @@ public enum InfoPlist: Equatable, Codable, Sendable { extension InfoPlist: ExpressibleByStringLiteral { public init(stringLiteral value: String) { - self = .file(path: try! AbsolutePath(validating: value)) // swiftlint:disable:this force_try + let regexPattern = #"^\$\((.+)\)$|^\$\{(.+)\}$"# + if let _ = value.range(of: regexPattern, options: .regularExpression) { + self = .variable(value) + } else { + self = .file(path: try! AbsolutePath(validating: value)) // swiftlint:disable:this force_try + } } } From 48107885b0e30dbde9b1b758c604ca2681f63ccb Mon Sep 17 00:00:00 2001 From: Alex Maimescu Date: Tue, 13 May 2025 13:21:36 +0100 Subject: [PATCH 2/2] Add a unit test --- Sources/XcodeGraph/Models/Plist.swift | 2 +- Tests/XcodeGraphTests/Models/InfoPlistTests.swift | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/XcodeGraph/Models/Plist.swift b/Sources/XcodeGraph/Models/Plist.swift index da027531..3af5c63a 100644 --- a/Sources/XcodeGraph/Models/Plist.swift +++ b/Sources/XcodeGraph/Models/Plist.swift @@ -126,7 +126,7 @@ public enum InfoPlist: Equatable, Codable, Sendable { extension InfoPlist: ExpressibleByStringLiteral { public init(stringLiteral value: String) { - let regexPattern = #"^\$\((.+)\)$|^\$\{(.+)\}$"# + let regexPattern = #"^\$\((.+)\)|^\$\{(.+)\}"# if let _ = value.range(of: regexPattern, options: .regularExpression) { self = .variable(value) } else { diff --git a/Tests/XcodeGraphTests/Models/InfoPlistTests.swift b/Tests/XcodeGraphTests/Models/InfoPlistTests.swift index e89db6ae..7dbcd0d1 100644 --- a/Tests/XcodeGraphTests/Models/InfoPlistTests.swift +++ b/Tests/XcodeGraphTests/Models/InfoPlistTests.swift @@ -41,4 +41,14 @@ final class InfoPlistTests: XCTestCase { // Then XCTAssertEqual(subject.path, try AbsolutePath(validating: "/path/Info.list")) } + + func test_expressive_by_string_literal_using_build_variable() { + // Given + let subject1: InfoPlist = "$(CONFIGURATION)/Info.list" + let subject2: InfoPlist = "${CONFIGURATION}/Info.list" + + // Then + XCTAssertEqual(subject1, .variable("$(CONFIGURATION)/Info.list", configuration: nil)) + XCTAssertEqual(subject2, .variable("${CONFIGURATION}/Info.list", configuration: nil)) + } }