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

fix(bazel): Always disable the disk cache #8811

Merged
merged 2 commits into from
Jun 28, 2024
Merged

Conversation

fviernau
Copy link
Member

@fviernau fviernau commented Jun 28, 2024

See individual commits.

@fviernau fviernau requested a review from a team as a code owner June 28, 2024 07:21
@fviernau
Copy link
Member Author

fviernau commented Jun 28, 2024

Reading up on [1], it may be better to always disable the disk cache. From the comments I guess that it
speeds up builds only if you make changes to the code / switch branches, which is not the case in ORT analysis.
Any thoughts @haikoschol @sschuberth ?

This can be done by:

        val modGraphProcess = run(
            "mod", "graph", "--output", "json", "--disk_cache", "\"\"", workingDir = projectDir
        )

[1] https://stackoverflow.com/questions/61282419/bazel-how-outputroot-and-disk-cache-relate-regarding-local-caching

@nnobelis
Copy link
Member

@fviernau As I mentioned in the issue, you need to specify the parameter (temp disk cache or no disk cache) to EVERY Bazel command run by ORT, even the --version.

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.79%. Comparing base (767475e) to head (5a6dbac).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8811   +/-   ##
=========================================
  Coverage     67.79%   67.79%           
  Complexity     1164     1164           
=========================================
  Files           243      243           
  Lines          7711     7711           
  Branches        861      861           
=========================================
  Hits           5228     5228           
  Misses         2127     2127           
  Partials        356      356           
Flag Coverage Δ
funTest-non-docker 33.96% <ø> (ø)
test 38.12% <ø> (ø)

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.

@fviernau
Copy link
Member Author

@fviernau As I mentioned in the issue, you need to specify the parameter (temp disk cache or no disk cache) to EVERY Bazel command run by ORT, even the --version.

Did I miss any bazel command invocations?

@@ -0,0 +1 @@
common --disk_cache=/non-existing-dir
Copy link
Member

Choose a reason for hiding this comment

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

Missing line at the end

@@ -20,6 +20,7 @@
package org.ossreviewtoolkit.plugins.packagemanagers.bazel
Copy link
Member

Choose a reason for hiding this comment

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

Commit message: fixes the related issue.

@nnobelis
Copy link
Member

nnobelis commented Jun 28, 2024

@fviernau As I mentioned in the issue, you need to specify the parameter (temp disk cache or no disk cache) to EVERY Bazel command run by ORT, even the --version.

Did I miss any bazel command invocations?

As I said version here https://github.com/oss-review-toolkit/ort/blob/main/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt#L85

@haikoschol
Copy link
Contributor

Reading up on [1], it may be better to always disable the disk cache. From the comments I guess that it speeds up builds only if you make changes to the code / switch branches, which is not the case in ORT analysis. Any thoughts @haikoschol @sschuberth ?

I agree that always disabling the disk cache seems like the best approach.

@fviernau
Copy link
Member Author

As I said version here https://github.com/oss-review-toolkit/ort/blob/main/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt#L85

I am able to run bazel --version successfully. Have you managed to reproduce the problem with bazel --version ?

@nnobelis
Copy link
Member

This is really strange. bazel version works fine in the CLI but it fails when ORT runs it:

Exception in thread "main" java.io.IOException: Running 'bazel version' in '/path' failed with exit code 2:
ERROR: /home/dockeruser/.cache/bazel_disk_cache (Permission denied)
ERROR: Error initializing RemoteModule

@nnobelis
Copy link
Member

@fviernau As a sidenote, please note that there is bazel version run by ORT which gives a verbose output and bazel --version which just give the version number.

Maybe we can use --version and remove transformBazelVersion alltogether.

@haikoschol Would it be ok?

@fviernau fviernau force-pushed the bazel-set-disk-cache branch from 17f0735 to 60f1cd1 Compare June 28, 2024 07:54
@sschuberth
Copy link
Member

bazel version works fine in the CLI but it fails when ORT runs it:

Maybe due to different implicit working directories?

@fviernau
Copy link
Member Author

Maybe due to different implicit working directories?

I've run bazel in the directory in which the .bazelrc resides in.

@fviernau fviernau changed the title fix(bazel): Use a fixed disk cache directory fix(bazel): Always disable the disk cache Jun 28, 2024
@fviernau fviernau requested a review from nnobelis June 28, 2024 07:56
@@ -171,7 +171,10 @@ class Bazel(
}.getOrNull()

