Export of internal Abseil changes

--
d09230db053c544c2dc7fd7d95d1ebe4302071e9 by Abseil Team <absl-team@google.com>:

Move testonly_uses_linear_node_search to BtreeNodePeer

PiperOrigin-RevId: 338210523

--
7b11c945dbba7a354103c194877eba240f7f0cbc by Derek Mauro <dmauro@google.com>:

Allow pinning to a GoogleTest commit to make the build reproducible
Allow using a cached copy of the commit to avoid depending on GitHub

PiperOrigin-RevId: 338115715

--
8414f496c570a6398744da8324e158b39a2e3d92 by Andy Getzendanner <durandal@google.com>:

Generate a pkg-config file per absl_cc_library.

PiperOrigin-RevId: 337986219
GitOrigin-RevId: d09230db053c544c2dc7fd7d95d1ebe4302071e9
Change-Id: Iae398ab8ad5c0c6833abd01aa5198315f5b6fa99
pull/827/head
Abseil Team 4 years ago committed by Gennadiy Rozental
parent 4b915e7092
commit eb317a701b
  1. 39
      CMake/AbseilHelpers.cmake
  2. 18
      CMake/Googletest/CMakeLists.txt.in
  3. 18
      CMake/install_test_project/test.sh
  4. 17
      CMakeLists.txt
  5. 1
      WORKSPACE
  6. 61
      absl/container/btree_test.cc
  7. 13
      absl/container/internal/btree.h
  8. 1
      absl/container/internal/btree_container.h
  9. 25
      ci/cmake_common.sh
  10. 2
      ci/cmake_install_test.sh
  11. 16
      ci/linux_gcc-latest_libstdcxx_cmake.sh
  12. 14
      ci/linux_gcc_alpine_cmake.sh
  13. 12
      ci/macos_xcode_cmake.sh

@ -137,6 +137,45 @@ function(absl_cc_library)
set(_build_type "static")
endif()
# Generate a pkg-config file for every library:
if(${_build_type} STREQUAL "static" OR ${_build_type} STREQUAL "shared")
if(NOT ABSL_CC_LIB_TESTONLY)
if(absl_VERSION)
set(PC_VERSION "${absl_VERSION}")
else()
set(PC_VERSION "head")
endif()
foreach(dep ${ABSL_CC_LIB_DEPS})
if(${dep} MATCHES "^absl::(.*)")
set(PC_DEPS "${PC_DEPS} absl_${CMAKE_MATCH_1} = ${PC_VERSION}")
endif()
endforeach()
foreach(cflag ${ABSL_CC_LIB_COPTS})
if(${cflag} MATCHES "^(-Wno|/wd)")
# These flags are needed to suppress warnings that might fire in our headers.
set(PC_CFLAGS "${PC_CFLAGS} ${cflag}")
elseif(${cflag} MATCHES "^(-W|/w[1234eo])")
# Don't impose our warnings on others.
else()
set(PC_CFLAGS "${PC_CFLAGS} ${cflag}")
endif()
endforeach()
FILE(GENERATE OUTPUT "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig/absl_${_NAME}.pc" CONTENT "\
prefix=${CMAKE_INSTALL_PREFIX}\n\
exec_prefix=\${prefix}\n\
libdir=\${prefix}/lib\n\
includedir=\${prefix}/include\n\
\n\
Name: absl_${_NAME}\n\
Description: Abseil ${_NAME} library\n\
URL: https://abseil.io/\n\
Version: ${PC_VERSION}\n\
Requires.private:${PC_DEPS}\n\
Libs: -L\${libdir} $<JOIN:${ABSL_CC_LIB_LINKOPTS}, > $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE}>>:-labsl_${_NAME}>\n\
Cflags: -I\${includedir}${PC_CFLAGS}\n")
endif()
endif()
if(NOT ABSL_CC_LIB_IS_INTERFACE)
if(${_build_type} STREQUAL "dll_dep")
# This target depends on the DLL. When adding dependencies to this target,

