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
218 changes: 183 additions & 35 deletions test/fixtures/generator/bwb.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
-headerpad_max_install_names
-no-canonical-prefixes
-lc++
$(BAZEL_OUT)/darwin_x86_64-dbg-ST-5a06a31acc4f/bin/tools/generator/libgenerator.library.a
$(BAZEL_OUT)/darwin_x86_64-dbg-ST-5a06a31acc4f/bin/external/com_github_apple_swift_collections/libOrderedCollections.a
$(BAZEL_OUT)/darwin_x86_64-dbg-ST-5a06a31acc4f/bin/external/com_github_tuist_xcodeproj/libXcodeProj.a
$(BAZEL_OUT)/darwin_x86_64-dbg-ST-5a06a31acc4f/bin/external/com_github_tadija_aexml/libAEXML.a
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/generator/bwb_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
"//tools/generator/test:tests.library darwin_x86_64-dbg-ST-5a06a31acc4f",
[
"//tools/generator/test:tests darwin_x86_64-dbg-ST-5a06a31acc4f"
],
"//tools/generator:generator.library darwin_x86_64-dbg-ST-5a06a31acc4f",
[
"//tools/generator:generator darwin_x86_64-dbg-ST-5a06a31acc4f"
]
],
"targets": [
Expand Down
214 changes: 179 additions & 35 deletions test/fixtures/generator/bwx.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
-headerpad_max_install_names
-no-canonical-prefixes
-lc++
$(BUILD_DIR)/bazel-out/darwin_x86_64-dbg-ST-e7deb5c809c7/bin/tools/generator/libgenerator.library.a
$(BUILD_DIR)/bazel-out/darwin_x86_64-dbg-ST-e7deb5c809c7/bin/external/com_github_apple_swift_collections/libOrderedCollections.a
$(BUILD_DIR)/bazel-out/darwin_x86_64-dbg-ST-e7deb5c809c7/bin/external/com_github_tuist_xcodeproj/libXcodeProj.a
$(BAZEL_OUT)/darwin_x86_64-dbg-ST-e7deb5c809c7/bin/external/com_github_tadija_aexml/libAEXML.a
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/generator/bwx_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
"//tools/generator/test:tests.library darwin_x86_64-dbg-ST-e7deb5c809c7",
[
"//tools/generator/test:tests darwin_x86_64-dbg-ST-e7deb5c809c7"
],
"//tools/generator:generator.library darwin_x86_64-dbg-ST-e7deb5c809c7",
[
"//tools/generator:generator darwin_x86_64-dbg-ST-e7deb5c809c7"
]
],
"targets": [
Expand Down
33 changes: 27 additions & 6 deletions tools/generator/src/Generator/ProcessTargetMerges.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ extension Generator {
targets: inout [TargetID: Target],
targetMerges: [TargetID: Set<TargetID>]
) throws {
var mergedInto: [TargetID: TargetID] = [:]
for (source, destinations) in targetMerges {
for destination in destinations {
mergedInto[destination] = source
}
}

var fullyMerged: Set<TargetID> = []
for (source, destinations) in targetMerges {
guard let merging = targets[source] else {
throw PreconditionError(message: """
`targetMerges.key` (\(source)) references target that doesn't exist
""")
}

fullyMerged.insert(source)

for destination in destinations {
guard var merged = targets[destination] else {
throw PreconditionError(message: """
Expand All @@ -41,9 +51,6 @@ exist
""")
}

// Remove src
targets.removeValue(forKey: source)

// Update Package Bin Dir
// We take on the libraries bazel-out directory to prevent
// issues with search paths that are calculated in Starlark.
Expand Down Expand Up @@ -77,8 +84,16 @@ exist
merged.linkerInputs.forceLoad.remove(merging.product.path)

// Update dependencies
merged.dependencies.remove(source)
merged.dependencies.formUnion(merging.dependencies)

if merged.product.type != .uiTestBundle,
let testHost = merged.testHost,
let mergedTestHostLibrary = mergedInto[testHost]
{
merged.dependencies.remove(mergedTestHostLibrary)
}

// Update outputs
merged.outputs.merge(merging.outputs)

Expand All @@ -87,14 +102,20 @@ exist
}
}

// Update all targets
// Remove targets that are fully merged
for (id, target) in targets {
// Dependencies
if fullyMerged.contains(id) {
continue
}
for dependency in target.dependencies {
if targetMerges[dependency] != nil {
targets[id]!.dependencies.remove(dependency)
// Still used somewhere, so not fully merged
fullyMerged.remove(dependency)
}
}
}
for id in fullyMerged {
targets.removeValue(forKey: id)
}
}
}
5 changes: 1 addition & 4 deletions tools/generator/test/Fixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ enum Fixtures {
name: "b",
path: .generated("a/b.framework")
),
inputs: .init(srcs: ["z.h", "z.mm"], hdrs: ["d.h"]),
dependencies: ["A 1"]
inputs: .init(srcs: ["z.h", "z.mm"], hdrs: ["d.h"])
),
// "B 2" not having a link on "A 1" represents a bundle_loader like
// relationship. This allows "A 1" to merge into "A 2".
Expand Down Expand Up @@ -2507,8 +2506,6 @@ $(MACOSX_FILES)
.addDependency(target: pbxTargets["C 1"]!)
_ = try! pbxTargets.nativeTarget("A 2")!
.addDependency(target: pbxTargets["R 1"]!)
_ = try! pbxTargets.nativeTarget("B 1")!
.addDependency(target: pbxTargets["A 1"]!)
_ = try! pbxTargets.nativeTarget("B 2")!
.addDependency(target: pbxTargets["A 2"]!)
_ = try! pbxTargets.nativeTarget("B 2")!
Expand Down
2 changes: 1 addition & 1 deletion tools/generator/test/ProcessTargetMergesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class TargetMergingTests: XCTestCase {
XCTAssertNoDifference(targets, expectedTargets)
}

