Skip to content

Commit

Permalink
Force addition of macro flags regardless of inherited presence (#6051)
Browse files Browse the repository at this point in the history
  • Loading branch information
fortmarek committed Mar 8, 2024
1 parent ad0b0d8 commit 8db6e11
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 10 additions & 4 deletions Sources/TuistGenerator/Generator/ConfigGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ final class ConfigGenerator: ConfigGenerating {
settingsHelper.extend(buildSettings: &settings, with: target.settings?.baseDebug ?? [:])
}
settingsHelper.extend(buildSettings: &settings, with: configuration?.settings ?? [:])
settingsHelper
.extend(
buildSettings: &settings,
with: swiftMacrosDerivedSettings(
target: target,
graphTraverser: graphTraverser,
projectPath: project.path
),
inherit: true
)

let variantBuildConfiguration = XCBuildConfiguration(
name: buildConfiguration.xcodeValue,
Expand Down Expand Up @@ -223,10 +233,6 @@ final class ConfigGenerator: ConfigGenerating {
settings.merge(deploymentTargetDerivedSettings(target: target)) { $1 }
settings
.merge(watchTargetDerivedSettings(target: target, graphTraverser: graphTraverser, projectPath: project.path)) { $1 }
settings
.merge(swiftMacrosDerivedSettings(target: target, graphTraverser: graphTraverser, projectPath: project.path)) {
$1
}
}

private func generalTargetDerivedSettings(
Expand Down
17 changes: 10 additions & 7 deletions Sources/TuistGenerator/Utils/SettingsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import TuistGraph
import XcodeProj

final class SettingsHelper {
/// - Parameters:
/// - inherit: Forces the new settings to inherit the old settings
func extend(
buildSettings: inout SettingsDictionary,
with other: SettingsDictionary
with other: SettingsDictionary,
inherit: Bool = false
) {
for (key, newValue) in other {
buildSettings[key] = merge(oldValue: buildSettings[key], newValue: newValue).normalize()
buildSettings[key] = merge(oldValue: buildSettings[key], newValue: newValue, inherit: inherit).normalize()
}
}

Expand Down Expand Up @@ -61,7 +64,7 @@ final class SettingsHelper {

// MARK: - Private

private func merge(oldValue: SettingValue?, newValue: SettingValue) -> SettingValue {
private func merge(oldValue: SettingValue?, newValue: SettingValue, inherit: Bool) -> SettingValue {
// No need to merge, just return newValue when the oldValue is nil (buildSettings[key] == nil).
guard let oldValue else {
return newValue
Expand All @@ -84,21 +87,21 @@ final class SettingsHelper {
// would result in ["$(inherited)", "$(inherited)", "VALUE_1", "VALUE_2"] if .sortAndTrim() was not used.
let inherited = "$(inherited)"
switch (oldValue, newValue) {
case let (.string(old), .string(new)) where new.contains(inherited):
case let (.string(old), .string(new)) where new.contains(inherited) || inherit:
// Example: ("OLD", "$(inherited) NEW") -> ["$(inherited) NEW", "OLD"]
// This case shouldn't happen as all default multi-value settings are defined as NSArray<NSString>
return .array(Self.sortAndTrim(array: [old, new], element: inherited))

case let (.string(old), .array(new)) where new.contains(inherited):
case let (.string(old), .array(new)) where new.contains(inherited) || inherit:
// Example: ("OLD", ["$(inherited)", "NEW"]) -> ["$(inherited)", "NEW", "OLD"]
return .array(Self.sortAndTrim(array: [old] + new, element: inherited))

case let (.array(old), .string(new)) where new.contains(inherited):
case let (.array(old), .string(new)) where new.contains(inherited) || inherit:
// Example: (["OLD", "OLD_2"], "$(inherited) NEW") -> ["$(inherited) NEW", "OLD", "OLD_2"]
// This case shouldn't happen as all default multi-value settings are defined as NSArray<NSString>
return .array(Self.sortAndTrim(array: old + [new], element: inherited))

case let (.array(old), .array(new)) where new.contains(inherited):
case let (.array(old), .array(new)) where new.contains(inherited) || inherit:
// Example: (["OLD", "OLD_2"], ["$(inherited)", "NEW"]) -> ["$(inherited)", "NEW", "OLD", OLD_2"]
return .array(Self.sortAndTrim(array: old + new, element: inherited))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extension ProjectDescription.Settings {

public static var targetSettings: Self {
.settings(
base: [:].otherSwiftFlags("-enable-actor-data-race-checks"),
configurations: BuildEnvironment.allCases.map(\.targetConfiguration)
)
}
Expand Down

0 comments on commit 8db6e11

Please sign in to comment.