Skip to content

Commit

Permalink
Use only the debug settings from the most-downstream Swift target (#3073
Browse files Browse the repository at this point in the history
)

This prevents settings which are specific to a particular Swift module
compilation, such as clang module maps in a mixed-language library, from
getting accumulated with the public settings. Before this change using
`mixed_language_library` would result in module redefinition errors in
lldb.

I’m not sure if this has a chance of not setting some flags that would
need to be set. In local testing everything worked, but as with all
things lldb, wider user testing is needed. Ideally long term we can use
serialized debug info instead (and/or explicit modules).

**Note:** For this to work the best, the single dep of a top-level
target needs to be a `swift_library` or `mixed_language_target`. This
change might result in lldb regressions for custom setups that don't
meet that requirement.

---------

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones committed Aug 20, 2024
1 parent d426da1 commit 4d750eb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ extension Generator.ProcessSwiftArgs {
frameworkIncludes: OrderedSet<String>,
swiftIncludes: OrderedSet<String>
) {
var (hasDebugInfo, clangArgs, frameworkIncludes, onceClangArgs, swiftIncludes) = try await _process_swift_args(
var (
hasDebugInfo,
clangArgs,
frameworkIncludes,
onceClangArgs,
swiftIncludes,
includeTransitiveSwiftDebugSettings
) = try await _process_swift_args(
argsStream: argsStream,
buildSettings: &buildSettings,
includeSelfSwiftDebugSettings: includeSelfSwiftDebugSettings,
Expand All @@ -118,13 +125,15 @@ extension Generator.ProcessSwiftArgs {
processSwiftFrontendArg: processSwiftFrontendArg
)

try await parseTransitiveSwiftDebugSettings(
transitiveSwiftDebugSettingPaths,
clangArgs: &clangArgs,
frameworkIncludes: &frameworkIncludes,
onceClangArgs: &onceClangArgs,
swiftIncludes: &swiftIncludes
)
if includeTransitiveSwiftDebugSettings {
try await parseTransitiveSwiftDebugSettings(
transitiveSwiftDebugSettingPaths,
clangArgs: &clangArgs,
frameworkIncludes: &frameworkIncludes,
onceClangArgs: &onceClangArgs,
swiftIncludes: &swiftIncludes
)
}

return (hasDebugInfo, clangArgs, frameworkIncludes, swiftIncludes)
}
Expand All @@ -146,8 +155,9 @@ extension Generator.ProcessSwiftArgs {
clangArgs: [String],
frameworkIncludes: OrderedSet<String>,
onceClangArgs: Set<String>,
swiftIncludes: OrderedSet<String>
) {
swiftIncludes: OrderedSet<String>,
includeTransitiveSwiftDebugSettings: Bool
) {
var previousArg: String? = nil
var previousClangArg: String? = nil
var previousFrontendArg: String? = nil
Expand All @@ -158,7 +168,7 @@ extension Generator.ProcessSwiftArgs {
guard let tool = try await iterator.next(),
tool != Generator.argsSeparator
else {
return (false, [], [], [], [])
return (false, [], [], [], [], true)
}
_ = try await iterator.next()

Expand Down Expand Up @@ -312,7 +322,14 @@ extension Generator.ProcessSwiftArgs {
("OTHER_SWIFT_FLAGS", args.joined(separator: " ").pbxProjEscaped)
)

return (hasDebugInfo, clangArgs, frameworkIncludes, onceClangArgs, swiftIncludes)
return (
hasDebugInfo,
clangArgs,
frameworkIncludes,
onceClangArgs,
swiftIncludes,
!includeSelfSwiftDebugSettings
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def _process_incremental_library_target(
transitive = [
info.swift_debug_settings
for info in transitive_infos
],
order = "topological",
] if not swift_debug_settings_file else None,
)

if apple_common.AppleDebugOutputs in target:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ def _process_focused_top_level_target(
info.swift_debug_settings
for info in deps_infos
],
order = "topological",
)

top_level_focused_deps = [
Expand Down Expand Up @@ -749,7 +748,6 @@ def _process_unfocused_top_level_target(
# FIXME: Exclude `avoid_deps`
for info in deps_infos
],
order = "topological",
)

(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def _process_incremental_unsupported_target(
info.swift_debug_settings
for info in transitive_infos
],
order = "topological",
),
target_output_groups = output_groups.merge(
transitive_infos = transitive_infos,
Expand Down
8 changes: 1 addition & 7 deletions xcodeproj/internal/processed_targets/mergeable_infos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,7 @@ def _mixed_language_mergeable_info(
],
),
swift_args = swift.args.swift,
swift_debug_settings_to_merge = memory_efficient_depset(
transitive = [
swift.swift_debug_settings,
cc.swift_debug_settings,
],
order = "topological",
),
swift_debug_settings_to_merge = swift.swift_debug_settings,
)

def _swift_mergeable_info(
Expand Down

0 comments on commit 4d750eb

Please sign in to comment.