From fd6b3fb946c5f3cc5a7b1e2cc52f324bcfbf6580 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Fri, 28 Jun 2024 10:03:01 +0200 Subject: [PATCH] chore(bazel): Simplify obtaining the Bazel version 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 --- .../bazel/src/main/kotlin/Bazel.kt | 12 +----------- .../bazel/src/test/kotlin/BazelTest.kt | 19 ------------------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt index cab4123c4b254..c289d4e8ddaf4 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt @@ -82,9 +82,7 @@ class Bazel( override fun command(workingDir: File?) = "bazel" - override fun getVersionArguments() = "version" - - override fun transformVersion(output: String) = transformBazelVersion(output) + override fun transformVersion(output: String) = output.removePrefix("bazel ") // Bazel 6.0 already supports bzlmod but it is not enabled by default. // Supporting it would require adding the flag "--enable_bzlmod=true" at the correct position of all bazel @@ -204,14 +202,6 @@ class Bazel( ) } -internal fun transformBazelVersion(output: String) = - output.lineSequence() - .find { it.startsWith("Build label") } - .orEmpty() - .split(':') - .getOrElse(1) { "" } - .trim() - private fun ModuleMetadata.vcsInfo(): VcsInfo { val repo = repository?.firstOrNull().orEmpty() diff --git a/plugins/package-managers/bazel/src/test/kotlin/BazelTest.kt b/plugins/package-managers/bazel/src/test/kotlin/BazelTest.kt index c573bb261b41d..de237945e455f 100644 --- a/plugins/package-managers/bazel/src/test/kotlin/BazelTest.kt +++ b/plugins/package-managers/bazel/src/test/kotlin/BazelTest.kt @@ -22,7 +22,6 @@ package org.ossreviewtoolkit.plugins.packagemanagers.bazel import io.kotest.core.spec.style.WordSpec import io.kotest.engine.spec.tempdir import io.kotest.matchers.collections.beEmpty -import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNot import org.ossreviewtoolkit.model.config.AnalyzerConfiguration @@ -30,24 +29,6 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.utils.test.getAssetFile class BazelTest : WordSpec({ - "transformBazelVersion()" should { - "remove everything except for the version number" { - val bazelVersionOutput = """ - Bazelisk version: development - WARNING: Invoking Bazel in batch mode since it is not invoked from within a workspace (below a directory having a WORKSPACE file). - OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release. - Build label: 7.0.1 - Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer - Build time: Thu Jan 18 18:05:58 2024 (1705601158) - Build timestamp: 1705601158 - Build timestamp as int: 1705601158 - """.trimIndent() - - val result = transformBazelVersion(bazelVersionOutput) - result shouldBe "7.0.1" - } - } - "Bazel package manager" should { "support local registry" { val projectAssets = getAssetFile("projects/synthetic/bazel-local-registry/")