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

Use bazel's native json decode method #659

Merged
merged 2 commits into from
Mar 24, 2022
Merged

Conversation

shs96c
Copy link
Collaborator

@shs96c shs96c commented Jan 19, 2022

This means that rules_jvm_external is only compatible with
Bazel 4 and later. That shipped on 2021-01-21, and so should
be widely adopted already. Older versions of this ruleset
will continue to work for repos using older versions of Bazel
so it's not removing any existing functionality, and the new
Bazel 5 release should have already shipped.

The main reason for doing this is that the native json
decoding is significantly faster than the starlark-based one.

The following options were explored as alternatives:

  1. Making the json_parse method check the bazel version and
    optionally use the json module if it was present. This
    doesn't work because of
    Starlark: provide a way to probe builtins availability bazel#12735
  2. Create a json repository rule that creates a repo that
    exposes a json.bzl file that delegates to the native
    json module if present, or the starlark one if not
    (as determined by looking at the major version number of
    bazel). This doesn't work because maven_install is used
    by RJE's own repositories.bzl file, so there's no chance
    to load the repository rule before it's needed.

@shs96c shs96c force-pushed the native-json branch 2 times, most recently from e9681e6 to 3e10de6 Compare January 28, 2022 10:07
This means that `rules_jvm_external` is only compatible with
Bazel 4 and later. That shipped on 2021-01-21, and so should
be widely adopted already. Older versions of this ruleset
will continue to work for repos using older versions of Bazel
so it's not removing any existing functionality, and the new
Bazel 5 release should have already shipped.

The main reason for doing this is that the native json
decoding is significantly faster than the starlark-based one.

The following options were explored as alternatives:

1. Making the `json_parse` method check the bazel version and
   optionally use the `json` module if it was present. This
   doesn't work because of #12735

2. Create a `json` repository rule that creates a repo that
   exposes a `json.bzl` file that delegates to the native
   `json` module if present, or the starlark one if not
   (as determined by looking at the major version number of
   bazel). This doesn't work because `maven_install` is used
   by RJE's own `repositories.bzl` file, so there's no chance
   to load the repository rule before it's needed.

Links:

12735: bazelbuild/bazel#12735
Copy link
Member

@jin jin left a comment

Choose a reason for hiding this comment

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

nice! some nits.

coursier.bzl Outdated
@@ -132,7 +122,9 @@ def _execute(repository_ctx, cmd, timeout = 600, environment = {}, progress_mess
# The representation of a Windows path when read from the parsed Coursier JSON
# is delimited by 4 back slashes. Replace them with 1 forward slash.
def _normalize_to_unix_path(path):
return path.replace("\\\\", "/")
if path == None:
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? Seems error prone to have None paths being passed around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just being paranoid. I'll back it out.

coursier.bzl Outdated
@@ -227,7 +219,7 @@ def _compute_dependency_tree_signature(artifacts):
if artifact["file"] != None:
artifact_group.extend([
artifact["sha256"],
artifact["file"],
artifact["file"].replace("\\", "/"), # Make sure we represent files in a stable way cross-platform
Copy link
Member

Choose a reason for hiding this comment

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

why not use _normalize_to_unix_path? here and below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@shs96c shs96c merged commit 156ba5b into bazelbuild:master Mar 24, 2022
@shs96c shs96c deleted the native-json branch March 24, 2022 15:36
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.

None yet

2 participants