-pull/812/head 201908089ee91d3e43
Export of internal Abseil changes by Abseil Team <absl-team@google.com> -8efba58a3b
Export of internal Abseil changes by Abseil Team <absl-team@google.com> -b49b8d16b6
Export of internal Abseil changes by Abseil Team <absl-team@google.com> -67222ffc4c
Export of internal Abseil changes by Abseil Team <absl-team@google.com> -c5c4db4f51
Export of internal Abseil changes by Abseil Team <absl-team@google.com> -14550beb3b
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -52e88ee56b
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -36d37ab992
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -ad1485c898
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -f3840bc5e3
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -278b26058c
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -c6c3c1b498
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -44efe96dfc
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -3c98fcc046
Merge pull request #340 from jtsylve/macos_cxx17_fix by Matt Calabrese <38107210+mattcalabrese-google@users.noreply.github.com> -74d91756c1
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -e6b050212c
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -c964fcffac
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -72e09a54d9
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -d65e19dfcd
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -5162fc83d2
Merge pull request #336 from shields/patch-2 by Shaindel Schwartz <31392632+shaindelschwartz@users.noreply.github.com> -0389f7bf58
Merge pull request #335 from shields/patch-1 by Shaindel Schwartz <31392632+shaindelschwartz@users.noreply.github.com> -e9324d926a
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -43ef2148c0
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -a13d3df2b3
Merge pull request #323 from gosnik/master by Gennadiy Rozental <rogeeff@google.com> -310a11865c
Merge pull request #324 from RasPat1/patch-1 by Gennadiy Rozental <rogeeff@google.com> -8f11724067
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -b1dd425423
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -361cb8a9db
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -0238ab0a83
Merge pull request #321 from christoph-cullmann/c4245_fix... by Xiaoyi Zhang <zhangxy988@gmail.com> -61c9bf3e3e
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -bc9101f998
Merge pull request #320 from christoph-cullmann/master by Xiaoyi Zhang <zhangxy988@gmail.com> -2f76a9bf50
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -4adaf54909
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -27c30ec671
Avoid undefined behavior when nullptr is passed to memcpy... by Roman Gershman <romange@gmail.com> -ce65f5ac3c
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -a18fc7461e
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -8a394b19c1
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -daf381e853
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -fa00c32107
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -436ba6c4a0
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -0cbdc774b9
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -27c2f6e2f3
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -aa468ad755
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -cd86d0d20a
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -33841c5c96
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -ca3f87560a
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -d902eb869b
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -a02f62f456
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -0b545b4601
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -dbae8764fb
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -044da8a29c
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -6cc6ac44e0
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -666fc1266b
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -93dfcf74cb
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -2c8421e1c6
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -5b65c4af51
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -eab2078b53
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -253eb74164
[CMake] Set correct flags for clang-cl (#278) by Loo Rong Jie <loorongjie@gmail.com> -e75672f6af
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -bf29470384
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -6fd827124f
Merge pull request #280 from chiumichael/master by Derek Mauro <761129+derekmauro@users.noreply.github.com> -7c7754fb3e
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -256be56344
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -88a152ae74
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -c1cecb25a9
Implement Span::first and Span::last from C++20 (#274) by Girts <girtsf@users.noreply.github.com> -38b704384c
Changed HTTP URLs to HTTPS where possible (#270) by nik7273 <nik8470@gmail.com> -febc5ee6a9
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -9fdf5e5b80
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -419f3184f8
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -b312c3cb53
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -308ce31528
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -93d155bc44
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -426eaa4aa4
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -2901ec32a9
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -d78310fe5a
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -a4cb1c8ba6
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -540e2537b9
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -89ea0c5ff3
Merge pull request #255 from uilianries/hotfix/conan by ahedberg <ahedberg@google.com> -5e0dcf72c6
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -0dffca4e36
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -6b4201f9ef
Fix GCC8 warnings by Boris Staletic <boris.staletic@gmail.com> -0b1e6d417b
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -efccc50260
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -5e6a78131f
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -5eea0f713c
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -66f9becbb9
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -018b4db1d7
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -9449ae9439
Merge pull request #243 from ThomsonTan/FixIntrinsic by Alex Strelnikov <strel@google.com> -b16aeb6756
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -7ffbe09f3d
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -01b471d9f3
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -7bd8f36c74
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -968a34ffda
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -3e2e9b5557
Merge pull request #231 from uilianries/feature/conan by Mark Barolak <mbxx@users.noreply.github.com> -111ca7060a
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -389ec3f906
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -8fbcdb9095
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -455dc17ba1
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -f197d7c72a
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> -284378a71b
Export of internal Abseil changes. by Abseil Team <absl-team@google.com> GitOrigin-RevId:9ee91d3e43
Change-Id: Ia06e548bc106cc9d136f6c65714be6645317aced
parent
fcb104594b
commit
aa844899c9
1069 changed files with 48041 additions and 6846 deletions
@ -1,145 +0,0 @@ |
||||
# Abseil-specific compiler flags. See absl/copts.bzl for description. |
||||
# DO NOT CHANGE THIS FILE WITHOUT THE CORRESPONDING CHANGE TO absl/copts.bzl |
||||
|
||||
list(APPEND GCC_FLAGS |
||||
-Wall |
||||
-Wextra |
||||
-Wcast-qual |
||||
-Wconversion-null |
||||
-Wmissing-declarations |
||||
-Woverlength-strings |
||||
-Wpointer-arith |
||||
-Wunused-local-typedefs |
||||
-Wunused-result |
||||
-Wvarargs |
||||
-Wwrite-strings |
||||
-Wno-sign-compare |
||||
) |
||||
|
||||
list(APPEND GCC_TEST_FLAGS |
||||
-Wno-conversion-null |
||||
-Wno-missing-declarations |
||||
-Wno-sign-compare |
||||
-Wno-unused-function |
||||
-Wno-unused-parameter |
||||
-Wno-unused-private-field |
||||
) |
||||
|
||||
list(APPEND LLVM_FLAGS |
||||
-Wall |
||||
-Wextra |
||||
-Weverything |
||||
-Wno-c++98-compat-pedantic |
||||
-Wno-conversion |
||||
-Wno-covered-switch-default |
||||
-Wno-deprecated |
||||
-Wno-disabled-macro-expansion |
||||
-Wno-double-promotion |
||||
-Wno-comma |
||||
-Wno-extra-semi |
||||
-Wno-packed |
||||
-Wno-padded |
||||
-Wno-sign-compare |
||||
-Wno-float-conversion |
||||
-Wno-float-equal |
||||
-Wno-format-nonliteral |
||||
-Wno-gcc-compat |
||||
-Wno-global-constructors |
||||
-Wno-exit-time-destructors |
||||
-Wno-nested-anon-types |
||||
-Wno-non-modular-include-in-module |
||||
-Wno-old-style-cast |
||||
-Wno-range-loop-analysis |
||||
-Wno-reserved-id-macro |
||||
-Wno-shorten-64-to-32 |
||||
-Wno-switch-enum |
||||
-Wno-thread-safety-negative |
||||
-Wno-undef |
||||
-Wno-unknown-warning-option |
||||
-Wno-unreachable-code |
||||
-Wno-unused-macros |
||||
-Wno-weak-vtables |
||||
-Wbitfield-enum-conversion |
||||
-Wbool-conversion |
||||
-Wconstant-conversion |
||||
-Wenum-conversion |
||||
-Wint-conversion |
||||
-Wliteral-conversion |
||||
-Wnon-literal-null-conversion |
||||
-Wnull-conversion |
||||
-Wobjc-literal-conversion |
||||
-Wno-sign-conversion |
||||
-Wstring-conversion |
||||
) |
||||
|
||||
list(APPEND LLVM_TEST_FLAGS |
||||
-Wno-c99-extensions |
||||
-Wno-missing-noreturn |
||||
-Wno-missing-prototypes |
||||
-Wno-missing-variable-declarations |
||||
-Wno-null-conversion |
||||
-Wno-shadow |
||||
-Wno-shift-sign-overflow |
||||
-Wno-sign-compare |
||||
-Wno-unused-function |
||||
-Wno-unused-member-function |
||||
-Wno-unused-parameter |
||||
-Wno-unused-private-field |
||||
-Wno-unused-template |
||||
-Wno-used-but-marked-unused |
||||
-Wno-zero-as-null-pointer-constant |
||||
-Wno-gnu-zero-variadic-macro-arguments |
||||
) |
||||
|
||||
list(APPEND MSVC_FLAGS |
||||
/W3 |
||||
/wd4005 |
||||
/wd4018 |
||||
/wd4068 |
||||
/wd4180 |
||||
/wd4244 |
||||
/wd4267 |
||||
/wd4800 |
||||
/DNOMINMAX |
||||
/DWIN32_LEAN_AND_MEAN |
||||
/D_CRT_SECURE_NO_WARNINGS |
||||
/D_SCL_SECURE_NO_WARNINGS |
||||
/D_ENABLE_EXTENDED_ALIGNED_STORAGE |
||||
) |
||||
|
||||
list(APPEND MSVC_TEST_FLAGS |
||||
/wd4101 |
||||
/wd4503 |
||||
) |
||||
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
||||
set(ABSL_DEFAULT_COPTS "${GCC_FLAGS}") |
||||
set(ABSL_TEST_COPTS "${GCC_FLAGS};${GCC_TEST_FLAGS}") |
||||
set(ABSL_EXCEPTIONS_FLAG "-fexceptions") |
||||
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
||||
# MATCHES so we get both Clang and AppleClang |
||||
set(ABSL_DEFAULT_COPTS "${LLVM_FLAGS}") |
||||
set(ABSL_TEST_COPTS "${LLVM_FLAGS};${LLVM_TEST_FLAGS}") |
||||
set(ABSL_EXCEPTIONS_FLAG "-fexceptions") |
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
||||
set(ABSL_DEFAULT_COPTS "${MSVC_FLAGS}") |
||||
set(ABSL_TEST_COPTS "${MSVC_FLAGS};${MSVC_TEST_FLAGS}") |
||||
set(ABSL_EXCEPTIONS_FLAG "/U_HAS_EXCEPTIONS;/D_HAS_EXCEPTIONS=1;/EHsc") |
||||
else() |
||||
message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER}. Building with no default flags") |
||||
set(ABSL_DEFAULT_COPTS "") |
||||
set(ABSL_TEST_COPTS "") |
||||
set(ABSL_EXCEPTIONS_FLAG "") |
||||
endif() |
||||
|
||||
# This flag is used internally for Bazel builds and is kept here for consistency |
||||
set(ABSL_EXCEPTIONS_FLAG_LINKOPTS "") |
||||
|
||||
if("${CMAKE_CXX_STANDARD}" EQUAL 98) |
||||
message(FATAL_ERROR "Abseil requires at least C++11") |
||||
elseif(NOT "${CMAKE_CXX_STANDARD}") |
||||
message(STATUS "No CMAKE_CXX_STANDARD set, assuming 11") |
||||
set(ABSL_CXX_STANDARD 11) |
||||
else() |
||||
set(ABSL_CXX_STANDARD "${CMAKE_CXX_STANDARD}") |
||||
endif() |
@ -0,0 +1,20 @@ |
||||
include(GNUInstallDirs) |
||||
|
||||
# absl_VERSION is only set if we are an LTS release being installed, in which |
||||
# case it may be into a system directory and so we need to make subdirectories |
||||
# for each installed version of Abseil. This mechanism is implemented in |
||||
# Abseil's internal Copybara (https://github.com/google/copybara) workflows and |
||||
# isn't visible in the CMake buildsystem itself. |
||||
|
||||
if(absl_VERSION) |
||||
set(ABSL_SUBDIR "${PROJECT_NAME}_${PROJECT_VERSION}") |
||||
set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}/${ABSL_SUBDIR}") |
||||
set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${ABSL_SUBDIR}") |
||||
set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/{ABSL_SUBDIR}") |
||||
set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${ABSL_SUBDIR}") |
||||
else() |
||||
set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}") |
||||
set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") |
||||
set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") |
||||
set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}") |
||||
endif() |
@ -0,0 +1,7 @@ |
||||
# absl CMake configuration file. |
||||
|
||||
include(FindThreads) |
||||
|
||||
@PACKAGE_INIT@ |
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") |
@ -0,0 +1,27 @@ |
||||
# |
||||
# Copyright 2019 The Abseil Authors. |
||||
# |
||||
# 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 |
||||
# |
||||
# https://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. |
||||
|
||||
# A simple CMakeLists.txt for testing cmake installation |
||||
|
||||
cmake_minimum_required(VERSION 3.5) |
||||
project(absl_cmake_testing CXX) |
||||
|
||||
set(CMAKE_CXX_STANDARD 11) |
||||
|
||||
add_executable(simple simple.cc) |
||||
|
||||
find_package(absl REQUIRED) |
||||
|
||||
target_link_libraries(simple absl::strings) |
@ -0,0 +1,23 @@ |
||||
//
|
||||
// Copyright 2019 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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 <iostream> |
||||
#include "absl/strings/substitute.h" |
||||
|
||||
int main(int argc, char** argv) { |
||||
for (int i = 0; i < argc; ++i) { |
||||
std::cout << absl::Substitute("Arg $0: $1\n", i, argv[i]); |
||||
} |
||||
} |
@ -0,0 +1,144 @@ |
||||
#!/bin/bash |
||||
# |
||||
# Copyright 2019 The Abseil Authors. |
||||
# |
||||
# 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 |
||||
# |
||||
# https://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. |
||||
|
||||
# "Unit" and integration tests for Absl CMake installation |
||||
|
||||
# TODO(absl-team): This script isn't fully hermetic because |
||||
# -DABSL_USE_GOOGLETEST_HEAD=ON means that this script isn't pinned to a fixed |
||||
# version of GoogleTest. This means that an upstream change to GoogleTest could |
||||
# break this test. Fix this by allowing this script to pin to a known-good |
||||
# version of GoogleTest. |
||||
|
||||
# Fail on any error. Treat unset variables an error. Print commands as executed. |
||||
set -euox pipefail |
||||
|
||||
install_absl() { |
||||
pushd "${absl_build_dir}" |
||||
if [[ "${#}" -eq 1 ]]; then |
||||
cmake -DCMAKE_INSTALL_PREFIX="${1}" "${absl_dir}" |
||||
else |
||||
cmake "${absl_dir}" |
||||
fi |
||||
cmake --build . --target install -- -j |
||||
popd |
||||
} |
||||
|
||||
uninstall_absl() { |
||||
xargs rm < "${absl_build_dir}"/install_manifest.txt |
||||
rm -rf "${absl_build_dir}" |
||||
mkdir -p "${absl_build_dir}" |
||||
} |
||||
|
||||
lts_install="" |
||||
|
||||
while getopts ":l" lts; do |
||||
case "${lts}" in |
||||
l ) |
||||
lts_install="true" |
||||
;; |
||||
esac |
||||
done |
||||
|
||||
absl_dir=/abseil-cpp |
||||
absl_build_dir=/buildfs/absl-build |
||||
project_dir="${absl_dir}"/CMake/install_test_project |
||||
project_build_dir=/buildfs/project-build |
||||
|
||||
mkdir -p "${absl_build_dir}" |
||||
mkdir -p "${project_build_dir}" |
||||
|
||||
if [[ "${lts_install}" ]]; then |
||||
install_dir="/usr/local" |
||||
else |
||||
install_dir="${project_build_dir}"/install |
||||
fi |
||||
mkdir -p "${install_dir}" |
||||
|
||||
# Test build, install, and link against installed abseil |
||||
pushd "${project_build_dir}" |
||||
if [[ "${lts_install}" ]]; then |
||||
install_absl |
||||
cmake "${project_dir}" |
||||
else |
||||
install_absl "${install_dir}" |
||||
cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}" |
||||
fi |
||||
|
||||
cmake --build . --target simple |
||||
|
||||
output="$(${project_build_dir}/simple "printme" 2>&1)" |
||||
if [[ "${output}" != *"Arg 1: printme"* ]]; then |
||||
echo "Faulty output on simple project:" |
||||
echo "${output}" |
||||
exit 1 |
||||
fi |
||||
|
||||
popd |
||||
|
||||
# Test that we haven't accidentally made absl::abslblah |
||||
pushd "${install_dir}" |
||||
|
||||
# Starting in CMake 3.12 the default install dir is lib$bit_width |
||||
if [[ -d lib64 ]]; then |
||||
libdir="lib64" |
||||
elif [[ -d lib ]]; then |
||||
libdir="lib" |
||||
else |
||||
echo "ls *, */*, */*/*:" |
||||
ls * |
||||
ls */* |
||||
ls */*/* |
||||
echo "unknown lib dir" |
||||
fi |
||||
|
||||
if [[ "${lts_install}" ]]; then |
||||
# LTS versions append the date of the release to the subdir. |
||||
# 9999/99/99 is the dummy date used in the local_lts workflow. |
||||
absl_subdir="absl_99999999" |
||||
else |
||||
absl_subdir="absl" |
||||
fi |
||||
|
||||
if ! grep absl::strings "${libdir}/cmake/${absl_subdir}/abslTargets.cmake"; then |
||||
cat "${libdir}"/cmake/absl/abslTargets.cmake |
||||
echo "CMake targets named incorrectly" |
||||
exit 1 |
||||
fi |
||||
|
||||
uninstall_absl |
||||
popd |
||||
|
||||
if [[ ! "${lts_install}" ]]; then |
||||
# Test that we warn if installed without a prefix or a system prefix |
||||
output="$(install_absl 2>&1)" |
||||
if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then |
||||
echo "Install without prefix didn't warn as expected. Output:" |
||||
echo "${output}" |
||||
exit 1 |
||||
fi |
||||
uninstall_absl |
||||
|
||||
output="$(install_absl /usr 2>&1)" |
||||
if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then |
||||
echo "Install with /usr didn't warn as expected. Output:" |
||||
echo "${output}" |
||||
exit 1 |
||||
fi |
||||
uninstall_absl |
||||
fi |
||||
|
||||
echo "Install test complete!" |
||||
exit 0 |
@ -0,0 +1,17 @@ |
||||
# C++ Upgrade Tools |
||||
|
||||
Abseil may occassionally release API-breaking changes. As noted in our |
||||
[Compatibility Guidelines][compatibility-guide], we will aim to provide a tool |
||||
to do the work of effecting such API-breaking changes, when absolutely |
||||
necessary. |
||||
|
||||
These tools will be listed on the [C++ Upgrade Tools][upgrade-tools] guide on |
||||
https://abseil.io. |
||||
|
||||
For more information, the [C++ Automated Upgrade Guide][api-upgrades-guide] |
||||
outlines this process. |
||||
|
||||
[compatibility-guide]: https://abseil.io/about/compatibility |
||||
[api-upgrades-guide]: https://abseil.io/docs/cpp/tools/api-upgrades |
||||
[upgrade-tools]: https://abseil.io/docs/cpp/tools/upgrades/ |
||||
|
@ -0,0 +1,74 @@ |
||||
// Copyright 2017 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// kConstInit
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// A constructor tag used to mark an object as safe for use as a global
|
||||
// variable, avoiding the usual lifetime issues that can affect globals.
|
||||
|
||||
#ifndef ABSL_BASE_CONST_INIT_H_ |
||||
#define ABSL_BASE_CONST_INIT_H_ |
||||
|
||||
// In general, objects with static storage duration (such as global variables)
|
||||
// can trigger tricky object lifetime situations. Attempting to access them
|
||||
// from the constructors or destructors of other global objects can result in
|
||||
// undefined behavior, unless their constructors and destructors are designed
|
||||
// with this issue in mind.
|
||||
//
|
||||
// The normal way to deal with this issue in C++11 is to use constant
|
||||
// initialization and trivial destructors.
|
||||
//
|
||||
// Constant initialization is guaranteed to occur before any other code
|
||||
// executes. Constructors that are declared 'constexpr' are eligible for
|
||||
// constant initialization. You can annotate a variable declaration with the
|
||||
// ABSL_CONST_INIT macro to express this intent. For compilers that support
|
||||
// it, this annotation will cause a compilation error for declarations that
|
||||
// aren't subject to constant initialization (perhaps because a runtime value
|
||||
// was passed as a constructor argument).
|
||||
//
|
||||
// On program shutdown, lifetime issues can be avoided on global objects by
|
||||
// ensuring that they contain trivial destructors. A class has a trivial
|
||||
// destructor unless it has a user-defined destructor, a virtual method or base
|
||||
// class, or a data member or base class with a non-trivial destructor of its
|
||||
// own. Objects with static storage duration and a trivial destructor are not
|
||||
// cleaned up on program shutdown, and are thus safe to access from other code
|
||||
// running during shutdown.
|
||||
//
|
||||
// For a few core Abseil classes, we make a best effort to allow for safe global
|
||||
// instances, even though these classes have non-trivial destructors. These
|
||||
// objects can be created with the absl::kConstInit tag. For example:
|
||||
// ABSL_CONST_INIT absl::Mutex global_mutex(absl::kConstInit);
|
||||
//
|
||||
// The line above declares a global variable of type absl::Mutex which can be
|
||||
// accessed at any point during startup or shutdown. global_mutex's destructor
|
||||
// will still run, but will not invalidate the object. Note that C++ specifies
|
||||
// that accessing an object after its destructor has run results in undefined
|
||||
// behavior, but this pattern works on the toolchains we support.
|
||||
//
|
||||
// The absl::kConstInit tag should only be used to define objects with static
|
||||
// or thread_local storage duration.
|
||||
|
||||
namespace absl { |
||||
inline namespace lts_2019_08_08 { |
||||
|
||||
enum ConstInitType { |
||||
kConstInit, |
||||
}; |
||||
|
||||
} // inline namespace lts_2019_08_08
|
||||
} // namespace absl
|
||||
|
||||
#endif // ABSL_BASE_CONST_INIT_H_
|
@ -0,0 +1,22 @@ |
||||
// Copyright 2018 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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 <iostream> |
||||
#include "absl/base/internal/thread_identity.h" |
||||
|
||||
int main() { |
||||
auto* tid = absl::base_internal::CurrentThreadIdentityIfPresent(); |
||||
// Make sure the above call can't be optimized out
|
||||
std::cout << (void*)tid << std::endl; |
||||
} |
@ -0,0 +1,81 @@ |
||||
// Copyright 2019 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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 "absl/base/internal/scoped_set_env.h" |
||||
|
||||
#ifdef _WIN32 |
||||
#include <windows.h> |
||||
#endif |
||||
|
||||
#include <cstdlib> |
||||
|
||||
#include "absl/base/internal/raw_logging.h" |
||||
|
||||
namespace absl { |
||||
inline namespace lts_2019_08_08 { |
||||
namespace base_internal { |
||||
|
||||
namespace { |
||||
|
||||
#ifdef _WIN32 |
||||
const int kMaxEnvVarValueSize = 1024; |
||||
#endif |
||||
|
||||
void SetEnvVar(const char* name, const char* value) { |
||||
#ifdef _WIN32 |
||||
SetEnvironmentVariableA(name, value); |
||||
#else |
||||
if (value == nullptr) { |
||||
::unsetenv(name); |
||||
} else { |
||||
::setenv(name, value, 1); |
||||
} |
||||
#endif |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
ScopedSetEnv::ScopedSetEnv(const char* var_name, const char* new_value) |
||||
: var_name_(var_name), was_unset_(false) { |
||||
#ifdef _WIN32 |
||||
char buf[kMaxEnvVarValueSize]; |
||||
auto get_res = GetEnvironmentVariableA(var_name_.c_str(), buf, sizeof(buf)); |
||||
ABSL_INTERNAL_CHECK(get_res < sizeof(buf), "value exceeds buffer size"); |
||||
|
||||
if (get_res == 0) { |
||||
was_unset_ = (GetLastError() == ERROR_ENVVAR_NOT_FOUND); |
||||
} else { |
||||
old_value_.assign(buf, get_res); |
||||
} |
||||
|
||||
SetEnvironmentVariableA(var_name_.c_str(), new_value); |
||||
#else |
||||
const char* val = ::getenv(var_name_.c_str()); |
||||
if (val == nullptr) { |
||||
was_unset_ = true; |
||||
} else { |
||||
old_value_ = val; |
||||
} |
||||
#endif |
||||
|
||||
SetEnvVar(var_name_.c_str(), new_value); |
||||
} |
||||
|
||||
ScopedSetEnv::~ScopedSetEnv() { |
||||
SetEnvVar(var_name_.c_str(), was_unset_ ? nullptr : old_value_.c_str()); |
||||
} |
||||
|
||||
} // namespace base_internal
|
||||
} // inline namespace lts_2019_08_08
|
||||
} // namespace absl
|
@ -0,0 +1,43 @@ |
||||
//
|
||||
// Copyright 2019 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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.
|
||||
//
|
||||
|
||||
#ifndef ABSL_BASE_INTERNAL_SCOPED_SET_ENV_H_ |
||||
#define ABSL_BASE_INTERNAL_SCOPED_SET_ENV_H_ |
||||
|
||||
#include <string> |
||||
|
||||
namespace absl { |
||||
inline namespace lts_2019_08_08 { |
||||
namespace base_internal { |
||||
|
||||
class ScopedSetEnv { |
||||
public: |
||||
ScopedSetEnv(const char* var_name, const char* new_value); |
||||
~ScopedSetEnv(); |
||||
|
||||
private: |
||||
std::string var_name_; |
||||
std::string old_value_; |
||||
|
||||
// True if the environment variable was initially not set.
|
||||
bool was_unset_; |
||||
}; |
||||
|
||||
} // namespace base_internal
|
||||
} // inline namespace lts_2019_08_08
|
||||
} // namespace absl
|
||||
|
||||
#endif // ABSL_BASE_INTERNAL_SCOPED_SET_ENV_H_
|
@ -0,0 +1,99 @@ |
||||
// Copyright 2019 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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.
|
||||
|
||||
#ifdef _WIN32 |
||||
#include <windows.h> |
||||
#endif |
||||
|
||||
#include "gtest/gtest.h" |
||||
#include "absl/base/internal/scoped_set_env.h" |
||||
|
||||
namespace { |
||||
|
||||
using absl::base_internal::ScopedSetEnv; |
||||
|
||||
std::string GetEnvVar(const char* name) { |
||||
#ifdef _WIN32 |
||||
char buf[1024]; |
||||
auto get_res = GetEnvironmentVariableA(name, buf, sizeof(buf)); |
||||
if (get_res >= sizeof(buf)) { |
||||
return "TOO_BIG"; |
||||
} |
||||
|
||||
if (get_res == 0) { |
||||
return "UNSET"; |
||||
} |
||||
|
||||
return std::string(buf, get_res); |
||||
#else |
||||
const char* val = ::getenv(name); |
||||
if (val == nullptr) { |
||||
return "UNSET"; |
||||
} |
||||
|
||||
return val; |
||||
#endif |
||||
} |
||||
|
||||
TEST(ScopedSetEnvTest, SetNonExistingVarToString) { |
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "UNSET"); |
||||
|
||||
{ |
||||
ScopedSetEnv scoped_set("SCOPED_SET_ENV_TEST_VAR", "value"); |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "value"); |
||||
} |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "UNSET"); |
||||
} |
||||
|
||||
TEST(ScopedSetEnvTest, SetNonExistingVarToNull) { |
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "UNSET"); |
||||
|
||||
{ |
||||
ScopedSetEnv scoped_set("SCOPED_SET_ENV_TEST_VAR", nullptr); |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "UNSET"); |
||||
} |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "UNSET"); |
||||
} |
||||
|
||||
TEST(ScopedSetEnvTest, SetExistingVarToString) { |
||||
ScopedSetEnv scoped_set("SCOPED_SET_ENV_TEST_VAR", "value"); |
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "value"); |
||||
|
||||
{ |
||||
ScopedSetEnv scoped_set("SCOPED_SET_ENV_TEST_VAR", "new_value"); |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "new_value"); |
||||
} |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "value"); |
||||
} |
||||
|
||||
TEST(ScopedSetEnvTest, SetExistingVarToNull) { |
||||
ScopedSetEnv scoped_set("SCOPED_SET_ENV_TEST_VAR", "value"); |
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "value"); |
||||
|
||||
{ |
||||
ScopedSetEnv scoped_set("SCOPED_SET_ENV_TEST_VAR", nullptr); |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "UNSET"); |
||||
} |
||||
|
||||
EXPECT_EQ(GetEnvVar("SCOPED_SET_ENV_TEST_VAR"), "value"); |
||||
} |
||||
|
||||
} // namespace
|
@ -0,0 +1,271 @@ |
||||
// Copyright 2019 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// File: thread_annotations.h
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// WARNING: This is a backwards compatible header and it will be removed after
|
||||
// the migration to prefixed thread annotations is finished; please include
|
||||
// "absl/base/thread_annotations.h".
|
||||
//
|
||||
// This header file contains macro definitions for thread safety annotations
|
||||
// that allow developers to document the locking policies of multi-threaded
|
||||
// code. The annotations can also help program analysis tools to identify
|
||||
// potential thread safety issues.
|
||||
//
|
||||
// These annotations are implemented using compiler attributes. Using the macros
|
||||
// defined here instead of raw attributes allow for portability and future
|
||||
// compatibility.
|
||||
//
|
||||
// When referring to mutexes in the arguments of the attributes, you should
|
||||
// use variable names or more complex expressions (e.g. my_object->mutex_)
|
||||
// that evaluate to a concrete mutex object whenever possible. If the mutex
|
||||
// you want to refer to is not in scope, you may use a member pointer
|
||||
// (e.g. &MyClass::mutex_) to refer to a mutex in some (unknown) object.
|
||||
|
||||
#ifndef ABSL_BASE_INTERNAL_THREAD_ANNOTATIONS_H_ |
||||
#define ABSL_BASE_INTERNAL_THREAD_ANNOTATIONS_H_ |
||||
|
||||
#if defined(__clang__) |
||||
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x)) |
||||
#else |
||||
#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
|
||||
#endif |
||||
|
||||
// GUARDED_BY()
|
||||
//
|
||||
// Documents if a shared field or global variable needs to be protected by a
|
||||
// mutex. GUARDED_BY() allows the user to specify a particular mutex that
|
||||
// should be held when accessing the annotated variable.
|
||||
//
|
||||
// Although this annotation (and PT_GUARDED_BY, below) cannot be applied to
|
||||
// local variables, a local variable and its associated mutex can often be
|
||||
// combined into a small class or struct, thereby allowing the annotation.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// class Foo {
|
||||
// Mutex mu_;
|
||||
// int p1_ GUARDED_BY(mu_);
|
||||
// ...
|
||||
// };
|
||||
#define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) |
||||
|
||||
// PT_GUARDED_BY()
|
||||
//
|
||||
// Documents if the memory location pointed to by a pointer should be guarded
|
||||
// by a mutex when dereferencing the pointer.
|
||||
//
|
||||
// Example:
|
||||
// class Foo {
|
||||
// Mutex mu_;
|
||||
// int *p1_ PT_GUARDED_BY(mu_);
|
||||
// ...
|
||||
// };
|
||||
//
|
||||
// Note that a pointer variable to a shared memory location could itself be a
|
||||
// shared variable.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // `q_`, guarded by `mu1_`, points to a shared memory location that is
|
||||
// // guarded by `mu2_`:
|
||||
// int *q_ GUARDED_BY(mu1_) PT_GUARDED_BY(mu2_);
|
||||
#define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) |
||||
|
||||
// ACQUIRED_AFTER() / ACQUIRED_BEFORE()
|
||||
//
|
||||
// Documents the acquisition order between locks that can be held
|
||||
// simultaneously by a thread. For any two locks that need to be annotated
|
||||
// to establish an acquisition order, only one of them needs the annotation.
|
||||
// (i.e. You don't have to annotate both locks with both ACQUIRED_AFTER
|
||||
// and ACQUIRED_BEFORE.)
|
||||
//
|
||||
// As with GUARDED_BY, this is only applicable to mutexes that are shared
|
||||
// fields or global variables.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// Mutex m1_;
|
||||
// Mutex m2_ ACQUIRED_AFTER(m1_);
|
||||
#define ACQUIRED_AFTER(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__)) |
||||
|
||||
#define ACQUIRED_BEFORE(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__)) |
||||
|
||||
// EXCLUSIVE_LOCKS_REQUIRED() / SHARED_LOCKS_REQUIRED()
|
||||
//
|
||||
// Documents a function that expects a mutex to be held prior to entry.
|
||||
// The mutex is expected to be held both on entry to, and exit from, the
|
||||
// function.
|
||||
//
|
||||
// An exclusive lock allows read-write access to the guarded data member(s), and
|
||||
// only one thread can acquire a lock exclusively at any one time. A shared lock
|
||||
// allows read-only access, and any number of threads can acquire a shared lock
|
||||
// concurrently.
|
||||
//
|
||||
// Generally, non-const methods should be annotated with
|
||||
// EXCLUSIVE_LOCKS_REQUIRED, while const methods should be annotated with
|
||||
// SHARED_LOCKS_REQUIRED.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// Mutex mu1, mu2;
|
||||
// int a GUARDED_BY(mu1);
|
||||
// int b GUARDED_BY(mu2);
|
||||
//
|
||||
// void foo() EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2) { ... }
|
||||
// void bar() const SHARED_LOCKS_REQUIRED(mu1, mu2) { ... }
|
||||
#define EXCLUSIVE_LOCKS_REQUIRED(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__)) |
||||
|
||||
#define SHARED_LOCKS_REQUIRED(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__)) |
||||
|
||||
// LOCKS_EXCLUDED()
|
||||
//
|
||||
// Documents the locks acquired in the body of the function. These locks
|
||||
// cannot be held when calling this function (as Abseil's `Mutex` locks are
|
||||
// non-reentrant).
|
||||
#define LOCKS_EXCLUDED(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) |
||||
|
||||
// LOCK_RETURNED()
|
||||
//
|
||||
// Documents a function that returns a mutex without acquiring it. For example,
|
||||
// a public getter method that returns a pointer to a private mutex should
|
||||
// be annotated with LOCK_RETURNED.
|
||||
#define LOCK_RETURNED(x) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x)) |
||||
|
||||
// LOCKABLE
|
||||
//
|
||||
// Documents if a class/type is a lockable type (such as the `Mutex` class).
|
||||
#define LOCKABLE \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(lockable) |
||||
|
||||
// SCOPED_LOCKABLE
|
||||
//
|
||||
// Documents if a class does RAII locking (such as the `MutexLock` class).
|
||||
// The constructor should use `LOCK_FUNCTION()` to specify the mutex that is
|
||||
// acquired, and the destructor should use `UNLOCK_FUNCTION()` with no
|
||||
// arguments; the analysis will assume that the destructor unlocks whatever the
|
||||
// constructor locked.
|
||||
#define SCOPED_LOCKABLE \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable) |
||||
|
||||
// EXCLUSIVE_LOCK_FUNCTION()
|
||||
//
|
||||
// Documents functions that acquire a lock in the body of a function, and do
|
||||
// not release it.
|
||||
#define EXCLUSIVE_LOCK_FUNCTION(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__)) |
||||
|
||||
// SHARED_LOCK_FUNCTION()
|
||||
//
|
||||
// Documents functions that acquire a shared (reader) lock in the body of a
|
||||
// function, and do not release it.
|
||||
#define SHARED_LOCK_FUNCTION(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__)) |
||||
|
||||
// UNLOCK_FUNCTION()
|
||||
//
|
||||
// Documents functions that expect a lock to be held on entry to the function,
|
||||
// and release it in the body of the function.
|
||||
#define UNLOCK_FUNCTION(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__)) |
||||
|
||||
// EXCLUSIVE_TRYLOCK_FUNCTION() / SHARED_TRYLOCK_FUNCTION()
|
||||
//
|
||||
// Documents functions that try to acquire a lock, and return success or failure
|
||||
// (or a non-boolean value that can be interpreted as a boolean).
|
||||
// The first argument should be `true` for functions that return `true` on
|
||||
// success, or `false` for functions that return `false` on success. The second
|
||||
// argument specifies the mutex that is locked on success. If unspecified, this
|
||||
// mutex is assumed to be `this`.
|
||||
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__)) |
||||
|
||||
#define SHARED_TRYLOCK_FUNCTION(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__)) |
||||
|
||||
// ASSERT_EXCLUSIVE_LOCK() / ASSERT_SHARED_LOCK()
|
||||
//
|
||||
// Documents functions that dynamically check to see if a lock is held, and fail
|
||||
// if it is not held.
|
||||
#define ASSERT_EXCLUSIVE_LOCK(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(assert_exclusive_lock(__VA_ARGS__)) |
||||
|
||||
#define ASSERT_SHARED_LOCK(...) \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_lock(__VA_ARGS__)) |
||||
|
||||
// NO_THREAD_SAFETY_ANALYSIS
|
||||
//
|
||||
// Turns off thread safety checking within the body of a particular function.
|
||||
// This annotation is used to mark functions that are known to be correct, but
|
||||
// the locking behavior is more complicated than the analyzer can handle.
|
||||
#define NO_THREAD_SAFETY_ANALYSIS \ |
||||
THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) |
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tool-Supplied Annotations
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// TS_UNCHECKED should be placed around lock expressions that are not valid
|
||||
// C++ syntax, but which are present for documentation purposes. These
|
||||
// annotations will be ignored by the analysis.
|
||||
#define TS_UNCHECKED(x) "" |
||||
|
||||
// TS_FIXME is used to mark lock expressions that are not valid C++ syntax.
|
||||
// It is used by automated tools to mark and disable invalid expressions.
|
||||
// The annotation should either be fixed, or changed to TS_UNCHECKED.
|
||||
#define TS_FIXME(x) "" |
||||
|
||||
// Like NO_THREAD_SAFETY_ANALYSIS, this turns off checking within the body of
|
||||
// a particular function. However, this attribute is used to mark functions
|
||||
// that are incorrect and need to be fixed. It is used by automated tools to
|
||||
// avoid breaking the build when the analysis is updated.
|
||||
// Code owners are expected to eventually fix the routine.
|
||||
#define NO_THREAD_SAFETY_ANALYSIS_FIXME NO_THREAD_SAFETY_ANALYSIS |
||||
|
||||
// Similar to NO_THREAD_SAFETY_ANALYSIS_FIXME, this macro marks a GUARDED_BY
|
||||
// annotation that needs to be fixed, because it is producing thread safety
|
||||
// warning. It disables the GUARDED_BY.
|
||||
#define GUARDED_BY_FIXME(x) |
||||
|
||||
// Disables warnings for a single read operation. This can be used to avoid
|
||||
// warnings when it is known that the read is not actually involved in a race,
|
||||
// but the compiler cannot confirm that.
|
||||
#define TS_UNCHECKED_READ(x) thread_safety_analysis::ts_unchecked_read(x) |
||||
|
||||
|
||||
namespace thread_safety_analysis { |
||||
|
||||
// Takes a reference to a guarded data member, and returns an unguarded
|
||||
// reference.
|
||||
template <typename T> |
||||
inline const T& ts_unchecked_read(const T& v) NO_THREAD_SAFETY_ANALYSIS { |
||||
return v; |
||||
} |
||||
|
||||
template <typename T> |
||||
inline T& ts_unchecked_read(T& v) NO_THREAD_SAFETY_ANALYSIS { |
||||
return v; |
||||
} |
||||
|
||||
} // namespace thread_safety_analysis
|
||||
|
||||
#endif // ABSL_BASE_INTERNAL_THREAD_ANNOTATIONS_H_
|
@ -0,0 +1,43 @@ |
||||
// Copyright 2018 The Abseil Authors.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// https://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 "absl/base/log_severity.h" |
||||
|
||||
#include <sstream> |
||||
#include <string> |
||||
|
||||
#include "gmock/gmock.h" |
||||
#include "gtest/gtest.h" |
||||
|
||||
namespace { |
||||
using testing::Eq; |
||||
|
||||
std::string StreamHelper(absl::LogSeverity value) { |
||||
std::ostringstream stream; |
||||
stream << value; |
||||
return stream.str(); |
||||
} |
||||
|
||||
TEST(StreamTest, Works) { |
||||
EXPECT_THAT(StreamHelper(static_cast<absl::LogSeverity>(-100)), |
||||
Eq("absl::LogSeverity(-100)")); |
||||
EXPECT_THAT(StreamHelper(absl::LogSeverity::kInfo), Eq("INFO")); |
||||
EXPECT_THAT(StreamHelper(absl::LogSeverity::kWarning), Eq("WARNING")); |
||||
EXPECT_THAT(StreamHelper(absl::LogSeverity::kError), Eq("ERROR")); |
||||
EXPECT_THAT(StreamHelper(absl::LogSeverity::kFatal), Eq("FATAL")); |
||||
EXPECT_THAT(StreamHelper(static_cast<absl::LogSeverity>(4)), |
||||
Eq("absl::LogSeverity(4)")); |
||||
} |
||||
|
||||
} // namespace
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue