Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ run -c opt --show_loading_progress=false --show_progress=false --ui_event_filter
run:verbose -c dbg --show_loading_progress=true --show_progress=true --ui_event_filters=info,error,debug
# https://github.com/mockito/mockito/issues/1879
test --sandbox_tmpfs_path=/tmp

# To allow stamping git tag for version.
build --workspace_status_command=$(pwd)/workspace_status.sh
12 changes: 12 additions & 0 deletions cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ config_setting(
},
)

genrule(
name = "version_file",
srcs = [],
outs = ["version"],
cmd_bash = """
version_tag=$$(grep ^STABLE_GIT_TAG bazel-out/stable-status.txt | cut -d' ' -f2); \
printf '%s' $$version_tag > $@;
""",
stamp = 1,
)

java_binary(
name = "bazel-diff",
jvm_flags = select({
Expand All @@ -22,6 +33,7 @@ java_binary(
kt_jvm_library(
name = "cli-lib",
srcs = glob(["src/main/kotlin/**/*.kt"]),
resources = [":version_file"],
deps = [
"@bazel_diff_maven//:com_google_code_gson_gson",
"@bazel_diff_maven//:com_google_guava_guava",
Expand Down
9 changes: 8 additions & 1 deletion cli/src/main/kotlin/com/bazel_diff/cli/VersionProvider.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.bazel_diff.cli

import picocli.CommandLine.IVersionProvider
import java.io.BufferedReader
import java.io.InputStreamReader

class VersionProvider : IVersionProvider {
override fun getVersion(): Array<String> {
return arrayOf("7.0.0")
val classLoader = this::class.java.classLoader
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make more sense to simply make a bazel rule that can accept the stable-status path and code gen this entire file? Seems like there are a couple steps here that could be collapsed into one?

val inputStream = classLoader.getResourceAsStream("cli/version")
?: throw IllegalArgumentException("unknown version as version file not found in resources")

val version = BufferedReader(InputStreamReader(inputStream)).use { it.readText().trim() }
return arrayOf(version)
}
}
4 changes: 4 additions & 0 deletions workspace_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Get the current Git tag or default to the commit hash
echo "STABLE_GIT_TAG $(git describe --tags --abbrev=0 2>/dev/null || git rev-parse HEAD)"