-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f4be763
Showing
13 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
workspace_status_command.exe | ||
workspace_status_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Building on non-windows with not clang-cl is not supported at this time | ||
# See issue: https://github.com/zaucy/ZoneControl/issues/82 | ||
build --compiler=clang-cl | ||
build --cxxopt=-fcolor-diagnostics | ||
build --cxxopt=-fansi-escape-codes | ||
build --cxxopt=/D_HAS_DEPRECATED_RESULT_OF=1 | ||
build --cxxopt=-Xclang | ||
build --cxxopt=-std=c++20 | ||
build --cxxopt=/Zc:__cplusplus | ||
|
||
# For boost, because it's really annoying. | ||
build --cxxopt=-Wno-macro-redefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.7.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
steps: | ||
- command: bazel build //... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/bazel-* | ||
/workspace_status_command.exe | ||
/workspace_status_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
load("@bzlws//:index.bzl", "bzlws_copy") | ||
load("@com_github_zaucy_rules_7zip//:defs.bzl", "pkg_7z") | ||
|
||
cc_binary( | ||
name = "workspace_status_command", | ||
visibility = ["//visibility:public"], | ||
srcs = ["workspace_status_command.cc"], | ||
defines = ["_SILENCE_CLANG_COROUTINE_MESSAGE=1"], | ||
deps = [ | ||
"@boost//:process", | ||
"@boost//:asio", | ||
], | ||
) | ||
|
||
bzlws_copy( | ||
name = "copy_workspace_status_command", | ||
out = "{FILENAME}", | ||
srcs = [":workspace_status_command"], | ||
) | ||
|
||
pkg_7z( | ||
name = "archive", | ||
extension = "zip", | ||
srcs = [ | ||
":workspace_status_command", | ||
"workspace_status.bat", | ||
"workspace_status.cmd", | ||
"workspace_status.sh", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
workspace(name = "zonecontrol_workspace_status_command") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
||
git_repository( | ||
name = "com_github_nelhage_rules_boost", | ||
commit = "df0dd370588b2e3b2307cc38872970397e76757b", | ||
remote = "https://github.com/zaucy/rules_boost", | ||
shallow_since = "1594588553 -0700", | ||
) | ||
|
||
http_archive( | ||
name = "boost", | ||
build_file = "@com_github_nelhage_rules_boost//:BUILD.boost", | ||
sha256 = "4eb3b8d442b426dc35346235c8733b5ae35ba431690e38c6a8263dce9fcbb402", | ||
strip_prefix = "boost_1_73_0", | ||
patches = [ | ||
# Temporary until https://github.com/boostorg/process/pull/167 gets | ||
# merged and released | ||
"//patches:boost_process_windows_file_descriptor.patch", | ||
], | ||
urls = [ | ||
"https://mirror.bazel.build/dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.bz2", | ||
"https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.bz2", | ||
], | ||
) | ||
|
||
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps") | ||
boost_deps() | ||
|
||
http_archive( | ||
name = "bzlws", | ||
strip_prefix = "bzlws-2c8efaf333818925490de36e2fb7c266f0b0bd40", | ||
url = "https://github.com/zaucy/bzlws/archive/2c8efaf333818925490de36e2fb7c266f0b0bd40.zip", | ||
sha256 = "14db184ec822cfa53449e34b551f3804a2acc087acfbec4dc7f139d1dbb65028", | ||
) | ||
|
||
load("@bzlws//:repo.bzl", "bzlws_deps") | ||
bzlws_deps() | ||
|
||
http_archive( | ||
name = "com_github_zaucy_rules_7zip", | ||
strip_prefix = "rules_7zip-7c9fb2b1bdab4d4c3fdd49b1e12d21a5b728dc57", | ||
urls = ["https://github.com/zaucy/rules_7zip/archive/7c9fb2b1bdab4d4c3fdd49b1e12d21a5b728dc57.zip"], | ||
sha256 = "7adf6bcd53403ab9a44d8b42db0e8afe7fd547dbee21a5c6f5479966d96462a5", | ||
) | ||
|
||
load("@com_github_zaucy_rules_7zip//:setup.bzl", "setup_7zip") | ||
setup_7zip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
exports_files(glob(["*.patch"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- boost/process/detail/windows/file_descriptor.hpp | ||
+++ boost/process/detail/windows/file_descriptor.hpp | ||
@@ -102,6 +102,7 @@ struct file_descriptor | ||
if (_handle != ::boost::winapi::INVALID_HANDLE_VALUE_) | ||
::boost::winapi::CloseHandle(_handle); | ||
_handle = boost::exchange(other._handle, ::boost::winapi::INVALID_HANDLE_VALUE_); | ||
+ return *this; | ||
} | ||
|
||
~file_descriptor() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
:; ./workspace_status.sh "$@" | ||
:; exit | ||
|
||
@ECHO OFF | ||
|
||
@REM Workaround to have workspace status command on both UNIX based systems and | ||
@REM Windows: https://github.com/bazelbuild/bazel/issues/5958 | ||
|
||
%~dp0\workspace_status.cmd %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%~dp0\workspace_status_command.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
./workspace_status_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
#include <future> | ||
#include <boost/process.hpp> | ||
#include <boost/asio.hpp> | ||
|
||
namespace bp = boost::process; | ||
namespace asio = boost::asio; | ||
|
||
struct build_info { | ||
/// Commit hash | ||
std::string commit; | ||
|
||
/// If the current commit belongs to a tag | ||
std::string tag; | ||
|
||
/// Current working tree has uncommitted changes | ||
bool dirty; | ||
}; | ||
|
||
static build_info get_build_info(); | ||
|
||
int main() { | ||
try { | ||
auto build_info = get_build_info(); | ||
|
||
std::cout | ||
<< "STABLE_GIT_COMMIT " << build_info.commit << "\n" | ||
<< "STABLE_GIT_TAG " << build_info.tag << "\n" | ||
<< "STABLE_GIT_DIRTY " << (build_info.dirty ? "true" : "false") << "\n"; | ||
} catch(const std::exception& err) { | ||
std::cerr << "EXCEPTION THROWN: " << err.what() << std::endl; | ||
return 2; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
std::string parse_git_commit_output | ||
( std::string&& output | ||
) | ||
{ | ||
return output; | ||
} | ||
|
||
std::string parse_git_tag_output | ||
( std::string&& output | ||
) | ||
{ | ||
return output; | ||
} | ||
|
||
bool parse_git_dity_output | ||
( std::string&& output | ||
) | ||
{ | ||
return output.ends_with("-dirty") | ||
|| output.ends_with("-broken"); | ||
} | ||
|
||
std::string get_system_output | ||
( std::string cmd | ||
) | ||
{ | ||
bp::ipstream stdout_stream; | ||
bp::ipstream stderr_stream; | ||
auto exit_code = bp::system( | ||
cmd, | ||
bp::std_out > stdout_stream, | ||
bp::std_err > stderr_stream | ||
); | ||
|
||
std::string line; | ||
if(exit_code == 0) { | ||
std::getline(stdout_stream, line); | ||
return line; | ||
} | ||
|
||
std::getline(stderr_stream, line); | ||
std::cerr | ||
<< "'" << cmd << "' exited with code " << exit_code << ": " << line << cmd; | ||
std::exit(1); | ||
|
||
return line; | ||
} | ||
|
||
build_info get_build_info() { | ||
return build_info{ | ||
.commit = get_system_output("git rev-parse HEAD"), | ||
.tag = get_system_output("git tag --points-at HEAD"), | ||
.dirty = parse_git_dity_output( | ||
get_system_output("git describe --always --dirty --broken") | ||
), | ||
}; | ||
} |