Skip to content

Commit f6933ff

Browse files
committed
fix: update xcconfig in the main target only if using cocoapods
1 parent 3da2bbe commit f6933ff

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

Sources/VariantsCore/Factory/iOS/XcodeProjFactory.swift

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct XcodeProjFactory {
1616

1717
private let logger: Logger
1818

19-
init(enableVerboseLog: Bool = true) {
19+
init(enableVerboseLog: Bool = false) {
2020
logger = Logger(verbose: enableVerboseLog)
2121
}
2222

@@ -136,21 +136,40 @@ struct XcodeProjFactory {
136136
target: iOSTarget,
137137
autoSave: Bool = false) {
138138
do {
139+
let isUsingCocoapodsWorkspace = isCocoapodsWorkspace(
140+
configurations: xcodeProject.pbxproj.buildConfigurations)
141+
139142
for conf in xcodeProject.pbxproj.buildConfigurations {
140-
if
141-
let infoList = conf.buildSettings["INFOPLIST_FILE"] as? String,
142-
infoList == target.source.info {
143+
if isUsingCocoapodsWorkspace {
144+
let confName = conf.baseConfiguration?.name?.lowercased()
145+
guard confName?.contains("pods") == false else { continue }
146+
conf.baseConfiguration = fileReference
147+
} else {
148+
guard conf.infoPlistFile == target.source.info else { continue }
143149
conf.baseConfiguration = fileReference
144150
}
145151
}
146-
if autoSave { try xcodeProject.write(path: path) }
152+
153+
if autoSave {
154+
try xcodeProject.write(path: path)
155+
}
156+
147157
logger.logInfo("", item: "Changed baseConfiguration of target '\(target.name)'",
148158
color: .green)
149159
} catch {
150160
logger.logFatal("", item: "Unable to edit baseConfiguration for target '\(target.name)'")
151161
}
152162
}
153-
163+
164+
private func isCocoapodsWorkspace(configurations: [XCBuildConfiguration]) -> Bool {
165+
for conf in configurations {
166+
if conf.baseConfiguration?.name?.lowercased().contains("pods") == true {
167+
return true
168+
}
169+
}
170+
return false
171+
}
172+
154173
/// Modify value directly in `.xcodeproj/project.pbxproj`
155174
/// - Parameters:
156175
/// - keyValue: Key/value pair to be modified
@@ -168,7 +187,7 @@ struct XcodeProjFactory {
168187
logger.logInfo("Updating: ", item: projectPath)
169188

170189
project.pbxproj.buildConfigurations
171-
.filter({ ($0.buildSettings["INFOPLIST_FILE"] as? String)?.contains(targetName) ?? false })
190+
.filter({ $0.infoPlistFile?.contains(targetName) ?? false })
172191
.filter({ configTypeNames.contains($0.name.lowercased()) })
173192
.forEach { conf in
174193
logger.logDebug(
@@ -243,3 +262,9 @@ private extension XcodeProjFactory {
243262
}
244263
}
245264
}
265+
266+
private extension XCBuildConfiguration {
267+
var infoPlistFile: String? {
268+
buildSettings["INFO_PLIST"] as? String
269+
}
270+
}

0 commit comments

Comments
 (0)