@ -3,24 +3,12 @@ cmake_minimum_required(VERSION 2.8.2)
project(googletest-external NONE)
include(ExternalProject)
if(${ABSL_USE_GOOGLETEST_HEAD})
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
ExternalProject_Add(googletest
URL "${absl_gtest_download_url}" # May be empty
SOURCE_DIR "${absl_gtest_src_dir}"
BINARY_DIR "${absl_gtest_build_dir}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
else()
ExternalProject_Add(googletest
SOURCE_DIR "${absl_gtest_src_dir}"
BINARY_DIR "${absl_gtest_build_dir}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
endif()
)

@ -118,6 +118,24 @@ if ! grep absl::strings "${libdir}/cmake/${absl_subdir}/abslTargets.cmake"; then
exit 1
fi
pushd "${HOME}"
cat > hello-abseil.cc << EOF
#include <cstdlib>
#include "absl/strings/str_format.h"
int main(int argc, char **argv) {
absl::PrintF("Hello Abseil!\n");
return EXIT_SUCCESS;
}
EOF
export PKG_CONFIG_PATH="${install_dir}/${libdir}/pkgconfig"
pc_args=($(pkg-config --cflags --libs --static absl_str_format))
g++ -static -o hello-abseil hello-abseil.cc "${pc_args[@]}"
hello="$(./hello-abseil)"
[[ "${hello}" == "Hello Abseil!" ]]
popd
uninstall_absl
popd

@ -95,12 +95,13 @@ find_package(Threads REQUIRED)
option(ABSL_USE_EXTERNAL_GOOGLETEST
"If ON, Abseil will assume that the targets for GoogleTest are already provided by the including project. This makes sense when Abseil is used with add_subproject." OFF)
option(ABSL_USE_GOOGLETEST_HEAD
"If ON, abseil will download HEAD from googletest at config time." OFF)
"If ON, abseil will download HEAD from GoogleTest at config time." OFF)
set(ABSL_GOOGLETEST_DOWNLOAD_URL "" CACHE STRING "If set, download GoogleTest from this URL")
set(ABSL_LOCAL_GOOGLETEST_DIR "/usr/src/googletest" CACHE PATH
"If ABSL_USE_GOOGLETEST_HEAD is OFF, specifies the directory of a local googletest checkout."
"If ABSL_USE_GOOGLETEST_HEAD is OFF and ABSL_GOOGLETEST_URL is not set, specifies the directory of a local GoogleTest checkout."
)
option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
@ -113,7 +114,15 @@ if(${ABSL_RUN_TESTS})
## check targets
if (NOT ABSL_USE_EXTERNAL_GOOGLETEST)
set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
if(${ABSL_USE_GOOGLETEST_HEAD})
if(ABSL_USE_GOOGLETEST_HEAD AND ABSL_GOOGLETEST_DOWNLOAD_URL)
message(FATAL_ERROR "Do not set both ABSL_USE_GOOGLETEST_HEAD and ABSL_GOOGLETEST_DOWNLOAD_URL")
endif()
if(ABSL_USE_GOOGLETEST_HEAD)
set(absl_gtest_download_url "https://github.com/google/googletest/archive/master.zip")
elseif(ABSL_GOOGLETEST_DOWNLOAD_URL)
set(absl_gtest_download_url ${ABSL_GOOGLETEST_DOWNLOAD_URL})
endif()
if(absl_gtest_download_url)
set(absl_gtest_src_dir ${CMAKE_BINARY_DIR}/googletest-src)
else()
set(absl_gtest_src_dir ${ABSL_LOCAL_GOOGLETEST_DIR})

