Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures the determinism of vfsoverlay file #912

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
10 changes: 8 additions & 2 deletions rules/framework/vfs_overlay.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ in-memory tree roots, it pre-pends the prefix of the `vfsoverlay` path
to each of the entries.
"""

load("//rules:providers.bzl", "FrameworkInfo")
load("//rules:features.bzl", "feature_names")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_common")
load("//rules:features.bzl", "feature_names")
load("//rules:providers.bzl", "FrameworkInfo")

FRAMEWORK_SEARCH_PATH = "/build_bazel_rules_ios/frameworks"

Expand Down Expand Up @@ -376,6 +376,12 @@ def make_vfsoverlay(ctx, hdrs, module_map, private_hdrs, has_swift, swiftmodules
vfs_parent_len = len(vfs_parent.split("/")) - 1
vfs_prefix = _make_relative_prefix(vfs_parent_len)

# Ensures the determinism of vfsoverlay file
# hdrs, private_hdrs and swiftmodules of the same framework may be in different order.
hdrs = sorted(hdrs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to verify that these sort steps don't introduce a significant performance regression in the analysis phase.

Copy link
Contributor Author

@congt congt Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overhead should be fine. apple_library has already sorted all srcs files. The number of hdrs, private_hdrs and swiftmodules is smaller than that of srcs, especially for swift modules.

Copy link
Contributor

@gyfelton gyfelton Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what kind of CI test can red green on this... sandbox mode only ensure all inputs that should be present are present in the inputs list, but nothing about ensuring no change on file content when a rebuild happens

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe start with adding before after in the PR desc? I am sure we can figure some CI test out in future based on the repro

private_hdrs = sorted(private_hdrs)
swiftmodules = sorted(swiftmodules)

data = struct(
bin_dir_path = ctx.bin_dir.path,
build_file_path = ctx.build_file_path,
Expand Down
Loading