Skip to content

Commit

Permalink
chore(bazel): Simplify obtaining the Bazel version
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
fviernau authored and sschuberth committed Jun 28, 2024
1 parent 767475e commit fd6b3fb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
12 changes: 1 addition & 11 deletions plugins/package-managers/bazel/src/main/kotlin/Bazel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
19 changes: 0 additions & 19 deletions plugins/package-managers/bazel/src/test/kotlin/BazelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,13 @@ 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
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/")
Expand Down

0 comments on commit fd6b3fb

Please sign in to comment.