55// Created by Arthur Alves
66//
77
8+ // swiftlint:disable file_length
9+
810import Foundation
911import XcodeProj
1012import PathKit
@@ -16,7 +18,7 @@ struct XcodeProjFactory {
1618
1719 private let logger : Logger
1820
19- init ( enableVerboseLog: Bool = true ) {
21+ init ( enableVerboseLog: Bool = false ) {
2022 logger = Logger ( verbose: enableVerboseLog)
2123 }
2224
@@ -136,21 +138,41 @@ struct XcodeProjFactory {
136138 target: iOSTarget ,
137139 autoSave: Bool = false ) {
138140 do {
141+ let isUsingCocoapodsWorkspace = isCocoapodsWorkspace (
142+ configurations: xcodeProject. pbxproj. buildConfigurations)
143+
139144 for conf in xcodeProject. pbxproj. buildConfigurations {
140- if
141- let infoList = conf. buildSettings [ " INFOPLIST_FILE " ] as? String ,
142- infoList == target. source. info {
145+ if isUsingCocoapodsWorkspace {
146+ let confName = conf. baseConfiguration? . name? . lowercased ( )
147+ guard confName? . contains ( " pods " ) == false else { continue }
148+ conf. baseConfiguration = fileReference
149+ } else {
150+ guard conf. infoPlistFile == target. source. info else { continue }
143151 conf. baseConfiguration = fileReference
144152 }
145153 }
146- if autoSave { try xcodeProject. write ( path: path) }
154+
155+ if autoSave {
156+ try xcodeProject. write ( path: path)
157+ }
158+
147159 logger. logInfo ( " ✅ " , item: " Changed baseConfiguration of target ' \( target. name) ' " ,
148160 color: . green)
149161 } catch {
150162 logger. logFatal ( " ❌ " , item: " Unable to edit baseConfiguration for target ' \( target. name) ' " )
151163 }
152164 }
153-
165+
166+ private func isCocoapodsWorkspace( configurations: [ XCBuildConfiguration ] ) -> Bool {
167+ for conf in configurations {
168+ // swiftlint:disable:next for_where
169+ if conf. baseConfiguration? . name? . lowercased ( ) . contains ( " pods " ) == true {
170+ return true
171+ }
172+ }
173+ return false
174+ }
175+
154176 /// Modify value directly in `.xcodeproj/project.pbxproj`
155177 /// - Parameters:
156178 /// - keyValue: Key/value pair to be modified
@@ -168,7 +190,7 @@ struct XcodeProjFactory {
168190 logger. logInfo ( " Updating: " , item: projectPath)
169191
170192 project. pbxproj. buildConfigurations
171- . filter ( { ( $0. buildSettings [ " INFOPLIST_FILE " ] as? String ) ? . contains ( targetName) ?? false } )
193+ . filter ( { $0. infoPlistFile ? . contains ( targetName) ?? false } )
172194 . filter ( { configTypeNames. contains ( $0. name. lowercased ( ) ) } )
173195 . forEach { conf in
174196 logger. logDebug (
@@ -243,3 +265,11 @@ private extension XcodeProjFactory {
243265 }
244266 }
245267}
268+
269+ private extension XCBuildConfiguration {
270+ var infoPlistFile : String ? {
271+ buildSettings [ " INFO_PLIST " ] as? String
272+ }
273+ }
274+
275+ // swiftlint:enable file_length
0 commit comments