From 1c5b2773a38cec49e8655341cf2440fb99879e57 Mon Sep 17 00:00:00 2001 From: Diogo Autilio Date: Sat, 14 May 2022 13:12:17 -0300 Subject: [PATCH] Feature: Add four new SettingsTransformers (#4427) --- .../SettingsTransformers.swift | 34 +++++++++++- .../SettingsTests.swift | 52 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/Sources/ProjectDescription/SettingsTransformers.swift b/Sources/ProjectDescription/SettingsTransformers.swift index ea3c86fed..55a13ce57 100644 --- a/Sources/ProjectDescription/SettingsTransformers.swift +++ b/Sources/ProjectDescription/SettingsTransformers.swift @@ -97,18 +97,27 @@ extension SettingsDictionary { return merging(versionSettings) } - // MARK: - Swift Settings + // MARK: - Swift Compiler - Language /// Sets `"SWIFT_VERSION"` to `version` public func swiftVersion(_ version: String) -> SettingsDictionary { merging(["SWIFT_VERSION": SettingValue(version)]) } + // MARK: - Swift Compiler - Custom Flags + /// Sets `"OTHER_SWIFT_FLAGS"` to `flags` public func otherSwiftFlags(_ flags: String...) -> SettingsDictionary { merging(["OTHER_SWIFT_FLAGS": SettingValue(flags.joined(separator: " "))]) } + /// Sets `"SWIFT_ACTIVE_COMPILATION_CONDITIONS"` to `conditions` + public func swiftActiveCompilationConditions(_ conditions: String...) -> SettingsDictionary { + merging(["SWIFT_ACTIVE_COMPILATION_CONDITIONS": SettingValue(conditions.joined(separator: " "))]) + } + + // MARK: - Swift Compiler - Code Generation + /// Sets `"SWIFT_COMPILATION_MODE"` to the available `SwiftCompilationMode` (`"singlefile"` or `"wholemodule"`) public func swiftCompilationMode(_ mode: SwiftCompilationMode) -> SettingsDictionary { merging(["SWIFT_COMPILATION_MODE": SettingValue(mode)]) @@ -124,6 +133,29 @@ extension SettingsDictionary { merging(["SWIFT_OPTIMIZE_OBJECT_LIFETIME": SettingValue(enabled)]) } + // MARK: - Swift Compiler - General + + /// Sets `"SWIFT_OBJC_BRIDGING_HEADER"` to `path` + public func swiftObjcBridingHeaderPath(_ path: String) -> SettingsDictionary { + var settings = self + settings["SWIFT_OBJC_BRIDGING_HEADER"] = SettingValue(path) + return settings + } + + // MARK: - Apple Clang - Custom Compiler Flags + + /// Sets `"OTHER_CFLAGS"` to `flags` + public func otherCFlags(_ flags: [String]) -> SettingsDictionary { + merging(["OTHER_CFLAGS": .array(flags)]) + } + + // MARK: - Linking + + /// Sets `"OTHER_LDFLAGS"` to `flags` + public func otherLinkerFlags(_ flags: [String]) -> SettingsDictionary { + merging(["OTHER_LDFLAGS": .array(flags)]) + } + // MARK: - Bitcode /// Sets `"ENABLE_BITCODE"` to `"YES"` or `"NO"` diff --git a/Tests/ProjectDescriptionTests/SettingsTests.swift b/Tests/ProjectDescriptionTests/SettingsTests.swift index 84802b83e..8c6c1fcb0 100644 --- a/Tests/ProjectDescriptionTests/SettingsTests.swift +++ b/Tests/ProjectDescriptionTests/SettingsTests.swift @@ -98,6 +98,10 @@ final class SettingsTests: XCTestCase { .otherSwiftFlags("first", "second", "third") .bitcodeEnabled(true) .debugInformationFormat(.dwarf) + .swiftActiveCompilationConditions("FIRST", "SECOND", "THIRD") + .swiftObjcBridingHeaderPath("/my/briding/header/path.h") + .otherCFlags(["$(inherited)", "-my-c-flag"]) + .otherLinkerFlags(["$(inherited)", "-my-linker-flag"]) /// Then XCTAssertEqual(settings, [ @@ -114,6 +118,10 @@ final class SettingsTests: XCTestCase { "OTHER_SWIFT_FLAGS": "first second third", "ENABLE_BITCODE": "YES", "DEBUG_INFORMATION_FORMAT": "dwarf", + "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "FIRST SECOND THIRD", + "SWIFT_OBJC_BRIDGING_HEADER": "/my/briding/header/path.h", + "OTHER_CFLAGS": ["$(inherited)", "-my-c-flag"], + "OTHER_LDFLAGS": ["$(inherited)", "-my-linker-flag"], ]) } @@ -130,6 +138,17 @@ final class SettingsTests: XCTestCase { ]) } + func test_settingsDictionary_swiftActiveCompilationConditions() { + /// Given/When + let settings = SettingsDictionary() + .swiftActiveCompilationConditions("FIRST", "SECOND", "THIRD") + + /// Then + XCTAssertEqual(settings, [ + "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "FIRST SECOND THIRD", + ]) + } + func test_settingsDictionary_SwiftCompilationMode() { /// Given/When let settings1 = SettingsDictionary() @@ -179,6 +198,39 @@ final class SettingsTests: XCTestCase { ]) } + func test_settingsDictionary_swiftObjcBridingHeaderPath() { + /// Given/When + let settings = SettingsDictionary() + .swiftObjcBridingHeaderPath("/my/briding/header/path.h") + + /// Then + XCTAssertEqual(settings, [ + "SWIFT_OBJC_BRIDGING_HEADER": "/my/briding/header/path.h", + ]) + } + + func test_settingsDictionary_otherCFlags() { + /// Given/When + let settings = SettingsDictionary() + .otherCFlags(["$(inherited)", "-my-c-flag"]) + + /// Then + XCTAssertEqual(settings, [ + "OTHER_CFLAGS": ["$(inherited)", "-my-c-flag"], + ]) + } + + func test_settingsDictionary_otherLinkerFlags() { + /// Given/When + let settings = SettingsDictionary() + .otherLinkerFlags(["$(inherited)", "-my-linker-flag"]) + + /// Then + XCTAssertEqual(settings, [ + "OTHER_LDFLAGS": ["$(inherited)", "-my-linker-flag"], + ]) + } + func test_settingsDictionary_SwiftOptimizeObjectLifetimes() { /// Given/When let settings1 = SettingsDictionary()