Skip to content

feat: make --version flag optional build #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2023
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
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import %workspace%/bazel/common.bazelrc

common [email protected]//:use_std_fs
common --//:use_sdk_version
build:windows --workspace_status_command=bazel/tools/wsc.cmd
build:linux --workspace_status_command=bazel/tools/wsc.sh

Expand Down
9 changes: 9 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_ecsact//ecsact:toolchain.bzl", "ecsact_toolchain")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//bazel/tools:cc_stamp_header.bzl", "cc_stamp_header")
load("//bazel:copts.bzl", "copts")

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

bool_flag(name = "use_sdk_version", build_setting_default = False)
config_setting(name = "use_sdk_version_enabled", flag_values = {":use_sdk_version": "true"})
config_setting(name = "use_sdk_version_disabled", flag_values = {":use_sdk_version": "false"})

cc_stamp_header(
name = "bazel_stamp_header",
out = "bazel_stamp_header.hh",
Expand All @@ -16,6 +21,10 @@ cc_binary(
"ecsact_cli.cc",
"bazel_stamp_header.hh",
],
defines = select({
":use_sdk_version_enabled": ["ECSACT_CLI_USE_SDK_VERSION"],
":use_sdk_version_disabled": [],
}),
copts = copts,
stamp = 1,
deps = [
Expand Down
13 changes: 11 additions & 2 deletions ecsact_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,19 @@ int main(int argc, char* argv[]) {
if(command == "-h" || command == "--help") {
print_usage();
return 0;
} else if(command == "-v" || command == "--version") {
}

if(command == "-v" || command == "--version") {
#ifdef ECSACT_CLI_USE_SDK_VERSION
std::cout << STABLE_ECSACT_SDK_VERSION << "\n";
return 0;
} else if(command.starts_with('-')) {
#else
std::cerr << "No version available in this build\n";
return 1;
#endif
}

if(command.starts_with('-')) {
std::cerr << "Expected subcommand and instead got '" << command << "'\n";
print_usage();
return 1;
Expand Down
2 changes: 0 additions & 2 deletions test/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import %workspace%/../bazel/common.bazelrc

common [email protected]//:use_std_fs
build:windows --workspace_status_command=../bazel/tools/wsc.cmd
build:linux --workspace_status_command=../bazel/tools/wsc.sh

try-import %workspace%/user.bazelrc