This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Add build info #278
Merged
Merged
feat: Add build info #278
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d177d6d
Added spanner/internal/build_info.cc.in and friends
devjgm 31aa056
formatted
devjgm d33d4b4
fixed regex
devjgm e0a155b
fixed include guards
devjgm 669100d
changed formatting of most functions
devjgm 2ed2a45
reverted regex changes
devjgm efb2886
better deduping of punct
devjgm 364db20
added scripts to make bazel build look like cmake build
devjgm 8f298fe
formatted
devjgm b648b60
wording
devjgm 10260e5
use bazel's location function to find scripts
devjgm 1fbc12a
PR comments: fixed some //build and //ci scripts
devjgm 2bf41cb
changed usage-check in scripts
devjgm b986577
fixed bazel's git commit stamping
devjgm b68b38b
relax compiler ID regex to work with AppleClang and others
devjgm a01f00e
formatted
devjgm 8994355
renamed CompilerFlags -> BuildFlags
devjgm 8ac854d
removes 'sha.' prefix from build metadata
devjgm 12b9a53
removed workspace_status_command; bazel builds never know git commit
devjgm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,48 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Given an argument that is the path to a compiler, tries to determine an | ||
# identification string for the compiler according to the CMake-defined IDs: | ||
# https://cmake.org/cmake/help/v3.5/variable/CMAKE_LANG_COMPILER_ID.html | ||
|
||
if [[ $# -ne 1 ]]; then | ||
echo "Usage: $0 <path-to-compiler>" | ||
exit 1 | ||
fi | ||
|
||
version="$("${1}" --version 2> /dev/null \ | ||
| head -1 \ | ||
| tr '[:upper:]' '[:lower:]')" | ||
|
||
case "${version}" in | ||
*gcc* | *g++*) | ||
echo "GNU" | ||
;; | ||
|
||
*clang*) | ||
echo "Clang" | ||
;; | ||
|
||
*msvc* | *microsoft*) | ||
# I don't think "--version" above will actually work on Windows, so we | ||
# should figure out how to do that correctly. See #281. | ||
echo "MSVC" | ||
;; | ||
|
||
*) | ||
echo "unknown" | ||
;; | ||
esac |
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,34 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Given an argument that is the path to a compiler, tries to determine | ||
# the compiler's version by looking for the first string that looks like | ||
# X.Y with more optional numbers, '.', '-', and '+'. | ||
|
||
if [[ $# -ne 1 ]]; then | ||
echo "Usage: $0 <path-to-compiler>" | ||
exit 1 | ||
fi | ||
|
||
version="$("${1}" --version 2> /dev/null \ | ||
| grep -Eo "[0-9]+\.[0-9.+-]+" \ | ||
| head -1)" | ||
|
||
if [[ -n "${version}" ]]; then | ||
echo "${version}" | ||
else | ||
echo unknown | ||
fi |
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
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
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
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
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
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,94 @@ | ||
// Copyright 2017 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/spanner/internal/build_info.h" | ||
#include "google/cloud/internal/port_platform.h" | ||
#include <algorithm> | ||
#include <cctype> | ||
#include <iterator> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace spanner { | ||
inline namespace SPANNER_CLIENT_NS { | ||
namespace internal { | ||
|
||
std::string CompilerId() { return R"""(@CMAKE_CXX_COMPILER_ID@)"""; } | ||
|
||
std::string CompilerVersion() { return R"""(@CMAKE_CXX_COMPILER_VERSION@)"""; } | ||
|
||
std::string BuildFlags() { | ||
static auto const* const kFlags = [] { | ||
auto* flags = new std::string(R"""(@CMAKE_CXX_FLAGS@)"""); | ||
if (!flags->empty()) *flags += ' '; | ||
*flags += | ||
R"""(${CMAKE_CXX_FLAGS_${GOOGLE_CLOUD_CPP_SPANNER_BUILD_TYPE_UPPER}})"""; | ||
return flags; | ||
}(); | ||
return *kFlags; | ||
} | ||
|
||
std::string CompilerFeatures() { | ||
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS | ||
return "ex"; | ||
#else | ||
return "noex"; | ||
#endif // GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS | ||
} | ||
|
||
std::string LanguageVersion() { | ||
static auto const* const kLanguageVersion = [] { | ||
auto* s = new std::string; | ||
switch (__cplusplus) { | ||
case 199711L: | ||
*s += "98"; | ||
break; | ||
case 201103L: | ||
*s += "2011"; | ||
break; | ||
case 201402L: | ||
*s += "2014"; | ||
break; | ||
case 201703L: | ||
*s += "2017"; | ||
break; | ||
default: | ||
*s += "unknown"; | ||
} | ||
return s; | ||
}(); | ||
return *kLanguageVersion; | ||
} | ||
|
||
bool IsRelease() { | ||
static bool const kIsRelease = []() -> bool { | ||
// NOLINTNEXTLINE(readability-redundant-string-init) | ||
std::string value = R"""(@GOOGLE_CLOUD_CPP_SPANNER_IS_RELEASE@)"""; | ||
for (char& c : value) { | ||
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); | ||
} | ||
return value == "yes" || value == "1" || value == "true"; | ||
}(); | ||
return kIsRelease; | ||
} | ||
|
||
std::string BuildMetadata() { | ||
return R"""(@GOOGLE_CLOUD_CPP_SPANNER_BUILD_METADATA@)"""; | ||
} | ||
|
||
} // namespace internal | ||
} // namespace GOOGLE_CLOUD_CPP_NS | ||
} // namespace spanner | ||
} // namespace cloud | ||
} // namespace google |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to support multiple compilers, the script will probably grow larger as we detect the executable and use the appropriate switch/flags. Just spitballing, but what do you think about adopting an approach similar to this? TL;DR, compile a program in Bazel that uses compiler-specific version macros then spits out the information.