Skip to content

Commit 6353b04

Browse files
authored
feat: added --version flag to CLI (#249)
* feat: added --version flag to CLI * executable wsc.sh and variable fixes * use GITHUB_REF if set * use GITHUB_REF if available (windows) * add windows build to github actions * update rules_blender
1 parent 66c373f commit 6353b04

File tree

7 files changed

+56
-5
lines changed

7 files changed

+56
-5
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ build --enable_runfiles
66

77
build:windows --platforms=//bazel/platforms:windows
88
build:windows --host_platform=//bazel/platforms:windows
9+
build:windows --workspace_status_command=bazel/tools/wsc.cmd
910

1011
build:linux --platforms=//bazel/platforms:linux
1112
build:linux --host_platform=//bazel/platforms:linux
1213
build:linux --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux
14+
build:linux --workspace_status_command=bazel/tools/wsc.sh
1315

1416
common:ci --announce_rc
1517
common:ci --disk_cache=~/.cache/bazel-disk-cache

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ jobs:
2828
key: ${{runner.os}}-bazel-cache
2929
- uses: actions/checkout@v3
3030
- run: bazel build --config=ci ...
31+
build-windows:
32+
runs-on: windows-latest
33+
steps:
34+
- uses: actions/cache@v3
35+
with:
36+
path: |
37+
/Users/runneradmin/AppData/Local/bazelisk
38+
/Users/runneradmin/.cache/bazel-disk-cache
39+
key: ${{runner.os}}-bazel-cache
40+
- uses: actions/checkout@v3
41+
- run: bazel build --config=ci //...
3142
check-dist:
3243
runs-on: ubuntu-latest
3344
steps:

WORKSPACE.bazel

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
5252

5353
rules_pkg_dependencies()
5454

55+
http_archive(
56+
name = "rules_cc_stamp",
57+
strip_prefix = "rules_cc_stamp-63d4861f4d420b574fa0f112599aae2b8aee785e",
58+
urls = ["https://github.com/zaucy/rules_cc_stamp/archive/63d4861f4d420b574fa0f112599aae2b8aee785e.zip"],
59+
sha256 = "f469a3b97eeabeb850c655f59ea17799ff40badd3a0b3e9de38534c89ad2f87d",
60+
)
61+
5562
http_archive(
5663
name = "ecsact_si_wasm",
5764
sha256 = "4153154fd80e2cd48ddd8e0d0c208691f134b33d5c67dc6fc081b3f77149b2c2",
@@ -188,9 +195,9 @@ bazel_skylib_workspace()
188195

189196
http_archive(
190197
name = "rules_blender",
191-
sha256 = "1ae03c77c6e41b90904296f8d6269c3de9ffa12d0faef997a50e4edb225ef64c",
192-
strip_prefix = "rules_blender-6f17aa27b6d76ecda9df0dab2be61adc2bc11c61",
193-
urls = ["https://github.com/zaucy/rules_blender/archive/6f17aa27b6d76ecda9df0dab2be61adc2bc11c61.zip"],
198+
sha256 = "734b08d1f0eb29a09f81509803cc324c2012a09f47e692a13c41af1370fcb648",
199+
strip_prefix = "rules_blender-ef5c746f0ef3e9b8523175bed4ac8e8157fe0be3",
200+
urls = ["https://github.com/zaucy/rules_blender/archive/ef5c746f0ef3e9b8523175bed4ac8e8157fe0be3.zip"],
194201
)
195202

196203
load("@rules_blender//:repo.bzl", "blender_repository")

bazel/tools/wsc.cmd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
3+
if "%GITHUB_REF%"=="" (
4+
for /f %%i in ('git describe --tags --abbrev^=0') do (
5+
set GITHUB_REF=%%i
6+
)
7+
)
8+
9+
echo STABLE_ECSACT_SDK_VERSION %GITHUB_REF%
10+

bazel/tools/wsc.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [[ -z "${GITHUB_REF}" ]]; then
6+
echo "STABLE_ECSACT_SDK_VERSION $(git describe --tags --abbrev=0)"
7+
else
8+
echo "STABLE_ECSACT_SDK_VERSION ${GITHUB_REF}"
9+
fi
10+

cli/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
load("@rules_cc_stamp//:index.bzl", "cc_stamp_header")
23
load("//bazel:copts.bzl", "copts")
34

45
package(default_visibility = ["//visibility:public"])
56

7+
cc_stamp_header(
8+
name = "bazel_stamp_header",
9+
out = "bazel_stamp_header.hh",
10+
)
11+
612
cc_binary(
713
name = "ecsact",
8-
srcs = ["cli.cc"],
14+
srcs = ["cli.cc", "bazel_stamp_header.hh"],
915
copts = copts,
16+
stamp = 1,
1017
deps = [
1118
"//cli/commands:codegen",
1219
"//cli/commands:command",

cli/cli.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44
#include <string_view>
55
#include <unordered_map>
6+
#include "cli/bazel_stamp_header.hh"
67

78
#include "./commands/command.hh"
89
#include "./commands/codegen.hh"
@@ -25,9 +26,9 @@ constexpr auto USAGE = R"(Ecsact SDK Command Line
2526
2627
Usage:
2728
ecsact (--help | -h)
29+
ecsact (--version | -v)
2830
ecsact config ([<options>...] | --help)
2931
ecsact codegen ([<options>...] | --help)
30-
3132
)";
3233

3334
std::string colorize_logo() {
@@ -74,6 +75,9 @@ int main(int argc, char* argv[]) {
7475
if(command == "-h" || command == "--help") {
7576
print_usage();
7677
return 0;
78+
} else if(command == "-v" || command == "--version") {
79+
std::cout << STABLE_ECSACT_SDK_VERSION << "\n";
80+
return 0;
7781
} else if(command.starts_with('-')) {
7882
std::cerr << "Expected subcommand and instead got '" << command << "'\n";
7983
print_usage();

0 commit comments

Comments
 (0)