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

Add support for overlay in source.json #2046

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fzakaria
Copy link

@fzakaria fzakaria commented May 16, 2024

  • Add support for overlay key in source.json
  • Automatically set BUILD.bazel and MODULE.bazel in the overlay key rather than creating patches for them.
  • Remove validation for MODULE.bazel in patches as this is no longer needed.

Tested by building a new version of asio at 1.29.0 done locally.

{
    "url": "https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-29-0.zip",
    "integrity": "sha256-RaeWfpu/6LevQE2urtS5IU/WY77wCtT1LDySOZKXRFs=",
    "overlay": {
        "MODULE.bazel": "sha256-GC9+wtNSPwyvW68p87iJ3AZSNJw9fm96hU0/CFnyfWg=",
        "BUILD.bazel": "sha256-+XSYvh+c3DMc1ypmCpO423qgidC0BnlH5stG+aRipBo="
    },
    "strip_prefix": "asio-asio-1-29-0/asio/include",
    "patch_strip": 0
}
$ cat MODULE.bazel
bazel_dep(name = "asio", version = "1.29.0")

$ ../bazel/bazel-bin/src/bazel-dev build @asio//:asio --registry="file:///workspaces/bazel-central-registry"
INFO: Analyzed target @@asio~//:asio (70 packages loaded, 940 targets configured).
INFO: Found 1 target...
Target @@asio~//:asio up-to-date (nothing to build)
INFO: Elapsed time: 2.772s, Critical Path: 0.07s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

This change requires bazel#22349

fixed #1566

* Add support for overlay key in source.json
* Automatically set BUILD.bazel and MODULE.bazel in the overlay key
rather than creating patches for them.
* Remove validation for MODULE.bazel in patches as this is no longer
needed.

Tested by building a new version of asio at 1.29.0 done locally.

```json
{
    "url": "https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-29-0.zip",
    "integrity": "sha256-RaeWfpu/6LevQE2urtS5IU/WY77wCtT1LDySOZKXRFs=",
    "overlay": {
        "MODULE.bazel": "sha256-GC9+wtNSPwyvW68p87iJ3AZSNJw9fm96hU0/CFnyfWg=",
        "BUILD.bazel": "sha256-+XSYvh+c3DMc1ypmCpO423qgidC0BnlH5stG+aRipBo="
    },
    "strip_prefix": "asio-asio-1-29-0/asio/include",
    "patch_strip": 0
}
```
```console
$ ../bazel/bazel-bin/src/bazel-dev build @asio//:asio --registry="file:///workspaces/bazel-central-registry"
INFO: Analyzed target @@asio~//:asio (70 packages loaded, 940 targets configured).
INFO: Found 1 target...
Target @@asio~//:asio up-to-date (nothing to build)
INFO: Elapsed time: 2.772s, Critical Path: 0.07s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
@fzakaria

This comment was marked as outdated.

Comment on lines -229 to -248
source_module_dot_bazel = source_root.joinpath("MODULE.bazel")
if source_module_dot_bazel.exists():
source_module_dot_bazel_content = open(source_module_dot_bazel, "r").readlines()
else:
source_module_dot_bazel_content = []
bcr_module_dot_bazel_content = open(self.registry.get_module_dot_bazel_path(module_name, version), "r").readlines()
source_module_dot_bazel_content = fix_line_endings(source_module_dot_bazel_content)
bcr_module_dot_bazel_content = fix_line_endings(bcr_module_dot_bazel_content)
file_name = "a/" * int(source.get("patch_strip", 0)) + "MODULE.bazel"
diff = list(unified_diff(source_module_dot_bazel_content, bcr_module_dot_bazel_content, fromfile=file_name, tofile=file_name))

if diff:
self.report(BcrValidationResult.FAILED,
"Checked in MODULE.bazel file doesn't match the one in the extracted and patched sources.\n"
+ f"Please fix the MODULE.bazel file or you can add the following patch to {module_name}@{version}:\n"
+ " " + " ".join(diff))
if self.should_fix:
self.add_module_dot_bazel_patch(diff, module_name, version)
else:
self.report(BcrValidationResult.GOOD, "Checked in MODULE.bazel matches the sources.")
Copy link
Author

Choose a reason for hiding this comment

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

If we expect all new versions to include overlay -- I think it's simpler to remove this functionality entirely.
We don't need to support it for older versions as they are already "validated"

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's reasonable to assume that all new versions will only support Bazel 7.2.0+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Idea] Support Starlark overlays without patches
2 participants