@ -20,6 +20,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# GoogleTest/GoogleMock framework. Used by most unit-tests.
http_archive(
name = "com_google_googletest",
# Keep this URL in sync with ABSL_GOOGLETEST_COMMIT in ci/cmake_common.sh.
urls = ["https://github.com/google/googletest/archive/8567b09290fe402cf01923e2131c5635b8ed851b.zip"], # 2020-06-12T22:24:28Z
strip_prefix = "googletest-8567b09290fe402cf01923e2131c5635b8ed851b",
sha256 = "9a8a166eb6a56c7b3d7b19dc2c946fe4778fd6f21c7a12368ad3b836d8f1be48",

@ -1183,6 +1183,39 @@ TEST(Btree, RangeCtorSanity) {
EXPECT_EQ(1, tmap.size());
}
} // namespace
class BtreeNodePeer {
public:
// Yields the size of a leaf node with a specific number of values.
template <typename ValueType>
constexpr static size_t GetTargetNodeSize(size_t target_values_per_node) {
return btree_node<
set_params<ValueType, std::less<ValueType>, std::allocator<ValueType>,
/*TargetNodeSize=*/256, // This parameter isn't used here.
/*Multi=*/false>>::SizeWithNValues(target_values_per_node);
}
// Yields the number of values in a (non-root) leaf node for this btree.
template <typename Btree>
constexpr static size_t GetNumValuesPerNode() {
return btree_node<typename Btree::params_type>::kNodeValues;
}
template <typename Btree>
constexpr static size_t GetMaxFieldType() {
return std::numeric_limits<
typename btree_node<typename Btree::params_type>::field_type>::max();
}
template <typename Btree>
constexpr static bool UsesLinearNodeSearch() {
return btree_node<typename Btree::params_type>::use_linear_search::value;
}
};
namespace {
TEST(Btree, BtreeMapCanHoldMoveOnlyTypes) {
absl::btree_map<std::string, std::unique_ptr<std::string>> m;
@ -1328,34 +1361,6 @@ TEST(Btree, RValueInsert) {
EXPECT_EQ(tracker.swaps(), 0);
}
} // namespace
class BtreeNodePeer {
public:
// Yields the size of a leaf node with a specific number of values.
template <typename ValueType>
constexpr static size_t GetTargetNodeSize(size_t target_values_per_node) {
return btree_node<
set_params<ValueType, std::less<ValueType>, std::allocator<ValueType>,
/*TargetNodeSize=*/256, // This parameter isn't used here.
/*Multi=*/false>>::SizeWithNValues(target_values_per_node);
}
// Yields the number of values in a (non-root) leaf node for this set.
template <typename Set>
constexpr static size_t GetNumValuesPerNode() {
return btree_node<typename Set::params_type>::kNodeValues;
}
template <typename Set>
constexpr static size_t GetMaxFieldType() {
return std::numeric_limits<
typename btree_node<typename Set::params_type>::field_type>::max();
}
};
namespace {
// A btree set with a specific number of values per node.
template <typename Key, int TargetValuesPerNode, typename Cmp = std::less<Key>>
class SizedBtreeSet

@ -803,12 +803,6 @@ class btree_node {
// Deletes a node and all of its children.
static void clear_and_delete(btree_node *node, allocator_type *alloc);
public:
// Exposed only for tests.
static bool testonly_uses_linear_node_search() {
return use_linear_search::value;
}
private:
template <typename... Args>
void value_init(const field_type i, allocator_type *alloc, Args &&... args) {
@ -1496,13 +1490,6 @@ class btree {
return res;
}
public:
// Exposed only for tests.
static bool testonly_uses_linear_node_search() {
return node_type::testonly_uses_linear_node_search();
}
private:
// We use compressed tuple in order to save space because key_compare and
// allocator_type are usually empty.
absl::container_internal::CompressedTuple<key_compare, allocator_type,

@ -370,6 +370,7 @@ template <typename Tree>
class btree_map_container : public btree_set_container<Tree> {
using super_type = btree_set_container<Tree>;
using params_type = typename Tree::params_type;
friend class BtreeNodePeer;
private:
template <class K>

@ -0,0 +1,25 @@
# Copyright 2020 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.
# The commit of GoogleTest to be used in the CMake tests in this directory.
# Keep this in sync with the commit in the WORKSPACE file.
readonly ABSL_GOOGLETEST_COMMIT="8567b09290fe402cf01923e2131c5635b8ed851b"
# Avoid depending on GitHub by looking for a cached copy of the commit first.
if [[ -r "${KOKORO_GFILE_DIR}/distdir/${ABSL_GOOGLETEST_COMMIT}.zip" ]]; then
DOCKER_EXTRA_ARGS="--mount type=bind,source=${KOKORO_GFILE_DIR}/distdir,target=/distdir,readonly ${DOCKER_EXTRA_ARGS:-}"
ABSL_GOOGLETEST_DOWNLOAD_URL="file:///distdir/${ABSL_GOOGLETEST_COMMIT}.zip"
else
ABSL_GOOGLETEST_DOWNLOAD_URL="https://github.com/google/googletest/archive/${ABSL_GOOGLETEST_COMMIT}.zip"
fi

@ -20,6 +20,8 @@ if [[ -z ${ABSEIL_ROOT:-} ]]; then
ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
fi
source "${ABSEIL_ROOT}/ci/cmake_common.sh"
source "${ABSEIL_ROOT}/ci/linux_docker_containers.sh"
readonly DOCKER_CONTAINER=${LINUX_GCC_LATEST_CONTAINER}

@ -14,18 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
set -euox pipefail
if [[ -z ${ABSEIL_ROOT:-} ]]; then
ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
fi
source "${ABSEIL_ROOT}/ci/cmake_common.sh"
if [[ -z ${ABSL_CMAKE_CXX_STANDARDS:-} ]]; then
ABSL_CMAKE_CXX_STANDARDS="11 14 17 20"
fi
@ -46,17 +42,17 @@ for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
for build_shared in ${ABSL_CMAKE_BUILD_SHARED}; do
time docker run \
--mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp,readonly \
--workdir=/abseil-cpp \
--tmpfs=/buildfs:exec \
--workdir=/buildfs \
--cap-add=SYS_PTRACE \
--rm \
-e CFLAGS="-Werror" \
-e CXXFLAGS="-Werror" \
${DOCKER_CONTAINER} \
${DOCKER_EXTRA_ARGS:-} \
"${DOCKER_CONTAINER}" \
/bin/bash -c "
cd /buildfs && \
cmake /abseil-cpp \
-DABSL_USE_GOOGLETEST_HEAD=ON \
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
-DABSL_RUN_TESTS=ON \
-DBUILD_SHARED_LIBS=${build_shared} \
-DCMAKE_BUILD_TYPE=${compilation_mode} \

@ -14,18 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
set -euox pipefail
if [[ -z ${ABSEIL_ROOT:-} ]]; then
ABSEIL_ROOT="$(realpath $(dirname ${0})/..)"
fi
source "${ABSEIL_ROOT}/ci/cmake_common.sh"
if [[ -z ${ABSL_CMAKE_CXX_STANDARDS:-} ]]; then
ABSL_CMAKE_CXX_STANDARDS="11 14 17"
fi
@ -46,17 +42,17 @@ for std in ${ABSL_CMAKE_CXX_STANDARDS}; do
for build_shared in ${ABSL_CMAKE_BUILD_SHARED}; do
time docker run \
--mount type=bind,source="${ABSEIL_ROOT}",target=/abseil-cpp,readonly \
--workdir=/abseil-cpp \
--tmpfs=/buildfs:exec \
--workdir=/buildfs \
--cap-add=SYS_PTRACE \
--rm \
-e CFLAGS="-Werror" \
-e CXXFLAGS="-Werror" \
${DOCKER_EXTRA_ARGS:-} \
"${DOCKER_CONTAINER}" \
/bin/sh -c "
cd /buildfs && \
cmake /abseil-cpp \
-DABSL_USE_GOOGLETEST_HEAD=ON \
-DABSL_GOOGLETEST_DOWNLOAD_URL=${ABSL_GOOGLETEST_DOWNLOAD_URL} \
-DABSL_RUN_TESTS=ON \
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=${std} \

@ -14,9 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# This script is invoked on Kokoro to test Abseil on macOS.
# It is not hermetic and may break when Kokoro is updated.
set -euox pipefail
if [[ -z ${ABSEIL_ROOT:-} ]]; then
@ -24,6 +21,13 @@ if [[ -z ${ABSEIL_ROOT:-} ]]; then
fi
ABSEIL_ROOT=$(realpath ${ABSEIL_ROOT})
source "${ABSEIL_ROOT}/ci/cmake_common.sh"
# The MacOS build doesn't run in a docker container, so we have to override ABSL_GOOGLETEST_DOWNLOAD_URL.
if [[ -r "${KOKORO_GFILE_DIR}/distdir/${ABSL_GOOGLETEST_COMMIT}.zip" ]]; then
ABSL_GOOGLETEST_DOWNLOAD_URL="file://${KOKORO_GFILE_DIR}/distdir/${ABSL_GOOGLETEST_COMMIT}.zip"
fi
if [[ -z ${ABSL_CMAKE_BUILD_TYPES:-} ]]; then
ABSL_CMAKE_BUILD_TYPES="Debug"
fi
@ -44,7 +48,7 @@ for compilation_mode in ${ABSL_CMAKE_BUILD_TYPES}; do
-DCMAKE_BUILD_TYPE=${compilation_mode} \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_MODULE_LINKER_FLAGS="-Wl,--no-undefined" \
-DABSL_USE_GOOGLETEST_HEAD=ON \
-DABSL_GOOGLETEST_DOWNLOAD_URL="${ABSL_GOOGLETEST_DOWNLOAD_URL}" \
-DABSL_RUN_TESTS=ON
time cmake --build .
time ctest -C ${compilation_mode} --output-on-failure

Loading…
Cancel
Save