From ca055a552ce81f0b197c1399ba8463b5e7fa11f9 Mon Sep 17 00:00:00 2001 From: Gabriel Minucci Date: Mon, 3 Mar 2025 14:22:18 +0100 Subject: [PATCH 1/2] Update xcconfig in the main target only if using cocoapods (#263) * fix: update xcconfig in the main target only if using cocoapods * fix: linter errors --- .../Factory/iOS/XcodeProjFactory.swift | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/Sources/VariantsCore/Factory/iOS/XcodeProjFactory.swift b/Sources/VariantsCore/Factory/iOS/XcodeProjFactory.swift index c29862dd..d049d552 100644 --- a/Sources/VariantsCore/Factory/iOS/XcodeProjFactory.swift +++ b/Sources/VariantsCore/Factory/iOS/XcodeProjFactory.swift @@ -5,6 +5,8 @@ // Created by Arthur Alves // +// swiftlint:disable file_length + import Foundation import XcodeProj import PathKit @@ -16,7 +18,7 @@ struct XcodeProjFactory { private let logger: Logger - init(enableVerboseLog: Bool = true) { + init(enableVerboseLog: Bool = false) { logger = Logger(verbose: enableVerboseLog) } @@ -136,21 +138,41 @@ struct XcodeProjFactory { target: iOSTarget, autoSave: Bool = false) { do { + let isUsingCocoapodsWorkspace = isCocoapodsWorkspace( + configurations: xcodeProject.pbxproj.buildConfigurations) + for conf in xcodeProject.pbxproj.buildConfigurations { - if - let infoList = conf.buildSettings["INFOPLIST_FILE"] as? String, - infoList == target.source.info { + if isUsingCocoapodsWorkspace { + let confName = conf.baseConfiguration?.name?.lowercased() + guard confName?.contains("pods") == false else { continue } + conf.baseConfiguration = fileReference + } else { + guard conf.infoPlistFile == target.source.info else { continue } conf.baseConfiguration = fileReference } } - if autoSave { try xcodeProject.write(path: path) } + + if autoSave { + try xcodeProject.write(path: path) + } + logger.logInfo("✅ ", item: "Changed baseConfiguration of target '\(target.name)'", color: .green) } catch { logger.logFatal("❌ ", item: "Unable to edit baseConfiguration for target '\(target.name)'") } } - + + private func isCocoapodsWorkspace(configurations: [XCBuildConfiguration]) -> Bool { + for conf in configurations { + // swiftlint:disable:next for_where + if conf.baseConfiguration?.name?.lowercased().contains("pods") == true { + return true + } + } + return false + } + /// Modify value directly in `.xcodeproj/project.pbxproj` /// - Parameters: /// - keyValue: Key/value pair to be modified @@ -168,7 +190,7 @@ struct XcodeProjFactory { logger.logInfo("Updating: ", item: projectPath) project.pbxproj.buildConfigurations - .filter({ ($0.buildSettings["INFOPLIST_FILE"] as? String)?.contains(targetName) ?? false }) + .filter({ $0.infoPlistFile?.contains(targetName) ?? false }) .filter({ configTypeNames.contains($0.name.lowercased()) }) .forEach { conf in logger.logDebug( @@ -243,3 +265,11 @@ private extension XcodeProjFactory { } } } + +private extension XCBuildConfiguration { + var infoPlistFile: String? { + buildSettings["INFO_PLIST"] as? String + } +} + +// swiftlint:enable file_length From 0d8bf790c2b52ef724589fbd749e1700b56503f6 Mon Sep 17 00:00:00 2001 From: Gabriel Minucci Date: Mon, 3 Mar 2025 15:27:49 +0200 Subject: [PATCH 2/2] chore: bump version to 1.3.1 --- Sources/Variants/main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Variants/main.swift b/Sources/Variants/main.swift index 13bd9dc7..c8613436 100644 --- a/Sources/Variants/main.swift +++ b/Sources/Variants/main.swift @@ -12,7 +12,7 @@ struct Variants: ParsableCommand { static var configuration = CommandConfiguration( commandName: "variants", abstract: "A command-line tool to setup deployment variants and working CI/CD setup", - version: "1.3.0", + version: "1.3.1", subcommands: [ Initializer.self, Setup.self,