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

Bazel: various fixes #9243

Merged

Conversation

nnobelis
Copy link
Member

@nnobelis nnobelis commented Oct 4, 2024

Please have a look at the individual commit messages for the details.

@nnobelis nnobelis requested a review from a team as a code owner October 4, 2024 13:32
@@ -50,6 +52,11 @@ internal class MultiBazelModuleRegistryService(
// Add the default Bazel registry as a fallback.
val registryUrls = (urls + DEFAULT_URL).distinctBy { it.removeSuffix("/") }

logger.info { "Creating a multi Bazel module registry:" }
Copy link
Member

Choose a reason for hiding this comment

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

IMO this should be debug instead of info.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since the logging occurs only one, I think there is no harm in letting it to info, especially considering how noisy debug is.

@@ -110,9 +110,9 @@ class Bazel(
super.run(
args = args,
workingDir = workingDir,
// Disable the optional wrapper script under `tools/bazel`, to ensure the --version option works.
// Disable the optional wrapper script under `tools/bazel` only for the "--version" call.
Copy link
Member

Choose a reason for hiding this comment

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

can be relevant by defining

I don't understand this. Do you mean "can be relevant e.g. in case a specific '.bazelrc'
depending on the value of an environment variable is defined"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to explain the setup of our customer project and the phrasing is quite difficult...

They have in their project a wrapper script in tools/bazel. This script reads an environment variable and, depending on its value, change the .bazelrc of the project.
Therefore when you call bazel mod graph, this script "setups" your build environment depending on this environment variable.
However, bazel uses this script for all commands even if you call bazel version. In that case, the script fails because it does not support the --version parameter. While the correct fix would be to change the wrapper script to support this parameter, this is not possible to force all the projects to do so.
And, in all cases, ORT must make sure that the wrapper script is enabled when mod graph is called, as it may contain some build changing logic as described above.

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.65%. Comparing base (46afc3a) to head (e4046fe).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9243   +/-   ##
=========================================
  Coverage     67.65%   67.65%           
  Complexity     1185     1185           
=========================================
  Files           239      239           
  Lines          7795     7795           
  Branches        899      899           
=========================================
  Hits           5274     5274           
  Misses         2153     2153           
  Partials        368      368           
Flag Coverage Δ
funTest-docker 60.23% <ø> (ø)
funTest-non-docker 34.71% <ø> (ø)
test 37.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nnobelis nnobelis force-pushed the nnobelis/bazel_metadata branch 2 times, most recently from 278302b to dffeaae Compare October 7, 2024 09:18
Copy link
Member

@sschuberth sschuberth left a comment

Choose a reason for hiding this comment

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

Sorry for some follow-up requests for changes.

@@ -35,7 +35,7 @@ const val SOURCE_JSON = "source.json"
/**
* A Bazel registry which is located on the local file system.
*/
class LocalBazelModuleRegistryService(directory: File) : BazelModuleRegistryService {
class LocalBazelModuleRegistryService(val url: String, directory: File) : BazelModuleRegistryService {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, same thing here: Drop val. The inspection did not trigger here as the properly is public currently.

Copy link
Member

Choose a reason for hiding this comment

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

Also, please document the url and directory constructor parameters to explain their relation (e.g., I was wondering whether the directory can't be deduced from the file://-type url).

Comment on lines 36 to 37
* A remote Bazel Module Registry, based on the directory structure of https://bcr.bazel.build/ and the Git repository
* it is based on (https://github.com/bazelbuild/bazel-central-registry/).
Copy link
Member

Choose a reason for hiding this comment

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

Also here, while rewording the docs anyway, please incorporate the client and baseUrl parameters to explain their meaning.

@sschuberth
Copy link
Member

Please have a look at the MockKException in MultiBazelModuleRegistryServiceTest.

The `MultiBazelModuleRegistryService` tries several Bazel registries one
after each other in order to query the `metadata.json` and the
`source.json` of a module. If this information cannot be resolved, the
server collates all the error messages and outputs them. To facilitate the
analysis of the logs, each error message is now prefixed with the URL of
the registry that created it.
The URL property is now provided by each Bazel registry service. This
required making `RemoteBazelModuleRegistryService.kt` a proper class that
delegates the module lookups to a Retrofit client.

Signed-off-by: Nicolas Nobelis <[email protected]>
@sschuberth sschuberth enabled auto-merge (rebase) October 7, 2024 13:31
@sschuberth
Copy link
Member

Sorry again for finding more (optional) stuff:

chore(bazel): Support github in the module metadata JSON file

Shouldn't this be "feat" instead of "chore?

chore(bazel): Disable the wrapper script only for the --version call

Shouldn't this say "fix" instead of "chore"? Otherwise there wouldn't be a single "fix" commit in this "Bazel: various fixes" PR 😉

This is currently unused (as the whole `Maintainer` class) but it contains
information that could be relevant in the future. See [1].

[1]: https://github.com/bazelbuild/bazel-central-registry/blob/main/metadata.schema.json

Signed-off-by: Nicolas Nobelis <[email protected]>
The wrapper script can be relevant by defining e.g. a specific '.bazelrc'
depending on the value of an environment variable.
This is a fixup for 310470d.

Signed-off-by: Nicolas Nobelis <[email protected]>
@nnobelis nnobelis enabled auto-merge (rebase) October 7, 2024 13:38
@nnobelis nnobelis merged commit 1d71126 into oss-review-toolkit:main Oct 7, 2024
23 checks passed
@nnobelis nnobelis deleted the nnobelis/bazel_metadata branch October 7, 2024 14:01
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.

2 participants