private fun getDependencyGraph(projectDir: File, depDirectives: Map<String, BazelDepDirective>): Set<Scope> {
val modGraphProcess = run("mod", "graph", "--output", "json", workingDir = projectDir)
val modGraphProcess = run(
"mod", "graph", "--output", "json", "--disk_cache", "\"\"", workingDir = projectDir
Copy link
Member

Choose a reason for hiding this comment

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

I did my tests with run("mod", "graph", "--output", "json", "--disk_cache=", workingDir = projectDir) and it worked fine.

Copy link
Member

Choose a reason for hiding this comment

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

So you mean to remove the "dummy" "\"\"" argument in favor of adding a = after the option name?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

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 changed it as @nnobelis has put it.

@haikoschol
Copy link
Contributor

@fviernau As a sidenote, please note that there is bazel version run by ORT which gives a verbose output and bazel --version which just give the version number.

Maybe we can use --version and remove transformBazelVersion alltogether.

@haikoschol Would it be ok?

I don't see why not. Weird that I didn't discover --version myself back then.

BTW, I run Bazel through Bazelisk on my laptop, which seems to intercept the version command:

$ bazel version
Bazelisk version: 1.20.0
Build label: 7.2.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Tue Jun 25 15:53:57 2024 (1719330837)
Build timestamp: 1719330837
Build timestamp as int: 1719330837

And --version still has some more output than the version number, but again, might be a Bazelisk thing:

$ bazel --version
bazel 7.2.1

@fviernau fviernau force-pushed the bazel-set-disk-cache branch from 60f1cd1 to c727623 Compare June 28, 2024 08:04
@fviernau
Copy link
Member Author

fviernau commented Jun 28, 2024

Thanks guys, very helpful! I've added a commit to switch to bazel --version.

@fviernau fviernau requested a review from nnobelis June 28, 2024 08:06
@fviernau fviernau force-pushed the bazel-set-disk-cache branch from c727623 to 63a30bd Compare June 28, 2024 08:08
"transformBazelVersion()" should {
"remove everything except for the version number" {
val bazelVersionOutput = """
Bazelisk version: development
Copy link
Contributor

Choose a reason for hiding this comment

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

I even put the Bazelisk output in the test, even though I didn't use it in the Docker image. Surprising that this ever worked. 😅

override fun getVersionArguments() = "version"

override fun transformVersion(output: String) = transformBazelVersion(output)
override fun transformVersion(output: String) = output.removePrefix("bazel ")
Copy link
Member

@sschuberth sschuberth Jun 28, 2024

Choose a reason for hiding this comment

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

Nit: Maybe say "Using the default bazel --version..." to better explain why this works by basically just removing code.

@@ -171,7 +171,10 @@ class Bazel(
}.getOrNull()

private fun getDependencyGraph(projectDir: File, depDirectives: Map<String, BazelDepDirective>): Set<Scope> {
val modGraphProcess = run("mod", "graph", "--output", "json", workingDir = projectDir)
val modGraphProcess = run(
"mod", "graph", "--output", "json", "--disk_cache", "\"\"", workingDir = projectDir
Copy link
Member

Choose a reason for hiding this comment

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

So you mean to remove the "dummy" "\"\"" argument in favor of adding a = after the option name?

fviernau added 2 commits June 28, 2024 10:39
Using the default `bazel --version` is simpler and more resilient in
case of mis-configuration, such as the disk cache pointing to a
non-existing directory.

Signed-off-by: Frank Viernau <[email protected]>
When the disk-cache is set via `.bazelrc` to a non-existing directory,
`bazel mod graph` fails with a complaint about permissions, which in
turn makes the analysis fail.

The disk cache is a build cache which seems to target speeding up
builds in case of code changes (such as switching branches) [1]. During
ORT analysis code changes are not in play, so the disk cache seems to
be of little use anyway. Simply disable it to avoid running into that
permission issue.

Fixes: #8802.

[1] https://stackoverflow.com/questions/61282419/bazel-how-outputroot-and-disk-cache-relate-regarding-local-caching

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the bazel-set-disk-cache branch from 63a30bd to 5a6dbac Compare June 28, 2024 08:42
@fviernau fviernau requested a review from sschuberth June 28, 2024 08:43
@sschuberth sschuberth enabled auto-merge (rebase) June 28, 2024 08:50
@sschuberth sschuberth merged commit a6894a2 into main Jun 28, 2024
20 checks passed
@sschuberth sschuberth deleted the bazel-set-disk-cache branch June 28, 2024 08:58
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.

4 participants