Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/generator/src/DTO/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct Target: Equatable {
let appClips: Set<TargetID>
var dependencies: Set<TargetID>
var outputs: Outputs
let isUnfocusedDependency: Bool
}

extension Target {
Expand Down Expand Up @@ -57,6 +58,7 @@ extension Target: Decodable {
case appClips
case dependencies
case outputs
case isUnfocusedDependency
}

init(from decoder: Decoder) throws {
Expand Down Expand Up @@ -99,6 +101,8 @@ extension Target: Decodable {
dependencies = try container.decodeTargetIDs(.dependencies)
outputs = try container
.decodeIfPresent(Outputs.self, forKey: .outputs) ?? .init()
isUnfocusedDependency = try container
.decodeIfPresent(Bool.self, forKey: .isUnfocusedDependency) ?? false
}
}

Expand Down
4 changes: 4 additions & 0 deletions tools/generator/src/Generator/CreateFilesAndGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ extension Generator {
switch buildMode {
case .xcode:
for (_, target) in targets {
guard !target.isUnfocusedDependency else {
continue
}

xcodeGeneratedFiles.insert(target.product.path)
if let filePath = target.outputs.swift?.module {
xcodeGeneratedFiles.insert(filePath)
Expand Down
7 changes: 7 additions & 0 deletions tools/generator/src/Generator/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class Generator {
var targets = project.targets
try environment.processTargetMerges(&targets, project.targetMerges)

let isUnfocusedDependencyTargetIDs = Set(
targets.filter(\.value.isUnfocusedDependency).keys
)
for id in targets.keys {
targets[id]!.dependencies.subtract(isUnfocusedDependencyTargetIDs)
}

let consolidatedTargets = try environment.consolidateTargets(
targets,
logger
Expand Down
6 changes: 4 additions & 2 deletions tools/generator/test/Target+Testing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ extension Target {
extensions: Set<TargetID> = [],
appClips: Set<TargetID> = [],
dependencies: Set<TargetID> = [],
outputs: Outputs = .init()
outputs: Outputs = .init(),
isUnfocusedDependency: Bool = false
) -> Self {
return Target(
name: product.name,
Expand All @@ -47,7 +48,8 @@ extension Target {
extensions: extensions,
appClips: appClips,
dependencies: dependencies,
outputs: outputs
outputs: outputs,
isUnfocusedDependency: isUnfocusedDependency
)
}
}
Expand Down
27 changes: 26 additions & 1 deletion xcodeproj/internal/input_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def _collect(
generated = generated,
))

# Collect unfocused target outputs
# Collect unfocused target info
unfocused_libraries = None
if should_include_non_xcode_outputs(ctx = ctx):
if unfocused == None:
dep_compilation_providers = comp_providers.merge(
Expand All @@ -323,6 +324,12 @@ def _collect(
unfocused = bool(direct_libraries)
if unfocused:
generated.extend(transitive_libraries)
unfocused_libraries = depset(
[
file_path(file)
for file in transitive_libraries
],
)

if unfocused and SwiftInfo in target:
non_target_swift_info_modules = target[SwiftInfo].transitive_modules
Expand Down Expand Up @@ -361,6 +368,16 @@ def _collect(
else:
direct_group_list = None

if not unfocused_libraries:
unfocused_libraries = depset(
transitive = [
info.inputs.unfocused_libraries
for attr, info in transitive_infos
if (info.target_type in
automatic_target_info.xcode_targets.get(attr, [None]))
],
)

return struct(
_non_target_swift_info_modules = non_target_swift_info_modules,
_output_group_list = depset(
Expand Down Expand Up @@ -435,6 +452,7 @@ def _collect(
automatic_target_info.xcode_targets.get(attr, [None]))
],
),
unfocused_libraries = unfocused_libraries,
)

def _from_resource_bundle(bundle):
Expand All @@ -455,6 +473,7 @@ def _from_resource_bundle(bundle):
important_generated = depset(),
extra_files = depset(),
uncategorized = depset(),
unfocused_libraries = depset(),
)

def _merge(*, transitive_infos, extra_generated = None):
Expand Down Expand Up @@ -532,6 +551,12 @@ def _merge(*, transitive_infos, extra_generated = None):
for _, info in transitive_infos
],
),
unfocused_libraries = depset(
transitive = [
info.inputs.unfocused_libraries
for _, info in transitive_infos
],
),
)

def _to_dto(inputs):
Expand Down
5 changes: 4 additions & 1 deletion xcodeproj/internal/xcode_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _make(
product = product,
)

def _to_dto(xcode_target):
def _to_dto(xcode_target, *, is_unfocused_dependency = False):
inputs = xcode_target._inputs

dto = {
Expand All @@ -111,6 +111,9 @@ def _to_dto(xcode_target):
if not xcode_target._is_swift:
dto["is_swift"] = False

if is_unfocused_dependency:
dto["is_unfocused_dependency"] = True

set_if_true(dto, "test_host", xcode_target._test_host)
set_if_true(dto, "build_settings", xcode_target._build_settings)
set_if_true(
Expand Down
10 changes: 9 additions & 1 deletion xcodeproj/internal/xcodeproj_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ def _write_json_spec(
if not sets.contains(non_mergable_targets_set, merge.src.product_path):
target_merges.setdefault(merge.src.id, []).append(merge.dest)

unfocused_libraries = sets.make(inputs.unfocused_libraries.to_list())

targets = {}
for xcode_target in targets_depset.to_list():
targets[xcode_target.id] = xcode_targets.to_dto(xcode_target)
targets[xcode_target.id] = xcode_targets.to_dto(
xcode_target,
is_unfocused_dependency = sets.contains(
unfocused_libraries,
xcode_target.product.path,
),
)
targets_json = json.encode(
flattened_key_values.to_list(targets),
)
Expand Down