From 60f1cd15a1cbb6bf1fdd1bbcdc8e25e6bc6b9041 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Fri, 28 Jun 2024 08:57:28 +0200 Subject: [PATCH] fix(bazel): Always disable the disk cache 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 --- .../src/funTest/assets/projects/synthetic/bazel/.bazelrc | 1 + plugins/package-managers/bazel/src/main/kotlin/Bazel.kt | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel/.bazelrc diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel/.bazelrc b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel/.bazelrc new file mode 100644 index 0000000000000..962c769bcc2b1 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel/.bazelrc @@ -0,0 +1 @@ +common --disk_cache=/non-existing-dir diff --git a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt index cab4123c4b254..73b19a8b7dfe1 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt @@ -171,7 +171,10 @@ class Bazel( }.getOrNull() private fun getDependencyGraph(projectDir: File, depDirectives: Map): Set { - val modGraphProcess = run("mod", "graph", "--output", "json", workingDir = projectDir) + val modGraphProcess = run( + "mod", "graph", "--output", "json", "--disk_cache", "\"\"", workingDir = projectDir + ) + val node = JSON.decodeFromString(modGraphProcess.stdout) val devDeps = node.dependencies.filter { depDirectives[it.key]?.devDependency == true }.toSet() val mainDeps = node.dependencies.toSet() - devDeps