func test_merges_without_required_links() throws {
func test_merges() throws {
// Arrange

var targets = Fixtures.targets
Expand Down
4 changes: 0 additions & 4 deletions xcodeproj/internal/processed_target.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def processed_target(
inputs,
library = None,
lldb_context,
non_mergable_targets = None,
outputs,
potential_target_merges = None,
resource_bundle_informations = None,
Expand All @@ -37,8 +36,6 @@ def processed_target(
library: A `File` for the static library produced by this target, or
`None`.
lldb_context: A value as returned from `lldb_context.collect`.
non_mergable_targets: An optional `list` of strings that will be in the
`XcodeProjInfo.non_mergable_targets` `depset`.
outputs: A value as returned from `output_files.collect` that will
provide values for the `XcodeProjInfo.outputs` field.
potential_target_merges: An optional `list` of `struct`s that will be in
Expand All @@ -63,7 +60,6 @@ def processed_target(
inputs = inputs,
library = library,
lldb_context = lldb_context,
non_mergable_targets = non_mergable_targets,
outputs = outputs,
potential_target_merges = potential_target_merges,
resource_bundle_informations = resource_bundle_informations,
Expand Down
4 changes: 0 additions & 4 deletions xcodeproj/internal/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ project, but are not associated with any targets.
A `depset` of `struct`s with 'src' and 'dest' fields. The 'src' field is the id
of the target that can be merged into the target with the id of the 'dest'
field.
""",
"non_mergable_targets": """\
A `depset` of all static library files that are linked into top-level targets
besides their primary top-level targets.
""",
"outputs": """\
A value returned from `output_files.collect`, that contains information about
Expand Down
11 changes: 0 additions & 11 deletions xcodeproj/internal/top_level_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ def process_top_level_target(
)
if len(xcode_library_targets) == 1 and not inputs.srcs:
mergeable_target = xcode_library_targets[0]
mergeable_label = mergeable_target.label
potential_target_merges = [struct(
src = struct(
id = mergeable_target.id,
Expand All @@ -364,15 +363,6 @@ The xcodeproj rule requires {} rules to have a single library dep. {} has {}.\
""".format(ctx.rule.kind, label, len(xcode_library_targets)))
else:
potential_target_merges = None
mergeable_label = None

non_mergable_targets = [
library
for library in linker_input_files.get_top_level_static_libraries(
linker_inputs,
)
if mergeable_label and library.owner != mergeable_label
]

set_if_true(
build_settings,
Expand Down Expand Up @@ -456,7 +446,6 @@ The xcodeproj rule requires {} rules to have a single library dep. {} has {}.\
hosted_targets = hosted_targets,
inputs = inputs,
lldb_context = lldb_context,
non_mergable_targets = non_mergable_targets,
outputs = outputs,
potential_target_merges = potential_target_merges,
search_paths = search_paths,
Expand Down
8 changes: 0 additions & 8 deletions xcodeproj/internal/xcodeproj_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,11 @@ def _write_json_spec(
potential_target_merges = depset(
transitive = [info.potential_target_merges for info in infos],
).to_list()
non_mergable_targets = sets.make([
file_path(file)
for file in depset(
transitive = [info.non_mergable_targets for info in infos],
).to_list()
])

target_merges = {}
for merge in potential_target_merges:
if merge.src.id not in targets or merge.dest not in targets:
continue
if (sets.contains(non_mergable_targets, merge.src.product_path)):
continue
target_merges.setdefault(merge.src.id, []).append(merge.dest)

# `target_hosts`
Expand Down
23 changes: 0 additions & 23 deletions xcodeproj/internal/xcodeprojinfo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def _target_info_fields(
hosted_targets,
inputs,
lldb_context,
non_mergable_targets,
outputs,
potential_target_merges,
resource_bundle_informations,
Expand All @@ -78,8 +77,6 @@ def _target_info_fields(
hosted_targets: Maps to the `XcodeProjInfo.hosted_targets` field.
inputs: Maps to the `XcodeProjInfo.inputs` field.
lldb_context: Maps to the `XcodeProjInfo.lldb_context` field.
non_mergable_targets: Maps to the `XcodeProjInfo.non_mergable_targets`
field.
outputs: Maps to the `XcodeProjInfo.outputs` field.
potential_target_merges: Maps to the
`XcodeProjInfo.potential_target_merges` field.
Expand All @@ -102,7 +99,6 @@ def _target_info_fields(
* `hosted_targets`
* `inputs`
* `lldb_context`
* `non_mergable_targets`
* `outputs`
* `potential_target_merges`
* `resource_bundle_informations`
Expand All @@ -119,7 +115,6 @@ def _target_info_fields(
"hosted_targets": hosted_targets,
"inputs": inputs,
"lldb_context": lldb_context,
"non_mergable_targets": non_mergable_targets,
"outputs": outputs,
"potential_target_merges": potential_target_merges,
"resource_bundle_informations": resource_bundle_informations,
Expand Down Expand Up @@ -191,12 +186,6 @@ def _skip_target(*, deps, transitive_infos):
for _, info in transitive_infos
],
),
non_mergable_targets = depset(
transitive = [
info.non_mergable_targets
for _, info in transitive_infos
],
),
outputs = output_files.merge(
automatic_target_info = None,
transitive_infos = transitive_infos,
Expand Down Expand Up @@ -303,18 +292,6 @@ def _create_xcodeprojinfo(*, ctx, target, transitive_infos):
),
inputs = processed_target.inputs,
lldb_context = processed_target.lldb_context,
non_mergable_targets = depset(
processed_target.non_mergable_targets,
transitive = [
info.non_mergable_targets
for attr, info in transitive_infos
if (info.target_type in
processed_target.automatic_target_info.xcode_targets.get(
attr,
[None],
))
],
),
outputs = processed_target.outputs,
potential_target_merges = depset(
processed_target.potential_target_merges,
Expand Down