mirror of
https://gitee.com/270580156/weiyu.git
synced 2026-05-16 12:18:10 +00:00
Sync from bytedesk-private: update
This commit is contained in:
2
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/download_ffmpeg.sh
vendored
Normal file
2
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/download_ffmpeg.sh
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
wget https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/dep_libs/ffmpeg-N-111383-g20b8688092-linux64-gpl-shared.tar.xz
|
||||
tar -xvf ffmpeg-N-111383-g20b8688092-linux64-gpl-shared.tar.xz
|
||||
5
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/download_onnxruntime.sh
vendored
Normal file
5
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/download_onnxruntime.sh
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
# download an appropriate onnxruntime from https://github.com/microsoft/onnxruntime/releases/tag/v1.14.0
|
||||
# here we get a copy of onnxruntime for linux 64
|
||||
wget https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-linux-x64-1.14.0.tgz
|
||||
tar -zxvf onnxruntime-linux-x64-1.14.0.tgz
|
||||
3
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/.gitattributes
vendored
Normal file
3
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# treat all files in this repository as text files
|
||||
# and normalize them to LF line endings when committed
|
||||
* text
|
||||
4
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/.gitmodules
vendored
Normal file
4
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/.gitmodules
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[submodule "doc"]
|
||||
path = doc
|
||||
url = https://github.com/gflags/gflags.git
|
||||
branch = gh-pages
|
||||
20
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/.travis.yml
vendored
Normal file
20
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/.travis.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# Ubuntu 14.04 Trusty support, to get newer cmake and compilers.
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
language: cpp
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
|
||||
env:
|
||||
- CONFIG=Release
|
||||
- CONFIG=Debug
|
||||
|
||||
script:
|
||||
- mkdir out && cd out && cmake -D CMAKE_BUILD_TYPE=$CONFIG -D GFLAGS_BUILD_SHARED_LIBS=ON -D GFLAGS_BUILD_STATIC_LIBS=ON -D GFLAGS_BUILD_TESTING=ON .. && cmake --build . --config $CONFIG && ctest
|
||||
2
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/AUTHORS.txt
vendored
Normal file
2
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/AUTHORS.txt
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
google-gflags@googlegroups.com
|
||||
|
||||
741
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/CMakeLists.txt
vendored
Normal file
741
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,741 @@
|
||||
## CMake configuration file of gflags project
|
||||
##
|
||||
## This CMakeLists.txt defines some gflags specific configuration variables
|
||||
## using the "gflags_define" utility macro. The default values of these variables
|
||||
## can be overridden either on the CMake command-line using the -D option of
|
||||
## the cmake command or in a super-project which includes the gflags source
|
||||
## tree by setting the GFLAGS_<varname> CMake variables before adding the
|
||||
## gflags source directory via CMake's "add_subdirectory" command. Only when
|
||||
## the non-cached variable GFLAGS_IS_SUBPROJECT has a value equivalent to FALSE,
|
||||
## these configuration variables are added to the CMake cache so they can be
|
||||
## edited in the CMake GUI. By default, GFLAGS_IS_SUBPROJECT is set to TRUE when
|
||||
## the CMAKE_SOURCE_DIR is not identical to the directory of this CMakeLists.txt
|
||||
## file, i.e., the top-level directory of the gflags project source tree.
|
||||
##
|
||||
## When this project is a subproject (GFLAGS_IS_SUBPROJECT is TRUE), the default
|
||||
## settings are such that only the static single-threaded library is built without
|
||||
## installation of the gflags files. The "gflags::gflags" target is in this case an ALIAS
|
||||
## library target for the "gflags_nothreads_static" library target. Targets which
|
||||
## depend on the gflags library should link to the "gflags::gflags" library target.
|
||||
##
|
||||
## Example CMakeLists.txt of user project which requires separate gflags installation:
|
||||
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
||||
##
|
||||
## project(Foo)
|
||||
##
|
||||
## find_package(gflags REQUIRED)
|
||||
##
|
||||
## add_executable(foo src/foo.cc)
|
||||
## target_link_libraries(foo gflags::gflags)
|
||||
##
|
||||
## Example CMakeLists.txt of user project which requires separate single-threaded static gflags installation:
|
||||
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
||||
##
|
||||
## project(Foo)
|
||||
##
|
||||
## find_package(gflags COMPONENTS nothreads_static)
|
||||
##
|
||||
## add_executable(foo src/foo.cc)
|
||||
## target_link_libraries(foo gflags::gflags)
|
||||
##
|
||||
## Example CMakeLists.txt of super-project which contains gflags source tree:
|
||||
## cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
||||
##
|
||||
## project(Foo)
|
||||
##
|
||||
## add_subdirectory(gflags)
|
||||
##
|
||||
## add_executable(foo src/foo.cc)
|
||||
## target_link_libraries(foo gflags::gflags)
|
||||
##
|
||||
## Variables to configure the source files:
|
||||
## - GFLAGS_IS_A_DLL
|
||||
## - GFLAGS_NAMESPACE
|
||||
## - GFLAGS_ATTRIBUTE_UNUSED
|
||||
## - GFLAGS_INTTYPES_FORMAT
|
||||
##
|
||||
## Variables to configure the build:
|
||||
## - GFLAGS_SOVERSION
|
||||
## - GFLAGS_BUILD_SHARED_LIBS
|
||||
## - GFLAGS_BUILD_STATIC_LIBS
|
||||
## - GFLAGS_BUILD_gflags_LIB
|
||||
## - GFLAGS_BUILD_gflags_nothreads_LIB
|
||||
## - GFLAGS_BUILD_TESTING
|
||||
## - GFLAGS_BUILD_PACKAGING
|
||||
##
|
||||
## Variables to configure the installation:
|
||||
## - GFLAGS_INCLUDE_DIR
|
||||
## - GFLAGS_LIBRARY_INSTALL_DIR or LIB_INSTALL_DIR or LIB_SUFFIX
|
||||
## - GFLAGS_INSTALL_HEADERS
|
||||
## - GFLAGS_INSTALL_SHARED_LIBS
|
||||
## - GFLAGS_INSTALL_STATIC_LIBS
|
||||
|
||||
cmake_minimum_required (VERSION 3.0.2 FATAL_ERROR)
|
||||
|
||||
if (POLICY CMP0042)
|
||||
cmake_policy (SET CMP0042 NEW)
|
||||
endif ()
|
||||
|
||||
if (POLICY CMP0048)
|
||||
cmake_policy (SET CMP0048 NEW)
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# includes
|
||||
include ("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# package information
|
||||
set (PACKAGE_NAME "gflags")
|
||||
set (PACKAGE_VERSION "2.2.2")
|
||||
set (PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
|
||||
set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
|
||||
set (PACKAGE_BUGREPORT "https://github.com/gflags/gflags/issues")
|
||||
set (PACKAGE_DESCRIPTION "A commandline flags library that allows for distributed flags.")
|
||||
set (PACKAGE_URL "http://gflags.github.io/gflags")
|
||||
|
||||
project (${PACKAGE_NAME} VERSION ${PACKAGE_VERSION} LANGUAGES CXX)
|
||||
if (CMAKE_VERSION VERSION_LESS 3.4)
|
||||
# C language still needed because the following required CMake modules
|
||||
# (or their dependencies, respectively) are not correctly handling
|
||||
# the case where only CXX is enabled
|
||||
# - CheckTypeSize.cmake (fixed in CMake 3.1, cf. https://cmake.org/Bug/view.php?id=14056)
|
||||
# - FindThreads.cmake (fixed in CMake 3.4, cf. https://cmake.org/Bug/view.php?id=14905)
|
||||
enable_language (C)
|
||||
endif ()
|
||||
|
||||
version_numbers (
|
||||
${PACKAGE_VERSION}
|
||||
PACKAGE_VERSION_MAJOR
|
||||
PACKAGE_VERSION_MINOR
|
||||
PACKAGE_VERSION_PATCH
|
||||
)
|
||||
|
||||
# shared library ABI version number, can be overridden by package maintainers
|
||||
# using -DGFLAGS_SOVERSION=XXX on the command-line
|
||||
if (GFLAGS_SOVERSION)
|
||||
set (PACKAGE_SOVERSION "${GFLAGS_SOVERSION}")
|
||||
else ()
|
||||
# TODO: Change default SOVERSION back to PACKAGE_VERSION_MAJOR with the
|
||||
# next increase of major version number (i.e., 3.0.0 -> SOVERSION 3)
|
||||
# The <major>.<minor> SOVERSION should be used for the 2.x releases
|
||||
# versions only which temporarily broke the API by changing the default
|
||||
# namespace from "google" to "gflags".
|
||||
set (PACKAGE_SOVERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
|
||||
endif ()
|
||||
|
||||
# when gflags is included as subproject (e.g., as Git submodule/subtree) in the source
|
||||
# tree of a project that uses it, no variables should be added to the CMake cache;
|
||||
# users may set the non-cached variable GFLAGS_IS_SUBPROJECT before add_subdirectory(gflags)
|
||||
if (NOT DEFINED GFLAGS_IS_SUBPROJECT)
|
||||
if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
|
||||
set (GFLAGS_IS_SUBPROJECT FALSE)
|
||||
else ()
|
||||
set (GFLAGS_IS_SUBPROJECT TRUE)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# prefix for package variables in CMake configuration file
|
||||
string (TOUPPER "${PACKAGE_NAME}" PACKAGE_PREFIX)
|
||||
|
||||
# convert file path on Windows with back slashes to path with forward slashes
|
||||
# otherwise this causes an issue with the cmake_install.cmake script
|
||||
file (TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# options
|
||||
|
||||
# maintain binary backwards compatibility with gflags library version <= 2.0,
|
||||
# but at the same time enable the use of the preferred new "gflags" namespace
|
||||
gflags_define (STRING NAMESPACE "Name(s) of library namespace (separate multiple options by semicolon)" "google;${PACKAGE_NAME}" "${PACKAGE_NAME}")
|
||||
gflags_property (NAMESPACE ADVANCED TRUE)
|
||||
set (GFLAGS_NAMESPACE_SECONDARY "${NAMESPACE}")
|
||||
list (REMOVE_DUPLICATES GFLAGS_NAMESPACE_SECONDARY)
|
||||
if (NOT GFLAGS_NAMESPACE_SECONDARY)
|
||||
message (FATAL_ERROR "GFLAGS_NAMESPACE must be set to one (or more) valid C++ namespace identifier(s separated by semicolon \";\").")
|
||||
endif ()
|
||||
foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
|
||||
if (NOT ns MATCHES "^[a-zA-Z][a-zA-Z0-9_]*$")
|
||||
message (FATAL_ERROR "GFLAGS_NAMESPACE contains invalid namespace identifier: ${ns}")
|
||||
endif ()
|
||||
endforeach ()
|
||||
list (GET GFLAGS_NAMESPACE_SECONDARY 0 GFLAGS_NAMESPACE)
|
||||
list (REMOVE_AT GFLAGS_NAMESPACE_SECONDARY 0)
|
||||
|
||||
# cached build options when gflags is not a subproject, otherwise non-cached CMake variables
|
||||
# usage: gflags_define(BOOL <name> <doc> <default> [<subproject default>])
|
||||
gflags_define (BOOL BUILD_SHARED_LIBS "Request build of shared libraries." OFF OFF)
|
||||
gflags_define (BOOL BUILD_STATIC_LIBS "Request build of static libraries (default if BUILD_SHARED_LIBS is OFF)." OFF ON)
|
||||
gflags_define (BOOL BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON OFF)
|
||||
gflags_define (BOOL BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON ON)
|
||||
gflags_define (BOOL BUILD_PACKAGING "Enable build of distribution packages using CPack." OFF OFF)
|
||||
gflags_define (BOOL BUILD_TESTING "Enable build of the unit tests and their execution using CTest." OFF OFF)
|
||||
gflags_define (BOOL INSTALL_HEADERS "Request installation of headers and other development files." ON OFF)
|
||||
gflags_define (BOOL INSTALL_SHARED_LIBS "Request installation of shared libraries." ON ON)
|
||||
gflags_define (BOOL INSTALL_STATIC_LIBS "Request installation of static libraries." ON OFF)
|
||||
gflags_define (BOOL REGISTER_BUILD_DIR "Request entry of build directory in CMake's package registry." OFF OFF)
|
||||
gflags_define (BOOL REGISTER_INSTALL_PREFIX "Request entry of installed package in CMake's package registry." ON OFF)
|
||||
|
||||
gflags_property (BUILD_STATIC_LIBS ADVANCED TRUE)
|
||||
gflags_property (INSTALL_HEADERS ADVANCED TRUE)
|
||||
gflags_property (INSTALL_SHARED_LIBS ADVANCED TRUE)
|
||||
gflags_property (INSTALL_STATIC_LIBS ADVANCED TRUE)
|
||||
|
||||
if (NOT GFLAGS_IS_SUBPROJECT)
|
||||
foreach (varname IN ITEMS CMAKE_INSTALL_PREFIX)
|
||||
gflags_property (${varname} ADVANCED FALSE)
|
||||
endforeach ()
|
||||
foreach (varname IN ITEMS CMAKE_CONFIGURATION_TYPES CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
||||
gflags_property (${varname} ADVANCED TRUE)
|
||||
endforeach ()
|
||||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
|
||||
gflags_set (CMAKE_BUILD_TYPE Release)
|
||||
endif ()
|
||||
if (CMAKE_CONFIGURATION_TYPES)
|
||||
gflags_property (CMAKE_BUILD_TYPE STRINGS "${CMAKE_CONFIGURATION_TYPES}")
|
||||
endif ()
|
||||
endif () # NOT GFLAGS_IS_SUBPROJECT
|
||||
|
||||
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
|
||||
set (BUILD_STATIC_LIBS ON)
|
||||
endif ()
|
||||
if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
|
||||
message (FATAL_ERROR "At least one of [GFLAGS_]BUILD_gflags_LIB and [GFLAGS_]BUILD_gflags_nothreads_LIB must be ON.")
|
||||
endif ()
|
||||
|
||||
gflags_define (STRING INCLUDE_DIR "Name of include directory of installed header files relative to CMAKE_INSTALL_PREFIX/include/" "${PACKAGE_NAME}")
|
||||
gflags_property (INCLUDE_DIR ADVANCED TRUE)
|
||||
file (TO_CMAKE_PATH "${INCLUDE_DIR}" INCLUDE_DIR)
|
||||
if (IS_ABSOLUTE INCLUDE_DIR)
|
||||
message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must be a path relative to CMAKE_INSTALL_PREFIX/include/")
|
||||
endif ()
|
||||
if (INCLUDE_DIR MATCHES "^\\.\\.[/\\]")
|
||||
message (FATAL_ERROR "[GFLAGS_]INCLUDE_DIR must not start with parent directory reference (../)")
|
||||
endif ()
|
||||
set (GFLAGS_INCLUDE_DIR "${INCLUDE_DIR}")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# system checks
|
||||
include (CheckTypeSize)
|
||||
include (CheckIncludeFileCXX)
|
||||
include (CheckCXXSymbolExists)
|
||||
|
||||
if (WIN32 AND NOT CYGWIN)
|
||||
set (OS_WINDOWS 1)
|
||||
else ()
|
||||
set (OS_WINDOWS 0)
|
||||
endif ()
|
||||
|
||||
if (MSVC)
|
||||
set (HAVE_SYS_TYPES_H 1)
|
||||
set (HAVE_STDDEF_H 1) # used by CheckTypeSize module
|
||||
set (HAVE_UNISTD_H 0)
|
||||
set (HAVE_SYS_STAT_H 1)
|
||||
set (HAVE_SHLWAPI_H 1)
|
||||
if (MSVC_VERSION VERSION_LESS 1600)
|
||||
check_include_file_cxx ("stdint.h" HAVE_STDINT_H)
|
||||
bool_to_int (HAVE_STDINT_H) # used in #if directive
|
||||
else ()
|
||||
set (HAVE_STDINT_H 1)
|
||||
endif ()
|
||||
if (MSVC_VERSION VERSION_LESS 1800)
|
||||
check_include_file_cxx ("inttypes.h" HAVE_INTTYPES_H)
|
||||
bool_to_int (HAVE_INTTYPES_H) # used in #if directive
|
||||
else ()
|
||||
set (HAVE_INTTYPES_H 1)
|
||||
endif ()
|
||||
else ()
|
||||
foreach (fname IN ITEMS unistd stdint inttypes sys/types sys/stat fnmatch)
|
||||
string (TOUPPER "${fname}" FNAME)
|
||||
string (REPLACE "/" "_" FNAME "${FNAME}")
|
||||
if (NOT HAVE_${FNAME}_H)
|
||||
check_include_file_cxx ("${fname}.h" HAVE_${FNAME}_H)
|
||||
endif ()
|
||||
endforeach ()
|
||||
if (NOT HAVE_FNMATCH_H AND OS_WINDOWS)
|
||||
check_include_file_cxx ("shlwapi.h" HAVE_SHLWAPI_H)
|
||||
endif ()
|
||||
# the following are used in #if directives not #ifdef
|
||||
bool_to_int (HAVE_STDINT_H)
|
||||
bool_to_int (HAVE_SYS_TYPES_H)
|
||||
bool_to_int (HAVE_INTTYPES_H)
|
||||
endif ()
|
||||
|
||||
gflags_define (STRING INTTYPES_FORMAT "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)" "")
|
||||
gflags_property (INTTYPES_FORMAT STRINGS "C99;BSD;VC7")
|
||||
gflags_property (INTTYPES_FORMAT ADVANCED TRUE)
|
||||
if (NOT INTTYPES_FORMAT)
|
||||
set (TYPES uint32_t u_int32_t)
|
||||
if (MSVC)
|
||||
list (INSERT TYPES 0 __int32)
|
||||
endif ()
|
||||
foreach (type IN LISTS TYPES)
|
||||
check_type_size (${type} ${type} LANGUAGE CXX)
|
||||
if (HAVE_${type})
|
||||
break ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
if (HAVE_uint32_t)
|
||||
gflags_set (INTTYPES_FORMAT C99)
|
||||
elseif (HAVE_u_int32_t)
|
||||
gflags_set (INTTYPES_FORMAT BSD)
|
||||
elseif (HAVE___int32)
|
||||
gflags_set (INTTYPES_FORMAT VC7)
|
||||
else ()
|
||||
gflags_property (INTTYPES_FORMAT ADVANCED FALSE)
|
||||
message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
|
||||
" Neither uint32_t, u_int32_t, nor __int32 seem to be available."
|
||||
" Set [GFLAGS_]INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
|
||||
endif ()
|
||||
endif ()
|
||||
# use of special characters in strings to circumvent bug #0008226
|
||||
if ("^${INTTYPES_FORMAT}$" STREQUAL "^WIN$")
|
||||
gflags_set (INTTYPES_FORMAT VC7)
|
||||
endif ()
|
||||
if (NOT INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
|
||||
message (FATAL_ERROR "Invalid value for [GFLAGS_]INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
|
||||
endif ()
|
||||
set (GFLAGS_INTTYPES_FORMAT "${INTTYPES_FORMAT}")
|
||||
set (GFLAGS_INTTYPES_FORMAT_C99 0)
|
||||
set (GFLAGS_INTTYPES_FORMAT_BSD 0)
|
||||
set (GFLAGS_INTTYPES_FORMAT_VC7 0)
|
||||
set ("GFLAGS_INTTYPES_FORMAT_${INTTYPES_FORMAT}" 1)
|
||||
|
||||
if (MSVC)
|
||||
set (HAVE_strtoll 0)
|
||||
set (HAVE_strtoq 0)
|
||||
else ()
|
||||
check_cxx_symbol_exists (strtoll stdlib.h HAVE_STRTOLL)
|
||||
if (NOT HAVE_STRTOLL)
|
||||
check_cxx_symbol_exists (strtoq stdlib.h HAVE_STRTOQ)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (BUILD_gflags_LIB)
|
||||
set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
find_package (Threads)
|
||||
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
|
||||
set (HAVE_PTHREAD 1)
|
||||
check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
|
||||
else ()
|
||||
set (HAVE_PTHREAD 0)
|
||||
endif ()
|
||||
if (UNIX AND NOT HAVE_PTHREAD)
|
||||
if (CMAKE_HAVE_PTHREAD_H)
|
||||
set (what "library")
|
||||
else ()
|
||||
set (what ".h file")
|
||||
endif ()
|
||||
message (FATAL_ERROR "Could not find pthread${what}. Check the log file"
|
||||
"\n\t${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
|
||||
"\nor disable the build of the multi-threaded gflags library (BUILD_gflags_LIB=OFF).")
|
||||
endif ()
|
||||
else ()
|
||||
set (HAVE_PTHREAD 0)
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# source files - excluding root subdirectory and/or .in suffix
|
||||
set (PUBLIC_HDRS
|
||||
"gflags.h"
|
||||
"gflags_declare.h"
|
||||
"gflags_completions.h"
|
||||
)
|
||||
|
||||
if (GFLAGS_NAMESPACE_SECONDARY)
|
||||
set (INCLUDE_GFLAGS_NS_H "// Import gflags library symbols into alternative/deprecated namespace(s)")
|
||||
foreach (ns IN LISTS GFLAGS_NAMESPACE_SECONDARY)
|
||||
string (TOUPPER "${ns}" NS)
|
||||
set (gflags_ns_h "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/gflags_${ns}.h")
|
||||
configure_file ("${PROJECT_SOURCE_DIR}/src/gflags_ns.h.in" "${gflags_ns_h}" @ONLY)
|
||||
list (APPEND PUBLIC_HDRS "${gflags_ns_h}")
|
||||
set (INCLUDE_GFLAGS_NS_H "${INCLUDE_GFLAGS_NS_H}\n#include \"gflags_${ns}.h\"")
|
||||
endforeach ()
|
||||
else ()
|
||||
set (INCLUDE_GFLAGS_NS_H)
|
||||
endif ()
|
||||
|
||||
set (PRIVATE_HDRS
|
||||
"defines.h"
|
||||
"config.h"
|
||||
"util.h"
|
||||
"mutex.h"
|
||||
)
|
||||
|
||||
set (GFLAGS_SRCS
|
||||
"gflags.cc"
|
||||
"gflags_reporting.cc"
|
||||
"gflags_completions.cc"
|
||||
)
|
||||
|
||||
if (OS_WINDOWS)
|
||||
list (APPEND PRIVATE_HDRS "windows_port.h")
|
||||
list (APPEND GFLAGS_SRCS "windows_port.cc")
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# configure source files
|
||||
if (NOT DEFINED GFLAGS_ATTRIBUTE_UNUSED)
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
|
||||
else ()
|
||||
set (GFLAGS_ATTRIBUTE_UNUSED)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# whenever we build a shared library (DLL on Windows), configure the public
|
||||
# headers of the API for use of this shared library rather than the optionally
|
||||
# also build statically linked library; users can override GFLAGS_DLL_DECL
|
||||
# in particular, this done by setting the INTERFACE_COMPILE_DEFINITIONS of
|
||||
# static libraries to include an empty definition for GFLAGS_DLL_DECL
|
||||
if (NOT DEFINED GFLAGS_IS_A_DLL)
|
||||
if (BUILD_SHARED_LIBS)
|
||||
set (GFLAGS_IS_A_DLL 1)
|
||||
else ()
|
||||
set (GFLAGS_IS_A_DLL 0)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
|
||||
configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
|
||||
configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# output directories
|
||||
if (NOT GFLAGS_IS_SUBPROJECT)
|
||||
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
|
||||
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
|
||||
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
|
||||
endif ()
|
||||
# Set postfixes for generated libraries based on buildtype.
|
||||
set(CMAKE_RELEASE_POSTFIX "")
|
||||
set(CMAKE_DEBUG_POSTFIX "_debug")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# installation directories
|
||||
if (OS_WINDOWS)
|
||||
set (RUNTIME_INSTALL_DIR "bin")
|
||||
set (LIBRARY_INSTALL_DIR "lib")
|
||||
set (INCLUDE_INSTALL_DIR "include")
|
||||
set (CONFIG_INSTALL_DIR "lib/cmake/${PACKAGE_NAME}")
|
||||
set (PKGCONFIG_INSTALL_DIR)
|
||||
else ()
|
||||
set (RUNTIME_INSTALL_DIR bin)
|
||||
# The LIB_INSTALL_DIR and LIB_SUFFIX variables are used by the Fedora
|
||||
# package maintainers. Also package maintainers of other distribution
|
||||
# packages need to be able to specify the name of the library directory.
|
||||
if (NOT GFLAGS_LIBRARY_INSTALL_DIR AND LIB_INSTALL_DIR)
|
||||
set (GFLAGS_LIBRARY_INSTALL_DIR "${LIB_INSTALL_DIR}")
|
||||
endif ()
|
||||
gflags_define (PATH LIBRARY_INSTALL_DIR "Directory of installed libraries, e.g., \"lib64\"" "lib${LIB_SUFFIX}")
|
||||
gflags_property (LIBRARY_INSTALL_DIR ADVANCED TRUE)
|
||||
set (INCLUDE_INSTALL_DIR include)
|
||||
set (CONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/cmake/${PACKAGE_NAME})
|
||||
set (PKGCONFIG_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/pkgconfig)
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# add library targets
|
||||
set (TARGETS)
|
||||
# static vs. shared
|
||||
foreach (TYPE IN ITEMS STATIC SHARED)
|
||||
if (BUILD_${TYPE}_LIBS)
|
||||
string (TOLOWER "${TYPE}" type)
|
||||
# whether or not targets are a DLL
|
||||
if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^SHARED$")
|
||||
set (GFLAGS_IS_A_DLL 1)
|
||||
else ()
|
||||
set (GFLAGS_IS_A_DLL 0)
|
||||
endif ()
|
||||
# filename suffix for static libraries on Windows
|
||||
if (OS_WINDOWS AND "^${TYPE}$" STREQUAL "^STATIC$")
|
||||
set (type_suffix "_${type}")
|
||||
else ()
|
||||
set (type_suffix "")
|
||||
endif ()
|
||||
# multi-threaded vs. single-threaded
|
||||
foreach (opts IN ITEMS "" _nothreads)
|
||||
if (BUILD_gflags${opts}_LIB)
|
||||
set (target_name "gflags${opts}_${type}")
|
||||
add_library (${target_name} ${TYPE} ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
|
||||
set_target_properties (${target_name} PROPERTIES
|
||||
OUTPUT_NAME "gflags${opts}${type_suffix}"
|
||||
VERSION "${PACKAGE_VERSION}"
|
||||
SOVERSION "${PACKAGE_SOVERSION}"
|
||||
)
|
||||
set (include_dirs "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>")
|
||||
if (INSTALL_HEADERS)
|
||||
list (APPEND include_dirs "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>")
|
||||
endif ()
|
||||
target_include_directories (${target_name}
|
||||
PUBLIC "${include_dirs}"
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/src;${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}"
|
||||
)
|
||||
target_compile_definitions (${target_name} PUBLIC GFLAGS_IS_A_DLL=${GFLAGS_IS_A_DLL})
|
||||
if (opts MATCHES "nothreads")
|
||||
target_compile_definitions (${target_name} PRIVATE NO_THREADS)
|
||||
elseif (CMAKE_USE_PTHREADS_INIT)
|
||||
target_link_libraries (${target_name} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif ()
|
||||
if (HAVE_SHLWAPI_H)
|
||||
target_link_libraries (${target_name} shlwapi.lib)
|
||||
endif ()
|
||||
list (APPEND TARGETS ${target_name})
|
||||
# add convenience make target for build of both shared and static libraries
|
||||
if (NOT GFLAGS_IS_SUBPROJECT)
|
||||
if (NOT TARGET gflags${opts})
|
||||
add_custom_target (gflags${opts})
|
||||
endif ()
|
||||
add_dependencies (gflags${opts} ${target_name})
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# add ALIAS target for use in super-project, prefer static over shared, single-threaded over multi-threaded
|
||||
if (GFLAGS_IS_SUBPROJECT)
|
||||
foreach (type IN ITEMS static shared)
|
||||
foreach (opts IN ITEMS "_nothreads" "")
|
||||
if (TARGET gflags${opts}_${type})
|
||||
# Define "gflags" alias for super-projects treating targets of this library as part of their own project
|
||||
# (also for backwards compatibility with gflags 2.2.1 which only defined this alias)
|
||||
add_library (gflags ALIAS gflags${opts}_${type})
|
||||
# Define "gflags::gflags" alias for projects that support both find_package(gflags) and add_subdirectory(gflags)
|
||||
add_library (gflags::gflags ALIAS gflags${opts}_${type})
|
||||
break ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
if (TARGET gflags::gflags)
|
||||
break ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# installation rules
|
||||
set (EXPORT_NAME ${PACKAGE_NAME}-targets)
|
||||
file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
|
||||
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
|
||||
configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
|
||||
|
||||
if (BUILD_SHARED_LIBS AND INSTALL_SHARED_LIBS)
|
||||
foreach (opts IN ITEMS "" _nothreads)
|
||||
if (BUILD_gflags${opts}_LIB)
|
||||
install (TARGETS gflags${opts}_shared
|
||||
EXPORT ${EXPORT_NAME}
|
||||
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
|
||||
LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
|
||||
ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
|
||||
)
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
if (BUILD_STATIC_LIBS AND INSTALL_STATIC_LIBS)
|
||||
foreach (opts IN ITEMS "" _nothreads)
|
||||
if (BUILD_gflags${opts}_LIB)
|
||||
install (TARGETS gflags${opts}_static
|
||||
EXPORT ${EXPORT_NAME}
|
||||
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
|
||||
LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
|
||||
ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
|
||||
)
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
|
||||
if (INSTALL_HEADERS)
|
||||
install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_INCLUDE_DIR})
|
||||
install (
|
||||
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
|
||||
RENAME ${PACKAGE_NAME}-config.cmake
|
||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||
)
|
||||
install (
|
||||
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
|
||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||
)
|
||||
install (
|
||||
EXPORT ${EXPORT_NAME}
|
||||
NAMESPACE ${PACKAGE_NAME}::
|
||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||
)
|
||||
install (
|
||||
EXPORT ${EXPORT_NAME}
|
||||
FILE ${PACKAGE_NAME}-nonamespace-targets.cmake
|
||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||
)
|
||||
if (UNIX)
|
||||
install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (PKGCONFIG_INSTALL_DIR)
|
||||
configure_file ("cmake/package.pc.in" "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}.pc" @ONLY)
|
||||
install (FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}")
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# support direct use of build tree
|
||||
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
|
||||
export (
|
||||
TARGETS ${TARGETS}
|
||||
NAMESPACE ${PACKAGE_NAME}::
|
||||
FILE "${PROJECT_BINARY_DIR}/${EXPORT_NAME}.cmake"
|
||||
)
|
||||
export (
|
||||
TARGETS ${TARGETS}
|
||||
FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-nonamespace-targets.cmake"
|
||||
)
|
||||
if (REGISTER_BUILD_DIR)
|
||||
export (PACKAGE ${PACKAGE_NAME})
|
||||
endif ()
|
||||
if (REGISTER_INSTALL_PREFIX)
|
||||
register_gflags_package(${CONFIG_INSTALL_DIR})
|
||||
endif ()
|
||||
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# testing - MUST follow the generation of the build tree config file
|
||||
if (BUILD_TESTING)
|
||||
include (CTest)
|
||||
add_subdirectory (test)
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# packaging
|
||||
if (BUILD_PACKAGING)
|
||||
|
||||
if (NOT BUILD_SHARED_LIBS AND NOT INSTALL_HEADERS)
|
||||
message (WARNING "Package will contain static libraries without headers!"
|
||||
"\nRecommended options for generation of runtime package:"
|
||||
"\n BUILD_SHARED_LIBS=ON"
|
||||
"\n BUILD_STATIC_LIBS=OFF"
|
||||
"\n INSTALL_HEADERS=OFF"
|
||||
"\n INSTALL_SHARED_LIBS=ON"
|
||||
"\nRecommended options for generation of development package:"
|
||||
"\n BUILD_SHARED_LIBS=ON"
|
||||
"\n BUILD_STATIC_LIBS=ON"
|
||||
"\n INSTALL_HEADERS=ON"
|
||||
"\n INSTALL_SHARED_LIBS=ON"
|
||||
"\n INSTALL_STATIC_LIBS=ON"
|
||||
)
|
||||
endif ()
|
||||
|
||||
# default package generators
|
||||
if (APPLE)
|
||||
set (PACKAGE_GENERATOR "PackageMaker")
|
||||
set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
|
||||
elseif (UNIX)
|
||||
set (PACKAGE_GENERATOR "DEB;RPM")
|
||||
set (PACKAGE_SOURCE_GENERATOR "TGZ;ZIP")
|
||||
else ()
|
||||
set (PACKAGE_GENERATOR "ZIP")
|
||||
set (PACKAGE_SOURCE_GENERATOR "ZIP")
|
||||
endif ()
|
||||
|
||||
# used package generators
|
||||
set (CPACK_GENERATOR "${PACKAGE_GENERATOR}" CACHE STRING "List of binary package generators (CPack).")
|
||||
set (CPACK_SOURCE_GENERATOR "${PACKAGE_SOURCE_GENERATOR}" CACHE STRING "List of source package generators (CPack).")
|
||||
mark_as_advanced (CPACK_GENERATOR CPACK_SOURCE_GENERATOR)
|
||||
|
||||
# some package generators (e.g., PackageMaker) do not allow .md extension
|
||||
configure_file ("${CMAKE_CURRENT_LIST_DIR}/README.md" "${CMAKE_CURRENT_BINARY_DIR}/README.txt" COPYONLY)
|
||||
|
||||
# common package information
|
||||
set (CPACK_PACKAGE_VENDOR "Andreas Schuh")
|
||||
set (CPACK_PACKAGE_CONTACT "google-gflags@googlegroups.com")
|
||||
set (CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
|
||||
set (CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}")
|
||||
set (CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}")
|
||||
set (CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}")
|
||||
set (CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}")
|
||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE_DESCRIPTION}")
|
||||
set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
|
||||
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/COPYING.txt")
|
||||
set (CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
|
||||
set (CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||
set (CPACK_OUTPUT_FILE_PREFIX packages)
|
||||
set (CPACK_PACKAGE_RELOCATABLE TRUE)
|
||||
set (CPACK_MONOLITHIC_INSTALL TRUE)
|
||||
|
||||
# RPM package information -- used in cmake/package.cmake.in also for DEB
|
||||
set (CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
|
||||
set (CPACK_RPM_PACKAGE_LICENSE "BSD")
|
||||
set (CPACK_RPM_PACKAGE_URL "${PACKAGE_URL}")
|
||||
set (CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_LIST_DIR}/ChangeLog.txt")
|
||||
|
||||
if (INSTALL_HEADERS)
|
||||
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/doc/index.html")
|
||||
else ()
|
||||
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/cmake/README_runtime.txt")
|
||||
endif ()
|
||||
|
||||
# system/architecture
|
||||
if (WINDOWS)
|
||||
if (CMAKE_CL_64)
|
||||
set (CPACK_SYSTEM_NAME "win64")
|
||||
else ()
|
||||
set (CPACK_SYSTEM_NAME "win32")
|
||||
endif ()
|
||||
set (CPACK_PACKAGE_ARCHITECTURE)
|
||||
elseif (APPLE)
|
||||
set (CPACK_PACKAGE_ARCHITECTURE darwin)
|
||||
else ()
|
||||
string (TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
|
||||
if (CMAKE_CXX_FLAGS MATCHES "-m32")
|
||||
set (CPACK_PACKAGE_ARCHITECTURE i386)
|
||||
else ()
|
||||
execute_process (
|
||||
COMMAND dpkg --print-architecture
|
||||
RESULT_VARIABLE RV
|
||||
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
|
||||
)
|
||||
if (RV EQUAL 0)
|
||||
string (STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE)
|
||||
else ()
|
||||
execute_process (COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE)
|
||||
if (CPACK_PACKAGE_ARCHITECTURE MATCHES "x86_64")
|
||||
set (CPACK_PACKAGE_ARCHITECTURE amd64)
|
||||
else ()
|
||||
set (CPACK_PACKAGE_ARCHITECTURE i386)
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# source package settings
|
||||
set (CPACK_SOURCE_TOPLEVEL_TAG "source")
|
||||
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;\\\\.swp$;\\\\.#;/#;\\\\.*~;cscope\\\\.*;/[Bb]uild[.+-_a-zA-Z0-9]*/")
|
||||
|
||||
# default binary package settings
|
||||
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
|
||||
if (CPACK_PACKAGE_ARCHITECTURE)
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_ARCHITECTURE}")
|
||||
endif ()
|
||||
|
||||
# generator specific configuration file
|
||||
#
|
||||
# allow package maintainers to use their own configuration file
|
||||
# $ cmake -DCPACK_PROJECT_CONFIG_FILE:FILE=/path/to/package/config
|
||||
if (NOT CPACK_PROJECT_CONFIG_FILE)
|
||||
configure_file (
|
||||
"${CMAKE_CURRENT_LIST_DIR}/cmake/package.cmake.in"
|
||||
"${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake" @ONLY
|
||||
)
|
||||
set (CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-package.cmake")
|
||||
endif ()
|
||||
|
||||
include (CPack)
|
||||
|
||||
endif () # BUILD_PACKAGING
|
||||
|
||||
if (NOT GFLAGS_IS_SUBPROJECT AND NOT TARGET uninstall)
|
||||
configure_file (
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" @ONLY
|
||||
)
|
||||
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
|
||||
endif ()
|
||||
28
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/COPYING.txt
vendored
Normal file
28
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/COPYING.txt
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright (c) 2006, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
276
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/ChangeLog.txt
vendored
Normal file
276
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/ChangeLog.txt
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
* Sun Nov 11 2018 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
||||
|
||||
- gflags: version 2.2.2
|
||||
Fixed 267: Support build with GCC option "-fvisibility=hidden".
|
||||
Fixed 262: Declare FALGS_no##name variables as static to avoid "previous extern" warning.
|
||||
Fixed 261: Declare FlagRegisterer c’tor explicit template instanations as extern in header
|
||||
Fixed 257: Build with _UNICODE support on Windows.
|
||||
Fixed 233/234/235: Move CMake defines that are unused by Bazel to separate header; makes config.h private again
|
||||
Fixed 228: Build with recent MinGW versions that define setenv.
|
||||
Fixed 226: Remove obsolete and unused CleanFileName code
|
||||
Merged 266: Various PVS Studio and GCC warnings.
|
||||
Merged 258: Fix build with some Clang variants that define "restrict" macro.
|
||||
Merged 252: Update documentation on how to use Bazel.
|
||||
Merged 249: Use "_debug" postfix for debug libraries.
|
||||
Merged 247: CMake "project" VERSION; no enable_testing(); "gflags::" import target prefix.
|
||||
Merged 246: Add Bazel-on-Windows support.
|
||||
Merged 239: Use GFLAGS_NAMESPACE instead of "gflags" in test executable.
|
||||
Merged 237: Removed unused functions; fixes compilation with -Werror compiler option.
|
||||
Merged 232: Fix typo in Bazel's BUILD definition
|
||||
Merged 230: Remove using ::fLS::clstring.
|
||||
Merged 221: Add convenience 'uninstall' target
|
||||
|
||||
* Tue Jul 11 2017 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
||||
|
||||
- gflags: version 2.2.1
|
||||
- Link to online documentation in README
|
||||
- Merged 194: Include utils by file instead of CMAKE_MODULE_PATH search
|
||||
- Merged 195: Remove unused program_name variable
|
||||
- Merged 196: Enable language C for older CMake versions when needed
|
||||
- Merged 202: Changed include directory in bazel build
|
||||
- Merged 207: Mark single argument constructors in mutex.h as explicit
|
||||
- Merged 209: Use inttypes.h on VC++ 2013 and later
|
||||
- Merged 212: Fix statically linked gflags library with MSVC
|
||||
- Meregd 213: Modify installation paths on Windows for vcpkg
|
||||
- Merged 215: Fix static initialization order fiasco caused by global registry lock
|
||||
- Merged 216: Fix use of ARGC in CMake macros
|
||||
- Merged 222: Static code analyzer error regarding strncmp with empty kRootDir
|
||||
- Merged 224: Check HAVE_STDINT_H or HAVE_INTTYPES_H for older MSVC versions
|
||||
|
||||
* Fri Nov 25 2016 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
||||
|
||||
- gflags: version 2.2.0
|
||||
- Merged 178: Implicitly convert dashes in option names to underscores
|
||||
- Merged 159: CI builds and automatic tests with Travis CI and AppVeyor
|
||||
- Merged 158: Use enum for flag value types
|
||||
- Merged 126: File name postfix for static libraries on Windows
|
||||
- Closed issue 120: Configure and install gflags.pc file for pkg-config users
|
||||
- Fixed issue 127: snprintf already defined when building with MSVC 2015
|
||||
- Fixed issue 51/138: Memory leaks reported by valgrind
|
||||
- Fixed issue 173: Validate flags only once
|
||||
- Fixed issue 168: Unsigned and signed comparison in gflags_reporting.cc
|
||||
- Fixed issues 176/153: Add -lpthread link argument to Bazel build, refactor BUILD rules
|
||||
- Fixed issue 89: Add GFLAGS_IS_A_DLL to imported CMake target INTERFACE_COMPILE_DEFINITIONS
|
||||
- Fixed issue 104: Set INTERFACE_INCLUDE_DIRECTORIES of exported CMake targets
|
||||
- Fixed issue 174: Missing gflags-targets.cmake file after installation
|
||||
- Fixed issue 186: Error linking to gflags IMPLIB with MSVC using CMake
|
||||
- Closed issue 106: Add example project to test use of gflags library
|
||||
|
||||
* Tue Mar 24 2014 - Andreas Schuh <andreas.schuh.84@gmail.com>
|
||||
|
||||
- gflags: version 2.1.2
|
||||
- Moved project to GitHub
|
||||
- Added GFLAGS_NAMESPACE definition to gflags_declare.h
|
||||
- Fixed issue 94: Keep "google" as primary namespace and import symbols into "gflags" namespace
|
||||
- Fixed issue 96: Fix binary ABI compatibility with gflags 2.0 using "google" as primary namespace
|
||||
- Fixed issue 97/101: Removed (patched) CMake modules and enabled C language instead
|
||||
- Fixed issue 103: Set CMake policy CMP0042 to silence warning regarding MACOS_RPATH setting
|
||||
|
||||
* Sun Mar 20 2014 - Andreas Schuh <google-gflags@googlegroups.com>
|
||||
|
||||
- gflags: version 2.1.1
|
||||
- Fixed issue 77: GFLAGS_IS_A_DLL expands to empty string in gflags_declare.h
|
||||
- Fixed issue 79: GFLAGS_NAMESPACE not expanded to actual namespace in gflags_declare.h
|
||||
- Fixed issue 80: Allow include path to differ from GFLAGS_NAMESPACE
|
||||
|
||||
* Thu Mar 20 2014 - Andreas Schuh <google-gflags@googlegroups.com>
|
||||
|
||||
- gflags: version 2.1.0
|
||||
- Build system configuration using CMake instead of autotools
|
||||
- CPack packaging support for Debian/Ubuntu, Red Hat, and Mac OS X
|
||||
- Fixed issue 54: Fix "invalid suffix on literal" (C++11)
|
||||
- Fixed issue 57: Use _strdup instead of strdup on Windows
|
||||
- Fixed issue 62: Change all preprocessor include guards to start with GFLAGS_
|
||||
- Fixed issue 64: Add DEFINE_validator macro
|
||||
- Fixed issue 73: Warnings in Visual Studio 2010 and unable to compile unit test
|
||||
|
||||
* Wed Jan 25 2012 - Google Inc. <google-gflags@googlegroups.com>
|
||||
|
||||
- gflags: version 2.0
|
||||
- Changed the 'official' gflags email in setup.py/etc
|
||||
- Renamed google-gflags.sln to gflags.sln
|
||||
- Changed copyright text to reflect Google's relinquished ownership
|
||||
|
||||
* Tue Dec 20 2011 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.7
|
||||
- Add CommandLineFlagInfo::flag_ptr pointing to current storage (musji)
|
||||
- PORTING: flush after writing to stderr, needed on cygwin
|
||||
- PORTING: Clean up the GFLAGS_DLL_DECL stuff better
|
||||
- Fix a bug in StringPrintf() that affected large strings (csilvers)
|
||||
- Die at configure-time when g++ isn't installed
|
||||
|
||||
* Fri Jul 29 2011 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.6
|
||||
- BUGFIX: Fix a bug where we were leaving out a required $(top_srcdir)
|
||||
- Fix definition of clstring (jyrki)
|
||||
- Split up flag declares into its own file (jyrki)
|
||||
- Add --version support (csilvers)
|
||||
- Update the README for gflags with static libs
|
||||
- Update acx_pthread.m4 for nostdlib
|
||||
- Change ReparseCommandLineFlags to return void (csilvers)
|
||||
- Some doc typofixes and example augmentation (various)
|
||||
|
||||
* Mon Jan 24 2011 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.5
|
||||
- Better reporting of current vs default value (handler)
|
||||
- Add API for cleaning up of memory at program-exit (jmarantz)
|
||||
- Fix macros to work inside namespaces (csilvers)
|
||||
- Use our own string typedef in case string is redefined (csilvers)
|
||||
- Updated to autoconf 2.65
|
||||
|
||||
* Wed Oct 13 2010 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.4
|
||||
- Add a check to prevent passing 0 to DEFINE_string (jorg)
|
||||
- Reduce compile (.o) size (jyrki)
|
||||
- Some small changes to quiet debug compiles (alexk)
|
||||
- PORTING: better support static linking on windows (csilvers)
|
||||
- DOCUMENTATION: change default values, use validators, etc.
|
||||
- Update the NEWS file to be non-empty
|
||||
- Add pkg-config (.pc) files for libgflags and libgflags_nothreads
|
||||
|
||||
* Mon Jan 4 2010 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.3
|
||||
- PORTABILITY: can now build and run tests under MSVC (csilvers)
|
||||
- Remove the python gflags code, which is now its own package (tansell)
|
||||
- Clarify that "last flag wins" in the docs (csilvers)
|
||||
- Comment danger of using GetAllFlags in validators (wojtekm)
|
||||
- PORTABILITY: Some fixes necessary for c++0x (mboerger)
|
||||
- Makefile fix: $(srcdir) -> $(top_srcdir) in one place (csilvres)
|
||||
- INSTALL: autotools to autoconf v2.64 + automake v1.11 (csilvers)
|
||||
|
||||
* Thu Sep 10 2009 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.2
|
||||
- PORTABILITY: can now build and run tests under mingw (csilvers)
|
||||
- Using a string arg for a bool flag is a compile-time error (rbayardo)
|
||||
- Add --helpxml to gflags.py (salcianu)
|
||||
- Protect against a hypothetical global d'tor mutex problem (csilvers)
|
||||
- BUGFIX: can now define a flag after 'using namespace google' (hamaji)
|
||||
|
||||
* Tue Apr 14 2009 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.1
|
||||
- Add both foo and nofoo for boolean flags, with --undefok (andychu)
|
||||
- Better document how validators work (wojtekm)
|
||||
- Improve binary-detection for bash-completion (mtamsky)
|
||||
- Python: Add a concept of "key flags", used with --help (salcianu)
|
||||
- Python: Robustify flag_values (salcianu)
|
||||
- Python: Add a new DEFINE_bool alias (keir, andrewliu)
|
||||
- Python: Do module introspection based on module name (dsturtevant)
|
||||
- Fix autoconf a bit better, especially on windows and solaris (ajenjo)
|
||||
- BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo)
|
||||
- BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo)
|
||||
- PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers)
|
||||
- PORTABILITY: Update deb.sh for more recenty debuilds (csilvers)
|
||||
- PORTABILITY: #include more headers to satify new gcc's (csilvers)
|
||||
- INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers)
|
||||
|
||||
* Fri Oct 3 2008 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.0
|
||||
- Add a missing newline to an error string (bcmills)
|
||||
- (otherwise exactly the same as gflags 1.0rc2)
|
||||
|
||||
* Thu Sep 18 2008 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.0rc2
|
||||
- Report current flag values in --helpxml (hdn)
|
||||
- Fix compilation troubles with gcc 4.3.3 (simonb)
|
||||
- BUG FIX: I was missing a std:: in DECLARE_string (csilvers)
|
||||
- BUG FIX: Clarify in docs how to specify --bool flags (csilvers)
|
||||
- BUG FIX: Fix --helpshort for source files not in a subdir (csilvers)
|
||||
- BUG FIX: Fix python unittest for 64-bit builds (bcmills)
|
||||
|
||||
* Tue Aug 19 2008 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 1.0rc1
|
||||
- Move #include files from google/ to gflags/ (csilvers)
|
||||
- Small optimizations to reduce binary (library) size (jyrki)
|
||||
- BUGFIX: forgot a std:: in one of the .h files (csilvers)
|
||||
- Speed up locking by making sure calls are inlined (ajenjo)
|
||||
- 64-BIT COMPATIBILITY: Use %PRId64 instead of %lld (csilvers)
|
||||
- PORTABILITY: fix Makefile to work with Cygwin (ajenjo)
|
||||
- PORTABILITY: fix code to compile under Visual Studio (ajenjo)
|
||||
- PORTABILITY: fix code to compile under Solaris 10 with CC (csilvers)
|
||||
|
||||
* Mon Jul 21 2008 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.9
|
||||
- Add the ability to validate a command-line flag (csilvers)
|
||||
- Add completion support for commandline flags in bash (daven)
|
||||
- Add -W compile flags to Makefile, when using gcc (csilvers)
|
||||
- Allow helpstring to be NULL (cristianoc)
|
||||
- Improved documentation of classes in the .cc file (csilvers)
|
||||
- Fix python bug with AppendFlagValues + shortnames (jjtswan)
|
||||
- Use bool instead of int for boolean flags in gflags.py (bcmills)
|
||||
- Simplify the way we declare flags, now more foolproof (csilvers)
|
||||
- Better error messages when bool flags collide (colohan)
|
||||
- Only evaluate DEFINE_foo macro args once (csilvers)
|
||||
|
||||
* Wed Mar 26 2008 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.8
|
||||
- Export DescribeOneFlag() in the API
|
||||
- Add support for automatic line wrapping at 80 cols for gflags.py
|
||||
- Bugfix: do not treat an isolated "-" the same as an isolated "--"
|
||||
- Update rpm spec to point to Google Code rather than sourceforge (!)
|
||||
- Improve documentation (including documenting thread-safety)
|
||||
- Improve #include hygiene
|
||||
- Improve testing
|
||||
|
||||
* Thu Oct 18 2007 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.7
|
||||
- Deal even more correctly with libpthread not linked in (csilvers)
|
||||
- Add STRIP_LOG, an improved DO_NOT_SHOW_COMMANDLINE_HELP (sioffe)
|
||||
- Be more accurate printing default flag values in --help (dsturtevant)
|
||||
- Reduce .o file size a bit by using shorter namespace names (jeff)
|
||||
- Use relative install path, so 'setup.py --home' works (csilvers)
|
||||
- Notice when a boolean flag has a non-boolean default (bnmouli)
|
||||
- Broaden --helpshort to match foo-main.cc and foo_main.cc (hendrie)
|
||||
- Fix "no modules match" message for --helpshort, etc (hendrie)
|
||||
|
||||
* Wed Aug 15 2007 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.6
|
||||
- Deal correctly with case that libpthread is not linked in (csilvers)
|
||||
- Update Makefile/tests so we pass "make distcheck" (csilvers)
|
||||
- Document and test that last assignment to a flag wins (wan)
|
||||
|
||||
* Tue Jun 12 2007 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.5
|
||||
- Include all m4 macros in the distribution (csilvers)
|
||||
- Python: Fix broken data_files field in setup.py (sidlon)
|
||||
- Python: better string serliaizing and unparsing (abo, csimmons)
|
||||
- Fix checks for NaN and inf to work with Mac OS X (csilvers)
|
||||
|
||||
* Thu Apr 19 2007 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.4
|
||||
- Remove is_default from GetCommandLineFlagInfo (csilvers)
|
||||
- Portability fixes: includes, strtoll, gcc4.3 errors (csilvers)
|
||||
- A few doc typo cleanups (csilvers)
|
||||
|
||||
* Wed Mar 28 2007 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.3
|
||||
- python portability fix: use popen instead of subprocess (csilvers)
|
||||
- Add is_default to CommandLineFlagInfo (pchien)
|
||||
- Make docs a bit prettier (csilvers)
|
||||
- Actually include the python files in the distribution! :-/ (csilvers)
|
||||
|
||||
* Mon Jan 22 2007 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.2
|
||||
- added support for python commandlineflags, as well as c++
|
||||
- gflags2man, a script to turn flags into a man page (dchristian)
|
||||
|
||||
* Wed Dec 13 2006 - Google Inc. <opensource@google.com>
|
||||
|
||||
- google-gflags: version 0.1
|
||||
83
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/INSTALL.md
vendored
Normal file
83
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/INSTALL.md
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
Installing a binary distribution package
|
||||
========================================
|
||||
|
||||
No official binary distribution packages are provided by the gflags developers.
|
||||
There may, however, be binary packages available for your OS. Please consult
|
||||
also the package repositories of your Linux distribution.
|
||||
|
||||
For example on Debian/Ubuntu Linux, gflags can be installed using the
|
||||
following command:
|
||||
|
||||
sudo apt-get install libgflags-dev
|
||||
|
||||
|
||||
Compiling the source code with CMake
|
||||
=========================
|
||||
|
||||
The build system of gflags is since version 2.1 based on [CMake](http://cmake.org).
|
||||
The common steps to build, test, and install software are therefore:
|
||||
|
||||
1. Extract source files.
|
||||
2. Create build directory and change to it.
|
||||
3. Run CMake to configure the build tree.
|
||||
4. Build the software using selected build tool.
|
||||
5. Test the built software.
|
||||
6. Install the built files.
|
||||
|
||||
On Unix-like systems with GNU Make as build tool, these build steps can be
|
||||
summarized by the following sequence of commands executed in a shell,
|
||||
where ```$package``` and ```$version``` are shell variables which represent
|
||||
the name of this package and the obtained version of the software.
|
||||
|
||||
$ tar xzf gflags-$version-source.tar.gz
|
||||
$ cd gflags-$version
|
||||
$ mkdir build && cd build
|
||||
$ ccmake ..
|
||||
|
||||
- Press 'c' to configure the build system and 'e' to ignore warnings.
|
||||
- Set CMAKE_INSTALL_PREFIX and other CMake variables and options.
|
||||
- Continue pressing 'c' until the option 'g' is available.
|
||||
- Then press 'g' to generate the configuration files for GNU Make.
|
||||
|
||||
$ make
|
||||
$ make test (optional)
|
||||
$ make install (optional)
|
||||
|
||||
In the following, only gflags-specific CMake settings available to
|
||||
configure the build and installation are documented. Note that most of these
|
||||
variables are for advanced users and binary package maintainers only.
|
||||
They usually do not have to be modified.
|
||||
|
||||
|
||||
CMake Option | Description
|
||||
--------------------------- | -------------------------------------------------------
|
||||
CMAKE_INSTALL_PREFIX | Installation directory, e.g., "/usr/local" on Unix and "C:\Program Files\gflags" on Windows.
|
||||
BUILD_SHARED_LIBS | Request build of dynamic link libraries.
|
||||
BUILD_STATIC_LIBS | Request build of static link libraries. Implied if BUILD_SHARED_LIBS is OFF.
|
||||
BUILD_PACKAGING | Enable binary package generation using CPack.
|
||||
BUILD_TESTING | Build tests for execution by CTest.
|
||||
BUILD_NC_TESTS | Request inclusion of negative compilation tests (requires Python).
|
||||
BUILD_CONFIG_TESTS | Request inclusion of package configuration tests (requires Python).
|
||||
BUILD_gflags_LIBS | Request build of multi-threaded gflags libraries (if threading library found).
|
||||
BUILD_gflags_nothreads_LIBS | Request build of single-threaded gflags libraries.
|
||||
GFLAGS_NAMESPACE | Name of the C++ namespace to be used by the gflags library. Note that the public source header files are installed in a subdirectory named after this namespace. To maintain backwards compatibility with the Google Commandline Flags, set this variable to "google". The default is "gflags".
|
||||
GFLAGS_INTTYPES_FORMAT | String identifying format of built-in integer types.
|
||||
GFLAGS_INCLUDE_DIR | Name of headers installation directory relative to CMAKE_INSTALL_PREFIX.
|
||||
LIBRARY_INSTALL_DIR | Name of library installation directory relative to CMAKE_INSTALL_PREFIX.
|
||||
INSTALL_HEADERS | Request installation of public header files.
|
||||
|
||||
Using gflags with [Bazel](http://bazel.io)
|
||||
=========================
|
||||
|
||||
To use gflags in a Bazel project, map it in as an external dependency by editing
|
||||
your WORKSPACE file:
|
||||
|
||||
git_repository(
|
||||
name = "com_github_gflags_gflags",
|
||||
commit = "<INSERT COMMIT SHA HERE>",
|
||||
remote = "https://github.com/gflags/gflags.git",
|
||||
)
|
||||
|
||||
You can then add `@com_github_gflags_gflags//:gflags` to the `deps` section of a
|
||||
`cc_binary` or `cc_library` rule, and `#include <gflags/gflags.h>` to include it
|
||||
in your source code.
|
||||
320
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/README.md
vendored
Normal file
320
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/README.md
vendored
Normal file
@@ -0,0 +1,320 @@
|
||||
[](https://travis-ci.org/gflags/gflags)
|
||||
[](https://ci.appveyor.com/project/schuhschuh/gflags/branch/master)
|
||||
|
||||
The documentation of the gflags library is available online at https://gflags.github.io/gflags/.
|
||||
|
||||
|
||||
11 November 2018
|
||||
----------------
|
||||
|
||||
I've just released gflags 2.2.2.
|
||||
|
||||
This maintenance release improves lives of Bazel users (no more "config.h" leaking into global include paths),
|
||||
fixes build with recent MinGW versions, and silences a number of static code analyzer and compiler warnings.
|
||||
The build targets exported by the CMake configuration of this library are now also prefixed by the package
|
||||
name "gflags::" following a more recent (unwritten) CMake convention. The unprefixed target names are still
|
||||
supported to avoid that dependent projects have to be modified due to this change in imported target names.
|
||||
|
||||
Please report any further issues with this release using the GitHub issue tracker.
|
||||
|
||||
|
||||
11 July 2017
|
||||
------------
|
||||
|
||||
I've just released gflags 2.2.1.
|
||||
|
||||
This maintenance release primarily fixes build issues on Windows and
|
||||
false alarms reported by static code analyzers.
|
||||
|
||||
Please report any further issues with this release using the GitHub issue tracker.
|
||||
|
||||
|
||||
25 November 2016
|
||||
----------------
|
||||
|
||||
I've finally released gflags 2.2.0.
|
||||
|
||||
This release adds support for use of the gflags library as external dependency
|
||||
not only in projects using CMake, but also [Bazel](https://bazel.build/),
|
||||
or [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/).
|
||||
One new minor feature is added in this release: when a command flag argument
|
||||
contains dashes, these are implicitly converted to underscores.
|
||||
This is to allow those used to separate words of the flag name by dashes
|
||||
to do so, while the flag variable names are required to use underscores.
|
||||
|
||||
Memory leaks reported by valgrind should be resolved by this release.
|
||||
This release fixes build errors with MS Visual Studio 2015.
|
||||
|
||||
Please report any further issues with this release using the GitHub issue tracker.
|
||||
|
||||
|
||||
24 March 2015
|
||||
-------------
|
||||
|
||||
I've just released gflags 2.1.2.
|
||||
|
||||
This release completes the namespace change fixes. In particular,
|
||||
it restores binary ABI compatibility with release version 2.0.
|
||||
The deprecated "google" namespace is by default still kept as
|
||||
primary namespace while symbols are imported into the new "gflags" namespace.
|
||||
This can be overridden using the CMake variable GFLAGS_NAMESPACE.
|
||||
|
||||
Other fixes of the build configuration are related to the (patched)
|
||||
CMake modules FindThreads.cmake and CheckTypeSize.cmake. These have
|
||||
been removed and instead the C language is enabled again even though
|
||||
gflags is written in C++ only.
|
||||
|
||||
This release also marks the complete move of the gflags project
|
||||
from Google Code to GitHub. Email addresses of original issue
|
||||
reporters got lost in the process. Given the age of most issue reports,
|
||||
this should be negligable.
|
||||
|
||||
Please report any further issues using the GitHub issue tracker.
|
||||
|
||||
|
||||
30 March 2014
|
||||
-------------
|
||||
|
||||
I've just released gflags 2.1.1.
|
||||
|
||||
This release fixes a few bugs in the configuration of gflags\_declare.h
|
||||
and adds a separate GFLAGS\_INCLUDE\_DIR CMake variable to the build configuration.
|
||||
Setting GFLAGS\_NAMESPACE to "google" no longer changes also the include
|
||||
path of the public header files. This allows the use of the library with
|
||||
other Google projects such as glog which still use the deprecated "google"
|
||||
namespace for the gflags library, but include it as "gflags/gflags.h".
|
||||
|
||||
20 March 2014
|
||||
-------------
|
||||
|
||||
I've just released gflags 2.1.
|
||||
|
||||
The major changes are the use of CMake for the build configuration instead
|
||||
of the autotools and packaging support through CPack. The default namespace
|
||||
of all C++ symbols is now "gflags" instead of "google". This can be
|
||||
configured via the GFLAGS\_NAMESPACE variable.
|
||||
|
||||
This release compiles with all major compilers without warnings and passed
|
||||
the unit tests on Ubuntu 12.04, Windows 7 (Visual Studio 2008 and 2010,
|
||||
Cygwin, MinGW), and Mac OS X (Xcode 5.1).
|
||||
|
||||
The SVN repository on Google Code is now frozen and replaced by a Git
|
||||
repository such that it can be used as Git submodule by projects. The main
|
||||
hosting of this project remains at Google Code. Thanks to the distributed
|
||||
character of Git, I can push (and pull) changes from both GitHub and Google Code
|
||||
in order to keep the two public repositories in sync.
|
||||
When fixing an issue for a pull request through either of these hosting
|
||||
platforms, please reference the issue number as
|
||||
[described here](https://code.google.com/p/support/wiki/IssueTracker#Integration_with_version_control).
|
||||
For the further development, I am following the
|
||||
[Git branching model](http://nvie.com/posts/a-successful-git-branching-model/)
|
||||
with feature branch names prefixed by "feature/" and bugfix branch names
|
||||
prefixed by "bugfix/", respectively.
|
||||
|
||||
Binary and source [packages](https://github.com/schuhschuh/gflags/releases) are available on GitHub.
|
||||
|
||||
|
||||
14 January 2014
|
||||
---------------
|
||||
|
||||
The migration of the build system to CMake is almost complete.
|
||||
What remains to be done is rewriting the tests in Python such they can be
|
||||
executed on non-Unix platforms and splitting them up into separate CTest tests.
|
||||
Though merging these changes into the master branch yet remains to be done,
|
||||
it is recommended to already start using the
|
||||
[cmake-migration](https://github.com/schuhschuh/gflags/tree/cmake-migration) branch.
|
||||
|
||||
|
||||
20 April 2013
|
||||
-------------
|
||||
|
||||
More than a year has past since I (Andreas) took over the maintenance for
|
||||
`gflags`. Only few minor changes have been made since then, much to my regret.
|
||||
To get more involved and stimulate participation in the further
|
||||
development of the library, I moved the project source code today to
|
||||
[GitHub](https://github.com/schuhschuh/gflags).
|
||||
I believe that the strengths of [Git](http://git-scm.com/) will allow for better community collaboration
|
||||
as well as ease the integration of changes made by others. I encourage everyone
|
||||
who would like to contribute to send me pull requests.
|
||||
Git's lightweight feature branches will also provide the right tool for more
|
||||
radical changes which should only be merged back into the master branch
|
||||
after these are complete and implement the desired behavior.
|
||||
|
||||
The SVN repository remains accessible at Google Code and I will keep the
|
||||
master branch of the Git repository hosted at GitHub and the trunk of the
|
||||
Subversion repository synchronized. Initially, I was going to simply switch the
|
||||
Google Code project to Git, but in this case the SVN repository would be
|
||||
frozen and force everyone who would like the latest development changes to
|
||||
use Git as well. Therefore I decided to host the public Git repository at GitHub
|
||||
instead.
|
||||
|
||||
Please continue to report any issues with gflags on Google Code. The GitHub project will
|
||||
only be used to host the Git repository.
|
||||
|
||||
One major change of the project structure I have in mind for the next weeks
|
||||
is the migration from autotools to [CMake](http://www.cmake.org/).
|
||||
Check out the (unstable!)
|
||||
[cmake-migration](https://github.com/schuhschuh/gflags/tree/cmake-migration)
|
||||
branch on GitHub for details.
|
||||
|
||||
|
||||
25 January 2012
|
||||
---------------
|
||||
|
||||
I've just released gflags 2.0.
|
||||
|
||||
The `google-gflags` project has been renamed to `gflags`. I
|
||||
(csilvers) am stepping down as maintainer, to be replaced by Andreas
|
||||
Schuh. Welcome to the team, Andreas! I've seen the energy you have
|
||||
around gflags and the ideas you have for the project going forward,
|
||||
and look forward to having you on the team.
|
||||
|
||||
I bumped the major version number up to 2 to reflect the new community
|
||||
ownership of the project. All the [changes](ChangeLog.txt)
|
||||
are related to the renaming. There are no functional changes from
|
||||
gflags 1.7. In particular, I've kept the code in the namespace
|
||||
`google`, though in a future version it should be renamed to `gflags`.
|
||||
I've also kept the `/usr/local/include/google/` subdirectory as
|
||||
synonym of `/usr/local/include/gflags/`, though the former name has
|
||||
been obsolete for some time now.
|
||||
|
||||
|
||||
18 January 2011
|
||||
---------------
|
||||
|
||||
The `google-gflags` Google Code page has been renamed to
|
||||
`gflags`, in preparation for the project being renamed to
|
||||
`gflags`. In the coming weeks, I'll be stepping down as
|
||||
maintainer for the gflags project, and as part of that Google is
|
||||
relinquishing ownership of the project; it will now be entirely
|
||||
community run. The name change reflects that shift.
|
||||
|
||||
|
||||
20 December 2011
|
||||
----------------
|
||||
|
||||
I've just released gflags 1.7. This is a minor release; the major
|
||||
change is that `CommandLineFlagInfo` now exports the address in memory
|
||||
where the flag is located. There has also been a bugfix involving
|
||||
very long --help strings, and some other minor [changes](ChangeLog.txt).
|
||||
|
||||
29 July 2011
|
||||
------------
|
||||
|
||||
I've just released gflags 1.6. The major new feature in this release
|
||||
is support for setting version info, so that --version does something
|
||||
useful.
|
||||
|
||||
One minor change has required bumping the library number:
|
||||
`ReparseCommandlineFlags` now returns `void` instead of `int` (the int
|
||||
return value was always meaningless). Though I doubt anyone ever used
|
||||
this (meaningless) return value, technically it's a change to the ABI
|
||||
that requires a version bump. A bit sad.
|
||||
|
||||
There's also a procedural change with this release: I've changed the
|
||||
internal tools used to integrate Google-supplied patches for gflags
|
||||
into the opensource release. These new tools should result in more
|
||||
frequent updates with better change descriptions. They will also
|
||||
result in future `ChangeLog` entries being much more verbose (for better
|
||||
or for worse).
|
||||
|
||||
See the [ChangeLog](ChangeLog.txt) for a full list of changes for this release.
|
||||
|
||||
24 January 2011
|
||||
---------------
|
||||
|
||||
I've just released gflags 1.5. This release has only minor changes
|
||||
from 1.4, including some slightly better reporting in --help, and
|
||||
an new memory-cleanup function that can help when running gflags-using
|
||||
libraries under valgrind. The major change is to fix up the macros
|
||||
(`DEFINE_bool` and the like) to work more reliably inside namespaces.
|
||||
|
||||
If you have not had a problem with these macros, and don't need any of
|
||||
the other changes described, there is no need to upgrade. See the
|
||||
[ChangeLog](ChangeLog.txt) for a full list of changes for this release.
|
||||
|
||||
11 October 2010
|
||||
---------------
|
||||
|
||||
I've just released gflags 1.4. This release has only minor changes
|
||||
from 1.3, including some documentation tweaks and some work to make
|
||||
the library smaller. If 1.3 is working well for you, there's no
|
||||
particular reason to upgrade.
|
||||
|
||||
4 January 2010
|
||||
--------------
|
||||
|
||||
I've just released gflags 1.3. gflags now compiles under MSVC, and
|
||||
all tests pass. I **really** never thought non-unix-y Windows folks
|
||||
would want gflags, but at least some of them do.
|
||||
|
||||
The major news, though, is that I've separated out the python package
|
||||
into its own library, [python-gflags](http://code.google.com/p/python-gflags).
|
||||
If you're interested in the Python version of gflags, that's the place to
|
||||
get it now.
|
||||
|
||||
10 September 2009
|
||||
-----------------
|
||||
|
||||
I've just released gflags 1.2. The major change from gflags 1.1 is it
|
||||
now compiles under MinGW (as well as cygwin), and all tests pass. I
|
||||
never thought Windows folks would want unix-style command-line flags,
|
||||
since they're so different from the Windows style, but I guess I was
|
||||
wrong!
|
||||
|
||||
The other changes are minor, such as support for --htmlxml in the
|
||||
python version of gflags.
|
||||
|
||||
15 April 2009
|
||||
-------------
|
||||
|
||||
I've just released gflags 1.1. It has only minor changes fdrom gflags
|
||||
1.0 (see the [ChangeLog](ChangeLog.txt) for details).
|
||||
The major change is that I moved to a new system for creating .deb and .rpm files.
|
||||
This allows me to create x86\_64 deb and rpm files.
|
||||
|
||||
In the process of moving to this new system, I noticed an
|
||||
inconsistency: the tar.gz and .rpm files created libraries named
|
||||
libgflags.so, but the deb file created libgoogle-gflags.so. I have
|
||||
fixed the deb file to create libraries like the others. I'm no expert
|
||||
in debian packaging, but I believe this has caused the package name to
|
||||
change as well. Please let me know (at
|
||||
[[mailto:google-gflags@googlegroups.com](mailto:google-gflags@googlegroups.com)
|
||||
google-gflags@googlegroups.com]) if this causes problems for you --
|
||||
especially if you know of a fix! I would be happy to change the deb
|
||||
packages to add symlinks from the old library name to the new
|
||||
(libgoogle-gflags.so -> libgflags.so), but that is beyond my knowledge
|
||||
of how to make .debs.
|
||||
|
||||
If you've tried to install a .rpm or .deb and it doesn't work for you,
|
||||
let me know. I'm excited to finally have 64-bit package files, but
|
||||
there may still be some wrinkles in the new system to iron out.
|
||||
|
||||
1 October 2008
|
||||
--------------
|
||||
|
||||
gflags 1.0rc2 was out for a few weeks without any issues, so gflags
|
||||
1.0 is now released. This is much like gflags 0.9. The major change
|
||||
is that the .h files have been moved from `/usr/include/google` to
|
||||
`/usr/include/gflags`. While I have backwards-compatibility
|
||||
forwarding headeds in place, please rewrite existing code to say
|
||||
```
|
||||
#include <gflags/gflags.h>
|
||||
```
|
||||
instead of
|
||||
```
|
||||
#include <google/gflags.h>
|
||||
```
|
||||
|
||||
I've kept the default namespace to google. You can still change with
|
||||
with the appropriate flag to the configure script (`./configure
|
||||
--help` to see the flags). If you have feedback as to whether the
|
||||
default namespace should change to gflags, which would be a
|
||||
non-backwards-compatible change, send mail to
|
||||
`google-gflags@googlegroups.com`!
|
||||
|
||||
Version 1.0 also has some neat new features, like support for bash
|
||||
commandline-completion of help flags. See the [ChangeLog](ChangeLog.txt)
|
||||
for more details.
|
||||
|
||||
If I don't hear any bad news for a few weeks, I'll release 1.0-final.
|
||||
6
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/WORKSPACE
vendored
Normal file
6
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/WORKSPACE
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# Copyright 2006 Google Inc. All Rights Reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the COPYING.txt file.
|
||||
|
||||
# Bazel (http://bazel.io/) WORKSPACE file for gflags.
|
||||
workspace(name="com_github_gflags_gflags")
|
||||
68
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/appveyor.yml
vendored
Normal file
68
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/appveyor.yml
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
# Configuration for continuous integration service at appveyor.com
|
||||
|
||||
version: '{build}'
|
||||
|
||||
os: Visual Studio 2015
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- Toolset: v140
|
||||
- Toolset: v120
|
||||
- Toolset: v110
|
||||
- Toolset: v100
|
||||
- Toolset: v90
|
||||
|
||||
platform:
|
||||
- Win32
|
||||
- x64
|
||||
|
||||
configuration:
|
||||
- Release
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- Toolset: v90
|
||||
platform: x64
|
||||
- Toolset: v100
|
||||
platform: x64
|
||||
|
||||
build:
|
||||
verbosity: minimal
|
||||
|
||||
before_build:
|
||||
- ps: |
|
||||
Write-Output "Configuration: $env:CONFIGURATION"
|
||||
Write-Output "Platform: $env:PLATFORM"
|
||||
$generator = switch ($env:TOOLSET)
|
||||
{
|
||||
"v140" {"Visual Studio 14 2015"}
|
||||
"v120" {"Visual Studio 12 2013"}
|
||||
"v110" {"Visual Studio 11 2012"}
|
||||
"v100" {"Visual Studio 10 2010"}
|
||||
"v90" {"Visual Studio 9 2008"}
|
||||
}
|
||||
if ($env:PLATFORM -eq "x64")
|
||||
{
|
||||
$generator = "$generator Win64"
|
||||
}
|
||||
|
||||
build_script:
|
||||
- ps: |
|
||||
md _build -Force | Out-Null
|
||||
cd _build
|
||||
|
||||
& cmake -G "$generator" -D CMAKE_CONFIGURATION_TYPES="Debug;Release" -D GFLAGS_BUILD_TESTING=ON -D GFLAGS_BUILD_SHARED_LIBS=ON -D GFLAGS_BUILD_STATIC_LIBS=ON ..
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Exec: $ErrorMessage"
|
||||
}
|
||||
& cmake --build . --config $env:CONFIGURATION
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Exec: $ErrorMessage"
|
||||
}
|
||||
|
||||
test_script:
|
||||
- ps: |
|
||||
& ctest -C $env:CONFIGURATION --output-on-failure
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw "Exec: $ErrorMessage"
|
||||
}
|
||||
103
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/bazel/gflags.bzl
vendored
Normal file
103
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/bazel/gflags.bzl
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Add native rules to configure source files
|
||||
def gflags_sources(namespace=["google", "gflags"]):
|
||||
native.genrule(
|
||||
name = "gflags_declare_h",
|
||||
srcs = ["src/gflags_declare.h.in"],
|
||||
outs = ["gflags_declare.h"],
|
||||
cmd = ("awk '{ " +
|
||||
"gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); " +
|
||||
"gsub(/@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H|GFLAGS_INTTYPES_FORMAT_C99)@/, \"1\"); " +
|
||||
"gsub(/@([A-Z0-9_]+)@/, \"0\"); " +
|
||||
"print; }' $(<) > $(@)")
|
||||
)
|
||||
gflags_ns_h_files = []
|
||||
for ns in namespace[1:]:
|
||||
gflags_ns_h_file = "gflags_{}.h".format(ns)
|
||||
native.genrule(
|
||||
name = gflags_ns_h_file.replace('.', '_'),
|
||||
srcs = ["src/gflags_ns.h.in"],
|
||||
outs = [gflags_ns_h_file],
|
||||
cmd = ("awk '{ " +
|
||||
"gsub(/@ns@/, \"" + ns + "\"); " +
|
||||
"gsub(/@NS@/, \"" + ns.upper() + "\"); " +
|
||||
"print; }' $(<) > $(@)")
|
||||
)
|
||||
gflags_ns_h_files.append(gflags_ns_h_file)
|
||||
native.genrule(
|
||||
name = "gflags_h",
|
||||
srcs = ["src/gflags.h.in"],
|
||||
outs = ["gflags.h"],
|
||||
cmd = ("awk '{ " +
|
||||
"gsub(/@GFLAGS_ATTRIBUTE_UNUSED@/, \"\"); " +
|
||||
"gsub(/@INCLUDE_GFLAGS_NS_H@/, \"" + '\n'.join(["#include \\\"gflags/{}\\\"".format(hdr) for hdr in gflags_ns_h_files]) + "\"); " +
|
||||
"print; }' $(<) > $(@)")
|
||||
)
|
||||
native.genrule(
|
||||
name = "gflags_completions_h",
|
||||
srcs = ["src/gflags_completions.h.in"],
|
||||
outs = ["gflags_completions.h"],
|
||||
cmd = "awk '{ gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); print; }' $(<) > $(@)"
|
||||
)
|
||||
hdrs = [":gflags_h", ":gflags_declare_h", ":gflags_completions_h"]
|
||||
hdrs.extend([':' + hdr.replace('.', '_') for hdr in gflags_ns_h_files])
|
||||
srcs = [
|
||||
"src/config.h",
|
||||
"src/gflags.cc",
|
||||
"src/gflags_completions.cc",
|
||||
"src/gflags_reporting.cc",
|
||||
"src/mutex.h",
|
||||
"src/util.h",
|
||||
] + select({
|
||||
"//:x64_windows": [
|
||||
"src/windows_port.cc",
|
||||
"src/windows_port.h",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
return [hdrs, srcs]
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Add native rule to build gflags library
|
||||
def gflags_library(hdrs=[], srcs=[], threads=1):
|
||||
name = "gflags"
|
||||
copts = [
|
||||
"-DGFLAGS_BAZEL_BUILD",
|
||||
"-DGFLAGS_INTTYPES_FORMAT_C99",
|
||||
"-DGFLAGS_IS_A_DLL=0",
|
||||
# macros otherwise defined by CMake configured defines.h file
|
||||
"-DHAVE_STDINT_H",
|
||||
"-DHAVE_SYS_TYPES_H",
|
||||
"-DHAVE_INTTYPES_H",
|
||||
"-DHAVE_SYS_STAT_H",
|
||||
"-DHAVE_STRTOLL",
|
||||
"-DHAVE_STRTOQ",
|
||||
"-DHAVE_RWLOCK",
|
||||
] + select({
|
||||
"//:x64_windows": [
|
||||
"-DOS_WINDOWS",
|
||||
],
|
||||
"//conditions:default": [
|
||||
"-DHAVE_UNISTD_H",
|
||||
"-DHAVE_FNMATCH_H",
|
||||
"-DHAVE_PTHREAD",
|
||||
],
|
||||
})
|
||||
linkopts = []
|
||||
if threads:
|
||||
linkopts += select({
|
||||
"//:x64_windows": [],
|
||||
"//conditions:default": ["-lpthread"],
|
||||
})
|
||||
else:
|
||||
name += "_nothreads"
|
||||
copts += ["-DNO_THREADS"]
|
||||
native.cc_library(
|
||||
name = name,
|
||||
hdrs = hdrs,
|
||||
srcs = srcs,
|
||||
copts = copts,
|
||||
linkopts = linkopts,
|
||||
visibility = ["//visibility:public"],
|
||||
include_prefix = 'gflags'
|
||||
)
|
||||
@@ -0,0 +1,4 @@
|
||||
This package contains runtime libraries only which are required
|
||||
by applications that use these libraries for the commandline flags
|
||||
processing. If you want to develop such application, download
|
||||
and install the development package instead.
|
||||
@@ -0,0 +1,26 @@
|
||||
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||
|
||||
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
|
||||
set (CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")
|
||||
endif ()
|
||||
message(${CMAKE_INSTALL_PREFIX})
|
||||
|
||||
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
|
||||
string(REGEX REPLACE "\n" ";" files "${files}")
|
||||
foreach(file ${files})
|
||||
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
|
||||
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
||||
exec_program(
|
||||
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
||||
OUTPUT_VARIABLE rm_out
|
||||
RETURN_VALUE rm_retval
|
||||
)
|
||||
if(NOT "${rm_retval}" STREQUAL 0)
|
||||
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
|
||||
endif(NOT "${rm_retval}" STREQUAL 0)
|
||||
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
||||
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
|
||||
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
||||
endforeach(file)
|
||||
183
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/config.cmake.in
vendored
Normal file
183
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/config.cmake.in
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
## gflags CMake configuration file
|
||||
|
||||
# library version information
|
||||
set (@PACKAGE_PREFIX@_VERSION_STRING "@PACKAGE_VERSION@")
|
||||
set (@PACKAGE_PREFIX@_VERSION_MAJOR @PACKAGE_VERSION_MAJOR@)
|
||||
set (@PACKAGE_PREFIX@_VERSION_MINOR @PACKAGE_VERSION_MINOR@)
|
||||
set (@PACKAGE_PREFIX@_VERSION_PATCH @PACKAGE_VERSION_PATCH@)
|
||||
|
||||
# import targets
|
||||
if (NOT DEFINED @PACKAGE_PREFIX@_USE_TARGET_NAMESPACE)
|
||||
set (@PACKAGE_PREFIX@_USE_TARGET_NAMESPACE FALSE)
|
||||
endif ()
|
||||
if (@PACKAGE_PREFIX@_USE_TARGET_NAMESPACE)
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/@EXPORT_NAME@.cmake")
|
||||
set (@PACKAGE_PREFIX@_TARGET_NAMESPACE @PACKAGE_NAME@)
|
||||
else ()
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-nonamespace-targets.cmake")
|
||||
set (@PACKAGE_PREFIX@_TARGET_NAMESPACE)
|
||||
endif ()
|
||||
if (@PACKAGE_PREFIX@_TARGET_NAMESPACE)
|
||||
set (@PACKAGE_PREFIX@_TARGET_PREFIX ${@PACKAGE_PREFIX@_TARGET_NAMESPACE}::)
|
||||
else ()
|
||||
set (@PACKAGE_PREFIX@_TARGET_PREFIX)
|
||||
endif ()
|
||||
|
||||
# installation prefix
|
||||
get_filename_component (CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
get_filename_component (_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_PREFIX_REL2CONFIG_DIR@" ABSOLUTE)
|
||||
|
||||
# include directory
|
||||
#
|
||||
# Newer versions of CMake set the INTERFACE_INCLUDE_DIRECTORIES property
|
||||
# of the imported targets. It is hence not necessary to add this path
|
||||
# manually to the include search path for targets which link to gflags.
|
||||
set (@PACKAGE_PREFIX@_INCLUDE_DIR "${_INSTALL_PREFIX}/@INCLUDE_INSTALL_DIR@")
|
||||
|
||||
if (@PACKAGE_NAME@_FIND_COMPONENTS)
|
||||
foreach (@PACKAGE_NAME@_FIND_COMPONENT IN LISTS @PACKAGE_NAME@_FIND_COMPONENTS)
|
||||
if (@PACKAGE_NAME@_FIND_REQUIRED_${@PACKAGE_NAME@_FIND_COMPONENT} AND NOT TARGET @PACKAGE_NAME@_${@PACKAGE_NAME@_FIND_COMPONENT})
|
||||
message (FATAL_ERROR "Package @PACKAGE_NAME@ was installed without required component ${@PACKAGE_NAME@_FIND_COMPONENT}!")
|
||||
endif ()
|
||||
endforeach ()
|
||||
list (GET @PACKAGE_NAME@_FIND_COMPONENTS 0 @PACKAGE_NAME@_FIND_COMPONENT)
|
||||
else ()
|
||||
set (@PACKAGE_NAME@_FIND_COMPONENT)
|
||||
endif ()
|
||||
|
||||
# default settings of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS
|
||||
#
|
||||
# It is recommended to use either one of the following find_package commands
|
||||
# instead of setting the @PACKAGE_PREFIX@_(SHARED|NOTHREADS) variables:
|
||||
# - find_package(@PACKAGE_NAME@ REQUIRED)
|
||||
# - find_package(@PACKAGE_NAME@ COMPONENTS nothreads_static)
|
||||
# - find_package(@PACKAGE_NAME@ COMPONENTS nothreads_shared)
|
||||
# - find_package(@PACKAGE_NAME@ COMPONENTS static)
|
||||
# - find_package(@PACKAGE_NAME@ COMPONENTS shared)
|
||||
if (NOT DEFINED @PACKAGE_PREFIX@_SHARED)
|
||||
if (DEFINED @PACKAGE_NAME@_SHARED)
|
||||
set (@PACKAGE_PREFIX@_SHARED ${@PACKAGE_NAME@_SHARED})
|
||||
elseif (@PACKAGE_NAME@_FIND_COMPONENT)
|
||||
if (@PACKAGE_NAME@_FIND_COMPONENT MATCHES "shared")
|
||||
set (@PACKAGE_PREFIX@_SHARED TRUE)
|
||||
else ()
|
||||
set (@PACKAGE_PREFIX@_SHARED FALSE)
|
||||
endif ()
|
||||
elseif (TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_shared OR TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_shared)
|
||||
set (@PACKAGE_PREFIX@_SHARED TRUE)
|
||||
else ()
|
||||
set (@PACKAGE_PREFIX@_SHARED FALSE)
|
||||
endif ()
|
||||
endif ()
|
||||
if (NOT DEFINED @PACKAGE_PREFIX@_NOTHREADS)
|
||||
if (DEFINED @PACKAGE_NAME@_NOTHREADS)
|
||||
set (@PACKAGE_PREFIX@_NOTHREADS ${@PACKAGE_NAME@_NOTHREADS})
|
||||
elseif (@PACKAGE_NAME@_FIND_COMPONENT)
|
||||
if (@PACKAGE_NAME@_FIND_COMPONENT MATCHES "nothreads")
|
||||
set (@PACKAGE_PREFIX@_NOTHREADS TRUE)
|
||||
else ()
|
||||
set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
|
||||
endif ()
|
||||
elseif (TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}PACKAGE_NAME@_static OR TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_shared)
|
||||
set (@PACKAGE_PREFIX@_NOTHREADS FALSE)
|
||||
else ()
|
||||
set (@PACKAGE_PREFIX@_NOTHREADS TRUE)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# choose imported library target
|
||||
if (NOT @PACKAGE_PREFIX@_TARGET)
|
||||
if (@PACKAGE_NAME@_TARGET)
|
||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_NAME@_TARGET})
|
||||
elseif (@PACKAGE_PREFIX@_SHARED)
|
||||
if (@PACKAGE_PREFIX@_NOTHREADS)
|
||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_shared)
|
||||
else ()
|
||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_shared)
|
||||
endif ()
|
||||
else ()
|
||||
if (@PACKAGE_PREFIX@_NOTHREADS)
|
||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_nothreads_static)
|
||||
else ()
|
||||
set (@PACKAGE_PREFIX@_TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@_static)
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
if (NOT TARGET ${@PACKAGE_PREFIX@_TARGET})
|
||||
message (FATAL_ERROR "Your @PACKAGE_NAME@ installation does not contain a ${@PACKAGE_PREFIX@_TARGET} library target!"
|
||||
" Try a different combination of @PACKAGE_PREFIX@_SHARED and @PACKAGE_PREFIX@_NOTHREADS.")
|
||||
endif ()
|
||||
|
||||
# add more convenient "${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@" import target
|
||||
if (NOT TARGET ${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@)
|
||||
if (@PACKAGE_PREFIX@_SHARED)
|
||||
add_library (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ SHARED IMPORTED)
|
||||
else ()
|
||||
add_library (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ STATIC IMPORTED)
|
||||
endif ()
|
||||
# copy INTERFACE_* properties
|
||||
foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
|
||||
COMPILE_DEFINITIONS
|
||||
COMPILE_FEATURES
|
||||
COMPILE_OPTIONS
|
||||
INCLUDE_DIRECTORIES
|
||||
LINK_LIBRARIES
|
||||
POSITION_INDEPENDENT_CODE
|
||||
)
|
||||
get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME})
|
||||
if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
|
||||
set_target_properties(${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ PROPERTIES
|
||||
INTERFACE_${_@PACKAGE_PREFIX@_PROPERTY_NAME} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
|
||||
)
|
||||
endif ()
|
||||
endforeach ()
|
||||
# copy IMPORTED_*_<CONFIG> properties
|
||||
get_target_property (_@PACKAGE_PREFIX@_CONFIGURATIONS ${@PACKAGE_PREFIX@_TARGET} IMPORTED_CONFIGURATIONS)
|
||||
set_target_properties (${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ PROPERTIES IMPORTED_CONFIGURATIONS "${_@PACKAGE_PREFIX@_CONFIGURATIONS}")
|
||||
foreach (_@PACKAGE_PREFIX@_PROPERTY_NAME IN ITEMS
|
||||
IMPLIB
|
||||
LOCATION
|
||||
LINK_DEPENDENT_LIBRARIES
|
||||
LINK_INTERFACE_LIBRARIES
|
||||
LINK_INTERFACE_LANGUAGES
|
||||
LINK_INTERFACE_MULTIPLICITY
|
||||
NO_SONAME
|
||||
SONAME
|
||||
)
|
||||
foreach (_@PACKAGE_PREFIX@_CONFIG IN LISTS _@PACKAGE_PREFIX@_CONFIGURATIONS)
|
||||
get_target_property (_@PACKAGE_PREFIX@_PROPERTY_VALUE ${@PACKAGE_PREFIX@_TARGET} IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG})
|
||||
if (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
|
||||
set_target_properties(${@PACKAGE_PREFIX@_TARGET_PREFIX}@PACKAGE_NAME@ PROPERTIES
|
||||
IMPORTED_${_@PACKAGE_PREFIX@_PROPERTY_NAME}_${_@PACKAGE_PREFIX@_CONFIG} "${_@PACKAGE_PREFIX@_PROPERTY_VALUE}"
|
||||
)
|
||||
endif ()
|
||||
endforeach ()
|
||||
endforeach ()
|
||||
unset (_@PACKAGE_PREFIX@_CONFIGURATIONS)
|
||||
unset (_@PACKAGE_PREFIX@_CONFIG)
|
||||
unset (_@PACKAGE_PREFIX@_PROPERTY_NAME)
|
||||
unset (_@PACKAGE_PREFIX@_PROPERTY_VALUE)
|
||||
endif ()
|
||||
|
||||
# alias for default import target to be compatible with older CMake package configurations
|
||||
set (@PACKAGE_PREFIX@_LIBRARIES "${@PACKAGE_PREFIX@_TARGET}")
|
||||
|
||||
# set @PACKAGE_NAME@_* variables for backwards compatibility
|
||||
if (NOT "^@PACKAGE_NAME@$" STREQUAL "^@PACKAGE_PREFIX@$")
|
||||
foreach (_@PACKAGE_PREFIX@_VARIABLE IN ITEMS
|
||||
VERSION_STRING
|
||||
VERSION_MAJOR
|
||||
VERSION_MINOR
|
||||
VERSION_PATCH
|
||||
INCLUDE_DIR
|
||||
LIBRARIES
|
||||
TARGET
|
||||
)
|
||||
set (@PACKAGE_NAME@_${_@PACKAGE_PREFIX@_VARIABLE} "${@PACKAGE_PREFIX@_${_@PACKAGE_PREFIX@_VARIABLE}}")
|
||||
endforeach ()
|
||||
unset (_@PACKAGE_PREFIX@_VARIABLE)
|
||||
endif ()
|
||||
|
||||
# unset private variables
|
||||
unset (@PACKAGE_NAME@_FIND_COMPONENT)
|
||||
unset (_INSTALL_PREFIX)
|
||||
53
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/execute_test.cmake
vendored
Normal file
53
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/execute_test.cmake
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
# sanitize string stored in variable for use in regular expression.
|
||||
macro (sanitize_for_regex STRVAR)
|
||||
string (REGEX REPLACE "([.+*?^$()])" "\\\\\\1" ${STRVAR} "${${STRVAR}}")
|
||||
endmacro ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# script arguments
|
||||
if (NOT COMMAND)
|
||||
message (FATAL_ERROR "Test command not specified!")
|
||||
endif ()
|
||||
if (NOT DEFINED EXPECTED_RC)
|
||||
set (EXPECTED_RC 0)
|
||||
endif ()
|
||||
if (EXPECTED_OUTPUT)
|
||||
sanitize_for_regex(EXPECTED_OUTPUT)
|
||||
endif ()
|
||||
if (UNEXPECTED_OUTPUT)
|
||||
sanitize_for_regex(UNEXPECTED_OUTPUT)
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# set a few environment variables (useful for --tryfromenv)
|
||||
set (ENV{FLAGS_undefok} "foo,bar")
|
||||
set (ENV{FLAGS_weirdo} "")
|
||||
set (ENV{FLAGS_version} "true")
|
||||
set (ENV{FLAGS_help} "false")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# execute test command
|
||||
execute_process(
|
||||
COMMAND ${COMMAND}
|
||||
RESULT_VARIABLE RC
|
||||
OUTPUT_VARIABLE OUTPUT
|
||||
ERROR_VARIABLE OUTPUT
|
||||
)
|
||||
|
||||
if (OUTPUT)
|
||||
message ("${OUTPUT}")
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# check test result
|
||||
if (NOT RC EQUAL EXPECTED_RC)
|
||||
string (REPLACE ";" " " COMMAND "${COMMAND}")
|
||||
message (FATAL_ERROR "Command:\n\t${COMMAND}\nExit status is ${RC}, expected ${EXPECTED_RC}")
|
||||
endif ()
|
||||
if (EXPECTED_OUTPUT AND NOT OUTPUT MATCHES "${EXPECTED_OUTPUT}")
|
||||
message (FATAL_ERROR "Test output does not match expected output: ${EXPECTED_OUTPUT}")
|
||||
endif ()
|
||||
if (UNEXPECTED_OUTPUT AND OUTPUT MATCHES "${UNEXPECTED_OUTPUT}")
|
||||
message (FATAL_ERROR "Test output matches unexpected output: ${UNEXPECTED_OUTPUT}")
|
||||
endif ()
|
||||
49
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/package.cmake.in
vendored
Normal file
49
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/package.cmake.in
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# Per-generator CPack configuration file. See CPACK_PROJECT_CONFIG_FILE documented at
|
||||
# http://www.cmake.org/cmake/help/v2.8.12/cpack.html#variable:CPACK_PROJECT_CONFIG_FILE
|
||||
#
|
||||
# All common CPACK_* variables are set in CMakeLists.txt already. This file only
|
||||
# overrides some of these to provide package generator specific settings.
|
||||
|
||||
# whether package contains all development files or only runtime files
|
||||
set (DEVEL @INSTALL_HEADERS@)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Mac OS X package
|
||||
if (CPACK_GENERATOR MATCHES "PackageMaker|DragNDrop")
|
||||
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
||||
if (DEVEL)
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-devel")
|
||||
endif ()
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Debian package
|
||||
elseif (CPACK_GENERATOR MATCHES "DEB")
|
||||
|
||||
set (CPACK_PACKAGE_FILE_NAME "lib${CPACK_PACKAGE_NAME}")
|
||||
if (DEVEL)
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-dev")
|
||||
else ()
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}0")
|
||||
endif ()
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}_${CPACK_PACKAGE_VERSION}-1_${CPACK_PACKAGE_ARCHITECTURE}")
|
||||
|
||||
set (CPACK_DEBIAN_PACKAGE_DEPENDS)
|
||||
set (CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
||||
set (CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
|
||||
set (CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_RPM_PACKAGE_URL}")
|
||||
set (CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
|
||||
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_PACKAGE_ARCHITECTURE}")
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# RPM package
|
||||
elseif (CPACK_GENERATOR MATCHES "RPM")
|
||||
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
||||
if (DEVEL)
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-devel")
|
||||
endif ()
|
||||
set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-${CPACK_PACKAGE_VERSION}-1.${CPACK_PACKAGE_ARCHITECTURE}")
|
||||
|
||||
endif ()
|
||||
14
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/package.pc.in
vendored
Normal file
14
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/package.pc.in
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
bindir=${prefix}/@RUNTIME_INSTALL_DIR@
|
||||
libdir=${prefix}/@LIBRARY_INSTALL_DIR@
|
||||
includedir=${prefix}/@INCLUDE_INSTALL_DIR@
|
||||
|
||||
Name: @PACKAGE_NAME@
|
||||
Version: @PACKAGE_VERSION@
|
||||
Description: @PACKAGE_DESCRIPTION@
|
||||
URL: @PACKAGE_URL@
|
||||
Requires:
|
||||
Libs: -L${libdir} -lgflags
|
||||
Libs.private: -lpthread
|
||||
Cflags: -I${includedir}
|
||||
205
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/utils.cmake
vendored
Normal file
205
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/utils.cmake
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
## Utility CMake functions.
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Convert boolean value to 0 or 1
|
||||
macro (bool_to_int VAR)
|
||||
if (${VAR})
|
||||
set (${VAR} 1)
|
||||
else ()
|
||||
set (${VAR} 0)
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Extract version numbers from version string
|
||||
function (version_numbers version major minor patch)
|
||||
if (version MATCHES "([0-9]+)(\\.[0-9]+)?(\\.[0-9]+)?(rc[1-9][0-9]*|[a-z]+)?")
|
||||
if (CMAKE_MATCH_1)
|
||||
set (_major ${CMAKE_MATCH_1})
|
||||
else ()
|
||||
set (_major 0)
|
||||
endif ()
|
||||
if (CMAKE_MATCH_2)
|
||||
set (_minor ${CMAKE_MATCH_2})
|
||||
string (REGEX REPLACE "^\\." "" _minor "${_minor}")
|
||||
else ()
|
||||
set (_minor 0)
|
||||
endif ()
|
||||
if (CMAKE_MATCH_3)
|
||||
set (_patch ${CMAKE_MATCH_3})
|
||||
string (REGEX REPLACE "^\\." "" _patch "${_patch}")
|
||||
else ()
|
||||
set (_patch 0)
|
||||
endif ()
|
||||
else ()
|
||||
set (_major 0)
|
||||
set (_minor 0)
|
||||
set (_patch 0)
|
||||
endif ()
|
||||
set ("${major}" "${_major}" PARENT_SCOPE)
|
||||
set ("${minor}" "${_minor}" PARENT_SCOPE)
|
||||
set ("${patch}" "${_patch}" PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Determine if cache entry exists
|
||||
macro (gflags_is_cached retvar varname)
|
||||
if (DEFINED ${varname})
|
||||
get_property (${retvar} CACHE ${varname} PROPERTY TYPE SET)
|
||||
else ()
|
||||
set (${retvar} FALSE)
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Add gflags configuration variable
|
||||
#
|
||||
# The default value of the (cached) configuration value can be overridden either
|
||||
# on the CMake command-line or the super-project by setting the GFLAGS_<varname>
|
||||
# variable. When gflags is a subproject of another project (GFLAGS_IS_SUBPROJECT),
|
||||
# the variable is not added to the CMake cache. Otherwise it is cached.
|
||||
macro (gflags_define type varname docstring default)
|
||||
# note that ARGC must be expanded here, as it is not a "real" variable
|
||||
# (see the CMake documentation for the macro command)
|
||||
if ("${ARGC}" GREATER 5)
|
||||
message (FATAL_ERROR "gflags_variable: Too many macro arguments")
|
||||
endif ()
|
||||
if (NOT DEFINED GFLAGS_${varname})
|
||||
if (GFLAGS_IS_SUBPROJECT AND "${ARGC}" EQUAL 5)
|
||||
set (GFLAGS_${varname} "${ARGV4}")
|
||||
else ()
|
||||
set (GFLAGS_${varname} "${default}")
|
||||
endif ()
|
||||
endif ()
|
||||
if (GFLAGS_IS_SUBPROJECT)
|
||||
if (NOT DEFINED ${varname})
|
||||
set (${varname} "${GFLAGS_${varname}}")
|
||||
endif ()
|
||||
else ()
|
||||
set (${varname} "${GFLAGS_${varname}}" CACHE ${type} "${docstring}")
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Set property of cached gflags configuration variable
|
||||
macro (gflags_property varname property value)
|
||||
gflags_is_cached (_cached ${varname})
|
||||
if (_cached)
|
||||
# note that property must be expanded here, as it is not a "real" variable
|
||||
# (see the CMake documentation for the macro command)
|
||||
if ("${property}" STREQUAL "ADVANCED")
|
||||
if (${value})
|
||||
mark_as_advanced (FORCE ${varname})
|
||||
else ()
|
||||
mark_as_advanced (CLEAR ${varname})
|
||||
endif ()
|
||||
else ()
|
||||
set_property (CACHE ${varname} PROPERTY "${property}" "${value}")
|
||||
endif ()
|
||||
endif ()
|
||||
unset (_cached)
|
||||
endmacro ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Modify value of gflags configuration variable
|
||||
macro (gflags_set varname value)
|
||||
gflags_is_cached (_cached ${varname})
|
||||
if (_cached)
|
||||
set_property (CACHE ${varname} PROPERTY VALUE "${value}")
|
||||
else ()
|
||||
set (${varname} "${value}")
|
||||
endif ()
|
||||
unset (_cached)
|
||||
endmacro ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Configure public header files
|
||||
function (configure_headers out)
|
||||
set (tmp)
|
||||
foreach (src IN LISTS ARGN)
|
||||
if (IS_ABSOLUTE "${src}")
|
||||
list (APPEND tmp "${src}")
|
||||
elseif (EXISTS "${PROJECT_SOURCE_DIR}/src/${src}.in")
|
||||
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}.in" "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}" @ONLY)
|
||||
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}")
|
||||
else ()
|
||||
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}" "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}" COPYONLY)
|
||||
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}")
|
||||
endif ()
|
||||
endforeach ()
|
||||
set (${out} "${tmp}" PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Configure source files with .in suffix
|
||||
function (configure_sources out)
|
||||
set (tmp)
|
||||
foreach (src IN LISTS ARGN)
|
||||
if (src MATCHES ".h$" AND EXISTS "${PROJECT_SOURCE_DIR}/src/${src}.in")
|
||||
configure_file ("${PROJECT_SOURCE_DIR}/src/${src}.in" "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}" @ONLY)
|
||||
list (APPEND tmp "${PROJECT_BINARY_DIR}/include/${GFLAGS_INCLUDE_DIR}/${src}")
|
||||
else ()
|
||||
list (APPEND tmp "${PROJECT_SOURCE_DIR}/src/${src}")
|
||||
endif ()
|
||||
endforeach ()
|
||||
set (${out} "${tmp}" PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
## Add usage test
|
||||
#
|
||||
# Using PASS_REGULAR_EXPRESSION and FAIL_REGULAR_EXPRESSION would
|
||||
# do as well, but CMake/CTest does not allow us to specify an
|
||||
# expected exit status. Moreover, the execute_test.cmake script
|
||||
# sets environment variables needed by the --fromenv/--tryfromenv tests.
|
||||
macro (add_gflags_test name expected_rc expected_output unexpected_output cmd)
|
||||
set (args "--test_tmpdir=${PROJECT_BINARY_DIR}/Testing/Temporary"
|
||||
"--srcdir=${PROJECT_SOURCE_DIR}/test")
|
||||
add_test (
|
||||
NAME ${name}
|
||||
COMMAND "${CMAKE_COMMAND}" "-DCOMMAND:STRING=$<TARGET_FILE:${cmd}>;${args};${ARGN}"
|
||||
"-DEXPECTED_RC:STRING=${expected_rc}"
|
||||
"-DEXPECTED_OUTPUT:STRING=${expected_output}"
|
||||
"-DUNEXPECTED_OUTPUT:STRING=${unexpected_output}"
|
||||
-P "${PROJECT_SOURCE_DIR}/cmake/execute_test.cmake"
|
||||
WORKING_DIRECTORY "${GFLAGS_FLAGFILES_DIR}"
|
||||
)
|
||||
endmacro ()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
## Register installed package with CMake
|
||||
#
|
||||
# This function adds an entry to the CMake registry for packages with the
|
||||
# path of the directory where the package configuration file of the installed
|
||||
# package is located in order to help CMake find the package in a custom
|
||||
# installation prefix. This differs from CMake's export(PACKAGE) command
|
||||
# which registers the build directory instead.
|
||||
function (register_gflags_package CONFIG_DIR)
|
||||
if (NOT IS_ABSOLUTE "${CONFIG_DIR}")
|
||||
set (CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_DIR}")
|
||||
endif ()
|
||||
string (MD5 REGISTRY_ENTRY "${CONFIG_DIR}")
|
||||
if (WIN32)
|
||||
install (CODE
|
||||
"execute_process (
|
||||
COMMAND reg add \"HKCU\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\" /v \"${REGISTRY_ENTRY}\" /d \"${CONFIG_DIR}\" /t REG_SZ /f
|
||||
RESULT_VARIABLE RT
|
||||
ERROR_VARIABLE ERR
|
||||
OUTPUT_QUIET
|
||||
)
|
||||
if (RT EQUAL 0)
|
||||
message (STATUS \"Register: Added HKEY_CURRENT_USER\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\\\\${REGISTRY_ENTRY}\")
|
||||
else ()
|
||||
string (STRIP \"\${ERR}\" ERR)
|
||||
message (STATUS \"Register: Failed to add registry entry: \${ERR}\")
|
||||
endif ()"
|
||||
)
|
||||
elseif (IS_DIRECTORY "$ENV{HOME}")
|
||||
file (WRITE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry" "${CONFIG_DIR}")
|
||||
install (
|
||||
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry"
|
||||
DESTINATION "$ENV{HOME}/.cmake/packages/${PACKAGE_NAME}"
|
||||
RENAME "${REGISTRY_ENTRY}"
|
||||
)
|
||||
endif ()
|
||||
endfunction ()
|
||||
21
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/version.cmake.in
vendored
Normal file
21
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/cmake/version.cmake.in
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
## gflags CMake configuration version file
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# library version
|
||||
set (PACKAGE_VERSION "@PACKAGE_VERSION@")
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# check compatibility
|
||||
|
||||
# Perform compatibility check here using the input CMake variables.
|
||||
# See example in http://www.cmake.org/Wiki/CMake_2.6_Notes.
|
||||
|
||||
set (PACKAGE_VERSION_COMPATIBLE TRUE)
|
||||
set (PACKAGE_VERSION_UNSUITABLE FALSE)
|
||||
|
||||
if ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "@PACKAGE_VERSION_MAJOR@" AND
|
||||
"${PACKAGE_FIND_VERSION_MINOR}" EQUAL "@PACKAGE_VERSION_MINOR@")
|
||||
set (PACKAGE_VERSION_EXACT TRUE)
|
||||
else ()
|
||||
set (PACKAGE_VERSION_EXACT FALSE)
|
||||
endif ()
|
||||
59
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/config.h
vendored
Normal file
59
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/config.h
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
// Note: This header file is only used internally. It is not part of public interface!
|
||||
|
||||
#ifndef GFLAGS_CONFIG_H_
|
||||
#define GFLAGS_CONFIG_H_
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// System checks
|
||||
|
||||
// CMake build configuration is written to defines.h file, unused by Bazel build
|
||||
#if !defined(GFLAGS_BAZEL_BUILD)
|
||||
# include "defines.h"
|
||||
#endif
|
||||
|
||||
// gcc requires this to get PRId64, etc.
|
||||
#if defined(HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
|
||||
# define __STDC_FORMAT_MACROS 1
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Path separator
|
||||
#ifndef PATH_SEPARATOR
|
||||
# ifdef OS_WINDOWS
|
||||
# define PATH_SEPARATOR '\\'
|
||||
# else
|
||||
# define PATH_SEPARATOR '/'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Windows
|
||||
|
||||
// Always export symbols when compiling a shared library as this file is only
|
||||
// included by internal modules when building the gflags library itself.
|
||||
// The gflags_declare.h header file will set it to import these symbols otherwise.
|
||||
#ifndef GFLAGS_DLL_DECL
|
||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||
# define GFLAGS_DLL_DECL __declspec(dllexport)
|
||||
# elif defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define GFLAGS_DLL_DECL __attribute__((visibility("default")))
|
||||
# else
|
||||
# define GFLAGS_DLL_DECL
|
||||
# endif
|
||||
#endif
|
||||
// Flags defined by the gflags library itself must be exported
|
||||
#ifndef GFLAGS_DLL_DEFINE_FLAG
|
||||
# define GFLAGS_DLL_DEFINE_FLAG GFLAGS_DLL_DECL
|
||||
#endif
|
||||
|
||||
#ifdef OS_WINDOWS
|
||||
// The unittests import the symbols of the shared gflags library
|
||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||
# define GFLAGS_DLL_DECL_FOR_UNITTESTS __declspec(dllimport)
|
||||
# endif
|
||||
# include "windows_port.h"
|
||||
#endif
|
||||
|
||||
|
||||
#endif // GFLAGS_CONFIG_H_
|
||||
48
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/defines.h.in
vendored
Normal file
48
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/defines.h.in
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Generated from defines.h.in during build configuration using CMake. */
|
||||
|
||||
// Note: This header file is only used internally. It is not part of public interface!
|
||||
// Any cmakedefine is defined using the -D flag instead when Bazel is used.
|
||||
// For Bazel, this file is thus not used to avoid a private file in $(GENDIR).
|
||||
|
||||
#ifndef GFLAGS_DEFINES_H_
|
||||
#define GFLAGS_DEFINES_H_
|
||||
|
||||
|
||||
// Define if you build this library for a MS Windows OS.
|
||||
#cmakedefine OS_WINDOWS
|
||||
|
||||
// Define if you have the <stdint.h> header file.
|
||||
#cmakedefine HAVE_STDINT_H
|
||||
|
||||
// Define if you have the <sys/types.h> header file.
|
||||
#cmakedefine HAVE_SYS_TYPES_H
|
||||
|
||||
// Define if you have the <inttypes.h> header file.
|
||||
#cmakedefine HAVE_INTTYPES_H
|
||||
|
||||
// Define if you have the <sys/stat.h> header file.
|
||||
#cmakedefine HAVE_SYS_STAT_H
|
||||
|
||||
// Define if you have the <unistd.h> header file.
|
||||
#cmakedefine HAVE_UNISTD_H
|
||||
|
||||
// Define if you have the <fnmatch.h> header file.
|
||||
#cmakedefine HAVE_FNMATCH_H
|
||||
|
||||
// Define if you have the <shlwapi.h> header file (Windows 2000/XP).
|
||||
#cmakedefine HAVE_SHLWAPI_H
|
||||
|
||||
// Define if you have the strtoll function.
|
||||
#cmakedefine HAVE_STRTOLL
|
||||
|
||||
// Define if you have the strtoq function.
|
||||
#cmakedefine HAVE_STRTOQ
|
||||
|
||||
// Define if you have the <pthread.h> header file.
|
||||
#cmakedefine HAVE_PTHREAD
|
||||
|
||||
// Define if your pthread library defines the type pthread_rwlock_t
|
||||
#cmakedefine HAVE_RWLOCK
|
||||
|
||||
|
||||
#endif // GFLAGS_DEFINES_H_
|
||||
2013
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags.cc
vendored
Normal file
2013
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags.cc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
626
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags.h.in
vendored
Normal file
626
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags.h.in
vendored
Normal file
@@ -0,0 +1,626 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// ---
|
||||
// Revamped and reorganized by Craig Silverstein
|
||||
//
|
||||
// This is the file that should be included by any file which declares
|
||||
// or defines a command line flag or wants to parse command line flags
|
||||
// or print a program usage message (which will include information about
|
||||
// flags). Executive summary, in the form of an example foo.cc file:
|
||||
//
|
||||
// #include "foo.h" // foo.h has a line "DECLARE_int32(start);"
|
||||
// #include "validators.h" // hypothetical file defining ValidateIsFile()
|
||||
//
|
||||
// DEFINE_int32(end, 1000, "The last record to read");
|
||||
//
|
||||
// DEFINE_string(filename, "my_file.txt", "The file to read");
|
||||
// // Crash if the specified file does not exist.
|
||||
// static bool dummy = RegisterFlagValidator(&FLAGS_filename,
|
||||
// &ValidateIsFile);
|
||||
//
|
||||
// DECLARE_bool(verbose); // some other file has a DEFINE_bool(verbose, ...)
|
||||
//
|
||||
// void MyFunc() {
|
||||
// if (FLAGS_verbose) printf("Records %d-%d\n", FLAGS_start, FLAGS_end);
|
||||
// }
|
||||
//
|
||||
// Then, at the command-line:
|
||||
// ./foo --noverbose --start=5 --end=100
|
||||
//
|
||||
// For more details, see
|
||||
// doc/gflags.html
|
||||
//
|
||||
// --- A note about thread-safety:
|
||||
//
|
||||
// We describe many functions in this routine as being thread-hostile,
|
||||
// thread-compatible, or thread-safe. Here are the meanings we use:
|
||||
//
|
||||
// thread-safe: it is safe for multiple threads to call this routine
|
||||
// (or, when referring to a class, methods of this class)
|
||||
// concurrently.
|
||||
// thread-hostile: it is not safe for multiple threads to call this
|
||||
// routine (or methods of this class) concurrently. In gflags,
|
||||
// most thread-hostile routines are intended to be called early in,
|
||||
// or even before, main() -- that is, before threads are spawned.
|
||||
// thread-compatible: it is safe for multiple threads to read from
|
||||
// this variable (when applied to variables), or to call const
|
||||
// methods of this class (when applied to classes), as long as no
|
||||
// other thread is writing to the variable or calling non-const
|
||||
// methods of this class.
|
||||
|
||||
#ifndef GFLAGS_GFLAGS_H_
|
||||
#define GFLAGS_GFLAGS_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gflags/gflags_declare.h" // IWYU pragma: export
|
||||
|
||||
|
||||
// We always want to export variables defined in user code
|
||||
#ifndef GFLAGS_DLL_DEFINE_FLAG
|
||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||
# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
|
||||
# else
|
||||
# define GFLAGS_DLL_DEFINE_FLAG
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace GFLAGS_NAMESPACE {
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// To actually define a flag in a file, use DEFINE_bool,
|
||||
// DEFINE_string, etc. at the bottom of this file. You may also find
|
||||
// it useful to register a validator with the flag. This ensures that
|
||||
// when the flag is parsed from the commandline, or is later set via
|
||||
// SetCommandLineOption, we call the validation function. It is _not_
|
||||
// called when you assign the value to the flag directly using the = operator.
|
||||
//
|
||||
// The validation function should return true if the flag value is valid, and
|
||||
// false otherwise. If the function returns false for the new setting of the
|
||||
// flag, the flag will retain its current value. If it returns false for the
|
||||
// default value, ParseCommandLineFlags() will die.
|
||||
//
|
||||
// This function is safe to call at global construct time (as in the
|
||||
// example below).
|
||||
//
|
||||
// Example use:
|
||||
// static bool ValidatePort(const char* flagname, int32 value) {
|
||||
// if (value > 0 && value < 32768) // value is ok
|
||||
// return true;
|
||||
// printf("Invalid value for --%s: %d\n", flagname, (int)value);
|
||||
// return false;
|
||||
// }
|
||||
// DEFINE_int32(port, 0, "What port to listen on");
|
||||
// static bool dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort);
|
||||
|
||||
// Returns true if successfully registered, false if not (because the
|
||||
// first argument doesn't point to a command-line flag, or because a
|
||||
// validator is already registered for this flag).
|
||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const bool* flag, bool (*validate_fn)(const char*, bool));
|
||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int32* flag, bool (*validate_fn)(const char*, int32));
|
||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint32* flag, bool (*validate_fn)(const char*, uint32));
|
||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int64* flag, bool (*validate_fn)(const char*, int64));
|
||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint64* flag, bool (*validate_fn)(const char*, uint64));
|
||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const double* flag, bool (*validate_fn)(const char*, double));
|
||||
extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const std::string* flag, bool (*validate_fn)(const char*, const std::string&));
|
||||
|
||||
// Convenience macro for the registration of a flag validator
|
||||
#define DEFINE_validator(name, validator) \
|
||||
static const bool name##_validator_registered = \
|
||||
GFLAGS_NAMESPACE::RegisterFlagValidator(&FLAGS_##name, validator)
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// These methods are the best way to get access to info about the
|
||||
// list of commandline flags. Note that these routines are pretty slow.
|
||||
// GetAllFlags: mostly-complete info about the list, sorted by file.
|
||||
// ShowUsageWithFlags: pretty-prints the list to stdout (what --help does)
|
||||
// ShowUsageWithFlagsRestrict: limit to filenames with restrict as a substr
|
||||
//
|
||||
// In addition to accessing flags, you can also access argv[0] (the program
|
||||
// name) and argv (the entire commandline), which we sock away a copy of.
|
||||
// These variables are static, so you should only set them once.
|
||||
//
|
||||
// No need to export this data only structure from DLL, avoiding VS warning 4251.
|
||||
struct CommandLineFlagInfo {
|
||||
std::string name; // the name of the flag
|
||||
std::string type; // the type of the flag: int32, etc
|
||||
std::string description; // the "help text" associated with the flag
|
||||
std::string current_value; // the current value, as a string
|
||||
std::string default_value; // the default value, as a string
|
||||
std::string filename; // 'cleaned' version of filename holding the flag
|
||||
bool has_validator_fn; // true if RegisterFlagValidator called on this flag
|
||||
bool is_default; // true if the flag has the default value and
|
||||
// has not been set explicitly from the cmdline
|
||||
// or via SetCommandLineOption
|
||||
const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo)
|
||||
};
|
||||
|
||||
// Using this inside of a validator is a recipe for a deadlock.
|
||||
// TODO(user) Fix locking when validators are running, to make it safe to
|
||||
// call validators during ParseAllFlags.
|
||||
// Also make sure then to uncomment the corresponding unit test in
|
||||
// gflags_unittest.sh
|
||||
extern GFLAGS_DLL_DECL void GetAllFlags(std::vector<CommandLineFlagInfo>* OUTPUT);
|
||||
// These two are actually defined in gflags_reporting.cc.
|
||||
extern GFLAGS_DLL_DECL void ShowUsageWithFlags(const char *argv0); // what --help does
|
||||
extern GFLAGS_DLL_DECL void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict);
|
||||
|
||||
// Create a descriptive string for a flag.
|
||||
// Goes to some trouble to make pretty line breaks.
|
||||
extern GFLAGS_DLL_DECL std::string DescribeOneFlag(const CommandLineFlagInfo& flag);
|
||||
|
||||
// Thread-hostile; meant to be called before any threads are spawned.
|
||||
extern GFLAGS_DLL_DECL void SetArgv(int argc, const char** argv);
|
||||
|
||||
// The following functions are thread-safe as long as SetArgv() is
|
||||
// only called before any threads start.
|
||||
extern GFLAGS_DLL_DECL const std::vector<std::string>& GetArgvs();
|
||||
extern GFLAGS_DLL_DECL const char* GetArgv(); // all of argv as a string
|
||||
extern GFLAGS_DLL_DECL const char* GetArgv0(); // only argv0
|
||||
extern GFLAGS_DLL_DECL uint32 GetArgvSum(); // simple checksum of argv
|
||||
extern GFLAGS_DLL_DECL const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set
|
||||
extern GFLAGS_DLL_DECL const char* ProgramInvocationShortName(); // basename(argv0)
|
||||
|
||||
// ProgramUsage() is thread-safe as long as SetUsageMessage() is only
|
||||
// called before any threads start.
|
||||
extern GFLAGS_DLL_DECL const char* ProgramUsage(); // string set by SetUsageMessage()
|
||||
|
||||
// VersionString() is thread-safe as long as SetVersionString() is only
|
||||
// called before any threads start.
|
||||
extern GFLAGS_DLL_DECL const char* VersionString(); // string set by SetVersionString()
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Normally you access commandline flags by just saying "if (FLAGS_foo)"
|
||||
// or whatever, and set them by calling "FLAGS_foo = bar" (or, more
|
||||
// commonly, via the DEFINE_foo macro). But if you need a bit more
|
||||
// control, we have programmatic ways to get/set the flags as well.
|
||||
// These programmatic ways to access flags are thread-safe, but direct
|
||||
// access is only thread-compatible.
|
||||
|
||||
// Return true iff the flagname was found.
|
||||
// OUTPUT is set to the flag's value, or unchanged if we return false.
|
||||
extern GFLAGS_DLL_DECL bool GetCommandLineOption(const char* name, std::string* OUTPUT);
|
||||
|
||||
// Return true iff the flagname was found. OUTPUT is set to the flag's
|
||||
// CommandLineFlagInfo or unchanged if we return false.
|
||||
extern GFLAGS_DLL_DECL bool GetCommandLineFlagInfo(const char* name, CommandLineFlagInfo* OUTPUT);
|
||||
|
||||
// Return the CommandLineFlagInfo of the flagname. exit() if name not found.
|
||||
// Example usage, to check if a flag's value is currently the default value:
|
||||
// if (GetCommandLineFlagInfoOrDie("foo").is_default) ...
|
||||
extern GFLAGS_DLL_DECL CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
|
||||
|
||||
enum GFLAGS_DLL_DECL FlagSettingMode {
|
||||
// update the flag's value (can call this multiple times).
|
||||
SET_FLAGS_VALUE,
|
||||
// update the flag's value, but *only if* it has not yet been updated
|
||||
// with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef".
|
||||
SET_FLAG_IF_DEFAULT,
|
||||
// set the flag's default value to this. If the flag has not yet updated
|
||||
// yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef")
|
||||
// change the flag's current value to the new default value as well.
|
||||
SET_FLAGS_DEFAULT
|
||||
};
|
||||
|
||||
// Set a particular flag ("command line option"). Returns a string
|
||||
// describing the new value that the option has been set to. The
|
||||
// return value API is not well-specified, so basically just depend on
|
||||
// it to be empty if the setting failed for some reason -- the name is
|
||||
// not a valid flag name, or the value is not a valid value -- and
|
||||
// non-empty else.
|
||||
|
||||
// SetCommandLineOption uses set_mode == SET_FLAGS_VALUE (the common case)
|
||||
extern GFLAGS_DLL_DECL std::string SetCommandLineOption (const char* name, const char* value);
|
||||
extern GFLAGS_DLL_DECL std::string SetCommandLineOptionWithMode(const char* name, const char* value, FlagSettingMode set_mode);
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Saves the states (value, default value, whether the user has set
|
||||
// the flag, registered validators, etc) of all flags, and restores
|
||||
// them when the FlagSaver is destroyed. This is very useful in
|
||||
// tests, say, when you want to let your tests change the flags, but
|
||||
// make sure that they get reverted to the original states when your
|
||||
// test is complete.
|
||||
//
|
||||
// Example usage:
|
||||
// void TestFoo() {
|
||||
// FlagSaver s1;
|
||||
// FLAG_foo = false;
|
||||
// FLAG_bar = "some value";
|
||||
//
|
||||
// // test happens here. You can return at any time
|
||||
// // without worrying about restoring the FLAG values.
|
||||
// }
|
||||
//
|
||||
// Note: This class is marked with GFLAGS_ATTRIBUTE_UNUSED because all
|
||||
// the work is done in the constructor and destructor, so in the standard
|
||||
// usage example above, the compiler would complain that it's an
|
||||
// unused variable.
|
||||
//
|
||||
// This class is thread-safe. However, its destructor writes to
|
||||
// exactly the set of flags that have changed value during its
|
||||
// lifetime, so concurrent _direct_ access to those flags
|
||||
// (i.e. FLAGS_foo instead of {Get,Set}CommandLineOption()) is unsafe.
|
||||
|
||||
class GFLAGS_DLL_DECL FlagSaver {
|
||||
public:
|
||||
FlagSaver();
|
||||
~FlagSaver();
|
||||
|
||||
private:
|
||||
class FlagSaverImpl* impl_; // we use pimpl here to keep API steady
|
||||
|
||||
FlagSaver(const FlagSaver&); // no copying!
|
||||
void operator=(const FlagSaver&);
|
||||
}@GFLAGS_ATTRIBUTE_UNUSED@;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Some deprecated or hopefully-soon-to-be-deprecated functions.
|
||||
|
||||
// This is often used for logging. TODO(csilvers): figure out a better way
|
||||
extern GFLAGS_DLL_DECL std::string CommandlineFlagsIntoString();
|
||||
// Usually where this is used, a FlagSaver should be used instead.
|
||||
extern GFLAGS_DLL_DECL
|
||||
bool ReadFlagsFromString(const std::string& flagfilecontents,
|
||||
const char* prog_name,
|
||||
bool errors_are_fatal); // uses SET_FLAGS_VALUE
|
||||
|
||||
// These let you manually implement --flagfile functionality.
|
||||
// DEPRECATED.
|
||||
extern GFLAGS_DLL_DECL bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name);
|
||||
extern GFLAGS_DLL_DECL bool ReadFromFlagsFile(const std::string& filename, const char* prog_name, bool errors_are_fatal); // uses SET_FLAGS_VALUE
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Useful routines for initializing flags from the environment.
|
||||
// In each case, if 'varname' does not exist in the environment
|
||||
// return defval. If 'varname' does exist but is not valid
|
||||
// (e.g., not a number for an int32 flag), abort with an error.
|
||||
// Otherwise, return the value. NOTE: for booleans, for true use
|
||||
// 't' or 'T' or 'true' or '1', for false 'f' or 'F' or 'false' or '0'.
|
||||
|
||||
extern GFLAGS_DLL_DECL bool BoolFromEnv(const char *varname, bool defval);
|
||||
extern GFLAGS_DLL_DECL int32 Int32FromEnv(const char *varname, int32 defval);
|
||||
extern GFLAGS_DLL_DECL uint32 Uint32FromEnv(const char *varname, uint32 defval);
|
||||
extern GFLAGS_DLL_DECL int64 Int64FromEnv(const char *varname, int64 defval);
|
||||
extern GFLAGS_DLL_DECL uint64 Uint64FromEnv(const char *varname, uint64 defval);
|
||||
extern GFLAGS_DLL_DECL double DoubleFromEnv(const char *varname, double defval);
|
||||
extern GFLAGS_DLL_DECL const char *StringFromEnv(const char *varname, const char *defval);
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// The next two functions parse gflags from main():
|
||||
|
||||
// Set the "usage" message for this program. For example:
|
||||
// string usage("This program does nothing. Sample usage:\n");
|
||||
// usage += argv[0] + " <uselessarg1> <uselessarg2>";
|
||||
// SetUsageMessage(usage);
|
||||
// Do not include commandline flags in the usage: we do that for you!
|
||||
// Thread-hostile; meant to be called before any threads are spawned.
|
||||
extern GFLAGS_DLL_DECL void SetUsageMessage(const std::string& usage);
|
||||
|
||||
// Sets the version string, which is emitted with --version.
|
||||
// For instance: SetVersionString("1.3");
|
||||
// Thread-hostile; meant to be called before any threads are spawned.
|
||||
extern GFLAGS_DLL_DECL void SetVersionString(const std::string& version);
|
||||
|
||||
|
||||
// Looks for flags in argv and parses them. Rearranges argv to put
|
||||
// flags first, or removes them entirely if remove_flags is true.
|
||||
// If a flag is defined more than once in the command line or flag
|
||||
// file, the last definition is used. Returns the index (into argv)
|
||||
// of the first non-flag argument.
|
||||
// See top-of-file for more details on this function.
|
||||
#ifndef SWIG // In swig, use ParseCommandLineFlagsScript() instead.
|
||||
extern GFLAGS_DLL_DECL uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags);
|
||||
#endif
|
||||
|
||||
|
||||
// Calls to ParseCommandLineNonHelpFlags and then to
|
||||
// HandleCommandLineHelpFlags can be used instead of a call to
|
||||
// ParseCommandLineFlags during initialization, in order to allow for
|
||||
// changing default values for some FLAGS (via
|
||||
// e.g. SetCommandLineOptionWithMode calls) between the time of
|
||||
// command line parsing and the time of dumping help information for
|
||||
// the flags as a result of command line parsing. If a flag is
|
||||
// defined more than once in the command line or flag file, the last
|
||||
// definition is used. Returns the index (into argv) of the first
|
||||
// non-flag argument. (If remove_flags is true, will always return 1.)
|
||||
extern GFLAGS_DLL_DECL uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv, bool remove_flags);
|
||||
|
||||
// This is actually defined in gflags_reporting.cc.
|
||||
// This function is misnamed (it also handles --version, etc.), but
|
||||
// it's too late to change that now. :-(
|
||||
extern GFLAGS_DLL_DECL void HandleCommandLineHelpFlags(); // in gflags_reporting.cc
|
||||
|
||||
// Allow command line reparsing. Disables the error normally
|
||||
// generated when an unknown flag is found, since it may be found in a
|
||||
// later parse. Thread-hostile; meant to be called before any threads
|
||||
// are spawned.
|
||||
extern GFLAGS_DLL_DECL void AllowCommandLineReparsing();
|
||||
|
||||
// Reparse the flags that have not yet been recognized. Only flags
|
||||
// registered since the last parse will be recognized. Any flag value
|
||||
// must be provided as part of the argument using "=", not as a
|
||||
// separate command line argument that follows the flag argument.
|
||||
// Intended for handling flags from dynamically loaded libraries,
|
||||
// since their flags are not registered until they are loaded.
|
||||
extern GFLAGS_DLL_DECL void ReparseCommandLineNonHelpFlags();
|
||||
|
||||
// Clean up memory allocated by flags. This is only needed to reduce
|
||||
// the quantity of "potentially leaked" reports emitted by memory
|
||||
// debugging tools such as valgrind. It is not required for normal
|
||||
// operation, or for the google perftools heap-checker. It must only
|
||||
// be called when the process is about to exit, and all threads that
|
||||
// might access flags are quiescent. Referencing flags after this is
|
||||
// called will have unexpected consequences. This is not safe to run
|
||||
// when multiple threads might be running: the function is
|
||||
// thread-hostile.
|
||||
extern GFLAGS_DLL_DECL void ShutDownCommandLineFlags();
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Now come the command line flag declaration/definition macros that
|
||||
// will actually be used. They're kind of hairy. A major reason
|
||||
// for this is initialization: we want people to be able to access
|
||||
// variables in global constructors and have that not crash, even if
|
||||
// their global constructor runs before the global constructor here.
|
||||
// (Obviously, we can't guarantee the flags will have the correct
|
||||
// default value in that case, but at least accessing them is safe.)
|
||||
// The only way to do that is have flags point to a static buffer.
|
||||
// So we make one, using a union to ensure proper alignment, and
|
||||
// then use placement-new to actually set up the flag with the
|
||||
// correct default value. In the same vein, we have to worry about
|
||||
// flag access in global destructors, so FlagRegisterer has to be
|
||||
// careful never to destroy the flag-values it constructs.
|
||||
//
|
||||
// Note that when we define a flag variable FLAGS_<name>, we also
|
||||
// preemptively define a junk variable, FLAGS_no<name>. This is to
|
||||
// cause a link-time error if someone tries to define 2 flags with
|
||||
// names like "logging" and "nologging". We do this because a bool
|
||||
// flag FLAG can be set from the command line to true with a "-FLAG"
|
||||
// argument, and to false with a "-noFLAG" argument, and so this can
|
||||
// potentially avert confusion.
|
||||
//
|
||||
// We also put flags into their own namespace. It is purposefully
|
||||
// named in an opaque way that people should have trouble typing
|
||||
// directly. The idea is that DEFINE puts the flag in the weird
|
||||
// namespace, and DECLARE imports the flag from there into the current
|
||||
// namespace. The net result is to force people to use DECLARE to get
|
||||
// access to a flag, rather than saying "extern GFLAGS_DLL_DECL bool FLAGS_whatever;"
|
||||
// or some such instead. We want this so we can put extra
|
||||
// functionality (like sanity-checking) in DECLARE if we want, and
|
||||
// make sure it is picked up everywhere.
|
||||
//
|
||||
// We also put the type of the variable in the namespace, so that
|
||||
// people can't DECLARE_int32 something that they DEFINE_bool'd
|
||||
// elsewhere.
|
||||
|
||||
class GFLAGS_DLL_DECL FlagRegisterer {
|
||||
public:
|
||||
// We instantiate this template ctor for all supported types,
|
||||
// so it is possible to place implementation of the FlagRegisterer ctor in
|
||||
// .cc file.
|
||||
// Calling this constructor with unsupported type will produce linker error.
|
||||
template <typename FlagType>
|
||||
FlagRegisterer(const char* name,
|
||||
const char* help, const char* filename,
|
||||
FlagType* current_storage, FlagType* defvalue_storage);
|
||||
};
|
||||
|
||||
// Force compiler to not generate code for the given template specialization.
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1800 // Visual Studio 2013 version 12.0
|
||||
#define GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(type)
|
||||
#else
|
||||
#define GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(type) \
|
||||
extern template GFLAGS_DLL_DECL FlagRegisterer::FlagRegisterer( \
|
||||
const char* name, const char* help, const char* filename, \
|
||||
type* current_storage, type* defvalue_storage)
|
||||
#endif
|
||||
|
||||
// Do this for all supported flag types.
|
||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(bool);
|
||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(int32);
|
||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(uint32);
|
||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(int64);
|
||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(uint64);
|
||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(double);
|
||||
GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(std::string);
|
||||
|
||||
#undef GFLAGS_DECLARE_FLAG_REGISTERER_CTOR
|
||||
|
||||
// If your application #defines STRIP_FLAG_HELP to a non-zero value
|
||||
// before #including this file, we remove the help message from the
|
||||
// binary file. This can reduce the size of the resulting binary
|
||||
// somewhat, and may also be useful for security reasons.
|
||||
|
||||
extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
|
||||
|
||||
|
||||
} // namespace GFLAGS_NAMESPACE
|
||||
|
||||
|
||||
#ifndef SWIG // In swig, ignore the main flag declarations
|
||||
|
||||
#if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0
|
||||
// Need this construct to avoid the 'defined but not used' warning.
|
||||
#define MAYBE_STRIPPED_HELP(txt) \
|
||||
(false ? (txt) : GFLAGS_NAMESPACE::kStrippedFlagHelp)
|
||||
#else
|
||||
#define MAYBE_STRIPPED_HELP(txt) txt
|
||||
#endif
|
||||
|
||||
// Each command-line flag has two variables associated with it: one
|
||||
// with the current value, and one with the default value. However,
|
||||
// we have a third variable, which is where value is assigned; it's a
|
||||
// constant. This guarantees that FLAG_##value is initialized at
|
||||
// static initialization time (e.g. before program-start) rather than
|
||||
// than global construction time (which is after program-start but
|
||||
// before main), at least when 'value' is a compile-time constant. We
|
||||
// use a small trick for the "default value" variable, and call it
|
||||
// FLAGS_no<name>. This serves the second purpose of assuring a
|
||||
// compile error if someone tries to define a flag named no<name>
|
||||
// which is illegal (--foo and --nofoo both affect the "foo" flag).
|
||||
#define DEFINE_VARIABLE(type, shorttype, name, value, help) \
|
||||
namespace fL##shorttype { \
|
||||
static const type FLAGS_nono##name = value; \
|
||||
/* We always want to export defined variables, dll or no */ \
|
||||
GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \
|
||||
static type FLAGS_no##name = FLAGS_nono##name; \
|
||||
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
|
||||
#name, MAYBE_STRIPPED_HELP(help), __FILE__, \
|
||||
&FLAGS_##name, &FLAGS_no##name); \
|
||||
} \
|
||||
using fL##shorttype::FLAGS_##name
|
||||
|
||||
// For DEFINE_bool, we want to do the extra check that the passed-in
|
||||
// value is actually a bool, and not a string or something that can be
|
||||
// coerced to a bool. These declarations (no definition needed!) will
|
||||
// help us do that, and never evaluate From, which is important.
|
||||
// We'll use 'sizeof(IsBool(val))' to distinguish. This code requires
|
||||
// that the compiler have different sizes for bool & double. Since
|
||||
// this is not guaranteed by the standard, we check it with a
|
||||
// COMPILE_ASSERT.
|
||||
namespace fLB {
|
||||
struct CompileAssert {};
|
||||
typedef CompileAssert expected_sizeof_double_neq_sizeof_bool[
|
||||
(sizeof(double) != sizeof(bool)) ? 1 : -1];
|
||||
template<typename From> double GFLAGS_DLL_DECL IsBoolFlag(const From& from);
|
||||
GFLAGS_DLL_DECL bool IsBoolFlag(bool from);
|
||||
} // namespace fLB
|
||||
|
||||
// Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros
|
||||
// are in a separate include, gflags_declare.h, for reducing
|
||||
// the physical transitive size for DECLARE use.
|
||||
#define DEFINE_bool(name, val, txt) \
|
||||
namespace fLB { \
|
||||
typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \
|
||||
(sizeof(::fLB::IsBoolFlag(val)) != sizeof(double))? 1: -1]; \
|
||||
} \
|
||||
DEFINE_VARIABLE(bool, B, name, val, txt)
|
||||
|
||||
#define DEFINE_int32(name, val, txt) \
|
||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::int32, I, \
|
||||
name, val, txt)
|
||||
|
||||
#define DEFINE_uint32(name,val, txt) \
|
||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint32, U, \
|
||||
name, val, txt)
|
||||
|
||||
#define DEFINE_int64(name, val, txt) \
|
||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, \
|
||||
name, val, txt)
|
||||
|
||||
#define DEFINE_uint64(name,val, txt) \
|
||||
DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, \
|
||||
name, val, txt)
|
||||
|
||||
#define DEFINE_double(name, val, txt) \
|
||||
DEFINE_VARIABLE(double, D, name, val, txt)
|
||||
|
||||
// Strings are trickier, because they're not a POD, so we can't
|
||||
// construct them at static-initialization time (instead they get
|
||||
// constructed at global-constructor time, which is much later). To
|
||||
// try to avoid crashes in that case, we use a char buffer to store
|
||||
// the string, which we can static-initialize, and then placement-new
|
||||
// into it later. It's not perfect, but the best we can do.
|
||||
|
||||
namespace fLS {
|
||||
|
||||
inline clstring* dont_pass0toDEFINE_string(char *stringspot,
|
||||
const char *value) {
|
||||
return new(stringspot) clstring(value);
|
||||
}
|
||||
inline clstring* dont_pass0toDEFINE_string(char *stringspot,
|
||||
const clstring &value) {
|
||||
return new(stringspot) clstring(value);
|
||||
}
|
||||
inline clstring* dont_pass0toDEFINE_string(char *stringspot,
|
||||
int value);
|
||||
|
||||
// Auxiliary class used to explicitly call destructor of string objects
|
||||
// allocated using placement new during static program deinitialization.
|
||||
// The destructor MUST be an inline function such that the explicit
|
||||
// destruction occurs in the same compilation unit as the placement new.
|
||||
class StringFlagDestructor {
|
||||
void *current_storage_;
|
||||
void *defvalue_storage_;
|
||||
|
||||
public:
|
||||
|
||||
StringFlagDestructor(void *current, void *defvalue)
|
||||
: current_storage_(current), defvalue_storage_(defvalue) {}
|
||||
|
||||
~StringFlagDestructor() {
|
||||
reinterpret_cast<clstring*>(current_storage_ )->~clstring();
|
||||
reinterpret_cast<clstring*>(defvalue_storage_)->~clstring();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fLS
|
||||
|
||||
// We need to define a var named FLAGS_no##name so people don't define
|
||||
// --string and --nostring. And we need a temporary place to put val
|
||||
// so we don't have to evaluate it twice. Two great needs that go
|
||||
// great together!
|
||||
// The weird 'using' + 'extern' inside the fLS namespace is to work around
|
||||
// an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See
|
||||
// http://code.google.com/p/google-gflags/issues/detail?id=20
|
||||
#define DEFINE_string(name, val, txt) \
|
||||
namespace fLS { \
|
||||
using ::fLS::clstring; \
|
||||
using ::fLS::StringFlagDestructor; \
|
||||
static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \
|
||||
clstring* const FLAGS_no##name = ::fLS:: \
|
||||
dont_pass0toDEFINE_string(s_##name[0].s, \
|
||||
val); \
|
||||
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
|
||||
#name, MAYBE_STRIPPED_HELP(txt), __FILE__, \
|
||||
FLAGS_no##name, new (s_##name[1].s) clstring(*FLAGS_no##name)); \
|
||||
static StringFlagDestructor d_##name(s_##name[0].s, s_##name[1].s); \
|
||||
extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \
|
||||
using fLS::FLAGS_##name; \
|
||||
clstring& FLAGS_##name = *FLAGS_no##name; \
|
||||
} \
|
||||
using fLS::FLAGS_##name
|
||||
|
||||
#endif // SWIG
|
||||
|
||||
|
||||
@INCLUDE_GFLAGS_NS_H@
|
||||
|
||||
|
||||
#endif // GFLAGS_GFLAGS_H_
|
||||
772
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_completions.cc
vendored
Normal file
772
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_completions.cc
vendored
Normal file
@@ -0,0 +1,772 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---
|
||||
|
||||
// Bash-style command line flag completion for C++ binaries
|
||||
//
|
||||
// This module implements bash-style completions. It achieves this
|
||||
// goal in the following broad chunks:
|
||||
//
|
||||
// 1) Take a to-be-completed word, and examine it for search hints
|
||||
// 2) Identify all potentially matching flags
|
||||
// 2a) If there are no matching flags, do nothing.
|
||||
// 2b) If all matching flags share a common prefix longer than the
|
||||
// completion word, output just that matching prefix
|
||||
// 3) Categorize those flags to produce a rough ordering of relevence.
|
||||
// 4) Potentially trim the set of flags returned to a smaller number
|
||||
// that bash is happier with
|
||||
// 5) Output the matching flags in groups ordered by relevence.
|
||||
// 5a) Force bash to place most-relevent groups at the top of the list
|
||||
// 5b) Trim most flag's descriptions to fit on a single terminal line
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for strlen
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "config.h"
|
||||
#include "gflags/gflags.h"
|
||||
#include "gflags/gflags_completions.h"
|
||||
#include "util.h"
|
||||
|
||||
using std::set;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
|
||||
DEFINE_string(tab_completion_word, "",
|
||||
"If non-empty, HandleCommandLineCompletions() will hijack the "
|
||||
"process and attempt to do bash-style command line flag "
|
||||
"completion on this value.");
|
||||
DEFINE_int32(tab_completion_columns, 80,
|
||||
"Number of columns to use in output for tab completion");
|
||||
|
||||
|
||||
namespace GFLAGS_NAMESPACE {
|
||||
|
||||
|
||||
namespace {
|
||||
// Function prototypes and Type forward declarations. Code may be
|
||||
// more easily understood if it is roughly ordered according to
|
||||
// control flow, rather than by C's "declare before use" ordering
|
||||
struct CompletionOptions;
|
||||
struct NotableFlags;
|
||||
|
||||
// The entry point if flag completion is to be used.
|
||||
static void PrintFlagCompletionInfo(void);
|
||||
|
||||
|
||||
// 1) Examine search word
|
||||
static void CanonicalizeCursorWordAndSearchOptions(
|
||||
const string &cursor_word,
|
||||
string *canonical_search_token,
|
||||
CompletionOptions *options);
|
||||
|
||||
static bool RemoveTrailingChar(string *str, char c);
|
||||
|
||||
|
||||
// 2) Find all matches
|
||||
static void FindMatchingFlags(
|
||||
const vector<CommandLineFlagInfo> &all_flags,
|
||||
const CompletionOptions &options,
|
||||
const string &match_token,
|
||||
set<const CommandLineFlagInfo *> *all_matches,
|
||||
string *longest_common_prefix);
|
||||
|
||||
static bool DoesSingleFlagMatch(
|
||||
const CommandLineFlagInfo &flag,
|
||||
const CompletionOptions &options,
|
||||
const string &match_token);
|
||||
|
||||
|
||||
// 3) Categorize matches
|
||||
static void CategorizeAllMatchingFlags(
|
||||
const set<const CommandLineFlagInfo *> &all_matches,
|
||||
const string &search_token,
|
||||
const string &module,
|
||||
const string &package_dir,
|
||||
NotableFlags *notable_flags);
|
||||
|
||||
static void TryFindModuleAndPackageDir(
|
||||
const vector<CommandLineFlagInfo> &all_flags,
|
||||
string *module,
|
||||
string *package_dir);
|
||||
|
||||
|
||||
// 4) Decide which flags to use
|
||||
static void FinalizeCompletionOutput(
|
||||
const set<const CommandLineFlagInfo *> &matching_flags,
|
||||
CompletionOptions *options,
|
||||
NotableFlags *notable_flags,
|
||||
vector<string> *completions);
|
||||
|
||||
static void RetrieveUnusedFlags(
|
||||
const set<const CommandLineFlagInfo *> &matching_flags,
|
||||
const NotableFlags ¬able_flags,
|
||||
set<const CommandLineFlagInfo *> *unused_flags);
|
||||
|
||||
|
||||
// 5) Output matches
|
||||
static void OutputSingleGroupWithLimit(
|
||||
const set<const CommandLineFlagInfo *> &group,
|
||||
const string &line_indentation,
|
||||
const string &header,
|
||||
const string &footer,
|
||||
bool long_output_format,
|
||||
int *remaining_line_limit,
|
||||
size_t *completion_elements_added,
|
||||
vector<string> *completions);
|
||||
|
||||
// (helpers for #5)
|
||||
static string GetShortFlagLine(
|
||||
const string &line_indentation,
|
||||
const CommandLineFlagInfo &info);
|
||||
|
||||
static string GetLongFlagLine(
|
||||
const string &line_indentation,
|
||||
const CommandLineFlagInfo &info);
|
||||
|
||||
|
||||
//
|
||||
// Useful types
|
||||
|
||||
// Try to deduce the intentions behind this completion attempt. Return the
|
||||
// canonical search term in 'canonical_search_token'. Binary search options
|
||||
// are returned in the various booleans, which should all have intuitive
|
||||
// semantics, possibly except:
|
||||
// - return_all_matching_flags: Generally, we'll trim the number of
|
||||
// returned candidates to some small number, showing those that are
|
||||
// most likely to be useful first. If this is set, however, the user
|
||||
// really does want us to return every single flag as an option.
|
||||
// - force_no_update: Any time we output lines, all of which share a
|
||||
// common prefix, bash will 'helpfully' not even bother to show the
|
||||
// output, instead changing the current word to be that common prefix.
|
||||
// If it's clear this shouldn't happen, we'll set this boolean
|
||||
struct CompletionOptions {
|
||||
bool flag_name_substring_search;
|
||||
bool flag_location_substring_search;
|
||||
bool flag_description_substring_search;
|
||||
bool return_all_matching_flags;
|
||||
bool force_no_update;
|
||||
CompletionOptions(): flag_name_substring_search(false),
|
||||
flag_location_substring_search(false),
|
||||
flag_description_substring_search(false),
|
||||
return_all_matching_flags(false),
|
||||
force_no_update(false) { }
|
||||
};
|
||||
|
||||
// Notable flags are flags that are special or preferred for some
|
||||
// reason. For example, flags that are defined in the binary's module
|
||||
// are expected to be much more relevent than flags defined in some
|
||||
// other random location. These sets are specified roughly in precedence
|
||||
// order. Once a flag is placed in one of these 'higher' sets, it won't
|
||||
// be placed in any of the 'lower' sets.
|
||||
struct NotableFlags {
|
||||
typedef set<const CommandLineFlagInfo *> FlagSet;
|
||||
FlagSet perfect_match_flag;
|
||||
FlagSet module_flags; // Found in module file
|
||||
FlagSet package_flags; // Found in same directory as module file
|
||||
FlagSet most_common_flags; // One of the XXX most commonly supplied flags
|
||||
FlagSet subpackage_flags; // Found in subdirectories of package
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Tab completion implementation - entry point
|
||||
static void PrintFlagCompletionInfo(void) {
|
||||
string cursor_word = FLAGS_tab_completion_word;
|
||||
string canonical_token;
|
||||
CompletionOptions options = CompletionOptions();
|
||||
CanonicalizeCursorWordAndSearchOptions(
|
||||
cursor_word,
|
||||
&canonical_token,
|
||||
&options);
|
||||
|
||||
DVLOG(1) << "Identified canonical_token: '" << canonical_token << "'";
|
||||
|
||||
vector<CommandLineFlagInfo> all_flags;
|
||||
set<const CommandLineFlagInfo *> matching_flags;
|
||||
GetAllFlags(&all_flags);
|
||||
DVLOG(2) << "Found " << all_flags.size() << " flags overall";
|
||||
|
||||
string longest_common_prefix;
|
||||
FindMatchingFlags(
|
||||
all_flags,
|
||||
options,
|
||||
canonical_token,
|
||||
&matching_flags,
|
||||
&longest_common_prefix);
|
||||
DVLOG(1) << "Identified " << matching_flags.size() << " matching flags";
|
||||
DVLOG(1) << "Identified " << longest_common_prefix
|
||||
<< " as longest common prefix.";
|
||||
if (longest_common_prefix.size() > canonical_token.size()) {
|
||||
// There's actually a shared common prefix to all matching flags,
|
||||
// so may as well output that and quit quickly.
|
||||
DVLOG(1) << "The common prefix '" << longest_common_prefix
|
||||
<< "' was longer than the token '" << canonical_token
|
||||
<< "'. Returning just this prefix for completion.";
|
||||
fprintf(stdout, "--%s", longest_common_prefix.c_str());
|
||||
return;
|
||||
}
|
||||
if (matching_flags.empty()) {
|
||||
VLOG(1) << "There were no matching flags, returning nothing.";
|
||||
return;
|
||||
}
|
||||
|
||||
string module;
|
||||
string package_dir;
|
||||
TryFindModuleAndPackageDir(all_flags, &module, &package_dir);
|
||||
DVLOG(1) << "Identified module: '" << module << "'";
|
||||
DVLOG(1) << "Identified package_dir: '" << package_dir << "'";
|
||||
|
||||
NotableFlags notable_flags;
|
||||
CategorizeAllMatchingFlags(
|
||||
matching_flags,
|
||||
canonical_token,
|
||||
module,
|
||||
package_dir,
|
||||
¬able_flags);
|
||||
DVLOG(2) << "Categorized matching flags:";
|
||||
DVLOG(2) << " perfect_match: " << notable_flags.perfect_match_flag.size();
|
||||
DVLOG(2) << " module: " << notable_flags.module_flags.size();
|
||||
DVLOG(2) << " package: " << notable_flags.package_flags.size();
|
||||
DVLOG(2) << " most common: " << notable_flags.most_common_flags.size();
|
||||
DVLOG(2) << " subpackage: " << notable_flags.subpackage_flags.size();
|
||||
|
||||
vector<string> completions;
|
||||
FinalizeCompletionOutput(
|
||||
matching_flags,
|
||||
&options,
|
||||
¬able_flags,
|
||||
&completions);
|
||||
|
||||
if (options.force_no_update)
|
||||
completions.push_back("~");
|
||||
|
||||
DVLOG(1) << "Finalized with " << completions.size()
|
||||
<< " chosen completions";
|
||||
|
||||
for (vector<string>::const_iterator it = completions.begin();
|
||||
it != completions.end();
|
||||
++it) {
|
||||
DVLOG(9) << " Completion entry: '" << *it << "'";
|
||||
fprintf(stdout, "%s\n", it->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 1) Examine search word (and helper method)
|
||||
static void CanonicalizeCursorWordAndSearchOptions(
|
||||
const string &cursor_word,
|
||||
string *canonical_search_token,
|
||||
CompletionOptions *options) {
|
||||
*canonical_search_token = cursor_word;
|
||||
if (canonical_search_token->empty()) return;
|
||||
|
||||
// Get rid of leading quotes and dashes in the search term
|
||||
if ((*canonical_search_token)[0] == '"')
|
||||
*canonical_search_token = canonical_search_token->substr(1);
|
||||
while ((*canonical_search_token)[0] == '-')
|
||||
*canonical_search_token = canonical_search_token->substr(1);
|
||||
|
||||
options->flag_name_substring_search = false;
|
||||
options->flag_location_substring_search = false;
|
||||
options->flag_description_substring_search = false;
|
||||
options->return_all_matching_flags = false;
|
||||
options->force_no_update = false;
|
||||
|
||||
// Look for all search options we can deduce now. Do this by walking
|
||||
// backwards through the term, looking for up to three '?' and up to
|
||||
// one '+' as suffixed characters. Consume them if found, and remove
|
||||
// them from the canonical search token.
|
||||
int found_question_marks = 0;
|
||||
int found_plusses = 0;
|
||||
while (true) {
|
||||
if (found_question_marks < 3 &&
|
||||
RemoveTrailingChar(canonical_search_token, '?')) {
|
||||
++found_question_marks;
|
||||
continue;
|
||||
}
|
||||
if (found_plusses < 1 &&
|
||||
RemoveTrailingChar(canonical_search_token, '+')) {
|
||||
++found_plusses;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (found_question_marks) { // all fallthroughs
|
||||
case 3: options->flag_description_substring_search = true;
|
||||
case 2: options->flag_location_substring_search = true;
|
||||
case 1: options->flag_name_substring_search = true;
|
||||
};
|
||||
|
||||
options->return_all_matching_flags = (found_plusses > 0);
|
||||
}
|
||||
|
||||
// Returns true if a char was removed
|
||||
static bool RemoveTrailingChar(string *str, char c) {
|
||||
if (str->empty()) return false;
|
||||
if ((*str)[str->size() - 1] == c) {
|
||||
*str = str->substr(0, str->size() - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 2) Find all matches (and helper methods)
|
||||
static void FindMatchingFlags(
|
||||
const vector<CommandLineFlagInfo> &all_flags,
|
||||
const CompletionOptions &options,
|
||||
const string &match_token,
|
||||
set<const CommandLineFlagInfo *> *all_matches,
|
||||
string *longest_common_prefix) {
|
||||
all_matches->clear();
|
||||
bool first_match = true;
|
||||
for (vector<CommandLineFlagInfo>::const_iterator it = all_flags.begin();
|
||||
it != all_flags.end();
|
||||
++it) {
|
||||
if (DoesSingleFlagMatch(*it, options, match_token)) {
|
||||
all_matches->insert(&*it);
|
||||
if (first_match) {
|
||||
first_match = false;
|
||||
*longest_common_prefix = it->name;
|
||||
} else {
|
||||
if (longest_common_prefix->empty() || it->name.empty()) {
|
||||
longest_common_prefix->clear();
|
||||
continue;
|
||||
}
|
||||
string::size_type pos = 0;
|
||||
while (pos < longest_common_prefix->size() &&
|
||||
pos < it->name.size() &&
|
||||
(*longest_common_prefix)[pos] == it->name[pos])
|
||||
++pos;
|
||||
longest_common_prefix->erase(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Given the set of all flags, the parsed match options, and the
|
||||
// canonical search token, produce the set of all candidate matching
|
||||
// flags for subsequent analysis or filtering.
|
||||
static bool DoesSingleFlagMatch(
|
||||
const CommandLineFlagInfo &flag,
|
||||
const CompletionOptions &options,
|
||||
const string &match_token) {
|
||||
// Is there a prefix match?
|
||||
string::size_type pos = flag.name.find(match_token);
|
||||
if (pos == 0) return true;
|
||||
|
||||
// Is there a substring match if we want it?
|
||||
if (options.flag_name_substring_search &&
|
||||
pos != string::npos)
|
||||
return true;
|
||||
|
||||
// Is there a location match if we want it?
|
||||
if (options.flag_location_substring_search &&
|
||||
flag.filename.find(match_token) != string::npos)
|
||||
return true;
|
||||
|
||||
// TODO(user): All searches should probably be case-insensitive
|
||||
// (especially this one...)
|
||||
if (options.flag_description_substring_search &&
|
||||
flag.description.find(match_token) != string::npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3) Categorize matches (and helper method)
|
||||
|
||||
// Given a set of matching flags, categorize them by
|
||||
// likely relevence to this specific binary
|
||||
static void CategorizeAllMatchingFlags(
|
||||
const set<const CommandLineFlagInfo *> &all_matches,
|
||||
const string &search_token,
|
||||
const string &module, // empty if we couldn't find any
|
||||
const string &package_dir, // empty if we couldn't find any
|
||||
NotableFlags *notable_flags) {
|
||||
notable_flags->perfect_match_flag.clear();
|
||||
notable_flags->module_flags.clear();
|
||||
notable_flags->package_flags.clear();
|
||||
notable_flags->most_common_flags.clear();
|
||||
notable_flags->subpackage_flags.clear();
|
||||
|
||||
for (set<const CommandLineFlagInfo *>::const_iterator it =
|
||||
all_matches.begin();
|
||||
it != all_matches.end();
|
||||
++it) {
|
||||
DVLOG(2) << "Examining match '" << (*it)->name << "'";
|
||||
DVLOG(7) << " filename: '" << (*it)->filename << "'";
|
||||
string::size_type pos = string::npos;
|
||||
if (!package_dir.empty())
|
||||
pos = (*it)->filename.find(package_dir);
|
||||
string::size_type slash = string::npos;
|
||||
if (pos != string::npos) // candidate for package or subpackage match
|
||||
slash = (*it)->filename.find(
|
||||
PATH_SEPARATOR,
|
||||
pos + package_dir.size() + 1);
|
||||
|
||||
if ((*it)->name == search_token) {
|
||||
// Exact match on some flag's name
|
||||
notable_flags->perfect_match_flag.insert(*it);
|
||||
DVLOG(3) << "Result: perfect match";
|
||||
} else if (!module.empty() && (*it)->filename == module) {
|
||||
// Exact match on module filename
|
||||
notable_flags->module_flags.insert(*it);
|
||||
DVLOG(3) << "Result: module match";
|
||||
} else if (!package_dir.empty() &&
|
||||
pos != string::npos && slash == string::npos) {
|
||||
// In the package, since there was no slash after the package portion
|
||||
notable_flags->package_flags.insert(*it);
|
||||
DVLOG(3) << "Result: package match";
|
||||
} else if (false) {
|
||||
// In the list of the XXX most commonly supplied flags overall
|
||||
// TODO(user): Compile this list.
|
||||
DVLOG(3) << "Result: most-common match";
|
||||
} else if (!package_dir.empty() &&
|
||||
pos != string::npos && slash != string::npos) {
|
||||
// In a subdirectory of the package
|
||||
notable_flags->subpackage_flags.insert(*it);
|
||||
DVLOG(3) << "Result: subpackage match";
|
||||
}
|
||||
|
||||
DVLOG(3) << "Result: not special match";
|
||||
}
|
||||
}
|
||||
|
||||
static void PushNameWithSuffix(vector<string>* suffixes, const char* suffix) {
|
||||
suffixes->push_back(
|
||||
StringPrintf("/%s%s", ProgramInvocationShortName(), suffix));
|
||||
}
|
||||
|
||||
static void TryFindModuleAndPackageDir(
|
||||
const vector<CommandLineFlagInfo> &all_flags,
|
||||
string *module,
|
||||
string *package_dir) {
|
||||
module->clear();
|
||||
package_dir->clear();
|
||||
|
||||
vector<string> suffixes;
|
||||
// TODO(user): There's some inherant ambiguity here - multiple directories
|
||||
// could share the same trailing folder and file structure (and even worse,
|
||||
// same file names), causing us to be unsure as to which of the two is the
|
||||
// actual package for this binary. In this case, we'll arbitrarily choose.
|
||||
PushNameWithSuffix(&suffixes, ".");
|
||||
PushNameWithSuffix(&suffixes, "-main.");
|
||||
PushNameWithSuffix(&suffixes, "_main.");
|
||||
// These four are new but probably merited?
|
||||
PushNameWithSuffix(&suffixes, "-test.");
|
||||
PushNameWithSuffix(&suffixes, "_test.");
|
||||
PushNameWithSuffix(&suffixes, "-unittest.");
|
||||
PushNameWithSuffix(&suffixes, "_unittest.");
|
||||
|
||||
for (vector<CommandLineFlagInfo>::const_iterator it = all_flags.begin();
|
||||
it != all_flags.end();
|
||||
++it) {
|
||||
for (vector<string>::const_iterator suffix = suffixes.begin();
|
||||
suffix != suffixes.end();
|
||||
++suffix) {
|
||||
// TODO(user): Make sure the match is near the end of the string
|
||||
if (it->filename.find(*suffix) != string::npos) {
|
||||
*module = it->filename;
|
||||
string::size_type sep = it->filename.rfind(PATH_SEPARATOR);
|
||||
*package_dir = it->filename.substr(0, (sep == string::npos) ? 0 : sep);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Can't specialize template type on a locally defined type. Silly C++...
|
||||
struct DisplayInfoGroup {
|
||||
const char* header;
|
||||
const char* footer;
|
||||
set<const CommandLineFlagInfo *> *group;
|
||||
|
||||
int SizeInLines() const {
|
||||
int size_in_lines = static_cast<int>(group->size()) + 1;
|
||||
if (strlen(header) > 0) {
|
||||
size_in_lines++;
|
||||
}
|
||||
if (strlen(footer) > 0) {
|
||||
size_in_lines++;
|
||||
}
|
||||
return size_in_lines;
|
||||
}
|
||||
};
|
||||
|
||||
// 4) Finalize and trim output flag set
|
||||
static void FinalizeCompletionOutput(
|
||||
const set<const CommandLineFlagInfo *> &matching_flags,
|
||||
CompletionOptions *options,
|
||||
NotableFlags *notable_flags,
|
||||
vector<string> *completions) {
|
||||
|
||||
// We want to output lines in groups. Each group needs to be indented
|
||||
// the same to keep its lines together. Unless otherwise required,
|
||||
// only 99 lines should be output to prevent bash from harassing the
|
||||
// user.
|
||||
|
||||
// First, figure out which output groups we'll actually use. For each
|
||||
// nonempty group, there will be ~3 lines of header & footer, plus all
|
||||
// output lines themselves.
|
||||
int max_desired_lines = // "999999 flags should be enough for anyone. -dave"
|
||||
(options->return_all_matching_flags ? 999999 : 98);
|
||||
int lines_so_far = 0;
|
||||
|
||||
vector<DisplayInfoGroup> output_groups;
|
||||
bool perfect_match_found = false;
|
||||
if (!notable_flags->perfect_match_flag.empty()) {
|
||||
perfect_match_found = true;
|
||||
DisplayInfoGroup group =
|
||||
{ "",
|
||||
"==========",
|
||||
¬able_flags->perfect_match_flag };
|
||||
lines_so_far += group.SizeInLines();
|
||||
output_groups.push_back(group);
|
||||
}
|
||||
if (lines_so_far < max_desired_lines &&
|
||||
!notable_flags->module_flags.empty()) {
|
||||
DisplayInfoGroup group = {
|
||||
"-* Matching module flags *-",
|
||||
"===========================",
|
||||
¬able_flags->module_flags };
|
||||
lines_so_far += group.SizeInLines();
|
||||
output_groups.push_back(group);
|
||||
}
|
||||
if (lines_so_far < max_desired_lines &&
|
||||
!notable_flags->package_flags.empty()) {
|
||||
DisplayInfoGroup group = {
|
||||
"-* Matching package flags *-",
|
||||
"============================",
|
||||
¬able_flags->package_flags };
|
||||
lines_so_far += group.SizeInLines();
|
||||
output_groups.push_back(group);
|
||||
}
|
||||
if (lines_so_far < max_desired_lines &&
|
||||
!notable_flags->most_common_flags.empty()) {
|
||||
DisplayInfoGroup group = {
|
||||
"-* Commonly used flags *-",
|
||||
"=========================",
|
||||
¬able_flags->most_common_flags };
|
||||
lines_so_far += group.SizeInLines();
|
||||
output_groups.push_back(group);
|
||||
}
|
||||
if (lines_so_far < max_desired_lines &&
|
||||
!notable_flags->subpackage_flags.empty()) {
|
||||
DisplayInfoGroup group = {
|
||||
"-* Matching sub-package flags *-",
|
||||
"================================",
|
||||
¬able_flags->subpackage_flags };
|
||||
lines_so_far += group.SizeInLines();
|
||||
output_groups.push_back(group);
|
||||
}
|
||||
|
||||
set<const CommandLineFlagInfo *> obscure_flags; // flags not notable
|
||||
if (lines_so_far < max_desired_lines) {
|
||||
RetrieveUnusedFlags(matching_flags, *notable_flags, &obscure_flags);
|
||||
if (!obscure_flags.empty()) {
|
||||
DisplayInfoGroup group = {
|
||||
"-* Other flags *-",
|
||||
"",
|
||||
&obscure_flags };
|
||||
lines_so_far += group.SizeInLines();
|
||||
output_groups.push_back(group);
|
||||
}
|
||||
}
|
||||
|
||||
// Second, go through each of the chosen output groups and output
|
||||
// as many of those flags as we can, while remaining below our limit
|
||||
int remaining_lines = max_desired_lines;
|
||||
size_t completions_output = 0;
|
||||
int indent = static_cast<int>(output_groups.size()) - 1;
|
||||
for (vector<DisplayInfoGroup>::const_iterator it =
|
||||
output_groups.begin();
|
||||
it != output_groups.end();
|
||||
++it, --indent) {
|
||||
OutputSingleGroupWithLimit(
|
||||
*it->group, // group
|
||||
string(indent, ' '), // line indentation
|
||||
string(it->header), // header
|
||||
string(it->footer), // footer
|
||||
perfect_match_found, // long format
|
||||
&remaining_lines, // line limit - reduces this by number printed
|
||||
&completions_output, // completions (not lines) added
|
||||
completions); // produced completions
|
||||
perfect_match_found = false;
|
||||
}
|
||||
|
||||
if (completions_output != matching_flags.size()) {
|
||||
options->force_no_update = false;
|
||||
completions->push_back("~ (Remaining flags hidden) ~");
|
||||
} else {
|
||||
options->force_no_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void RetrieveUnusedFlags(
|
||||
const set<const CommandLineFlagInfo *> &matching_flags,
|
||||
const NotableFlags ¬able_flags,
|
||||
set<const CommandLineFlagInfo *> *unused_flags) {
|
||||
// Remove from 'matching_flags' set all members of the sets of
|
||||
// flags we've already printed (specifically, those in notable_flags)
|
||||
for (set<const CommandLineFlagInfo *>::const_iterator it =
|
||||
matching_flags.begin();
|
||||
it != matching_flags.end();
|
||||
++it) {
|
||||
if (notable_flags.perfect_match_flag.count(*it) ||
|
||||
notable_flags.module_flags.count(*it) ||
|
||||
notable_flags.package_flags.count(*it) ||
|
||||
notable_flags.most_common_flags.count(*it) ||
|
||||
notable_flags.subpackage_flags.count(*it))
|
||||
continue;
|
||||
unused_flags->insert(*it);
|
||||
}
|
||||
}
|
||||
|
||||
// 5) Output matches (and helper methods)
|
||||
|
||||
static void OutputSingleGroupWithLimit(
|
||||
const set<const CommandLineFlagInfo *> &group,
|
||||
const string &line_indentation,
|
||||
const string &header,
|
||||
const string &footer,
|
||||
bool long_output_format,
|
||||
int *remaining_line_limit,
|
||||
size_t *completion_elements_output,
|
||||
vector<string> *completions) {
|
||||
if (group.empty()) return;
|
||||
if (!header.empty()) {
|
||||
if (*remaining_line_limit < 2) return;
|
||||
*remaining_line_limit -= 2;
|
||||
completions->push_back(line_indentation + header);
|
||||
completions->push_back(line_indentation + string(header.size(), '-'));
|
||||
}
|
||||
for (set<const CommandLineFlagInfo *>::const_iterator it = group.begin();
|
||||
it != group.end() && *remaining_line_limit > 0;
|
||||
++it) {
|
||||
--*remaining_line_limit;
|
||||
++*completion_elements_output;
|
||||
completions->push_back(
|
||||
(long_output_format
|
||||
? GetLongFlagLine(line_indentation, **it)
|
||||
: GetShortFlagLine(line_indentation, **it)));
|
||||
}
|
||||
if (!footer.empty()) {
|
||||
if (*remaining_line_limit < 1) return;
|
||||
--*remaining_line_limit;
|
||||
completions->push_back(line_indentation + footer);
|
||||
}
|
||||
}
|
||||
|
||||
static string GetShortFlagLine(
|
||||
const string &line_indentation,
|
||||
const CommandLineFlagInfo &info) {
|
||||
string prefix;
|
||||
bool is_string = (info.type == "string");
|
||||
SStringPrintf(&prefix, "%s--%s [%s%s%s] ",
|
||||
line_indentation.c_str(),
|
||||
info.name.c_str(),
|
||||
(is_string ? "'" : ""),
|
||||
info.default_value.c_str(),
|
||||
(is_string ? "'" : ""));
|
||||
int remainder =
|
||||
FLAGS_tab_completion_columns - static_cast<int>(prefix.size());
|
||||
string suffix;
|
||||
if (remainder > 0)
|
||||
suffix =
|
||||
(static_cast<int>(info.description.size()) > remainder ?
|
||||
(info.description.substr(0, remainder - 3) + "...").c_str() :
|
||||
info.description.c_str());
|
||||
return prefix + suffix;
|
||||
}
|
||||
|
||||
static string GetLongFlagLine(
|
||||
const string &line_indentation,
|
||||
const CommandLineFlagInfo &info) {
|
||||
|
||||
string output = DescribeOneFlag(info);
|
||||
|
||||
// Replace '-' with '--', and remove trailing newline before appending
|
||||
// the module definition location.
|
||||
string old_flagname = "-" + info.name;
|
||||
output.replace(
|
||||
output.find(old_flagname),
|
||||
old_flagname.size(),
|
||||
"-" + old_flagname);
|
||||
// Stick a newline and indentation in front of the type and default
|
||||
// portions of DescribeOneFlag()s description
|
||||
static const char kNewlineWithIndent[] = "\n ";
|
||||
output.replace(output.find(" type:"), 1, string(kNewlineWithIndent));
|
||||
output.replace(output.find(" default:"), 1, string(kNewlineWithIndent));
|
||||
output = StringPrintf("%s Details for '--%s':\n"
|
||||
"%s defined: %s",
|
||||
line_indentation.c_str(),
|
||||
info.name.c_str(),
|
||||
output.c_str(),
|
||||
info.filename.c_str());
|
||||
|
||||
// Eliminate any doubled newlines that crept in. Specifically, if
|
||||
// DescribeOneFlag() decided to break the line just before "type"
|
||||
// or "default", we don't want to introduce an extra blank line
|
||||
static const string line_of_spaces(FLAGS_tab_completion_columns, ' ');
|
||||
static const char kDoubledNewlines[] = "\n \n";
|
||||
for (string::size_type newlines = output.find(kDoubledNewlines);
|
||||
newlines != string::npos;
|
||||
newlines = output.find(kDoubledNewlines))
|
||||
// Replace each 'doubled newline' with a single newline
|
||||
output.replace(newlines, sizeof(kDoubledNewlines) - 1, string("\n"));
|
||||
|
||||
for (string::size_type newline = output.find('\n');
|
||||
newline != string::npos;
|
||||
newline = output.find('\n')) {
|
||||
int newline_pos = static_cast<int>(newline) % FLAGS_tab_completion_columns;
|
||||
int missing_spaces = FLAGS_tab_completion_columns - newline_pos;
|
||||
output.replace(newline, 1, line_of_spaces, 1, missing_spaces);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
} // anonymous
|
||||
|
||||
void HandleCommandLineCompletions(void) {
|
||||
if (FLAGS_tab_completion_word.empty()) return;
|
||||
PrintFlagCompletionInfo();
|
||||
gflags_exitfunc(0);
|
||||
}
|
||||
|
||||
|
||||
} // namespace GFLAGS_NAMESPACE
|
||||
121
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_completions.h.in
vendored
Normal file
121
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_completions.h.in
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---
|
||||
|
||||
//
|
||||
// Implement helpful bash-style command line flag completions
|
||||
//
|
||||
// ** Functional API:
|
||||
// HandleCommandLineCompletions() should be called early during
|
||||
// program startup, but after command line flag code has been
|
||||
// initialized, such as the beginning of HandleCommandLineHelpFlags().
|
||||
// It checks the value of the flag --tab_completion_word. If this
|
||||
// flag is empty, nothing happens here. If it contains a string,
|
||||
// however, then HandleCommandLineCompletions() will hijack the
|
||||
// process, attempting to identify the intention behind this
|
||||
// completion. Regardless of the outcome of this deduction, the
|
||||
// process will be terminated, similar to --helpshort flag
|
||||
// handling.
|
||||
//
|
||||
// ** Overview of Bash completions:
|
||||
// Bash can be told to programatically determine completions for the
|
||||
// current 'cursor word'. It does this by (in this case) invoking a
|
||||
// command with some additional arguments identifying the command
|
||||
// being executed, the word being completed, and the previous word
|
||||
// (if any). Bash then expects a sequence of output lines to be
|
||||
// printed to stdout. If these lines all contain a common prefix
|
||||
// longer than the cursor word, bash will replace the cursor word
|
||||
// with that common prefix, and display nothing. If there isn't such
|
||||
// a common prefix, bash will display the lines in pages using 'more'.
|
||||
//
|
||||
// ** Strategy taken for command line completions:
|
||||
// If we can deduce either the exact flag intended, or a common flag
|
||||
// prefix, we'll output exactly that. Otherwise, if information
|
||||
// must be displayed to the user, we'll take the opportunity to add
|
||||
// some helpful information beyond just the flag name (specifically,
|
||||
// we'll include the default flag value and as much of the flag's
|
||||
// description as can fit on a single terminal line width, as specified
|
||||
// by the flag --tab_completion_columns). Furthermore, we'll try to
|
||||
// make bash order the output such that the most useful or relevent
|
||||
// flags are the most likely to be shown at the top.
|
||||
//
|
||||
// ** Additional features:
|
||||
// To assist in finding that one really useful flag, substring matching
|
||||
// was implemented. Before pressing a <TAB> to get completion for the
|
||||
// current word, you can append one or more '?' to the flag to do
|
||||
// substring matching. Here's the semantics:
|
||||
// --foo<TAB> Show me all flags with names prefixed by 'foo'
|
||||
// --foo?<TAB> Show me all flags with 'foo' somewhere in the name
|
||||
// --foo??<TAB> Same as prior case, but also search in module
|
||||
// definition path for 'foo'
|
||||
// --foo???<TAB> Same as prior case, but also search in flag
|
||||
// descriptions for 'foo'
|
||||
// Finally, we'll trim the output to a relatively small number of
|
||||
// flags to keep bash quiet about the verbosity of output. If one
|
||||
// really wanted to see all possible matches, appending a '+' to the
|
||||
// search word will force the exhaustive list of matches to be printed.
|
||||
//
|
||||
// ** How to have bash accept completions from a binary:
|
||||
// Bash requires that it be informed about each command that programmatic
|
||||
// completion should be enabled for. Example addition to a .bashrc
|
||||
// file would be (your path to gflags_completions.sh file may differ):
|
||||
|
||||
/*
|
||||
$ complete -o bashdefault -o default -o nospace -C \
|
||||
'/home/build/eng/bash/bash_completions.sh --tab_completion_columns $COLUMNS' \
|
||||
time env binary_name another_binary [...]
|
||||
*/
|
||||
|
||||
// This would allow the following to work:
|
||||
// $ /path/to/binary_name --vmodule<TAB>
|
||||
// Or:
|
||||
// $ ./bin/path/another_binary --gfs_u<TAB>
|
||||
// (etc)
|
||||
//
|
||||
// Sadly, it appears that bash gives no easy way to force this behavior for
|
||||
// all commands. That's where the "time" in the above example comes in.
|
||||
// If you haven't specifically added a command to the list of completion
|
||||
// supported commands, you can still get completions by prefixing the
|
||||
// entire command with "env".
|
||||
// $ env /some/brand/new/binary --vmod<TAB>
|
||||
// Assuming that "binary" is a newly compiled binary, this should still
|
||||
// produce the expected completion output.
|
||||
|
||||
|
||||
#ifndef GFLAGS_COMPLETIONS_H_
|
||||
#define GFLAGS_COMPLETIONS_H_
|
||||
|
||||
namespace @GFLAGS_NAMESPACE@ {
|
||||
|
||||
extern void HandleCommandLineCompletions(void);
|
||||
|
||||
}
|
||||
|
||||
#endif // GFLAGS_COMPLETIONS_H_
|
||||
117
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_completions.sh
vendored
Normal file
117
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_completions.sh
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2008, Google Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# ---
|
||||
# Author: Dave Nicponski
|
||||
#
|
||||
# This script is invoked by bash in response to a matching compspec. When
|
||||
# this happens, bash calls this script using the command shown in the -C
|
||||
# block of the complete entry, but also appends 3 arguments. They are:
|
||||
# - The command being used for completion
|
||||
# - The word being completed
|
||||
# - The word preceding the completion word.
|
||||
#
|
||||
# Here's an example of how you might use this script:
|
||||
# $ complete -o bashdefault -o default -o nospace -C \
|
||||
# '/usr/local/bin/gflags_completions.sh --tab_completion_columns $COLUMNS' \
|
||||
# time env binary_name another_binary [...]
|
||||
|
||||
# completion_word_index gets the index of the (N-1)th argument for
|
||||
# this command line. completion_word gets the actual argument from
|
||||
# this command line at the (N-1)th position
|
||||
completion_word_index="$(($# - 1))"
|
||||
completion_word="${!completion_word_index}"
|
||||
|
||||
# TODO(user): Replace this once gflags_completions.cc has
|
||||
# a bool parameter indicating unambiguously to hijack the process for
|
||||
# completion purposes.
|
||||
if [ -z "$completion_word" ]; then
|
||||
# Until an empty value for the completion word stops being misunderstood
|
||||
# by binaries, don't actually execute the binary or the process
|
||||
# won't be hijacked!
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# binary_index gets the index of the command being completed (which bash
|
||||
# places in the (N-2)nd position. binary gets the actual command from
|
||||
# this command line at that (N-2)nd position
|
||||
binary_index="$(($# - 2))"
|
||||
binary="${!binary_index}"
|
||||
|
||||
# For completions to be universal, we may have setup the compspec to
|
||||
# trigger on 'harmless pass-through' commands, like 'time' or 'env'.
|
||||
# If the command being completed is one of those two, we'll need to
|
||||
# identify the actual command being executed. To do this, we need
|
||||
# the actual command line that the <TAB> was pressed on. Bash helpfully
|
||||
# places this in the $COMP_LINE variable.
|
||||
if [ "$binary" == "time" ] || [ "$binary" == "env" ]; then
|
||||
# we'll assume that the first 'argument' is actually the
|
||||
# binary
|
||||
|
||||
|
||||
# TODO(user): This is not perfect - the 'env' command, for instance,
|
||||
# is allowed to have options between the 'env' and 'the command to
|
||||
# be executed'. For example, consider:
|
||||
# $ env FOO="bar" bin/do_something --help<TAB>
|
||||
# In this case, we'll mistake the FOO="bar" portion as the binary.
|
||||
# Perhaps we should continuing consuming leading words until we
|
||||
# either run out of words, or find a word that is a valid file
|
||||
# marked as executable. I can't think of any reason this wouldn't
|
||||
# work.
|
||||
|
||||
# Break up the 'original command line' (not this script's command line,
|
||||
# rather the one the <TAB> was pressed on) and find the second word.
|
||||
parts=( ${COMP_LINE} )
|
||||
binary=${parts[1]}
|
||||
fi
|
||||
|
||||
# Build the command line to use for completion. Basically it involves
|
||||
# passing through all the arguments given to this script (except the 3
|
||||
# that bash added), and appending a '--tab_completion_word "WORD"' to
|
||||
# the arguments.
|
||||
params=""
|
||||
for ((i=1; i<=$(($# - 3)); ++i)); do
|
||||
params="$params \"${!i}\"";
|
||||
done
|
||||
params="$params --tab_completion_word \"$completion_word\""
|
||||
|
||||
# TODO(user): Perhaps stash the output in a temporary file somewhere
|
||||
# in /tmp, and only cat it to stdout if the command returned a success
|
||||
# code, to prevent false positives
|
||||
|
||||
# If we think we have a reasonable command to execute, then execute it
|
||||
# and hope for the best.
|
||||
candidate=$(type -p "$binary")
|
||||
if [ ! -z "$candidate" ]; then
|
||||
eval "$candidate 2>/dev/null $params"
|
||||
elif [ -f "$binary" ] && [ -x "$binary" ]; then
|
||||
eval "$binary 2>/dev/null $params"
|
||||
fi
|
||||
156
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_declare.h.in
vendored
Normal file
156
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_declare.h.in
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
// Copyright (c) 1999, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// ---
|
||||
//
|
||||
// Revamped and reorganized by Craig Silverstein
|
||||
//
|
||||
// This is the file that should be included by any file which declares
|
||||
// command line flag.
|
||||
|
||||
#ifndef GFLAGS_DECLARE_H_
|
||||
#define GFLAGS_DECLARE_H_
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Namespace of gflags library symbols.
|
||||
#define GFLAGS_NAMESPACE @GFLAGS_NAMESPACE@
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Windows DLL import/export.
|
||||
|
||||
// Whether gflags library is a DLL.
|
||||
//
|
||||
// Set to 1 by default when the shared gflags library was built on Windows.
|
||||
// Must be overwritten when this header file is used with the optionally also
|
||||
// built static library instead; set by CMake's INTERFACE_COMPILE_DEFINITIONS.
|
||||
#ifndef GFLAGS_IS_A_DLL
|
||||
# define GFLAGS_IS_A_DLL @GFLAGS_IS_A_DLL@
|
||||
#endif
|
||||
|
||||
// We always want to import the symbols of the gflags library.
|
||||
#ifndef GFLAGS_DLL_DECL
|
||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||
# define GFLAGS_DLL_DECL __declspec(dllimport)
|
||||
# elif defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define GFLAGS_DLL_DECL __attribute__((visibility("default")))
|
||||
# else
|
||||
# define GFLAGS_DLL_DECL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// We always want to import variables declared in user code.
|
||||
#ifndef GFLAGS_DLL_DECLARE_FLAG
|
||||
# if GFLAGS_IS_A_DLL && defined(_MSC_VER)
|
||||
# define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
|
||||
# elif defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define GFLAGS_DLL_DECLARE_FLAG __attribute__((visibility("default")))
|
||||
# else
|
||||
# define GFLAGS_DLL_DECLARE_FLAG
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Flag types
|
||||
#include <string>
|
||||
#if @HAVE_STDINT_H@
|
||||
# include <stdint.h> // the normal place uint32_t is defined
|
||||
#elif @HAVE_SYS_TYPES_H@
|
||||
# include <sys/types.h> // the normal place u_int32_t is defined
|
||||
#elif @HAVE_INTTYPES_H@
|
||||
# include <inttypes.h> // a third place for uint32_t or u_int32_t
|
||||
#endif
|
||||
|
||||
namespace GFLAGS_NAMESPACE {
|
||||
|
||||
#if @GFLAGS_INTTYPES_FORMAT_C99@ // C99
|
||||
typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
#elif @GFLAGS_INTTYPES_FORMAT_BSD@ // BSD
|
||||
typedef int32_t int32;
|
||||
typedef u_int32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef u_int64_t uint64;
|
||||
#elif @GFLAGS_INTTYPES_FORMAT_VC7@ // Windows
|
||||
typedef __int32 int32;
|
||||
typedef unsigned __int32 uint32;
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
#else
|
||||
# error Do not know how to define a 32-bit integer quantity on your system
|
||||
#endif
|
||||
|
||||
} // namespace GFLAGS_NAMESPACE
|
||||
|
||||
|
||||
namespace fLS {
|
||||
|
||||
// The meaning of "string" might be different between now and when the
|
||||
// macros below get invoked (e.g., if someone is experimenting with
|
||||
// other string implementations that get defined after this file is
|
||||
// included). Save the current meaning now and use it in the macros.
|
||||
typedef std::string clstring;
|
||||
|
||||
} // namespace fLS
|
||||
|
||||
|
||||
#define DECLARE_VARIABLE(type, shorttype, name) \
|
||||
/* We always want to import declared variables, dll or no */ \
|
||||
namespace fL##shorttype { extern GFLAGS_DLL_DECLARE_FLAG type FLAGS_##name; } \
|
||||
using fL##shorttype::FLAGS_##name
|
||||
|
||||
#define DECLARE_bool(name) \
|
||||
DECLARE_VARIABLE(bool, B, name)
|
||||
|
||||
#define DECLARE_int32(name) \
|
||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int32, I, name)
|
||||
|
||||
#define DECLARE_uint32(name) \
|
||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint32, U, name)
|
||||
|
||||
#define DECLARE_int64(name) \
|
||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int64, I64, name)
|
||||
|
||||
#define DECLARE_uint64(name) \
|
||||
DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint64, U64, name)
|
||||
|
||||
#define DECLARE_double(name) \
|
||||
DECLARE_VARIABLE(double, D, name)
|
||||
|
||||
#define DECLARE_string(name) \
|
||||
/* We always want to import declared variables, dll or no */ \
|
||||
namespace fLS { \
|
||||
extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \
|
||||
} \
|
||||
using fLS::FLAGS_##name
|
||||
|
||||
|
||||
#endif // GFLAGS_DECLARE_H_
|
||||
102
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_ns.h.in
vendored
Normal file
102
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_ns.h.in
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
// Copyright (c) 2014, Andreas Schuh
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Imports the gflags library symbols into an alternative/deprecated namespace.
|
||||
|
||||
#ifndef GFLAGS_GFLAGS_H_
|
||||
# error The internal header gflags_@ns@.h may only be included by gflags.h
|
||||
#endif
|
||||
|
||||
#ifndef GFLAGS_NS_@NS@_H_
|
||||
#define GFLAGS_NS_@NS@_H_
|
||||
|
||||
|
||||
namespace @ns@ {
|
||||
|
||||
|
||||
using GFLAGS_NAMESPACE::int32;
|
||||
using GFLAGS_NAMESPACE::uint32;
|
||||
using GFLAGS_NAMESPACE::int64;
|
||||
using GFLAGS_NAMESPACE::uint64;
|
||||
|
||||
using GFLAGS_NAMESPACE::RegisterFlagValidator;
|
||||
using GFLAGS_NAMESPACE::CommandLineFlagInfo;
|
||||
using GFLAGS_NAMESPACE::GetAllFlags;
|
||||
using GFLAGS_NAMESPACE::ShowUsageWithFlags;
|
||||
using GFLAGS_NAMESPACE::ShowUsageWithFlagsRestrict;
|
||||
using GFLAGS_NAMESPACE::DescribeOneFlag;
|
||||
using GFLAGS_NAMESPACE::SetArgv;
|
||||
using GFLAGS_NAMESPACE::GetArgvs;
|
||||
using GFLAGS_NAMESPACE::GetArgv;
|
||||
using GFLAGS_NAMESPACE::GetArgv0;
|
||||
using GFLAGS_NAMESPACE::GetArgvSum;
|
||||
using GFLAGS_NAMESPACE::ProgramInvocationName;
|
||||
using GFLAGS_NAMESPACE::ProgramInvocationShortName;
|
||||
using GFLAGS_NAMESPACE::ProgramUsage;
|
||||
using GFLAGS_NAMESPACE::VersionString;
|
||||
using GFLAGS_NAMESPACE::GetCommandLineOption;
|
||||
using GFLAGS_NAMESPACE::GetCommandLineFlagInfo;
|
||||
using GFLAGS_NAMESPACE::GetCommandLineFlagInfoOrDie;
|
||||
using GFLAGS_NAMESPACE::FlagSettingMode;
|
||||
using GFLAGS_NAMESPACE::SET_FLAGS_VALUE;
|
||||
using GFLAGS_NAMESPACE::SET_FLAG_IF_DEFAULT;
|
||||
using GFLAGS_NAMESPACE::SET_FLAGS_DEFAULT;
|
||||
using GFLAGS_NAMESPACE::SetCommandLineOption;
|
||||
using GFLAGS_NAMESPACE::SetCommandLineOptionWithMode;
|
||||
using GFLAGS_NAMESPACE::FlagSaver;
|
||||
using GFLAGS_NAMESPACE::CommandlineFlagsIntoString;
|
||||
using GFLAGS_NAMESPACE::ReadFlagsFromString;
|
||||
using GFLAGS_NAMESPACE::AppendFlagsIntoFile;
|
||||
using GFLAGS_NAMESPACE::ReadFromFlagsFile;
|
||||
using GFLAGS_NAMESPACE::BoolFromEnv;
|
||||
using GFLAGS_NAMESPACE::Int32FromEnv;
|
||||
using GFLAGS_NAMESPACE::Uint32FromEnv;
|
||||
using GFLAGS_NAMESPACE::Int64FromEnv;
|
||||
using GFLAGS_NAMESPACE::Uint64FromEnv;
|
||||
using GFLAGS_NAMESPACE::DoubleFromEnv;
|
||||
using GFLAGS_NAMESPACE::StringFromEnv;
|
||||
using GFLAGS_NAMESPACE::SetUsageMessage;
|
||||
using GFLAGS_NAMESPACE::SetVersionString;
|
||||
using GFLAGS_NAMESPACE::ParseCommandLineNonHelpFlags;
|
||||
using GFLAGS_NAMESPACE::HandleCommandLineHelpFlags;
|
||||
using GFLAGS_NAMESPACE::AllowCommandLineReparsing;
|
||||
using GFLAGS_NAMESPACE::ReparseCommandLineNonHelpFlags;
|
||||
using GFLAGS_NAMESPACE::ShutDownCommandLineFlags;
|
||||
using GFLAGS_NAMESPACE::FlagRegisterer;
|
||||
|
||||
#ifndef SWIG
|
||||
using GFLAGS_NAMESPACE::ParseCommandLineFlags;
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace @ns@
|
||||
|
||||
|
||||
#endif // GFLAGS_NS_@NS@_H_
|
||||
442
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_reporting.cc
vendored
Normal file
442
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/gflags_reporting.cc
vendored
Normal file
@@ -0,0 +1,442 @@
|
||||
// Copyright (c) 1999, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// ---
|
||||
//
|
||||
// Revamped and reorganized by Craig Silverstein
|
||||
//
|
||||
// This file contains code for handling the 'reporting' flags. These
|
||||
// are flags that, when present, cause the program to report some
|
||||
// information and then exit. --help and --version are the canonical
|
||||
// reporting flags, but we also have flags like --helpxml, etc.
|
||||
//
|
||||
// There's only one function that's meant to be called externally:
|
||||
// HandleCommandLineHelpFlags(). (Well, actually, ShowUsageWithFlags(),
|
||||
// ShowUsageWithFlagsRestrict(), and DescribeOneFlag() can be called
|
||||
// externally too, but there's little need for it.) These are all
|
||||
// declared in the main gflags.h header file.
|
||||
//
|
||||
// HandleCommandLineHelpFlags() will check what 'reporting' flags have
|
||||
// been defined, if any -- the "help" part of the function name is a
|
||||
// bit misleading -- and do the relevant reporting. It should be
|
||||
// called after all flag-values have been assigned, that is, after
|
||||
// parsing the command-line.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "config.h"
|
||||
#include "gflags/gflags.h"
|
||||
#include "gflags/gflags_completions.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
// The 'reporting' flags. They all call gflags_exitfunc().
|
||||
DEFINE_bool (help, false, "show help on all flags [tip: all flags can have two dashes]");
|
||||
DEFINE_bool (helpfull, false, "show help on all flags -- same as -help");
|
||||
DEFINE_bool (helpshort, false, "show help on only the main module for this program");
|
||||
DEFINE_string(helpon, "", "show help on the modules named by this flag value");
|
||||
DEFINE_string(helpmatch, "", "show help on modules whose name contains the specified substr");
|
||||
DEFINE_bool (helppackage, false, "show help on all modules in the main package");
|
||||
DEFINE_bool (helpxml, false, "produce an xml version of help");
|
||||
DEFINE_bool (version, false, "show version and build info and exit");
|
||||
|
||||
|
||||
namespace GFLAGS_NAMESPACE {
|
||||
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// DescribeOneFlag()
|
||||
// DescribeOneFlagInXML()
|
||||
// Routines that pretty-print info about a flag. These use
|
||||
// a CommandLineFlagInfo, which is the way the gflags
|
||||
// API exposes static info about a flag.
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
static const int kLineLength = 80;
|
||||
|
||||
static void AddString(const string& s,
|
||||
string* final_string, int* chars_in_line) {
|
||||
const int slen = static_cast<int>(s.length());
|
||||
if (*chars_in_line + 1 + slen >= kLineLength) { // < 80 chars/line
|
||||
*final_string += "\n ";
|
||||
*chars_in_line = 6;
|
||||
} else {
|
||||
*final_string += " ";
|
||||
*chars_in_line += 1;
|
||||
}
|
||||
*final_string += s;
|
||||
*chars_in_line += slen;
|
||||
}
|
||||
|
||||
static string PrintStringFlagsWithQuotes(const CommandLineFlagInfo& flag,
|
||||
const string& text, bool current) {
|
||||
const char* c_string = (current ? flag.current_value.c_str() :
|
||||
flag.default_value.c_str());
|
||||
if (strcmp(flag.type.c_str(), "string") == 0) { // add quotes for strings
|
||||
return StringPrintf("%s: \"%s\"", text.c_str(), c_string);
|
||||
} else {
|
||||
return StringPrintf("%s: %s", text.c_str(), c_string);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a descriptive string for a flag.
|
||||
// Goes to some trouble to make pretty line breaks.
|
||||
string DescribeOneFlag(const CommandLineFlagInfo& flag) {
|
||||
string main_part;
|
||||
SStringPrintf(&main_part, " -%s (%s)",
|
||||
flag.name.c_str(),
|
||||
flag.description.c_str());
|
||||
const char* c_string = main_part.c_str();
|
||||
int chars_left = static_cast<int>(main_part.length());
|
||||
string final_string = "";
|
||||
int chars_in_line = 0; // how many chars in current line so far?
|
||||
while (1) {
|
||||
assert(static_cast<size_t>(chars_left)
|
||||
== strlen(c_string)); // Unless there's a \0 in there?
|
||||
const char* newline = strchr(c_string, '\n');
|
||||
if (newline == NULL && chars_in_line+chars_left < kLineLength) {
|
||||
// The whole remainder of the string fits on this line
|
||||
final_string += c_string;
|
||||
chars_in_line += chars_left;
|
||||
break;
|
||||
}
|
||||
if (newline != NULL && newline - c_string < kLineLength - chars_in_line) {
|
||||
int n = static_cast<int>(newline - c_string);
|
||||
final_string.append(c_string, n);
|
||||
chars_left -= n + 1;
|
||||
c_string += n + 1;
|
||||
} else {
|
||||
// Find the last whitespace on this 80-char line
|
||||
int whitespace = kLineLength-chars_in_line-1; // < 80 chars/line
|
||||
while ( whitespace > 0 && !isspace(c_string[whitespace]) ) {
|
||||
--whitespace;
|
||||
}
|
||||
if (whitespace <= 0) {
|
||||
// Couldn't find any whitespace to make a line break. Just dump the
|
||||
// rest out!
|
||||
final_string += c_string;
|
||||
chars_in_line = kLineLength; // next part gets its own line for sure!
|
||||
break;
|
||||
}
|
||||
final_string += string(c_string, whitespace);
|
||||
chars_in_line += whitespace;
|
||||
while (isspace(c_string[whitespace])) ++whitespace;
|
||||
c_string += whitespace;
|
||||
chars_left -= whitespace;
|
||||
}
|
||||
if (*c_string == '\0')
|
||||
break;
|
||||
StringAppendF(&final_string, "\n ");
|
||||
chars_in_line = 6;
|
||||
}
|
||||
|
||||
// Append data type
|
||||
AddString(string("type: ") + flag.type, &final_string, &chars_in_line);
|
||||
// The listed default value will be the actual default from the flag
|
||||
// definition in the originating source file, unless the value has
|
||||
// subsequently been modified using SetCommandLineOptionWithMode() with mode
|
||||
// SET_FLAGS_DEFAULT, or by setting FLAGS_foo = bar before ParseCommandLineFlags().
|
||||
AddString(PrintStringFlagsWithQuotes(flag, "default", false), &final_string,
|
||||
&chars_in_line);
|
||||
if (!flag.is_default) {
|
||||
AddString(PrintStringFlagsWithQuotes(flag, "currently", true),
|
||||
&final_string, &chars_in_line);
|
||||
}
|
||||
|
||||
StringAppendF(&final_string, "\n");
|
||||
return final_string;
|
||||
}
|
||||
|
||||
// Simple routine to xml-escape a string: escape & and < only.
|
||||
static string XMLText(const string& txt) {
|
||||
string ans = txt;
|
||||
for (string::size_type pos = 0; (pos = ans.find("&", pos)) != string::npos; )
|
||||
ans.replace(pos++, 1, "&");
|
||||
for (string::size_type pos = 0; (pos = ans.find("<", pos)) != string::npos; )
|
||||
ans.replace(pos++, 1, "<");
|
||||
return ans;
|
||||
}
|
||||
|
||||
static void AddXMLTag(string* r, const char* tag, const string& txt) {
|
||||
StringAppendF(r, "<%s>%s</%s>", tag, XMLText(txt).c_str(), tag);
|
||||
}
|
||||
|
||||
|
||||
static string DescribeOneFlagInXML(const CommandLineFlagInfo& flag) {
|
||||
// The file and flagname could have been attributes, but default
|
||||
// and meaning need to avoid attribute normalization. This way it
|
||||
// can be parsed by simple programs, in addition to xml parsers.
|
||||
string r("<flag>");
|
||||
AddXMLTag(&r, "file", flag.filename);
|
||||
AddXMLTag(&r, "name", flag.name);
|
||||
AddXMLTag(&r, "meaning", flag.description);
|
||||
AddXMLTag(&r, "default", flag.default_value);
|
||||
AddXMLTag(&r, "current", flag.current_value);
|
||||
AddXMLTag(&r, "type", flag.type);
|
||||
r += "</flag>";
|
||||
return r;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ShowUsageWithFlags()
|
||||
// ShowUsageWithFlagsRestrict()
|
||||
// ShowXMLOfFlags()
|
||||
// These routines variously expose the registry's list of flag
|
||||
// values. ShowUsage*() prints the flag-value information
|
||||
// to stdout in a user-readable format (that's what --help uses).
|
||||
// The Restrict() version limits what flags are shown.
|
||||
// ShowXMLOfFlags() prints the flag-value information to stdout
|
||||
// in a machine-readable format. In all cases, the flags are
|
||||
// sorted: first by filename they are defined in, then by flagname.
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
static const char* Basename(const char* filename) {
|
||||
const char* sep = strrchr(filename, PATH_SEPARATOR);
|
||||
return sep ? sep + 1 : filename;
|
||||
}
|
||||
|
||||
static string Dirname(const string& filename) {
|
||||
string::size_type sep = filename.rfind(PATH_SEPARATOR);
|
||||
return filename.substr(0, (sep == string::npos) ? 0 : sep);
|
||||
}
|
||||
|
||||
// Test whether a filename contains at least one of the substrings.
|
||||
static bool FileMatchesSubstring(const string& filename,
|
||||
const vector<string>& substrings) {
|
||||
for (vector<string>::const_iterator target = substrings.begin();
|
||||
target != substrings.end();
|
||||
++target) {
|
||||
if (strstr(filename.c_str(), target->c_str()) != NULL)
|
||||
return true;
|
||||
// If the substring starts with a '/', that means that we want
|
||||
// the string to be at the beginning of a directory component.
|
||||
// That should match the first directory component as well, so
|
||||
// we allow '/foo' to match a filename of 'foo'.
|
||||
if (!target->empty() && (*target)[0] == PATH_SEPARATOR &&
|
||||
strncmp(filename.c_str(), target->c_str() + 1,
|
||||
strlen(target->c_str() + 1)) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Show help for every filename which matches any of the target substrings.
|
||||
// If substrings is empty, shows help for every file. If a flag's help message
|
||||
// has been stripped (e.g. by adding '#define STRIP_FLAG_HELP 1'
|
||||
// before including gflags/gflags.h), then this flag will not be displayed
|
||||
// by '--help' and its variants.
|
||||
static void ShowUsageWithFlagsMatching(const char *argv0,
|
||||
const vector<string> &substrings) {
|
||||
fprintf(stdout, "%s: %s\n", Basename(argv0), ProgramUsage());
|
||||
|
||||
vector<CommandLineFlagInfo> flags;
|
||||
GetAllFlags(&flags); // flags are sorted by filename, then flagname
|
||||
|
||||
string last_filename; // so we know when we're at a new file
|
||||
bool first_directory = true; // controls blank lines between dirs
|
||||
bool found_match = false; // stays false iff no dir matches restrict
|
||||
for (vector<CommandLineFlagInfo>::const_iterator flag = flags.begin();
|
||||
flag != flags.end();
|
||||
++flag) {
|
||||
if (substrings.empty() ||
|
||||
FileMatchesSubstring(flag->filename, substrings)) {
|
||||
// If the flag has been stripped, pretend that it doesn't exist.
|
||||
if (flag->description == kStrippedFlagHelp) continue;
|
||||
found_match = true; // this flag passed the match!
|
||||
if (flag->filename != last_filename) { // new file
|
||||
if (Dirname(flag->filename) != Dirname(last_filename)) { // new dir!
|
||||
if (!first_directory)
|
||||
fprintf(stdout, "\n\n"); // put blank lines between directories
|
||||
first_directory = false;
|
||||
}
|
||||
fprintf(stdout, "\n Flags from %s:\n", flag->filename.c_str());
|
||||
last_filename = flag->filename;
|
||||
}
|
||||
// Now print this flag
|
||||
fprintf(stdout, "%s", DescribeOneFlag(*flag).c_str());
|
||||
}
|
||||
}
|
||||
if (!found_match && !substrings.empty()) {
|
||||
fprintf(stdout, "\n No modules matched: use -help\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict_) {
|
||||
vector<string> substrings;
|
||||
if (restrict_ != NULL && *restrict_ != '\0') {
|
||||
substrings.push_back(restrict_);
|
||||
}
|
||||
ShowUsageWithFlagsMatching(argv0, substrings);
|
||||
}
|
||||
|
||||
void ShowUsageWithFlags(const char *argv0) {
|
||||
ShowUsageWithFlagsRestrict(argv0, "");
|
||||
}
|
||||
|
||||
// Convert the help, program, and usage to xml.
|
||||
static void ShowXMLOfFlags(const char *prog_name) {
|
||||
vector<CommandLineFlagInfo> flags;
|
||||
GetAllFlags(&flags); // flags are sorted: by filename, then flagname
|
||||
|
||||
// XML. There is no corresponding schema yet
|
||||
fprintf(stdout, "<?xml version=\"1.0\"?>\n");
|
||||
// The document
|
||||
fprintf(stdout, "<AllFlags>\n");
|
||||
// the program name and usage
|
||||
fprintf(stdout, "<program>%s</program>\n",
|
||||
XMLText(Basename(prog_name)).c_str());
|
||||
fprintf(stdout, "<usage>%s</usage>\n",
|
||||
XMLText(ProgramUsage()).c_str());
|
||||
// All the flags
|
||||
for (vector<CommandLineFlagInfo>::const_iterator flag = flags.begin();
|
||||
flag != flags.end();
|
||||
++flag) {
|
||||
if (flag->description != kStrippedFlagHelp)
|
||||
fprintf(stdout, "%s\n", DescribeOneFlagInXML(*flag).c_str());
|
||||
}
|
||||
// The end of the document
|
||||
fprintf(stdout, "</AllFlags>\n");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ShowVersion()
|
||||
// Called upon --version. Prints build-related info.
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
static void ShowVersion() {
|
||||
const char* version_string = VersionString();
|
||||
if (version_string && *version_string) {
|
||||
fprintf(stdout, "%s version %s\n",
|
||||
ProgramInvocationShortName(), version_string);
|
||||
} else {
|
||||
fprintf(stdout, "%s\n", ProgramInvocationShortName());
|
||||
}
|
||||
# if !defined(NDEBUG)
|
||||
fprintf(stdout, "Debug build (NDEBUG not #defined)\n");
|
||||
# endif
|
||||
}
|
||||
|
||||
static void AppendPrognameStrings(vector<string>* substrings,
|
||||
const char* progname) {
|
||||
string r("");
|
||||
r += PATH_SEPARATOR;
|
||||
r += progname;
|
||||
substrings->push_back(r + ".");
|
||||
substrings->push_back(r + "-main.");
|
||||
substrings->push_back(r + "_main.");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// HandleCommandLineHelpFlags()
|
||||
// Checks all the 'reporting' commandline flags to see if any
|
||||
// have been set. If so, handles them appropriately. Note
|
||||
// that all of them, by definition, cause the program to exit
|
||||
// if they trigger.
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void HandleCommandLineHelpFlags() {
|
||||
const char* progname = ProgramInvocationShortName();
|
||||
|
||||
HandleCommandLineCompletions();
|
||||
|
||||
vector<string> substrings;
|
||||
AppendPrognameStrings(&substrings, progname);
|
||||
|
||||
if (FLAGS_helpshort) {
|
||||
// show only flags related to this binary:
|
||||
// E.g. for fileutil.cc, want flags containing ... "/fileutil." cc
|
||||
ShowUsageWithFlagsMatching(progname, substrings);
|
||||
gflags_exitfunc(1);
|
||||
|
||||
} else if (FLAGS_help || FLAGS_helpfull) {
|
||||
// show all options
|
||||
ShowUsageWithFlagsRestrict(progname, ""); // empty restrict
|
||||
gflags_exitfunc(1);
|
||||
|
||||
} else if (!FLAGS_helpon.empty()) {
|
||||
string restrict_ = PATH_SEPARATOR + FLAGS_helpon + ".";
|
||||
ShowUsageWithFlagsRestrict(progname, restrict_.c_str());
|
||||
gflags_exitfunc(1);
|
||||
|
||||
} else if (!FLAGS_helpmatch.empty()) {
|
||||
ShowUsageWithFlagsRestrict(progname, FLAGS_helpmatch.c_str());
|
||||
gflags_exitfunc(1);
|
||||
|
||||
} else if (FLAGS_helppackage) {
|
||||
// Shows help for all files in the same directory as main(). We
|
||||
// don't want to resort to looking at dirname(progname), because
|
||||
// the user can pick progname, and it may not relate to the file
|
||||
// where main() resides. So instead, we search the flags for a
|
||||
// filename like "/progname.cc", and take the dirname of that.
|
||||
vector<CommandLineFlagInfo> flags;
|
||||
GetAllFlags(&flags);
|
||||
string last_package;
|
||||
for (vector<CommandLineFlagInfo>::const_iterator flag = flags.begin();
|
||||
flag != flags.end();
|
||||
++flag) {
|
||||
if (!FileMatchesSubstring(flag->filename, substrings))
|
||||
continue;
|
||||
const string package = Dirname(flag->filename) + PATH_SEPARATOR;
|
||||
if (package != last_package) {
|
||||
ShowUsageWithFlagsRestrict(progname, package.c_str());
|
||||
VLOG(7) << "Found package: " << package;
|
||||
if (!last_package.empty()) { // means this isn't our first pkg
|
||||
LOG(WARNING) << "Multiple packages contain a file=" << progname;
|
||||
}
|
||||
last_package = package;
|
||||
}
|
||||
}
|
||||
if (last_package.empty()) { // never found a package to print
|
||||
LOG(WARNING) << "Unable to find a package for file=" << progname;
|
||||
}
|
||||
gflags_exitfunc(1);
|
||||
|
||||
} else if (FLAGS_helpxml) {
|
||||
ShowXMLOfFlags(progname);
|
||||
gflags_exitfunc(1);
|
||||
|
||||
} else if (FLAGS_version) {
|
||||
ShowVersion();
|
||||
// Unlike help, we may be asking for version in a script, so return 0
|
||||
gflags_exitfunc(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace GFLAGS_NAMESPACE
|
||||
348
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/mutex.h
vendored
Normal file
348
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/mutex.h
vendored
Normal file
@@ -0,0 +1,348 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---
|
||||
//
|
||||
// A simple mutex wrapper, supporting locks and read-write locks.
|
||||
// You should assume the locks are *not* re-entrant.
|
||||
//
|
||||
// This class is meant to be internal-only and should be wrapped by an
|
||||
// internal namespace. Before you use this module, please give the
|
||||
// name of your internal namespace for this module. Or, if you want
|
||||
// to expose it, you'll want to move it to the Google namespace. We
|
||||
// cannot put this class in global namespace because there can be some
|
||||
// problems when we have multiple versions of Mutex in each shared object.
|
||||
//
|
||||
// NOTE: by default, we have #ifdef'ed out the TryLock() method.
|
||||
// This is for two reasons:
|
||||
// 1) TryLock() under Windows is a bit annoying (it requires a
|
||||
// #define to be defined very early).
|
||||
// 2) TryLock() is broken for NO_THREADS mode, at least in NDEBUG
|
||||
// mode.
|
||||
// If you need TryLock(), and either these two caveats are not a
|
||||
// problem for you, or you're willing to work around them, then
|
||||
// feel free to #define GMUTEX_TRYLOCK, or to remove the #ifdefs
|
||||
// in the code below.
|
||||
//
|
||||
// CYGWIN NOTE: Cygwin support for rwlock seems to be buggy:
|
||||
// http://www.cygwin.com/ml/cygwin/2008-12/msg00017.html
|
||||
// Because of that, we might as well use windows locks for
|
||||
// cygwin. They seem to be more reliable than the cygwin pthreads layer.
|
||||
//
|
||||
// TRICKY IMPLEMENTATION NOTE:
|
||||
// This class is designed to be safe to use during
|
||||
// dynamic-initialization -- that is, by global constructors that are
|
||||
// run before main() starts. The issue in this case is that
|
||||
// dynamic-initialization happens in an unpredictable order, and it
|
||||
// could be that someone else's dynamic initializer could call a
|
||||
// function that tries to acquire this mutex -- but that all happens
|
||||
// before this mutex's constructor has run. (This can happen even if
|
||||
// the mutex and the function that uses the mutex are in the same .cc
|
||||
// file.) Basically, because Mutex does non-trivial work in its
|
||||
// constructor, it's not, in the naive implementation, safe to use
|
||||
// before dynamic initialization has run on it.
|
||||
//
|
||||
// The solution used here is to pair the actual mutex primitive with a
|
||||
// bool that is set to true when the mutex is dynamically initialized.
|
||||
// (Before that it's false.) Then we modify all mutex routines to
|
||||
// look at the bool, and not try to lock/unlock until the bool makes
|
||||
// it to true (which happens after the Mutex constructor has run.)
|
||||
//
|
||||
// This works because before main() starts -- particularly, during
|
||||
// dynamic initialization -- there are no threads, so a) it's ok that
|
||||
// the mutex operations are a no-op, since we don't need locking then
|
||||
// anyway; and b) we can be quite confident our bool won't change
|
||||
// state between a call to Lock() and a call to Unlock() (that would
|
||||
// require a global constructor in one translation unit to call Lock()
|
||||
// and another global constructor in another translation unit to call
|
||||
// Unlock() later, which is pretty perverse).
|
||||
//
|
||||
// That said, it's tricky, and can conceivably fail; it's safest to
|
||||
// avoid trying to acquire a mutex in a global constructor, if you
|
||||
// can. One way it can fail is that a really smart compiler might
|
||||
// initialize the bool to true at static-initialization time (too
|
||||
// early) rather than at dynamic-initialization time. To discourage
|
||||
// that, we set is_safe_ to true in code (not the constructor
|
||||
// colon-initializer) and set it to true via a function that always
|
||||
// evaluates to true, but that the compiler can't know always
|
||||
// evaluates to true. This should be good enough.
|
||||
//
|
||||
// A related issue is code that could try to access the mutex
|
||||
// after it's been destroyed in the global destructors (because
|
||||
// the Mutex global destructor runs before some other global
|
||||
// destructor, that tries to acquire the mutex). The way we
|
||||
// deal with this is by taking a constructor arg that global
|
||||
// mutexes should pass in, that causes the destructor to do no
|
||||
// work. We still depend on the compiler not doing anything
|
||||
// weird to a Mutex's memory after it is destroyed, but for a
|
||||
// static global variable, that's pretty safe.
|
||||
|
||||
#ifndef GFLAGS_MUTEX_H_
|
||||
#define GFLAGS_MUTEX_H_
|
||||
|
||||
#include "gflags/gflags_declare.h" // to figure out pthreads support
|
||||
|
||||
#if defined(NO_THREADS)
|
||||
typedef int MutexType; // to keep a lock-count
|
||||
#elif defined(OS_WINDOWS)
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN // We only need minimal includes
|
||||
# endif
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX // Don't want windows to override min()/max()
|
||||
# endif
|
||||
# ifdef GMUTEX_TRYLOCK
|
||||
// We need Windows NT or later for TryEnterCriticalSection(). If you
|
||||
// don't need that functionality, you can remove these _WIN32_WINNT
|
||||
// lines, and change TryLock() to assert(0) or something.
|
||||
# ifndef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0400
|
||||
# endif
|
||||
# endif
|
||||
# include <windows.h>
|
||||
typedef CRITICAL_SECTION MutexType;
|
||||
#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
|
||||
// Needed for pthread_rwlock_*. If it causes problems, you could take it
|
||||
// out, but then you'd have to unset HAVE_RWLOCK (at least on linux -- it
|
||||
// *does* cause problems for FreeBSD, or MacOSX, but isn't needed
|
||||
// for locking there.)
|
||||
# ifdef __linux__
|
||||
# if _XOPEN_SOURCE < 500 // including not being defined at all
|
||||
# undef _XOPEN_SOURCE
|
||||
# define _XOPEN_SOURCE 500 // may be needed to get the rwlock calls
|
||||
# endif
|
||||
# endif
|
||||
# include <pthread.h>
|
||||
typedef pthread_rwlock_t MutexType;
|
||||
#elif defined(HAVE_PTHREAD)
|
||||
# include <pthread.h>
|
||||
typedef pthread_mutex_t MutexType;
|
||||
#else
|
||||
# error Need to implement mutex.h for your architecture, or #define NO_THREADS
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> // for abort()
|
||||
|
||||
#define MUTEX_NAMESPACE gflags_mutex_namespace
|
||||
|
||||
namespace MUTEX_NAMESPACE {
|
||||
|
||||
class Mutex {
|
||||
public:
|
||||
// This is used for the single-arg constructor
|
||||
enum LinkerInitialized { LINKER_INITIALIZED };
|
||||
|
||||
// Create a Mutex that is not held by anybody. This constructor is
|
||||
// typically used for Mutexes allocated on the heap or the stack.
|
||||
inline Mutex();
|
||||
// This constructor should be used for global, static Mutex objects.
|
||||
// It inhibits work being done by the destructor, which makes it
|
||||
// safer for code that tries to acqiure this mutex in their global
|
||||
// destructor.
|
||||
explicit inline Mutex(LinkerInitialized);
|
||||
|
||||
// Destructor
|
||||
inline ~Mutex();
|
||||
|
||||
inline void Lock(); // Block if needed until free then acquire exclusively
|
||||
inline void Unlock(); // Release a lock acquired via Lock()
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
inline bool TryLock(); // If free, Lock() and return true, else return false
|
||||
#endif
|
||||
// Note that on systems that don't support read-write locks, these may
|
||||
// be implemented as synonyms to Lock() and Unlock(). So you can use
|
||||
// these for efficiency, but don't use them anyplace where being able
|
||||
// to do shared reads is necessary to avoid deadlock.
|
||||
inline void ReaderLock(); // Block until free or shared then acquire a share
|
||||
inline void ReaderUnlock(); // Release a read share of this Mutex
|
||||
inline void WriterLock() { Lock(); } // Acquire an exclusive lock
|
||||
inline void WriterUnlock() { Unlock(); } // Release a lock from WriterLock()
|
||||
|
||||
private:
|
||||
MutexType mutex_;
|
||||
// We want to make sure that the compiler sets is_safe_ to true only
|
||||
// when we tell it to, and never makes assumptions is_safe_ is
|
||||
// always true. volatile is the most reliable way to do that.
|
||||
volatile bool is_safe_;
|
||||
// This indicates which constructor was called.
|
||||
bool destroy_;
|
||||
|
||||
inline void SetIsSafe() { is_safe_ = true; }
|
||||
|
||||
// Catch the error of writing Mutex when intending MutexLock.
|
||||
explicit Mutex(Mutex* /*ignored*/) {}
|
||||
// Disallow "evil" constructors
|
||||
Mutex(const Mutex&);
|
||||
void operator=(const Mutex&);
|
||||
};
|
||||
|
||||
// Now the implementation of Mutex for various systems
|
||||
#if defined(NO_THREADS)
|
||||
|
||||
// When we don't have threads, we can be either reading or writing,
|
||||
// but not both. We can have lots of readers at once (in no-threads
|
||||
// mode, that's most likely to happen in recursive function calls),
|
||||
// but only one writer. We represent this by having mutex_ be -1 when
|
||||
// writing and a number > 0 when reading (and 0 when no lock is held).
|
||||
//
|
||||
// In debug mode, we assert these invariants, while in non-debug mode
|
||||
// we do nothing, for efficiency. That's why everything is in an
|
||||
// assert.
|
||||
|
||||
Mutex::Mutex() : mutex_(0) { }
|
||||
Mutex::Mutex(Mutex::LinkerInitialized) : mutex_(0) { }
|
||||
Mutex::~Mutex() { assert(mutex_ == 0); }
|
||||
void Mutex::Lock() { assert(--mutex_ == -1); }
|
||||
void Mutex::Unlock() { assert(mutex_++ == -1); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { if (mutex_) return false; Lock(); return true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { assert(++mutex_ > 0); }
|
||||
void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
|
||||
|
||||
#elif defined(OS_WINDOWS)
|
||||
|
||||
Mutex::Mutex() : destroy_(true) {
|
||||
InitializeCriticalSection(&mutex_);
|
||||
SetIsSafe();
|
||||
}
|
||||
Mutex::Mutex(LinkerInitialized) : destroy_(false) {
|
||||
InitializeCriticalSection(&mutex_);
|
||||
SetIsSafe();
|
||||
}
|
||||
Mutex::~Mutex() { if (destroy_) DeleteCriticalSection(&mutex_); }
|
||||
void Mutex::Lock() { if (is_safe_) EnterCriticalSection(&mutex_); }
|
||||
void Mutex::Unlock() { if (is_safe_) LeaveCriticalSection(&mutex_); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { return is_safe_ ?
|
||||
TryEnterCriticalSection(&mutex_) != 0 : true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
|
||||
void Mutex::ReaderUnlock() { Unlock(); }
|
||||
|
||||
#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
|
||||
|
||||
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
|
||||
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
|
||||
} while (0)
|
||||
|
||||
Mutex::Mutex() : destroy_(true) {
|
||||
SetIsSafe();
|
||||
if (is_safe_ && pthread_rwlock_init(&mutex_, NULL) != 0) abort();
|
||||
}
|
||||
Mutex::Mutex(Mutex::LinkerInitialized) : destroy_(false) {
|
||||
SetIsSafe();
|
||||
if (is_safe_ && pthread_rwlock_init(&mutex_, NULL) != 0) abort();
|
||||
}
|
||||
Mutex::~Mutex() { if (destroy_) SAFE_PTHREAD(pthread_rwlock_destroy); }
|
||||
void Mutex::Lock() { SAFE_PTHREAD(pthread_rwlock_wrlock); }
|
||||
void Mutex::Unlock() { SAFE_PTHREAD(pthread_rwlock_unlock); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { return is_safe_ ?
|
||||
pthread_rwlock_trywrlock(&mutex_) == 0 : true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { SAFE_PTHREAD(pthread_rwlock_rdlock); }
|
||||
void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock); }
|
||||
#undef SAFE_PTHREAD
|
||||
|
||||
#elif defined(HAVE_PTHREAD)
|
||||
|
||||
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
|
||||
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
|
||||
} while (0)
|
||||
|
||||
Mutex::Mutex() : destroy_(true) {
|
||||
SetIsSafe();
|
||||
if (is_safe_ && pthread_mutex_init(&mutex_, NULL) != 0) abort();
|
||||
}
|
||||
Mutex::Mutex(Mutex::LinkerInitialized) : destroy_(false) {
|
||||
SetIsSafe();
|
||||
if (is_safe_ && pthread_mutex_init(&mutex_, NULL) != 0) abort();
|
||||
}
|
||||
Mutex::~Mutex() { if (destroy_) SAFE_PTHREAD(pthread_mutex_destroy); }
|
||||
void Mutex::Lock() { SAFE_PTHREAD(pthread_mutex_lock); }
|
||||
void Mutex::Unlock() { SAFE_PTHREAD(pthread_mutex_unlock); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { return is_safe_ ?
|
||||
pthread_mutex_trylock(&mutex_) == 0 : true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { Lock(); }
|
||||
void Mutex::ReaderUnlock() { Unlock(); }
|
||||
#undef SAFE_PTHREAD
|
||||
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Some helper classes
|
||||
|
||||
// MutexLock(mu) acquires mu when constructed and releases it when destroyed.
|
||||
class MutexLock {
|
||||
public:
|
||||
explicit MutexLock(Mutex *mu) : mu_(mu) { mu_->Lock(); }
|
||||
~MutexLock() { mu_->Unlock(); }
|
||||
private:
|
||||
Mutex * const mu_;
|
||||
// Disallow "evil" constructors
|
||||
MutexLock(const MutexLock&);
|
||||
void operator=(const MutexLock&);
|
||||
};
|
||||
|
||||
// ReaderMutexLock and WriterMutexLock do the same, for rwlocks
|
||||
class ReaderMutexLock {
|
||||
public:
|
||||
explicit ReaderMutexLock(Mutex *mu) : mu_(mu) { mu_->ReaderLock(); }
|
||||
~ReaderMutexLock() { mu_->ReaderUnlock(); }
|
||||
private:
|
||||
Mutex * const mu_;
|
||||
// Disallow "evil" constructors
|
||||
ReaderMutexLock(const ReaderMutexLock&);
|
||||
void operator=(const ReaderMutexLock&);
|
||||
};
|
||||
|
||||
class WriterMutexLock {
|
||||
public:
|
||||
explicit WriterMutexLock(Mutex *mu) : mu_(mu) { mu_->WriterLock(); }
|
||||
~WriterMutexLock() { mu_->WriterUnlock(); }
|
||||
private:
|
||||
Mutex * const mu_;
|
||||
// Disallow "evil" constructors
|
||||
WriterMutexLock(const WriterMutexLock&);
|
||||
void operator=(const WriterMutexLock&);
|
||||
};
|
||||
|
||||
// Catch bug where variable name is omitted, e.g. MutexLock (&mu);
|
||||
#define MutexLock(x) COMPILE_ASSERT(0, mutex_lock_decl_missing_var_name)
|
||||
#define ReaderMutexLock(x) COMPILE_ASSERT(0, rmutex_lock_decl_missing_var_name)
|
||||
#define WriterMutexLock(x) COMPILE_ASSERT(0, wmutex_lock_decl_missing_var_name)
|
||||
|
||||
} // namespace MUTEX_NAMESPACE
|
||||
|
||||
|
||||
#endif /* #define GFLAGS_MUTEX_H__ */
|
||||
373
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/util.h
vendored
Normal file
373
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/util.h
vendored
Normal file
@@ -0,0 +1,373 @@
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// ---
|
||||
//
|
||||
// Some generically useful utility routines that in google-land would
|
||||
// be their own projects. We make a shortened version here.
|
||||
|
||||
#ifndef GFLAGS_UTIL_H_
|
||||
#define GFLAGS_UTIL_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
#include <stdarg.h> // for va_*
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h> // for mkdir
|
||||
#endif
|
||||
|
||||
|
||||
namespace GFLAGS_NAMESPACE {
|
||||
|
||||
|
||||
// This is used for unittests for death-testing. It is defined in gflags.cc.
|
||||
extern GFLAGS_DLL_DECL void (*gflags_exitfunc)(int);
|
||||
|
||||
// Work properly if either strtoll or strtoq is on this system.
|
||||
#if defined(strtoll) || defined(HAVE_STRTOLL)
|
||||
# define strto64 strtoll
|
||||
# define strtou64 strtoull
|
||||
#elif defined(HAVE_STRTOQ)
|
||||
# define strto64 strtoq
|
||||
# define strtou64 strtouq
|
||||
// Neither strtoll nor strtoq are defined. I hope strtol works!
|
||||
#else
|
||||
# define strto64 strtol
|
||||
# define strtou64 strtoul
|
||||
#endif
|
||||
|
||||
// If we have inttypes.h, it will have defined PRId32/etc for us.
|
||||
// If not, take our best guess.
|
||||
#ifndef PRId32
|
||||
# define PRId32 "d"
|
||||
#endif
|
||||
#ifndef PRId64
|
||||
# define PRId64 "lld"
|
||||
#endif
|
||||
#ifndef PRIu64
|
||||
# define PRIu64 "llu"
|
||||
#endif
|
||||
|
||||
typedef signed char int8;
|
||||
typedef unsigned char uint8;
|
||||
|
||||
// -- utility macros ---------------------------------------------------------
|
||||
|
||||
template <bool b> struct CompileAssert;
|
||||
template <> struct CompileAssert<true> {};
|
||||
#define COMPILE_ASSERT(expr, msg) \
|
||||
enum { assert_##msg = sizeof(CompileAssert<bool(expr)>) }
|
||||
|
||||
// Returns the number of elements in an array.
|
||||
#define arraysize(arr) (sizeof(arr)/sizeof(*(arr)))
|
||||
|
||||
|
||||
// -- logging and testing ---------------------------------------------------
|
||||
|
||||
// For now, we ignore the level for logging, and don't show *VLOG's at
|
||||
// all, except by hand-editing the lines below
|
||||
#define LOG(level) std::cerr
|
||||
#define VLOG(level) if (true) {} else std::cerr
|
||||
#define DVLOG(level) if (true) {} else std::cerr
|
||||
|
||||
// CHECK dies with a fatal error if condition is not true. It is *not*
|
||||
// controlled by NDEBUG, so the check will be executed regardless of
|
||||
// compilation mode. Therefore, it is safe to do things like:
|
||||
// CHECK(fp->Write(x) == 4)
|
||||
// We allow stream-like objects after this for debugging, but they're ignored.
|
||||
#define EXPECT_TRUE(condition) \
|
||||
if (true) { \
|
||||
if (!(condition)) { \
|
||||
fprintf(stderr, "Check failed: %s\n", #condition); \
|
||||
exit(1); \
|
||||
} \
|
||||
} else std::cerr << ""
|
||||
|
||||
#define EXPECT_OP(op, val1, val2) \
|
||||
if (true) { \
|
||||
if (!((val1) op (val2))) { \
|
||||
fprintf(stderr, "Check failed: %s %s %s\n", #val1, #op, #val2); \
|
||||
exit(1); \
|
||||
} \
|
||||
} else std::cerr << ""
|
||||
|
||||
#define EXPECT_EQ(val1, val2) EXPECT_OP(==, val1, val2)
|
||||
#define EXPECT_NE(val1, val2) EXPECT_OP(!=, val1, val2)
|
||||
#define EXPECT_LE(val1, val2) EXPECT_OP(<=, val1, val2)
|
||||
#define EXPECT_LT(val1, val2) EXPECT_OP(< , val1, val2)
|
||||
#define EXPECT_GE(val1, val2) EXPECT_OP(>=, val1, val2)
|
||||
#define EXPECT_GT(val1, val2) EXPECT_OP(> , val1, val2)
|
||||
#define EXPECT_FALSE(cond) EXPECT_TRUE(!(cond))
|
||||
|
||||
// C99 declares isnan and isinf should be macros, so the #ifdef test
|
||||
// should be reliable everywhere. Of course, it's not, but these
|
||||
// are testing pertty marginal functionality anyway, so it's ok to
|
||||
// not-run them even in situations they might, with effort, be made to work.
|
||||
#ifdef isnan // Some compilers, like sun's for Solaris 10, don't define this
|
||||
#define EXPECT_NAN(arg) \
|
||||
do { \
|
||||
if (!isnan(arg)) { \
|
||||
fprintf(stderr, "Check failed: isnan(%s)\n", #arg); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define EXPECT_NAN(arg)
|
||||
#endif
|
||||
|
||||
#ifdef isinf // Some compilers, like sun's for Solaris 10, don't define this
|
||||
#define EXPECT_INF(arg) \
|
||||
do { \
|
||||
if (!isinf(arg)) { \
|
||||
fprintf(stderr, "Check failed: isinf(%s)\n", #arg); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define EXPECT_INF(arg)
|
||||
#endif
|
||||
|
||||
#define EXPECT_DOUBLE_EQ(val1, val2) \
|
||||
do { \
|
||||
if (((val1) < (val2) - 0.001 || (val1) > (val2) + 0.001)) { \
|
||||
fprintf(stderr, "Check failed: %s == %s\n", #val1, #val2); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define EXPECT_STREQ(val1, val2) \
|
||||
do { \
|
||||
if (strcmp((val1), (val2)) != 0) { \
|
||||
fprintf(stderr, "Check failed: streq(%s, %s)\n", #val1, #val2); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Call this in a .cc file where you will later call RUN_ALL_TESTS in main().
|
||||
#define TEST_INIT \
|
||||
static std::vector<void (*)()> g_testlist; /* the tests to run */ \
|
||||
static int RUN_ALL_TESTS() { \
|
||||
std::vector<void (*)()>::const_iterator it; \
|
||||
for (it = g_testlist.begin(); it != g_testlist.end(); ++it) { \
|
||||
(*it)(); /* The test will error-exit if there's a problem. */ \
|
||||
} \
|
||||
fprintf(stderr, "\nPassed %d tests\n\nPASS\n", \
|
||||
static_cast<int>(g_testlist.size())); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
// Note that this macro uses a FlagSaver to keep tests isolated.
|
||||
#define TEST(a, b) \
|
||||
struct Test_##a##_##b { \
|
||||
Test_##a##_##b() { g_testlist.push_back(&Run); } \
|
||||
static void Run() { \
|
||||
FlagSaver fs; \
|
||||
fprintf(stderr, "Running test %s/%s\n", #a, #b); \
|
||||
RunTest(); \
|
||||
} \
|
||||
static void RunTest(); \
|
||||
}; \
|
||||
static Test_##a##_##b g_test_##a##_##b; \
|
||||
void Test_##a##_##b::RunTest()
|
||||
|
||||
// This is a dummy class that eases the google->opensource transition.
|
||||
namespace testing {
|
||||
class Test {};
|
||||
}
|
||||
|
||||
// Call this in a .cc file where you will later call EXPECT_DEATH
|
||||
#define EXPECT_DEATH_INIT \
|
||||
static bool g_called_exit; \
|
||||
static void CalledExit(int) { g_called_exit = true; }
|
||||
|
||||
#define EXPECT_DEATH(fn, msg) \
|
||||
do { \
|
||||
g_called_exit = false; \
|
||||
gflags_exitfunc = &CalledExit; \
|
||||
fn; \
|
||||
gflags_exitfunc = &exit; /* set back to its default */ \
|
||||
if (!g_called_exit) { \
|
||||
fprintf(stderr, "Function didn't die (%s): %s\n", msg, #fn); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define GTEST_HAS_DEATH_TEST 1
|
||||
|
||||
// -- path routines ----------------------------------------------------------
|
||||
|
||||
// Tries to create the directory path as a temp-dir. If it fails,
|
||||
// changes path to some directory it *can* create.
|
||||
#if defined(__MINGW32__)
|
||||
#include <io.h>
|
||||
inline void MakeTmpdir(std::string* path) {
|
||||
if (!path->empty()) {
|
||||
path->append("/gflags_unittest_testdir");
|
||||
int err = mkdir(path->c_str());
|
||||
if (err == 0 || errno == EEXIST) return;
|
||||
}
|
||||
// I had trouble creating a directory in /tmp from mingw
|
||||
*path = "./gflags_unittest";
|
||||
mkdir(path->c_str());
|
||||
}
|
||||
#elif defined(_MSC_VER)
|
||||
#include <direct.h>
|
||||
inline void MakeTmpdir(std::string* path) {
|
||||
if (!path->empty()) {
|
||||
int err = _mkdir(path->c_str());
|
||||
if (err == 0 || errno == EEXIST) return;
|
||||
}
|
||||
char tmppath_buffer[1024];
|
||||
int tmppath_len = GetTempPathA(sizeof(tmppath_buffer), tmppath_buffer);
|
||||
assert(tmppath_len > 0 && tmppath_len < sizeof(tmppath_buffer));
|
||||
assert(tmppath_buffer[tmppath_len - 1] == '\\'); // API guarantees it
|
||||
*path = std::string(tmppath_buffer) + "gflags_unittest";
|
||||
_mkdir(path->c_str());
|
||||
}
|
||||
#else
|
||||
inline void MakeTmpdir(std::string* path) {
|
||||
if (!path->empty()) {
|
||||
int err = mkdir(path->c_str(), 0755);
|
||||
if (err == 0 || errno == EEXIST) return;
|
||||
}
|
||||
mkdir("/tmp/gflags_unittest", 0755);
|
||||
}
|
||||
#endif
|
||||
|
||||
// -- string routines --------------------------------------------------------
|
||||
|
||||
inline void InternalStringPrintf(std::string* output, const char* format,
|
||||
va_list ap) {
|
||||
char space[128]; // try a small buffer and hope it fits
|
||||
|
||||
// It's possible for methods that use a va_list to invalidate
|
||||
// the data in it upon use. The fix is to make a copy
|
||||
// of the structure before using it and use that copy instead.
|
||||
va_list backup_ap;
|
||||
va_copy(backup_ap, ap);
|
||||
int bytes_written = vsnprintf(space, sizeof(space), format, backup_ap);
|
||||
va_end(backup_ap);
|
||||
|
||||
if ((bytes_written >= 0) && (static_cast<size_t>(bytes_written) < sizeof(space))) {
|
||||
output->append(space, bytes_written);
|
||||
return;
|
||||
}
|
||||
|
||||
// Repeatedly increase buffer size until it fits.
|
||||
int length = sizeof(space);
|
||||
while (true) {
|
||||
if (bytes_written < 0) {
|
||||
// Older snprintf() behavior. :-( Just try doubling the buffer size
|
||||
length *= 2;
|
||||
} else {
|
||||
// We need exactly "bytes_written+1" characters
|
||||
length = bytes_written+1;
|
||||
}
|
||||
char* buf = new char[length];
|
||||
|
||||
// Restore the va_list before we use it again
|
||||
va_copy(backup_ap, ap);
|
||||
bytes_written = vsnprintf(buf, length, format, backup_ap);
|
||||
va_end(backup_ap);
|
||||
|
||||
if ((bytes_written >= 0) && (bytes_written < length)) {
|
||||
output->append(buf, bytes_written);
|
||||
delete[] buf;
|
||||
return;
|
||||
}
|
||||
delete[] buf;
|
||||
}
|
||||
}
|
||||
|
||||
// Clears output before writing to it.
|
||||
inline void SStringPrintf(std::string* output, const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
output->clear();
|
||||
InternalStringPrintf(output, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
inline void StringAppendF(std::string* output, const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
InternalStringPrintf(output, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
inline std::string StringPrintf(const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
std::string output;
|
||||
InternalStringPrintf(&output, format, ap);
|
||||
va_end(ap);
|
||||
return output;
|
||||
}
|
||||
|
||||
inline bool SafeGetEnv(const char *varname, std::string &valstr)
|
||||
{
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
char *val;
|
||||
size_t sz;
|
||||
if (_dupenv_s(&val, &sz, varname) != 0 || !val) return false;
|
||||
valstr = val;
|
||||
free(val);
|
||||
#else
|
||||
const char * const val = getenv(varname);
|
||||
if (!val) return false;
|
||||
valstr = val;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
inline int SafeFOpen(FILE **fp, const char* fname, const char *mode)
|
||||
{
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
return fopen_s(fp, fname, mode);
|
||||
#else
|
||||
assert(fp != NULL);
|
||||
*fp = fopen(fname, mode);
|
||||
// errno only guaranteed to be set on failure
|
||||
return ((*fp == NULL) ? errno : 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace GFLAGS_NAMESPACE
|
||||
|
||||
|
||||
#endif // GFLAGS_UTIL_H_
|
||||
73
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/windows_port.cc
vendored
Normal file
73
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/windows_port.cc
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/* Copyright (c) 2009, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* ---
|
||||
* Author: Craig Silverstein
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
# error You should only be including windows/port.cc in a windows environment!
|
||||
#endif
|
||||
|
||||
#include <string.h> // for strlen(), memset(), memcmp()
|
||||
#include <assert.h>
|
||||
#include <stdarg.h> // for va_list, va_start, va_end
|
||||
#include <windows.h>
|
||||
|
||||
#include "windows_port.h"
|
||||
|
||||
// These call the windows _vsnprintf, but always NUL-terminate.
|
||||
#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */
|
||||
#if !(defined(_MSC_VER) && _MSC_VER >= 1900) /* msvc 2015 already defines */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996) // ignore _vsnprintf security warning
|
||||
#endif
|
||||
int safe_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
|
||||
if (size == 0) // not even room for a \0?
|
||||
return -1; // not what C99 says to do, but what windows does
|
||||
str[size-1] = '\0';
|
||||
return _vsnprintf(str, size-1, format, ap);
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
int snprintf(char *str, size_t size, const char *format, ...) {
|
||||
int r;
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
r = vsnprintf(str, size, format, ap);
|
||||
va_end(ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* if !(defined(_MSC_VER) && _MSC_VER >= 1900) */
|
||||
#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */
|
||||
135
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/windows_port.h
vendored
Normal file
135
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/src/windows_port.h
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
/* Copyright (c) 2009, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* ---
|
||||
* Author: Craig Silverstein
|
||||
*
|
||||
* These are some portability typedefs and defines to make it a bit
|
||||
* easier to compile this code under VC++.
|
||||
*
|
||||
* Several of these are taken from glib:
|
||||
* http://developer.gnome.org/doc/API/glib/glib-windows-compatability-functions.html
|
||||
*/
|
||||
|
||||
#ifndef GFLAGS_WINDOWS_PORT_H_
|
||||
#define GFLAGS_WINDOWS_PORT_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
// This must be defined before the windows.h is included.
|
||||
// It's needed for mutex.h, to give access to the TryLock method.
|
||||
# if !defined(_WIN32_WINNT) && !(defined( __MINGW32__) || defined(__MINGW64__))
|
||||
# define _WIN32_WINNT 0x0400
|
||||
# endif
|
||||
// We always want minimal includes
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <direct.h> /* for mkdir */
|
||||
#include <stdlib.h> /* for _putenv, getenv */
|
||||
#include <stdio.h> /* need this to override stdio's snprintf, also defines _unlink used by unit tests */
|
||||
#include <stdarg.h> /* util.h uses va_copy */
|
||||
#include <string.h> /* for _stricmp and _strdup */
|
||||
|
||||
/* We can't just use _vsnprintf and _snprintf as drop-in-replacements,
|
||||
* because they don't always NUL-terminate. :-( We also can't use the
|
||||
* name vsnprintf, since windows defines that (but not snprintf (!)).
|
||||
*/
|
||||
#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */
|
||||
#if !(defined(_MSC_VER) && _MSC_VER >= 1900) /* msvc 2015 already defines */
|
||||
extern GFLAGS_DLL_DECL int snprintf(char *str, size_t size,
|
||||
const char *format, ...);
|
||||
extern int GFLAGS_DLL_DECL safe_vsnprintf(char *str, size_t size,
|
||||
const char *format, va_list ap);
|
||||
#define vsnprintf(str, size, format, ap) safe_vsnprintf(str, size, format, ap)
|
||||
#define va_copy(dst, src) (dst) = (src)
|
||||
#endif
|
||||
#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996) // ignore getenv security warning
|
||||
#endif
|
||||
#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
|
||||
inline void setenv(const char* name, const char* value, int) {
|
||||
// In windows, it's impossible to set a variable to the empty string.
|
||||
// We handle this by setting it to "0" and the NUL-ing out the \0.
|
||||
// That is, we putenv("FOO=0") and then find out where in memory the
|
||||
// putenv wrote "FOO=0", and change it in-place to "FOO=\0".
|
||||
// c.f. http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/environ.cpp?r1=611451&r2=637508&pathrev=637508
|
||||
static const char* const kFakeZero = "0";
|
||||
if (*value == '\0')
|
||||
value = kFakeZero;
|
||||
// Apparently the semantics of putenv() is that the input
|
||||
// must live forever, so we leak memory here. :-(
|
||||
const size_t nameval_len = strlen(name) + 1 + strlen(value) + 1;
|
||||
char* nameval = reinterpret_cast<char*>(malloc(nameval_len));
|
||||
snprintf(nameval, nameval_len, "%s=%s", name, value);
|
||||
_putenv(nameval);
|
||||
if (value == kFakeZero) {
|
||||
nameval[nameval_len - 2] = '\0'; // works when putenv() makes no copy
|
||||
if (*getenv(name) != '\0')
|
||||
*getenv(name) = '\0'; // works when putenv() copies nameval
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#define strcasecmp _stricmp
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
#define strdup _strdup
|
||||
#define unlink _unlink
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1800
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#define PRId32 "d"
|
||||
#define PRIu32 "u"
|
||||
#define PRId64 "I64d"
|
||||
#define PRIu64 "I64u"
|
||||
#endif
|
||||
|
||||
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||
#define strtoq _strtoi64
|
||||
#define strtouq _strtoui64
|
||||
#define strtoll _strtoi64
|
||||
#define strtoull _strtoui64
|
||||
#define atoll _atoi64
|
||||
#endif
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
#endif /* GFLAGS_WINDOWS_PORT_H_ */
|
||||
209
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/CMakeLists.txt
vendored
Normal file
209
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
## gflags tests
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# output directories
|
||||
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
|
||||
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
|
||||
|
||||
# set working directory of test commands
|
||||
set (GFLAGS_FLAGFILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# common include directories and link libraries
|
||||
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
include_directories ("${gflags_SOURCE_DIR}/src")
|
||||
include_directories ("${gflags_BINARY_DIR}/include")
|
||||
include_directories ("${gflags_BINARY_DIR}/include/gflags")
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
set (type shared)
|
||||
if (GFLAGS_IS_A_DLL)
|
||||
add_definitions(-DGFLAGS_IS_A_DLL)
|
||||
endif ()
|
||||
else ()
|
||||
set (type static)
|
||||
endif ()
|
||||
if (BUILD_gflags_LIB)
|
||||
link_libraries (gflags_${type})
|
||||
else ()
|
||||
link_libraries (gflags_nothreads_${type})
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# STRIP_FLAG_HELP
|
||||
add_executable (gflags_strip_flags_test gflags_strip_flags_test.cc)
|
||||
# Make sure the --help output doesn't print the stripped text.
|
||||
add_gflags_test (strip_flags_help 1 "" "This text should be stripped out" gflags_strip_flags_test --help)
|
||||
# Make sure the stripped text isn't in the binary at all.
|
||||
add_test (
|
||||
NAME strip_flags_binary
|
||||
COMMAND "${CMAKE_COMMAND}" "-DBINARY=$<TARGET_FILE:gflags_strip_flags_test>"
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/gflags_strip_flags_test.cmake"
|
||||
CONFIGURATIONS Release MinSizeRel
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# unit tests
|
||||
configure_file (gflags_unittest.cc gflags_unittest-main.cc COPYONLY)
|
||||
configure_file (gflags_unittest.cc gflags_unittest_main.cc COPYONLY)
|
||||
|
||||
add_executable (gflags_unittest gflags_unittest.cc)
|
||||
add_executable (gflags_unittest-main gflags_unittest-main.cc)
|
||||
add_executable (gflags_unittest_main gflags_unittest_main.cc)
|
||||
|
||||
if (OS_WINDOWS)
|
||||
set (SLASH "\\\\")
|
||||
else ()
|
||||
set (SLASH "/")
|
||||
endif ()
|
||||
|
||||
# First, just make sure the gflags_unittest works as-is
|
||||
add_gflags_test(unittest 0 "" "" gflags_unittest)
|
||||
|
||||
# --help should show all flags, including flags from gflags_reporting
|
||||
add_gflags_test(help-reporting 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --help)
|
||||
|
||||
# Make sure that --help prints even very long helpstrings.
|
||||
add_gflags_test(long-helpstring 1 "end of a long helpstring" "" gflags_unittest --help)
|
||||
|
||||
# Make sure --help reflects flag changes made before flag-parsing
|
||||
add_gflags_test(changed_bool1 1 "-changed_bool1 (changed) type: bool default: true" "" gflags_unittest --help)
|
||||
add_gflags_test(changed_bool2 1 "-changed_bool2 (changed) type: bool default: false currently: true" "" gflags_unittest --help)
|
||||
# And on the command-line, too
|
||||
add_gflags_test(changeable_string_var 1 "-changeable_string_var () type: string default: \"1\" currently: \"2\"" "" gflags_unittest --changeable_string_var 2 --help)
|
||||
|
||||
# --nohelp and --help=false should be as if we didn't say anything
|
||||
add_gflags_test(nohelp 0 "PASS" "" gflags_unittest --nohelp)
|
||||
add_gflags_test(help=false 0 "PASS" "" gflags_unittest --help=false)
|
||||
|
||||
# --helpfull is the same as help
|
||||
add_gflags_test(helpfull 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helpfull)
|
||||
|
||||
# --helpshort should show only flags from the gflags_unittest itself
|
||||
add_gflags_test(helpshort 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest --helpshort)
|
||||
|
||||
# --helpshort should show the tldflag we created in the gflags_unittest dir
|
||||
add_gflags_test(helpshort-tldflag1 1 "tldflag1" "${SLASH}google.cc:" gflags_unittest --helpshort)
|
||||
add_gflags_test(helpshort-tldflag2 1 "tldflag2" "${SLASH}google.cc:" gflags_unittest --helpshort)
|
||||
|
||||
# --helpshort should work if the main source file is suffixed with [_-]main
|
||||
add_gflags_test(helpshort-main 1 "${SLASH}gflags_unittest-main.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest-main --helpshort)
|
||||
add_gflags_test(helpshort_main 1 "${SLASH}gflags_unittest_main.cc:" "${SLASH}gflags_reporting.cc:" gflags_unittest_main --helpshort)
|
||||
|
||||
# --helpon needs an argument
|
||||
add_gflags_test(helpon 1 "'--helpon' is missing its argument; flag description: show help on" "" gflags_unittest --helpon)
|
||||
# --helpon argument indicates what file we'll show args from
|
||||
add_gflags_test(helpon=gflags 1 "${SLASH}gflags.cc:" "${SLASH}gflags_unittest.cc:" gflags_unittest --helpon=gflags)
|
||||
# another way of specifying the argument
|
||||
add_gflags_test(helpon_gflags 1 "${SLASH}gflags.cc:" "${SLASH}gflags_unittest.cc:" gflags_unittest --helpon gflags)
|
||||
# test another argument
|
||||
add_gflags_test(helpon=gflags_unittest 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags.cc:" gflags_unittest --helpon=gflags_unittest)
|
||||
|
||||
# helpmatch is like helpon but takes substrings
|
||||
add_gflags_test(helpmatch_reporting 1 "${SLASH}gflags_reporting.cc:" "${SLASH}gflags_unittest.cc:" gflags_unittest -helpmatch reporting)
|
||||
add_gflags_test(helpmatch=unittest 1 "${SLASH}gflags_unittest.cc:" "${SLASH}gflags.cc:" gflags_unittest -helpmatch=unittest)
|
||||
|
||||
# if no flags are found with helpmatch or helpon, suggest --help
|
||||
add_gflags_test(helpmatch=nosuchsubstring 1 "No modules matched" "${SLASH}gflags_unittest.cc:" gflags_unittest -helpmatch=nosuchsubstring)
|
||||
add_gflags_test(helpon=nosuchmodule 1 "No modules matched" "${SLASH}gflags_unittest.cc:" gflags_unittest -helpon=nosuchmodule)
|
||||
|
||||
# helppackage shows all the flags in the same dir as this unittest
|
||||
# --help should show all flags, including flags from google.cc
|
||||
add_gflags_test(helppackage 1 "${SLASH}gflags_reporting.cc:" "" gflags_unittest --helppackage)
|
||||
|
||||
# xml!
|
||||
add_gflags_test(helpxml 1 "${SLASH}gflags_unittest.cc</file>" "${SLASH}gflags_unittest.cc:" gflags_unittest --helpxml)
|
||||
|
||||
# just print the version info and exit
|
||||
add_gflags_test(version-1 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --version)
|
||||
add_gflags_test(version-2 0 "version test_version" "${SLASH}gflags_unittest.cc:" gflags_unittest --version)
|
||||
|
||||
# --undefok is a fun flag...
|
||||
add_gflags_test(undefok-1 1 "unknown command line flag 'foo'" "" gflags_unittest --undefok= --foo --unused_bool)
|
||||
add_gflags_test(undefok-2 0 "PASS" "" gflags_unittest --undefok=foo --foo --unused_bool)
|
||||
# If you say foo is ok to be undefined, we'll accept --nofoo as well
|
||||
add_gflags_test(undefok-3 0 "PASS" "" gflags_unittest --undefok=foo --nofoo --unused_bool)
|
||||
# It's ok if the foo is in the middle
|
||||
add_gflags_test(undefok-4 0 "PASS" "" gflags_unittest --undefok=fee,fi,foo,fum --foo --unused_bool)
|
||||
# But the spelling has to be just right...
|
||||
add_gflags_test(undefok-5 1 "unknown command line flag 'foo'" "" gflags_unittest --undefok=fo --foo --unused_bool)
|
||||
add_gflags_test(undefok-6 1 "unknown command line flag 'foo'" "" gflags_unittest --undefok=foot --foo --unused_bool)
|
||||
|
||||
# See if we can successfully load our flags from the flagfile
|
||||
add_gflags_test(flagfile.1 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest "--flagfile=flagfile.1")
|
||||
add_gflags_test(flagfile.2 0 "PASS" "" gflags_unittest "--flagfile=flagfile.2")
|
||||
add_gflags_test(flagfile.3 0 "PASS" "" gflags_unittest "--flagfile=flagfile.3")
|
||||
|
||||
# Also try to load flags from the environment
|
||||
add_gflags_test(fromenv=version 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --fromenv=version)
|
||||
add_gflags_test(tryfromenv=version 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=version)
|
||||
add_gflags_test(fromenv=help 0 "PASS" "" gflags_unittest --fromenv=help)
|
||||
add_gflags_test(tryfromenv=help 0 "PASS" "" gflags_unittest --tryfromenv=help)
|
||||
add_gflags_test(fromenv=helpfull 1 "helpfull not found in environment" "" gflags_unittest --fromenv=helpfull)
|
||||
add_gflags_test(tryfromenv=helpfull 0 "PASS" "" gflags_unittest --tryfromenv=helpfull)
|
||||
add_gflags_test(tryfromenv=undefok 0 "PASS" "" gflags_unittest --tryfromenv=undefok --foo)
|
||||
add_gflags_test(tryfromenv=weirdo 1 "unknown command line flag" "" gflags_unittest --tryfromenv=weirdo)
|
||||
add_gflags_test(tryfromenv-multiple 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --tryfromenv=test_bool,version,unused_bool)
|
||||
add_gflags_test(fromenv=test_bool 1 "not found in environment" "" gflags_unittest --fromenv=test_bool)
|
||||
add_gflags_test(fromenv=test_bool-ok 1 "unknown command line flag" "" gflags_unittest --fromenv=test_bool,ok)
|
||||
# Here, the --version overrides the fromenv
|
||||
add_gflags_test(version-overrides-fromenv 0 "gflags_unittest" "${SLASH}gflags_unittest.cc:" gflags_unittest --fromenv=test_bool,version,ok)
|
||||
|
||||
# Make sure -- by itself stops argv processing
|
||||
add_gflags_test(dashdash 0 "PASS" "" gflags_unittest -- --help)
|
||||
|
||||
# And we should die if the flag value doesn't pass the validator
|
||||
add_gflags_test(always_fail 1 "ERROR: failed validation of new value 'true' for flag 'always_fail'" "" gflags_unittest --always_fail)
|
||||
|
||||
# And if locking in validators fails
|
||||
# TODO(andreas): Worked on Windows 7 Release configuration, but causes
|
||||
# debugger abort() intervention in case of Debug configuration.
|
||||
#add_gflags_test(deadlock_if_cant_lock 0 "PASS" "" gflags_unittest --deadlock_if_cant_lock)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# use gflags_declare.h
|
||||
add_executable (gflags_declare_test gflags_declare_test.cc gflags_declare_flags.cc)
|
||||
|
||||
add_test(NAME gflags_declare COMMAND gflags_declare_test --message "Hello gflags!")
|
||||
set_tests_properties(gflags_declare PROPERTIES PASS_REGULAR_EXPRESSION "Hello gflags!")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# configure Python script which configures and builds a test project
|
||||
if (BUILD_NC_TESTS OR BUILD_CONFIG_TESTS)
|
||||
find_package (PythonInterp)
|
||||
if (NOT PYTHON_EXECUTABLE)
|
||||
message (FATAL_ERROR "No Python installation found! It is required by the (negative) compilation tests."
|
||||
" Either install Python or set BUILD_NC_TESTS and BUILD_CONFIG_TESTS to FALSE.")
|
||||
endif ()
|
||||
set (TMPDIR "${PROJECT_BINARY_DIR}/Testing/Temporary")
|
||||
configure_file (gflags_build.py.in "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/build.py" @ONLY)
|
||||
function (add_gflags_build_test name srcdir expect_fail)
|
||||
set (srcdir "${CMAKE_CURRENT_SOURCE_DIR}/${srcdir}")
|
||||
add_test (
|
||||
NAME "${name}"
|
||||
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/build.py"
|
||||
${name} ${srcdir} ${expect_fail}
|
||||
)
|
||||
endfunction ()
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# negative compilation tests
|
||||
option (BUILD_NC_TESTS "Request addition of negative compilation tests." OFF)
|
||||
mark_as_advanced (BUILD_NC_TESTS)
|
||||
if (BUILD_NC_TESTS)
|
||||
add_gflags_build_test (nc_sanity nc 0)
|
||||
add_gflags_build_test (nc_swapped_args nc 1)
|
||||
add_gflags_build_test (nc_int_instead_of_bool nc 1)
|
||||
add_gflags_build_test (nc_bool_in_quotes nc 1)
|
||||
add_gflags_build_test (nc_define_string_with_0 nc 1)
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# build configuration test
|
||||
option (BUILD_CONFIG_TESTS "Request addition of package configuration tests." OFF)
|
||||
mark_as_advanced (BUILD_CONFIG_TESTS)
|
||||
if (BUILD_CONFIG_TESTS)
|
||||
add_gflags_build_test (cmake_config config 0)
|
||||
endif ()
|
||||
10
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/config/CMakeLists.txt
vendored
Normal file
10
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/config/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
## gflags package configuration tests
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
|
||||
|
||||
project (gflags_${TEST_NAME})
|
||||
|
||||
find_package (gflags REQUIRED)
|
||||
|
||||
add_executable (foo main.cc)
|
||||
target_link_libraries (foo gflags::gflags)
|
||||
20
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/config/main.cc
vendored
Normal file
20
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/config/main.cc
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
DEFINE_string(message, "Hello World!", "The message to print");
|
||||
|
||||
static bool ValidateMessage(const char* flagname, const std::string &message)
|
||||
{
|
||||
return !message.empty();
|
||||
}
|
||||
DEFINE_validator(message, ValidateMessage);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
gflags::SetUsageMessage("Test CMake configuration of gflags library (gflags-config.cmake)");
|
||||
gflags::SetVersionString("0.1");
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
std::cout << FLAGS_message << std::endl;
|
||||
gflags::ShutDownCommandLineFlags();
|
||||
return 0;
|
||||
}
|
||||
1
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/flagfile.1
vendored
Normal file
1
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/flagfile.1
vendored
Normal file
@@ -0,0 +1 @@
|
||||
--version
|
||||
2
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/flagfile.2
vendored
Normal file
2
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/flagfile.2
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
--foo=bar
|
||||
--nounused_bool
|
||||
1
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/flagfile.3
vendored
Normal file
1
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/flagfile.3
vendored
Normal file
@@ -0,0 +1 @@
|
||||
--flagfile=flagfile.2
|
||||
43
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/gflags_build.py.in
vendored
Normal file
43
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/gflags_build.py.in
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
CMAKE = '@CMAKE_COMMAND@'
|
||||
CMAKE_BUILD_TYPE = '@CMAKE_BUILD_TYPE@'
|
||||
TMPDIR = '@TMPDIR@'
|
||||
SRCDIR = '@SRCDIR@'
|
||||
GFLAGS_DIR = '@gflags_BINARY_DIR@'
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 4:
|
||||
sys.stderr.write(' '.join(['usage:', sys.argv[0], '<test_name> <srcdir> <expect_fail:0|1>\n']))
|
||||
sys.exit(1)
|
||||
test_name = sys.argv[1]
|
||||
srcdir = sys.argv[2]
|
||||
expect_fail = (sys.argv[3].lower() in ['true', 'yes', 'on', '1'])
|
||||
bindir = os.path.join(TMPDIR, test_name)
|
||||
if TMPDIR == '':
|
||||
sys.stderr.write('Temporary directory not set!\n')
|
||||
sys.exit(1)
|
||||
# create build directory
|
||||
if os.path.isdir(bindir): shutil.rmtree(bindir)
|
||||
os.makedirs(bindir)
|
||||
# configure the build tree
|
||||
if subprocess.call([CMAKE, '-DCMAKE_BUILD_TYPE:STRING='+CMAKE_BUILD_TYPE,
|
||||
'-Dgflags_DIR:PATH='+GFLAGS_DIR,
|
||||
'-DTEST_NAME:STRING='+test_name, srcdir], cwd=bindir) != 0:
|
||||
sys.stderr.write('Failed to configure the build tree!\n')
|
||||
sys.exit(1)
|
||||
# build the test project
|
||||
exit_code = subprocess.call([CMAKE, '--build', bindir, '--config', CMAKE_BUILD_TYPE], cwd=bindir)
|
||||
if expect_fail == True:
|
||||
if exit_code == 0:
|
||||
sys.stderr.write('Build expected to fail, but it succeeded!\n')
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.stderr.write('Build failed as expected\n')
|
||||
exit_code = 0
|
||||
sys.exit(exit_code)
|
||||
@@ -0,0 +1,12 @@
|
||||
#define GFLAGS_DLL_DECLARE_FLAG
|
||||
|
||||
#include <iostream>
|
||||
#include <gflags/gflags_declare.h>
|
||||
|
||||
DECLARE_string(message); // in gflags_delcare_test.cc
|
||||
|
||||
void print_message();
|
||||
void print_message()
|
||||
{
|
||||
std::cout << FLAGS_message << std::endl;
|
||||
}
|
||||
12
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/gflags_declare_test.cc
vendored
Normal file
12
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/gflags_declare_test.cc
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
DEFINE_string(message, "", "The message to print");
|
||||
void print_message(); // in gflags_declare_flags.cc
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
GFLAGS_NAMESPACE::SetUsageMessage("Test compilation and use of gflags_declare.h");
|
||||
GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
|
||||
print_message();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2011, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---
|
||||
// Author: csilvers@google.com (Craig Silverstein)
|
||||
//
|
||||
// A simple program that uses STRIP_FLAG_HELP. We'll have a shell
|
||||
// script that runs 'strings' over this program and makes sure
|
||||
// that the help string is not in there.
|
||||
|
||||
#define STRIP_FLAG_HELP 1
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using GFLAGS_NAMESPACE::SetUsageMessage;
|
||||
using GFLAGS_NAMESPACE::ParseCommandLineFlags;
|
||||
|
||||
|
||||
DEFINE_bool(test, true, "This text should be stripped out");
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
SetUsageMessage("Usage message");
|
||||
ParseCommandLineFlags(&argc, &argv, false);
|
||||
|
||||
// Unfortunately, for us, libtool can replace executables with a shell
|
||||
// script that does some work before calling the 'real' executable
|
||||
// under a different name. We need the 'real' executable name to run
|
||||
// 'strings' on it, so we construct this binary to print the real
|
||||
// name (argv[0]) on stdout when run.
|
||||
puts(argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
if (NOT BINARY)
|
||||
message (FATAL_ERROR "BINARY file to check not specified!")
|
||||
endif ()
|
||||
file (STRINGS "${BINARY}" strings REGEX "This text should be stripped out")
|
||||
if (strings)
|
||||
message (FATAL_ERROR "Text not stripped from binary like it should be: ${BINARY}")
|
||||
endif ()
|
||||
1572
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/gflags_unittest.cc
vendored
Normal file
1572
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/gflags_unittest.cc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
--test_flag=1
|
||||
--test_flag=2
|
||||
16
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/nc/CMakeLists.txt
vendored
Normal file
16
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/nc/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
## gflags negative compilation tests
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
|
||||
|
||||
if (NOT TEST_NAME)
|
||||
message (FATAL_ERROR "Missing TEST_NAME CMake flag")
|
||||
endif ()
|
||||
string (TOUPPER ${TEST_NAME} TEST_NAME_UPPER)
|
||||
|
||||
project (gflags_${TEST_NAME})
|
||||
|
||||
find_package (gflags REQUIRED)
|
||||
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
add_definitions (-DTEST_${TEST_NAME_UPPER})
|
||||
add_executable (gflags_${TEST_NAME} gflags_nc.cc)
|
||||
target_link_libraries(gflags_${TEST_NAME} gflags)
|
||||
73
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/nc/gflags_nc.cc
vendored
Normal file
73
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/gflags/test/nc/gflags_nc.cc
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2009, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// ---
|
||||
//
|
||||
// A negative comiple test for gflags.
|
||||
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#if defined(TEST_NC_SWAPPED_ARGS)
|
||||
|
||||
DEFINE_bool(some_bool_flag,
|
||||
"the default value should go here, not the description",
|
||||
false);
|
||||
|
||||
|
||||
#elif defined(TEST_NC_INT_INSTEAD_OF_BOOL)
|
||||
|
||||
DEFINE_bool(some_bool_flag_2,
|
||||
0,
|
||||
"should have been an int32 flag but mistakenly used bool instead");
|
||||
|
||||
#elif defined(TEST_NC_BOOL_IN_QUOTES)
|
||||
|
||||
|
||||
DEFINE_bool(some_bool_flag_3,
|
||||
"false",
|
||||
"false in in quotes, which is wrong");
|
||||
|
||||
#elif defined(TEST_NC_SANITY)
|
||||
|
||||
DEFINE_bool(some_bool_flag_4,
|
||||
true,
|
||||
"this is the correct usage of DEFINE_bool");
|
||||
|
||||
#elif defined(TEST_NC_DEFINE_STRING_WITH_0)
|
||||
|
||||
DEFINE_string(some_string_flag,
|
||||
0,
|
||||
"Trying to construct a string by passing 0 would cause a crash.");
|
||||
|
||||
#endif
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
941
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/CMakeLists.txt
vendored
Normal file
941
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,941 @@
|
||||
cmake_minimum_required (VERSION 3.16)
|
||||
project (glog
|
||||
VERSION 0.7.0
|
||||
DESCRIPTION "C++ implementation of the Google logging module"
|
||||
HOMEPAGE_URL https://github.com/google/glog
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set (CPACK_PACKAGE_NAME glog)
|
||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Google logging library")
|
||||
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
|
||||
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
|
||||
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
|
||||
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
|
||||
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
include (CheckCXXCompilerFlag)
|
||||
include (CheckCXXSourceCompiles)
|
||||
include (CheckCXXSourceRuns)
|
||||
include (CheckCXXSymbolExists)
|
||||
include (CheckFunctionExists)
|
||||
include (CheckIncludeFileCXX)
|
||||
include (CheckLibraryExists)
|
||||
include (CheckStructHasMember)
|
||||
include (CheckTypeSize)
|
||||
include (CMakeDependentOption)
|
||||
include (CMakePackageConfigHelpers)
|
||||
include (CMakePushCheckState)
|
||||
include (CPack)
|
||||
include (CTest)
|
||||
include (DetermineGflagsNamespace)
|
||||
include (GenerateExportHeader)
|
||||
include (GetCacheVariables)
|
||||
include (GNUInstallDirs)
|
||||
|
||||
option (BUILD_SHARED_LIBS "Build shared libraries" ON)
|
||||
option (PRINT_UNSYMBOLIZED_STACK_TRACES
|
||||
"Print file offsets in traces instead of symbolizing" OFF)
|
||||
option (WITH_GFLAGS "Use gflags" ON)
|
||||
option (WITH_GTEST "Use Google Test" ON)
|
||||
option (WITH_PKGCONFIG "Enable pkg-config support" ON)
|
||||
option (WITH_SYMBOLIZE "Enable symbolize module" ON)
|
||||
option (WITH_THREADS "Enable multithreading support" ON)
|
||||
option (WITH_TLS "Enable Thread Local Storage (TLS) support" ON)
|
||||
option (WITH_UNWIND "Enable libunwind support" ON)
|
||||
|
||||
cmake_dependent_option (WITH_GMOCK "Use Google Mock" ON WITH_GTEST OFF)
|
||||
|
||||
set (WITH_FUZZING none CACHE STRING "Fuzzing engine")
|
||||
set_property (CACHE WITH_FUZZING PROPERTY STRINGS none libfuzzer ossfuzz)
|
||||
|
||||
if (NOT WITH_UNWIND)
|
||||
set (CMAKE_DISABLE_FIND_PACKAGE_Unwind ON)
|
||||
endif (NOT WITH_UNWIND)
|
||||
|
||||
if (NOT WITH_GTEST)
|
||||
set (CMAKE_DISABLE_FIND_PACKAGE_GTest ON)
|
||||
endif (NOT WITH_GTEST)
|
||||
|
||||
if (NOT WITH_THREADS)
|
||||
set (CMAKE_DISABLE_FIND_PACKAGE_Threads ON)
|
||||
endif (NOT WITH_THREADS)
|
||||
|
||||
set (CMAKE_C_VISIBILITY_PRESET hidden)
|
||||
set (CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
set (CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
||||
|
||||
set (CMAKE_DEBUG_POSTFIX d)
|
||||
set (CMAKE_THREAD_PREFER_PTHREAD 1)
|
||||
|
||||
find_package (GTest NO_MODULE)
|
||||
|
||||
if (GTest_FOUND)
|
||||
set (HAVE_LIB_GTEST 1)
|
||||
endif (GTest_FOUND)
|
||||
|
||||
if (WITH_GMOCK AND TARGET GTest::gmock)
|
||||
set (HAVE_LIB_GMOCK 1)
|
||||
endif (WITH_GMOCK AND TARGET GTest::gmock)
|
||||
|
||||
if (WITH_GFLAGS)
|
||||
find_package (gflags 2.2.2)
|
||||
|
||||
if (gflags_FOUND)
|
||||
set (HAVE_LIB_GFLAGS 1)
|
||||
determine_gflags_namespace (gflags_NAMESPACE)
|
||||
endif (gflags_FOUND)
|
||||
endif (WITH_GFLAGS)
|
||||
|
||||
find_package (Threads)
|
||||
find_package (Unwind)
|
||||
|
||||
if (Unwind_FOUND)
|
||||
set (HAVE_LIB_UNWIND 1)
|
||||
else (Unwind_FOUND)
|
||||
# Check whether linking actually succeeds. ARM toolchains of LLVM unwind
|
||||
# implementation do not necessarily provide the _Unwind_Backtrace function
|
||||
# which causes the previous check to succeed but the linking to fail.
|
||||
check_cxx_symbol_exists (_Unwind_Backtrace unwind.h HAVE__UNWIND_BACKTRACE)
|
||||
check_cxx_symbol_exists (_Unwind_GetIP unwind.h HAVE__UNWIND_GETIP)
|
||||
endif (Unwind_FOUND)
|
||||
|
||||
check_include_file_cxx (dlfcn.h HAVE_DLFCN_H)
|
||||
check_include_file_cxx (glob.h HAVE_GLOB_H)
|
||||
check_include_file_cxx (memory.h HAVE_MEMORY_H)
|
||||
check_include_file_cxx (pwd.h HAVE_PWD_H)
|
||||
check_include_file_cxx (strings.h HAVE_STRINGS_H)
|
||||
check_include_file_cxx (sys/stat.h HAVE_SYS_STAT_H)
|
||||
check_include_file_cxx (sys/syscall.h HAVE_SYS_SYSCALL_H)
|
||||
check_include_file_cxx (sys/time.h HAVE_SYS_TIME_H)
|
||||
check_include_file_cxx (sys/types.h HAVE_SYS_TYPES_H)
|
||||
check_include_file_cxx (sys/utsname.h HAVE_SYS_UTSNAME_H)
|
||||
check_include_file_cxx (sys/wait.h HAVE_SYS_WAIT_H)
|
||||
check_include_file_cxx (syscall.h HAVE_SYSCALL_H)
|
||||
check_include_file_cxx (syslog.h HAVE_SYSLOG_H)
|
||||
check_include_file_cxx (ucontext.h HAVE_UCONTEXT_H)
|
||||
check_include_file_cxx (unistd.h HAVE_UNISTD_H)
|
||||
|
||||
check_type_size (mode_t HAVE_MODE_T LANGUAGE CXX)
|
||||
check_type_size (ssize_t HAVE_SSIZE_T LANGUAGE CXX)
|
||||
|
||||
check_function_exists (dladdr HAVE_DLADDR)
|
||||
check_function_exists (fcntl HAVE_FCNTL)
|
||||
check_function_exists (pread HAVE_PREAD)
|
||||
check_function_exists (pwrite HAVE_PWRITE)
|
||||
check_function_exists (sigaction HAVE_SIGACTION)
|
||||
check_function_exists (sigaltstack HAVE_SIGALTSTACK)
|
||||
|
||||
check_cxx_symbol_exists (backtrace execinfo.h HAVE_EXECINFO_BACKTRACE)
|
||||
check_cxx_symbol_exists (backtrace_symbols execinfo.h
|
||||
HAVE_EXECINFO_BACKTRACE_SYMBOLS)
|
||||
|
||||
# NOTE gcc does not fail if you pass a non-existent -Wno-* option as an
|
||||
# argument. However, it will happily fail if you pass the corresponding -W*
|
||||
# option. So, we check whether options that disable warnings exist by testing
|
||||
# the availability of the corresponding option that enables the warning. This
|
||||
# eliminates the need to check for compiler for several (mainly Clang) options.
|
||||
|
||||
check_cxx_compiler_flag (-Wdeprecated HAVE_NO_DEPRECATED)
|
||||
check_cxx_compiler_flag (-Wunnamed-type-template-args
|
||||
HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS)
|
||||
|
||||
cmake_push_check_state (RESET)
|
||||
|
||||
if (Threads_FOUND)
|
||||
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
|
||||
endif (Threads_FOUND)
|
||||
|
||||
check_cxx_symbol_exists (pthread_threadid_np "pthread.h" HAVE_PTHREAD_THREADID_NP)
|
||||
cmake_pop_check_state ()
|
||||
|
||||
# NOTE: Cannot use check_function_exists here since >=vc-14.0 can define
|
||||
# snprintf as an inline function
|
||||
check_cxx_symbol_exists (snprintf cstdio HAVE_SNPRINTF)
|
||||
|
||||
check_library_exists (dbghelp UnDecorateSymbolName "" HAVE_DBGHELP)
|
||||
|
||||
check_cxx_source_compiles ("
|
||||
#include <cstdlib>
|
||||
static void foo(void) __attribute__ ((unused));
|
||||
int main(void) { return 0; }
|
||||
" HAVE___ATTRIBUTE__)
|
||||
|
||||
check_cxx_source_compiles ("
|
||||
#include <cstdlib>
|
||||
static void foo(void) __attribute__ ((visibility(\"default\")));
|
||||
int main(void) { return 0; }
|
||||
" HAVE___ATTRIBUTE__VISIBILITY_DEFAULT)
|
||||
|
||||
check_cxx_source_compiles ("
|
||||
#include <cstdlib>
|
||||
static void foo(void) __attribute__ ((visibility(\"hidden\")));
|
||||
int main(void) { return 0; }
|
||||
" HAVE___ATTRIBUTE__VISIBILITY_HIDDEN)
|
||||
|
||||
check_cxx_source_compiles ("
|
||||
int main(void) { if (__builtin_expect(0, 0)) return 1; return 0; }
|
||||
" HAVE___BUILTIN_EXPECT)
|
||||
|
||||
check_cxx_source_compiles ("
|
||||
int main(void)
|
||||
{
|
||||
int a; if (__sync_val_compare_and_swap(&a, 0, 1)) return 1; return 0;
|
||||
}
|
||||
" HAVE___SYNC_VAL_COMPARE_AND_SWAP)
|
||||
|
||||
if (Threads_FOUND)
|
||||
cmake_push_check_state (RESET)
|
||||
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
|
||||
check_cxx_source_compiles ("
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include <pthread.h>
|
||||
int main(void)
|
||||
{
|
||||
pthread_rwlock_t l;
|
||||
pthread_rwlock_init(&l, NULL);
|
||||
pthread_rwlock_rdlock(&l);
|
||||
return 0;
|
||||
}
|
||||
" HAVE_RWLOCK)
|
||||
cmake_pop_check_state ()
|
||||
endif (Threads_FOUND)
|
||||
|
||||
check_cxx_source_compiles ("
|
||||
__declspec(selectany) int a;
|
||||
int main(void) { return 0; }
|
||||
" HAVE___DECLSPEC)
|
||||
|
||||
if (WITH_TLS)
|
||||
set (GLOG_THREAD_LOCAL_STORAGE 1)
|
||||
endif (WITH_TLS)
|
||||
|
||||
set (_PC_FIELDS
|
||||
"gregs[REG_PC]"
|
||||
"gregs[REG_EIP]"
|
||||
"gregs[REG_RIP]"
|
||||
"sc_ip"
|
||||
"uc_regs->gregs[PT_NIP]"
|
||||
"gregs[R15]"
|
||||
"arm_pc"
|
||||
"mc_eip"
|
||||
"mc_rip"
|
||||
"__gregs[REG_EIP]"
|
||||
"__gregs[REG_RIP]"
|
||||
"ss.eip"
|
||||
"__ss.__eip"
|
||||
"ss.rip"
|
||||
"__ss.__rip"
|
||||
"ss.srr0"
|
||||
"__ss.__srr0"
|
||||
)
|
||||
|
||||
set (_PC_HEADERS ucontext.h signal.h)
|
||||
|
||||
if (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT)
|
||||
foreach (_PC_FIELD ${_PC_FIELDS})
|
||||
foreach (_PC_HEADER ${_PC_HEADERS})
|
||||
set (_TMP
|
||||
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/uctfield.cpp)
|
||||
file (WRITE ${_TMP} "
|
||||
#define _GNU_SOURCE 1
|
||||
#include <${_PC_HEADER}>
|
||||
int main(void)
|
||||
{
|
||||
ucontext_t u;
|
||||
return u.${_PC_FIELD} == 0;
|
||||
}
|
||||
")
|
||||
try_compile (HAVE_PC_FROM_UCONTEXT ${CMAKE_CURRENT_BINARY_DIR} ${_TMP}
|
||||
COMPILE_DEFINITIONS _GNU_SOURCE=1)
|
||||
|
||||
if (HAVE_PC_FROM_UCONTEXT)
|
||||
set (PC_FROM_UCONTEXT ${_PC_FIELD} CACHE)
|
||||
endif (HAVE_PC_FROM_UCONTEXT)
|
||||
endforeach (_PC_HEADER)
|
||||
endforeach (_PC_FIELD)
|
||||
endif (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT)
|
||||
|
||||
set (GOOGLE_NAMESPACE google)
|
||||
set (_START_GOOGLE_NAMESPACE_ "namespace ${GOOGLE_NAMESPACE} {")
|
||||
set (_END_GOOGLE_NAMESPACE_ "}")
|
||||
set (ac_cv_have_glog_export 1)
|
||||
|
||||
if (HAVE_LIB_GFLAGS)
|
||||
set (ac_cv_have_libgflags 1)
|
||||
else (HAVE_LIB_GFLAGS)
|
||||
set (ac_cv_have_libgflags 0)
|
||||
endif (HAVE_LIB_GFLAGS)
|
||||
|
||||
if (HAVE_SYS_TYPES_H)
|
||||
set (ac_cv_have_systypes_h 1)
|
||||
else (HAVE_SYS_TYPES_H)
|
||||
set (ac_cv_have_systypes_h 0)
|
||||
endif (HAVE_SYS_TYPES_H)
|
||||
|
||||
if (HAVE_SSIZE_T)
|
||||
set (ac_cv_have_ssize_t 1)
|
||||
else (HAVE_SSIZE_T)
|
||||
set (ac_cv_have_ssize_t 0)
|
||||
endif (HAVE_SSIZE_T)
|
||||
|
||||
if (HAVE_MODE_T)
|
||||
set (ac_cv_have_mode_t 1)
|
||||
else (HAVE_MODE_T)
|
||||
set (ac_cv_have_mode_t 0)
|
||||
endif (HAVE_MODE_T)
|
||||
|
||||
if (HAVE_UNISTD_H)
|
||||
set (ac_cv_have_unistd_h 1)
|
||||
else (HAVE_UNISTD_H)
|
||||
set (ac_cv_have_unistd_h 0)
|
||||
endif (HAVE_UNISTD_H)
|
||||
|
||||
set (ac_google_namespace ${GOOGLE_NAMESPACE})
|
||||
set (ac_google_end_namespace ${_END_GOOGLE_NAMESPACE_})
|
||||
set (ac_google_start_namespace ${_START_GOOGLE_NAMESPACE_})
|
||||
|
||||
if (HAVE___ATTRIBUTE__)
|
||||
set (ac_cv___attribute___noinline "__attribute__((noinline))")
|
||||
set (ac_cv___attribute___printf_4_5 "__attribute__((__format__(__printf__, 4, 5)))")
|
||||
elseif (HAVE___DECLSPEC)
|
||||
#set (ac_cv___attribute___noinline "__declspec(noinline)")
|
||||
endif (HAVE___ATTRIBUTE__)
|
||||
|
||||
if (HAVE___BUILTIN_EXPECT)
|
||||
set (ac_cv_have___builtin_expect 1)
|
||||
else (HAVE___BUILTIN_EXPECT)
|
||||
set (ac_cv_have___builtin_expect 0)
|
||||
endif (HAVE___BUILTIN_EXPECT)
|
||||
|
||||
if (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS)
|
||||
set (HAVE_STACKTRACE 1)
|
||||
endif (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS)
|
||||
|
||||
if (WITH_SYMBOLIZE)
|
||||
if (WIN32 OR CYGWIN)
|
||||
cmake_push_check_state (RESET)
|
||||
set (CMAKE_REQUIRED_LIBRARIES DbgHelp)
|
||||
|
||||
check_cxx_source_runs ([=[
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
#include <cstdlib>
|
||||
|
||||
void foobar() { }
|
||||
|
||||
int main()
|
||||
{
|
||||
HANDLE process = GetCurrentProcess();
|
||||
|
||||
if (!SymInitialize(process, NULL, TRUE))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
||||
SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(buf);
|
||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
symbol->MaxNameLen = MAX_SYM_NAME;
|
||||
|
||||
void* const pc = reinterpret_cast<void*>(&foobar);
|
||||
BOOL ret = SymFromAddr(process, reinterpret_cast<DWORD64>(pc), 0, symbol);
|
||||
|
||||
return ret ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
]=] HAVE_SYMBOLIZE)
|
||||
|
||||
cmake_pop_check_state ()
|
||||
|
||||
if (HAVE_SYMBOLIZE)
|
||||
set (HAVE_STACKTRACE 1)
|
||||
endif (HAVE_SYMBOLIZE)
|
||||
elseif (UNIX)
|
||||
cmake_push_check_state (RESET)
|
||||
check_cxx_source_compiles ([=[
|
||||
int main()
|
||||
{
|
||||
#ifndef __ELF__
|
||||
#error __ELF__ not defined
|
||||
#endif
|
||||
}
|
||||
]=] HAVE_SYMBOLIZE)
|
||||
cmake_pop_check_state ()
|
||||
elseif (APPLE AND HAVE_DLADDR)
|
||||
set (HAVE_SYMBOLIZE 1)
|
||||
endif (WIN32 OR CYGWIN)
|
||||
endif (WITH_SYMBOLIZE)
|
||||
|
||||
# CMake manages symbolize availability. The definition is necessary only when
|
||||
# building the library.
|
||||
add_compile_definitions (GLOG_NO_SYMBOLIZE_DETECTION)
|
||||
|
||||
check_cxx_source_compiles ("
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
int main()
|
||||
{
|
||||
time_t timep;
|
||||
struct tm result;
|
||||
localtime_r(&timep, &result);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
" HAVE_LOCALTIME_R)
|
||||
|
||||
set (SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
|
||||
|
||||
if (WITH_THREADS AND Threads_FOUND)
|
||||
if (CMAKE_USE_PTHREADS_INIT)
|
||||
set (HAVE_PTHREAD 1)
|
||||
endif (CMAKE_USE_PTHREADS_INIT)
|
||||
else (WITH_THREADS AND Threads_FOUND)
|
||||
set (NO_THREADS 1)
|
||||
endif (WITH_THREADS AND Threads_FOUND)
|
||||
|
||||
# fopen/open on Cygwin can not handle unix-type paths like /home/....
|
||||
# therefore we translate TEST_SRC_DIR to windows-path.
|
||||
if (CYGWIN)
|
||||
execute_process (COMMAND cygpath.exe -m ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
OUTPUT_VARIABLE TEST_SRC_DIR)
|
||||
set (TEST_SRC_DIR \"${TEST_SRC_DIR}\")
|
||||
else (CYGWIN)
|
||||
set (TEST_SRC_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\")
|
||||
endif (CYGWIN)
|
||||
|
||||
configure_file (src/config.h.cmake.in config.h)
|
||||
configure_file (src/glog/logging.h.in glog/logging.h @ONLY)
|
||||
configure_file (src/glog/raw_logging.h.in glog/raw_logging.h @ONLY)
|
||||
configure_file (src/glog/stl_logging.h.in glog/stl_logging.h @ONLY)
|
||||
configure_file (src/glog/vlog_is_on.h.in glog/vlog_is_on.h @ONLY)
|
||||
|
||||
add_compile_options ($<$<AND:$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>,$<NOT:$<CXX_COMPILER_ID:GNU>>>:-Wno-unnamed-type-template-args>)
|
||||
|
||||
set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR})
|
||||
set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
set (_glog_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR})
|
||||
set (_glog_CMake_INSTALLDIR ${_glog_CMake_LIBDIR}/cmake/glog)
|
||||
|
||||
set (_glog_CMake_DIR glog/cmake)
|
||||
set (_glog_CMake_DATADIR ${CMAKE_INSTALL_DATAROOTDIR}/${_glog_CMake_DIR})
|
||||
set (_glog_BINARY_CMake_DATADIR
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR})
|
||||
|
||||
# Add additional CMake find modules here.
|
||||
set (_glog_CMake_MODULES)
|
||||
|
||||
if (Unwind_FOUND)
|
||||
# Copy the module only if libunwind is actually used.
|
||||
list (APPEND _glog_CMake_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindUnwind.cmake)
|
||||
endif (Unwind_FOUND)
|
||||
|
||||
# Generate file name for each module in the binary directory
|
||||
foreach (_file ${_glog_CMake_MODULES})
|
||||
get_filename_component (_module "${_file}" NAME)
|
||||
|
||||
list (APPEND _glog_BINARY_CMake_MODULES
|
||||
${_glog_BINARY_CMake_DATADIR}/${_module})
|
||||
endforeach (_file)
|
||||
|
||||
if (_glog_CMake_MODULES)
|
||||
# Copy modules to binary directory during the build
|
||||
add_custom_command (OUTPUT ${_glog_BINARY_CMake_MODULES}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||
${_glog_BINARY_CMake_DATADIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${_glog_CMake_MODULES}
|
||||
${_glog_BINARY_CMake_DATADIR}
|
||||
DEPENDS ${_glog_CMake_MODULES}
|
||||
COMMENT "Copying find modules..."
|
||||
)
|
||||
endif (_glog_CMake_MODULES)
|
||||
|
||||
set (GLOG_PUBLIC_H
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog/export.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog/logging.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog/raw_logging.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog/stl_logging.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog/vlog_is_on.h
|
||||
src/glog/log_severity.h
|
||||
src/glog/platform.h
|
||||
)
|
||||
|
||||
set (GLOG_SRCS
|
||||
${GLOG_PUBLIC_H}
|
||||
src/base/commandlineflags.h
|
||||
src/base/googleinit.h
|
||||
src/base/mutex.h
|
||||
src/demangle.cc
|
||||
src/demangle.h
|
||||
src/logging.cc
|
||||
src/raw_logging.cc
|
||||
src/symbolize.cc
|
||||
src/symbolize.h
|
||||
src/utilities.cc
|
||||
src/utilities.h
|
||||
src/vlog_is_on.cc
|
||||
)
|
||||
|
||||
if (HAVE_PTHREAD OR WIN32 OR CYGWIN)
|
||||
list (APPEND GLOG_SRCS src/signalhandler.cc)
|
||||
endif (HAVE_PTHREAD OR WIN32 OR CYGWIN)
|
||||
|
||||
if (CYGWIN OR WIN32)
|
||||
list (APPEND GLOG_SRCS
|
||||
src/windows/port.cc
|
||||
src/windows/port.h
|
||||
)
|
||||
endif (CYGWIN OR WIN32)
|
||||
|
||||
add_library (glog_internal OBJECT
|
||||
${_glog_BINARY_CMake_MODULES}
|
||||
${GLOG_SRCS}
|
||||
)
|
||||
target_compile_features (glog_internal PUBLIC $<TARGET_PROPERTY:glog,COMPILE_FEATURES>)
|
||||
|
||||
add_library (glog
|
||||
$<TARGET_OBJECTS:glog_internal>
|
||||
)
|
||||
target_compile_features (glog PUBLIC cxx_std_14)
|
||||
|
||||
add_library (glog::glog ALIAS glog)
|
||||
|
||||
set (glog_libraries_options_for_static_linking)
|
||||
|
||||
if (Unwind_FOUND)
|
||||
target_link_libraries (glog PRIVATE unwind::unwind)
|
||||
set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -lunwind")
|
||||
set (Unwind_DEPENDENCY "find_dependency (Unwind ${Unwind_VERSION})")
|
||||
endif (Unwind_FOUND)
|
||||
|
||||
if (HAVE_DBGHELP)
|
||||
target_link_libraries (glog PRIVATE dbghelp)
|
||||
set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -ldbghelp")
|
||||
endif (HAVE_DBGHELP)
|
||||
|
||||
if (HAVE_PTHREAD)
|
||||
target_link_libraries (glog PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (CMAKE_THREAD_LIBS_INIT)
|
||||
set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} ${CMAKE_THREAD_LIBS_INIT}")
|
||||
endif (CMAKE_THREAD_LIBS_INIT)
|
||||
endif (HAVE_PTHREAD)
|
||||
|
||||
if (gflags_FOUND)
|
||||
# Prefer the gflags target that uses double colon convention
|
||||
if (TARGET gflags::gflags)
|
||||
target_link_libraries (glog PUBLIC gflags::gflags)
|
||||
else (TARGET gflags::gflags)
|
||||
target_link_libraries (glog PUBLIC gflags)
|
||||
endif (TARGET gflags::gflags)
|
||||
|
||||
set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -lgflags")
|
||||
endif (gflags_FOUND)
|
||||
|
||||
if (ANDROID)
|
||||
target_link_libraries (glog PRIVATE log)
|
||||
set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -llog")
|
||||
endif (ANDROID)
|
||||
|
||||
set_target_properties (glog PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
set_target_properties (glog PROPERTIES SOVERSION 1)
|
||||
|
||||
if (CYGWIN OR WIN32)
|
||||
target_compile_definitions (glog PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES)
|
||||
endif (CYGWIN OR WIN32)
|
||||
|
||||
set_target_properties (glog PROPERTIES PUBLIC_HEADER "${GLOG_PUBLIC_H}")
|
||||
|
||||
target_include_directories (glog BEFORE PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
|
||||
"$<INSTALL_INTERFACE:${_glog_CMake_INCLUDE_DIR}>"
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
if (CYGWIN OR WIN32)
|
||||
target_include_directories (glog_internal PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>"
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows)
|
||||
|
||||
target_include_directories (glog PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>"
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows)
|
||||
endif (CYGWIN OR WIN32)
|
||||
|
||||
set_target_properties (glog PROPERTIES DEFINE_SYMBOL GOOGLE_GLOG_IS_A_DLL)
|
||||
|
||||
target_include_directories (glog_internal PUBLIC
|
||||
$<TARGET_PROPERTY:glog,INCLUDE_DIRECTORIES>)
|
||||
target_compile_definitions (glog_internal PUBLIC
|
||||
$<TARGET_PROPERTY:glog,COMPILE_DEFINITIONS>
|
||||
PRIVATE GOOGLE_GLOG_IS_A_DLL)
|
||||
|
||||
generate_export_header (glog
|
||||
EXPORT_MACRO_NAME GLOG_EXPORT
|
||||
EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/glog/export.h)
|
||||
|
||||
string (STRIP "${glog_libraries_options_for_static_linking}" glog_libraries_options_for_static_linking)
|
||||
|
||||
if (WITH_PKGCONFIG)
|
||||
set (VERSION ${PROJECT_VERSION})
|
||||
set (prefix ${CMAKE_INSTALL_PREFIX})
|
||||
set (exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
|
||||
set (libdir ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||
set (includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
|
||||
|
||||
configure_file (
|
||||
"${PROJECT_SOURCE_DIR}/libglog.pc.in"
|
||||
"${PROJECT_BINARY_DIR}/libglog.pc"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
unset (VERSION)
|
||||
unset (prefix)
|
||||
unset (exec_prefix)
|
||||
unset (libdir)
|
||||
unset (includedir)
|
||||
endif (WITH_PKGCONFIG)
|
||||
|
||||
# Unit testing
|
||||
|
||||
if (NOT WITH_FUZZING STREQUAL "none")
|
||||
add_executable (fuzz_demangle
|
||||
src/fuzz_demangle.cc
|
||||
)
|
||||
|
||||
if (WITH_FUZZING STREQUAL "ossfuzz")
|
||||
set (LIB_FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE})
|
||||
target_link_libraries (fuzz_demangle PRIVATE glog ${LIB_FUZZING_ENGINE})
|
||||
elseif (WITH_FUZZING STREQUAL "libfuzzer")
|
||||
target_compile_options (fuzz_demangle PRIVATE -fsanitize=fuzzer)
|
||||
target_link_libraries (fuzz_demangle PRIVATE glog)
|
||||
else (WITH_FUZZING STREQUAL "libfuzzer")
|
||||
message (FATAL_ERROR "Unsupported fuzzing engine ${WITH_FUZZING}")
|
||||
endif (WITH_FUZZING STREQUAL "ossfuzz")
|
||||
endif (NOT WITH_FUZZING STREQUAL "none")
|
||||
|
||||
if (BUILD_TESTING)
|
||||
add_library (glogtest STATIC
|
||||
$<TARGET_OBJECTS:glog_internal>
|
||||
)
|
||||
|
||||
target_include_directories (glogtest PUBLIC
|
||||
$<TARGET_PROPERTY:glog,INCLUDE_DIRECTORIES>)
|
||||
target_compile_definitions (glogtest PUBLIC
|
||||
$<TARGET_PROPERTY:glog,COMPILE_DEFINITIONS> GLOG_STATIC_DEFINE)
|
||||
target_link_libraries (glogtest PUBLIC
|
||||
$<TARGET_PROPERTY:glog,LINK_LIBRARIES>)
|
||||
|
||||
set (_GLOG_TEST_LIBS glogtest)
|
||||
|
||||
if (HAVE_LIB_GTEST)
|
||||
list (APPEND _GLOG_TEST_LIBS GTest::gtest)
|
||||
endif (HAVE_LIB_GTEST)
|
||||
|
||||
if (HAVE_LIB_GMOCK)
|
||||
list (APPEND _GLOG_TEST_LIBS GTest::gmock)
|
||||
endif (HAVE_LIB_GMOCK)
|
||||
|
||||
add_executable (logging_unittest
|
||||
src/logging_unittest.cc
|
||||
)
|
||||
|
||||
target_link_libraries (logging_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
add_executable (stl_logging_unittest
|
||||
src/stl_logging_unittest.cc
|
||||
)
|
||||
|
||||
target_link_libraries (stl_logging_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
if (HAVE_NO_DEPRECATED)
|
||||
set_property (TARGET stl_logging_unittest APPEND PROPERTY COMPILE_OPTIONS
|
||||
-Wno-deprecated)
|
||||
endif (HAVE_NO_DEPRECATED)
|
||||
|
||||
if (HAVE_EXT_SLIST)
|
||||
target_compile_definitions (stl_logging_unittest PRIVATE
|
||||
GLOG_STL_LOGGING_FOR_EXT_SLIST)
|
||||
endif (HAVE_EXT_SLIST)
|
||||
|
||||
if (HAVE_SYMBOLIZE)
|
||||
add_executable (symbolize_unittest
|
||||
src/symbolize_unittest.cc
|
||||
)
|
||||
|
||||
target_link_libraries (symbolize_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
endif (HAVE_SYMBOLIZE)
|
||||
|
||||
add_executable (demangle_unittest
|
||||
src/demangle_unittest.cc
|
||||
)
|
||||
|
||||
target_link_libraries (demangle_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
if (HAVE_STACKTRACE)
|
||||
add_executable (stacktrace_unittest
|
||||
src/stacktrace_unittest.cc
|
||||
)
|
||||
|
||||
target_link_libraries (stacktrace_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
endif (HAVE_STACKTRACE)
|
||||
|
||||
add_executable (utilities_unittest
|
||||
src/utilities_unittest.cc
|
||||
)
|
||||
|
||||
target_link_libraries (utilities_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
if (HAVE_STACKTRACE AND HAVE_SYMBOLIZE)
|
||||
add_executable (signalhandler_unittest
|
||||
src/signalhandler_unittest.cc
|
||||
)
|
||||
|
||||
target_link_libraries (signalhandler_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
endif (HAVE_STACKTRACE AND HAVE_SYMBOLIZE)
|
||||
|
||||
add_test (NAME demangle COMMAND demangle_unittest)
|
||||
add_test (NAME logging COMMAND logging_unittest)
|
||||
|
||||
set_tests_properties (logging PROPERTIES TIMEOUT 30)
|
||||
# MacOS diff is not deterministic: use the output to determine whether the
|
||||
# test passed.
|
||||
set_tests_properties (logging PROPERTIES PASS_REGULAR_EXPRESSION ".*\nPASS\n.*")
|
||||
|
||||
# FIXME: Skip flaky test
|
||||
set_tests_properties (logging PROPERTIES SKIP_REGULAR_EXPRESSION
|
||||
"Check failed: time_ns within LogTimes::LOG_PERIOD_TOL_NS of LogTimes::LOG_PERIOD_NS")
|
||||
|
||||
if (APPLE)
|
||||
# FIXME: Skip flaky test
|
||||
set_property (TEST logging APPEND PROPERTY SKIP_REGULAR_EXPRESSION
|
||||
"unexpected new.*PASS\nTest with golden file failed. We'll try to show the diff:")
|
||||
endif (APPLE)
|
||||
|
||||
if (TARGET signalhandler_unittest)
|
||||
add_test (NAME signalhandler COMMAND signalhandler_unittest)
|
||||
endif (TARGET signalhandler_unittest)
|
||||
|
||||
if (TARGET stacktrace_unittest)
|
||||
add_test (NAME stacktrace COMMAND stacktrace_unittest)
|
||||
set_tests_properties (stacktrace PROPERTIES TIMEOUT 30)
|
||||
endif (TARGET stacktrace_unittest)
|
||||
|
||||
add_test (NAME stl_logging COMMAND stl_logging_unittest)
|
||||
|
||||
if (TARGET symbolize_unittest)
|
||||
add_test (NAME symbolize COMMAND symbolize_unittest)
|
||||
|
||||
# FIXME: Skip flaky test when compiled in C++20 mode
|
||||
set_tests_properties (symbolize PROPERTIES SKIP_REGULAR_EXPRESSION
|
||||
[=[Check failed: streq\("nonstatic_func"\, TrySymbolize\(\(void \*\)\(&nonstatic_func\)\)\)]=])
|
||||
endif (TARGET symbolize_unittest)
|
||||
|
||||
if (HAVE_LIB_GMOCK)
|
||||
add_executable (mock-log_unittest
|
||||
src/mock-log_unittest.cc
|
||||
src/mock-log.h
|
||||
)
|
||||
|
||||
target_link_libraries (mock-log_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
add_test (NAME mock-log COMMAND mock-log_unittest)
|
||||
endif (HAVE_LIB_GMOCK)
|
||||
|
||||
# Generate an initial cache
|
||||
|
||||
get_cache_variables (_CACHEVARS)
|
||||
|
||||
set (_INITIAL_CACHE
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test_package_config/glog_package_config_initial_cache.cmake)
|
||||
|
||||
# Package config test
|
||||
|
||||
add_test (NAME cmake_package_config_init COMMAND ${CMAKE_COMMAND}
|
||||
-DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config
|
||||
-DINITIAL_CACHE=${_INITIAL_CACHE}
|
||||
-DCACHEVARS=${_CACHEVARS}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestInitPackageConfig.cmake
|
||||
)
|
||||
|
||||
add_test (NAME cmake_package_config_generate COMMAND ${CMAKE_COMMAND}
|
||||
-DGENERATOR=${CMAKE_GENERATOR}
|
||||
-DGENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
|
||||
-DGENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
|
||||
-DINITIAL_CACHE=${_INITIAL_CACHE}
|
||||
-DPACKAGE_DIR=${CMAKE_CURRENT_BINARY_DIR}
|
||||
-DPATH=$ENV{PATH}
|
||||
-DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/src/package_config_unittest/working_config
|
||||
-DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestPackageConfig.cmake
|
||||
)
|
||||
|
||||
add_test (NAME cmake_package_config_build COMMAND
|
||||
${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config
|
||||
--config $<CONFIG>
|
||||
)
|
||||
|
||||
add_test (NAME cmake_package_config_cleanup COMMAND ${CMAKE_COMMAND} -E
|
||||
remove_directory
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test_package_config
|
||||
)
|
||||
|
||||
# Fixtures setup
|
||||
set_tests_properties (cmake_package_config_init PROPERTIES FIXTURES_SETUP
|
||||
cmake_package_config)
|
||||
set_tests_properties (cmake_package_config_generate PROPERTIES FIXTURES_SETUP
|
||||
cmake_package_config_working)
|
||||
|
||||
# Fixtures cleanup
|
||||
set_tests_properties (cmake_package_config_cleanup PROPERTIES FIXTURES_CLEANUP
|
||||
cmake_package_config)
|
||||
|
||||
# Fixture requirements
|
||||
set_tests_properties (cmake_package_config_generate PROPERTIES
|
||||
FIXTURES_REQUIRED cmake_package_config)
|
||||
set_tests_properties (cmake_package_config_build PROPERTIES
|
||||
FIXTURES_REQUIRED "cmake_package_config;cmake_package_config_working")
|
||||
|
||||
add_executable (cleanup_immediately_unittest
|
||||
src/cleanup_immediately_unittest.cc)
|
||||
|
||||
target_link_libraries (cleanup_immediately_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
add_executable (cleanup_with_absolute_prefix_unittest
|
||||
src/cleanup_with_absolute_prefix_unittest.cc)
|
||||
|
||||
target_link_libraries (cleanup_with_absolute_prefix_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
add_executable (cleanup_with_relative_prefix_unittest
|
||||
src/cleanup_with_relative_prefix_unittest.cc)
|
||||
|
||||
target_link_libraries (cleanup_with_relative_prefix_unittest PRIVATE ${_GLOG_TEST_LIBS})
|
||||
|
||||
set (CLEANUP_LOG_DIR ${CMAKE_CURRENT_BINARY_DIR}/cleanup_tests)
|
||||
|
||||
add_test (NAME cleanup_init COMMAND
|
||||
${CMAKE_COMMAND} -E make_directory ${CLEANUP_LOG_DIR})
|
||||
add_test (NAME cleanup_logdir COMMAND
|
||||
${CMAKE_COMMAND} -E remove_directory ${CLEANUP_LOG_DIR})
|
||||
add_test (NAME cleanup_immediately COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DLOGCLEANUP=$<TARGET_FILE:cleanup_immediately_unittest>
|
||||
# NOTE The trailing slash is important
|
||||
-DTEST_DIR=${CLEANUP_LOG_DIR}/
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest1.cmake
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_test (NAME cleanup_with_absolute_prefix COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DLOGCLEANUP=$<TARGET_FILE:cleanup_with_absolute_prefix_unittest>
|
||||
-DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest2.cmake
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_test (NAME cleanup_with_relative_prefix COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DLOGCLEANUP=$<TARGET_FILE:cleanup_with_relative_prefix_unittest>
|
||||
-DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/
|
||||
-DTEST_SUBDIR=test_subdir/
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest3.cmake
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# Fixtures setup
|
||||
set_tests_properties (cleanup_init PROPERTIES FIXTURES_SETUP logcleanuptest)
|
||||
## Fixtures cleanup
|
||||
set_tests_properties (cleanup_logdir PROPERTIES FIXTURES_CLEANUP logcleanuptest)
|
||||
# Fixture requirements
|
||||
set_tests_properties (cleanup_immediately PROPERTIES FIXTURES_REQUIRED logcleanuptest)
|
||||
set_tests_properties (cleanup_with_absolute_prefix PROPERTIES FIXTURES_REQUIRED logcleanuptest)
|
||||
set_tests_properties (cleanup_with_relative_prefix PROPERTIES FIXTURES_REQUIRED logcleanuptest)
|
||||
endif (BUILD_TESTING)
|
||||
|
||||
install (TARGETS glog
|
||||
EXPORT glog-targets
|
||||
RUNTIME DESTINATION ${_glog_CMake_BINDIR}
|
||||
PUBLIC_HEADER DESTINATION ${_glog_CMake_INCLUDE_DIR}/glog
|
||||
LIBRARY DESTINATION ${_glog_CMake_LIBDIR}
|
||||
ARCHIVE DESTINATION ${_glog_CMake_LIBDIR})
|
||||
|
||||
if (WITH_PKGCONFIG)
|
||||
install (
|
||||
FILES "${PROJECT_BINARY_DIR}/libglog.pc"
|
||||
DESTINATION "${_glog_CMake_LIBDIR}/pkgconfig"
|
||||
)
|
||||
endif (WITH_PKGCONFIG)
|
||||
|
||||
set (glog_CMake_VERSION 3.0)
|
||||
|
||||
if (gflags_FOUND)
|
||||
# Ensure clients locate only the package config and not third party find
|
||||
# modules having the same name. This avoid cmake_policy PUSH/POP errors.
|
||||
if (CMAKE_VERSION VERSION_LESS 3.9)
|
||||
set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION})")
|
||||
else (CMAKE_VERSION VERSION_LESS 3.9)
|
||||
# Passing additional find_package arguments to find_dependency is possible
|
||||
# starting with CMake 3.9.
|
||||
set (glog_CMake_VERSION 3.9)
|
||||
set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION} NO_MODULE)")
|
||||
endif (CMAKE_VERSION VERSION_LESS 3.9)
|
||||
endif (gflags_FOUND)
|
||||
|
||||
configure_package_config_file (glog-config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
|
||||
INSTALL_DESTINATION ${_glog_CMake_INSTALLDIR}
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||
|
||||
write_basic_package_version_file (
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake)
|
||||
export (PACKAGE glog)
|
||||
|
||||
get_filename_component (_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
|
||||
|
||||
# Directory containing the find modules relative to the config install
|
||||
# directory.
|
||||
file (RELATIVE_PATH glog_REL_CMake_MODULES
|
||||
${_PREFIX}/${_glog_CMake_INSTALLDIR}
|
||||
${_PREFIX}/${_glog_CMake_DATADIR}/glog-modules.cmake)
|
||||
|
||||
get_filename_component (glog_REL_CMake_DATADIR ${glog_REL_CMake_MODULES}
|
||||
DIRECTORY)
|
||||
|
||||
set (glog_FULL_CMake_DATADIR
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR})
|
||||
|
||||
configure_file (glog-modules.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog-modules.cmake @ONLY)
|
||||
|
||||
install (CODE
|
||||
"
|
||||
set (glog_FULL_CMake_DATADIR \"\\\${CMAKE_CURRENT_LIST_DIR}/${glog_REL_CMake_DATADIR}\")
|
||||
set (glog_DATADIR_DESTINATION ${_glog_CMake_INSTALLDIR})
|
||||
|
||||
if (NOT IS_ABSOLUTE ${_glog_CMake_INSTALLDIR})
|
||||
set (glog_DATADIR_DESTINATION \"\${CMAKE_INSTALL_PREFIX}/\${glog_DATADIR_DESTINATION}\")
|
||||
endif (NOT IS_ABSOLUTE ${_glog_CMake_INSTALLDIR})
|
||||
|
||||
configure_file (\"${CMAKE_CURRENT_SOURCE_DIR}/glog-modules.cmake.in\"
|
||||
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\" @ONLY)
|
||||
file (INSTALL
|
||||
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\"
|
||||
DESTINATION
|
||||
\"\${glog_DATADIR_DESTINATION}\")
|
||||
"
|
||||
COMPONENT Development
|
||||
)
|
||||
|
||||
install (FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
|
||||
DESTINATION ${_glog_CMake_INSTALLDIR})
|
||||
|
||||
# Find modules in share/glog/cmake
|
||||
install (DIRECTORY ${_glog_BINARY_CMake_DATADIR}
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/glog
|
||||
COMPONENT Development
|
||||
FILES_MATCHING PATTERN "*.cmake"
|
||||
)
|
||||
|
||||
install (EXPORT glog-targets NAMESPACE glog:: DESTINATION
|
||||
${_glog_CMake_INSTALLDIR})
|
||||
@@ -0,0 +1,69 @@
|
||||
macro(determine_gflags_namespace VARIABLE)
|
||||
if (NOT DEFINED "${VARIABLE}")
|
||||
if (CMAKE_REQUIRED_INCLUDES)
|
||||
set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
|
||||
else ()
|
||||
set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
|
||||
endif ()
|
||||
|
||||
set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
||||
|
||||
set(_NAMESPACES gflags google)
|
||||
set(_check_code
|
||||
"
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
GLOG_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
|
||||
}
|
||||
")
|
||||
if (NOT CMAKE_REQUIRED_QUIET)
|
||||
message (STATUS "Looking for gflags namespace")
|
||||
endif ()
|
||||
if (${ARGC} EQUAL 3)
|
||||
set (CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
|
||||
endif ()
|
||||
|
||||
set (_check_file
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/DetermineGflagsNamespace.cxx)
|
||||
|
||||
foreach (_namespace ${_NAMESPACES})
|
||||
file (WRITE "${_check_file}" "${_check_code}")
|
||||
try_compile (${VARIABLE}
|
||||
"${CMAKE_BINARY_DIR}" "${_check_file}"
|
||||
COMPILE_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}" -DGLOG_GFLAGS_NAMESPACE=${_namespace}
|
||||
LINK_LIBRARIES gflags
|
||||
CMAKE_FLAGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
OUTPUT_VARIABLE OUTPUT)
|
||||
|
||||
if (${VARIABLE})
|
||||
set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace" FORCE)
|
||||
break ()
|
||||
else ()
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Determining the gflags namespace ${_namespace} failed with the following output:\n"
|
||||
"${OUTPUT}\n\n")
|
||||
endif ()
|
||||
endforeach (_namespace)
|
||||
|
||||
if (${ARGC} EQUAL 3)
|
||||
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
|
||||
endif ()
|
||||
|
||||
if (${VARIABLE})
|
||||
if (NOT CMAKE_REQUIRED_QUIET)
|
||||
message (STATUS "Looking for gflags namespace - ${${VARIABLE}}")
|
||||
endif ()
|
||||
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining the gflags namespace passed with the following output:\n"
|
||||
"${OUTPUT}\n\n")
|
||||
else ()
|
||||
if (NOT CMAKE_REQUIRED_QUIET)
|
||||
message (STATUS "Looking for gflags namespace - failed")
|
||||
endif ()
|
||||
set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace")
|
||||
endif ()
|
||||
endif ()
|
||||
endmacro ()
|
||||
61
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/FindUnwind.cmake
vendored
Normal file
61
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/FindUnwind.cmake
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
# - Try to find libunwind
|
||||
# Once done this will define
|
||||
#
|
||||
# Unwind_FOUND - system has libunwind
|
||||
# unwind::unwind - cmake target for libunwind
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
find_path (Unwind_INCLUDE_DIR NAMES unwind.h libunwind.h DOC "unwind include directory")
|
||||
find_library (Unwind_LIBRARY NAMES unwind DOC "unwind library")
|
||||
|
||||
mark_as_advanced (Unwind_INCLUDE_DIR Unwind_LIBRARY)
|
||||
|
||||
# Extract version information
|
||||
if (Unwind_LIBRARY)
|
||||
set (_Unwind_VERSION_HEADER ${Unwind_INCLUDE_DIR}/libunwind-common.h)
|
||||
|
||||
if (EXISTS ${_Unwind_VERSION_HEADER})
|
||||
file (READ ${_Unwind_VERSION_HEADER} _Unwind_VERSION_CONTENTS)
|
||||
|
||||
string (REGEX REPLACE ".*#define UNW_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
|
||||
Unwind_VERSION_MAJOR "${_Unwind_VERSION_CONTENTS}")
|
||||
string (REGEX REPLACE ".*#define UNW_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
|
||||
Unwind_VERSION_MINOR "${_Unwind_VERSION_CONTENTS}")
|
||||
string (REGEX REPLACE ".*#define UNW_VERSION_EXTRA[ \t]+([0-9]+).*" "\\1"
|
||||
Unwind_VERSION_PATCH "${_Unwind_VERSION_CONTENTS}")
|
||||
|
||||
set (Unwind_VERSION ${Unwind_VERSION_MAJOR}.${Unwind_VERSION_MINOR})
|
||||
|
||||
if (CMAKE_MATCH_0)
|
||||
# Third version component may be empty
|
||||
set (Unwind_VERSION ${Unwind_VERSION}.${Unwind_VERSION_PATCH})
|
||||
set (Unwind_VERSION_COMPONENTS 3)
|
||||
else (CMAKE_MATCH_0)
|
||||
set (Unwind_VERSION_COMPONENTS 2)
|
||||
endif (CMAKE_MATCH_0)
|
||||
endif (EXISTS ${_Unwind_VERSION_HEADER})
|
||||
endif (Unwind_LIBRARY)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set Unwind_FOUND to TRUE
|
||||
# if all listed variables are TRUE
|
||||
find_package_handle_standard_args (Unwind
|
||||
REQUIRED_VARS Unwind_INCLUDE_DIR Unwind_LIBRARY
|
||||
VERSION_VAR Unwind_VERSION
|
||||
)
|
||||
|
||||
if (Unwind_FOUND)
|
||||
if (NOT TARGET unwind::unwind)
|
||||
add_library (unwind::unwind INTERFACE IMPORTED)
|
||||
|
||||
set_property (TARGET unwind::unwind PROPERTY
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR}
|
||||
)
|
||||
set_property (TARGET unwind::unwind PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY}
|
||||
)
|
||||
set_property (TARGET unwind::unwind PROPERTY
|
||||
IMPORTED_CONFIGURATIONS RELEASE
|
||||
)
|
||||
endif (NOT TARGET unwind::unwind)
|
||||
endif (Unwind_FOUND)
|
||||
70
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/GetCacheVariables.cmake
vendored
Normal file
70
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/GetCacheVariables.cmake
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
cmake_policy (PUSH)
|
||||
cmake_policy (VERSION 3.3)
|
||||
|
||||
include (CMakeParseArguments)
|
||||
|
||||
function (get_cache_variables _CACHEVARS)
|
||||
set (_SINGLE)
|
||||
set (_MULTI EXCLUDE)
|
||||
set (_OPTIONS)
|
||||
|
||||
cmake_parse_arguments (_ARGS "${_OPTIONS}" "${_SINGLE}" "${_MULTI}" ${ARGS} ${ARGN})
|
||||
|
||||
get_cmake_property (_VARIABLES VARIABLES)
|
||||
|
||||
set (CACHEVARS)
|
||||
|
||||
foreach (_VAR ${_VARIABLES})
|
||||
if (DEFINED _ARGS_EXCLUDE)
|
||||
if ("${_VAR}" IN_LIST _ARGS_EXCLUDE)
|
||||
continue ()
|
||||
endif ("${_VAR}" IN_LIST _ARGS_EXCLUDE)
|
||||
endif (DEFINED _ARGS_EXCLUDE)
|
||||
|
||||
get_property (_CACHEVARTYPE CACHE ${_VAR} PROPERTY TYPE)
|
||||
|
||||
if ("${_CACHEVARTYPE}" STREQUAL INTERNAL OR
|
||||
"${_CACHEVARTYPE}" STREQUAL STATIC OR
|
||||
"${_CACHEVARTYPE}" STREQUAL UNINITIALIZED)
|
||||
continue ()
|
||||
endif ("${_CACHEVARTYPE}" STREQUAL INTERNAL OR
|
||||
"${_CACHEVARTYPE}" STREQUAL STATIC OR
|
||||
"${_CACHEVARTYPE}" STREQUAL UNINITIALIZED)
|
||||
|
||||
get_property (_CACHEVARVAL CACHE ${_VAR} PROPERTY VALUE)
|
||||
|
||||
if ("${_CACHEVARVAL}" STREQUAL "")
|
||||
continue ()
|
||||
endif ("${_CACHEVARVAL}" STREQUAL "")
|
||||
|
||||
get_property (_CACHEVARDOC CACHE ${_VAR} PROPERTY HELPSTRING)
|
||||
|
||||
# Escape " in values
|
||||
string (REPLACE "\"" "\\\"" _CACHEVARVAL "${_CACHEVARVAL}")
|
||||
# Escape " in help strings
|
||||
string (REPLACE "\"" "\\\"" _CACHEVARDOC "${_CACHEVARDOC}")
|
||||
# Escape ; in values
|
||||
string (REPLACE ";" "\\\;" _CACHEVARVAL "${_CACHEVARVAL}")
|
||||
# Escape ; in help strings
|
||||
string (REPLACE ";" "\\\;" _CACHEVARDOC "${_CACHEVARDOC}")
|
||||
# Escape backslashes in values except those that are followed by a
|
||||
# quote.
|
||||
string (REGEX REPLACE "\\\\([^\"])" "\\\\\\1" _CACHEVARVAL "${_CACHEVARVAL}")
|
||||
# Escape backslashes in values that are followed by a letter to avoid
|
||||
# invalid escape sequence errors.
|
||||
string (REGEX REPLACE "\\\\([a-zA-Z])" "\\\\\\\\1" _CACHEVARVAL "${_CACHEVARVAL}")
|
||||
string (REPLACE "\\\\" "\\\\\\\\" _CACHEVARDOC "${_CACHEVARDOC}")
|
||||
|
||||
if (NOT "${_CACHEVARTYPE}" STREQUAL BOOL)
|
||||
set (_CACHEVARVAL "\"${_CACHEVARVAL}\"")
|
||||
endif (NOT "${_CACHEVARTYPE}" STREQUAL BOOL)
|
||||
|
||||
if (NOT "${_CACHEVARTYPE}" STREQUAL "" AND NOT "${_CACHEVARVAL}" STREQUAL "")
|
||||
set (CACHEVARS "${CACHEVARS}set (${_VAR} ${_CACHEVARVAL} CACHE ${_CACHEVARTYPE} \"${_CACHEVARDOC}\")\n")
|
||||
endif (NOT "${_CACHEVARTYPE}" STREQUAL "" AND NOT "${_CACHEVARVAL}" STREQUAL "")
|
||||
endforeach (_VAR)
|
||||
|
||||
set (${_CACHEVARS} ${CACHEVARS} PARENT_SCOPE)
|
||||
endfunction (get_cache_variables)
|
||||
|
||||
cmake_policy (POP)
|
||||
22
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/RunCleanerTest1.cmake
vendored
Normal file
22
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/RunCleanerTest1.cmake
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
set (RUNS 3)
|
||||
|
||||
foreach (iter RANGE 1 ${RUNS})
|
||||
set (ENV{GOOGLE_LOG_DIR} ${TEST_DIR})
|
||||
execute_process (COMMAND ${LOGCLEANUP} RESULT_VARIABLE _RESULT)
|
||||
|
||||
if (NOT _RESULT EQUAL 0)
|
||||
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
||||
endif (NOT _RESULT EQUAL 0)
|
||||
|
||||
# Ensure the log files to have different modification timestamps such that
|
||||
# exactly one log file remains at the end. Otherwise all log files will be
|
||||
# retained.
|
||||
execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 1)
|
||||
endforeach (iter)
|
||||
|
||||
file (GLOB LOG_FILES ${TEST_DIR}/*.foobar)
|
||||
list (LENGTH LOG_FILES NUM_FILES)
|
||||
|
||||
if (NOT NUM_FILES EQUAL 1)
|
||||
message (SEND_ERROR "Expected 1 log file in log directory but found ${NUM_FILES}")
|
||||
endif (NOT NUM_FILES EQUAL 1)
|
||||
22
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/RunCleanerTest2.cmake
vendored
Normal file
22
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/RunCleanerTest2.cmake
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
set (RUNS 3)
|
||||
|
||||
foreach (iter RANGE 1 ${RUNS})
|
||||
execute_process (COMMAND ${LOGCLEANUP} -log_dir=${TEST_DIR}
|
||||
RESULT_VARIABLE _RESULT)
|
||||
|
||||
if (NOT _RESULT EQUAL 0)
|
||||
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
||||
endif (NOT _RESULT EQUAL 0)
|
||||
|
||||
# Ensure the log files to have different modification timestamps such that
|
||||
# exactly one log file remains at the end. Otherwise all log files will be
|
||||
# retained.
|
||||
execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 1)
|
||||
endforeach (iter)
|
||||
|
||||
file (GLOB LOG_FILES ${TEST_DIR}/test_cleanup_*.barfoo)
|
||||
list (LENGTH LOG_FILES NUM_FILES)
|
||||
|
||||
if (NOT NUM_FILES EQUAL 1)
|
||||
message (SEND_ERROR "Expected 1 log file in build directory ${TEST_DIR} but found ${NUM_FILES}")
|
||||
endif (NOT NUM_FILES EQUAL 1)
|
||||
28
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/RunCleanerTest3.cmake
vendored
Normal file
28
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/RunCleanerTest3.cmake
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
set (RUNS 3)
|
||||
|
||||
# Create the subdirectory required by this unit test.
|
||||
file (MAKE_DIRECTORY ${TEST_DIR}/${TEST_SUBDIR})
|
||||
|
||||
foreach (iter RANGE 1 ${RUNS})
|
||||
execute_process (COMMAND ${LOGCLEANUP} -log_dir=${TEST_DIR}
|
||||
RESULT_VARIABLE _RESULT)
|
||||
|
||||
if (NOT _RESULT EQUAL 0)
|
||||
message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})")
|
||||
endif (NOT _RESULT EQUAL 0)
|
||||
|
||||
# Ensure the log files to have different modification timestamps such that
|
||||
# exactly one log file remains at the end. Otherwise all log files will be
|
||||
# retained.
|
||||
execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 2)
|
||||
endforeach (iter)
|
||||
|
||||
file (GLOB LOG_FILES ${TEST_DIR}/${TEST_SUBDIR}/test_cleanup_*.relativefoo)
|
||||
list (LENGTH LOG_FILES NUM_FILES)
|
||||
|
||||
if (NOT NUM_FILES EQUAL 1)
|
||||
message (SEND_ERROR "Expected 1 log file in build directory ${TEST_DIR}${TEST_SUBDIR} but found ${NUM_FILES}")
|
||||
endif (NOT NUM_FILES EQUAL 1)
|
||||
|
||||
# Remove the subdirectory required by this unit test.
|
||||
file (REMOVE_RECURSE ${TEST_DIR}/${TEST_SUBDIR})
|
||||
@@ -0,0 +1,11 @@
|
||||
# Create the build directory
|
||||
execute_process (
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR}
|
||||
RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED
|
||||
)
|
||||
|
||||
if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
|
||||
message (FATAL_ERROR "Failed to create build directory")
|
||||
endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
|
||||
|
||||
file (WRITE ${INITIAL_CACHE} "${CACHEVARS}")
|
||||
40
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/TestPackageConfig.cmake
vendored
Normal file
40
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/cmake/TestPackageConfig.cmake
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Create the build directory
|
||||
execute_process (
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR}
|
||||
RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED
|
||||
)
|
||||
|
||||
if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
|
||||
message (FATAL_ERROR "Failed to create build directory")
|
||||
endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
|
||||
|
||||
if (GENERATOR_TOOLSET)
|
||||
list (APPEND _ADDITIONAL_ARGS -T ${GENERATOR_TOOLSET})
|
||||
endif (GENERATOR_TOOLSET)
|
||||
|
||||
if (GENERATOR_PLATFORM)
|
||||
list (APPEND _ADDITIONAL_ARGS -A ${GENERATOR_PLATFORM})
|
||||
endif (GENERATOR_PLATFORM)
|
||||
|
||||
# Run CMake
|
||||
execute_process (
|
||||
# Capture the PATH environment variable content set during project generation
|
||||
# stage. This is required because later during the build stage the PATH is
|
||||
# modified again (e.g., for MinGW AppVeyor CI builds) by adding back the
|
||||
# directory containing git.exe. Incidently, the Git installation directory
|
||||
# also contains sh.exe which causes MinGW Makefile generation to fail.
|
||||
COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH}
|
||||
${CMAKE_COMMAND} -C ${INITIAL_CACHE}
|
||||
-G ${GENERATOR}
|
||||
${_ADDITIONAL_ARGS}
|
||||
-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
|
||||
-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON
|
||||
-DCMAKE_PREFIX_PATH=${PACKAGE_DIR}
|
||||
${SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${TEST_BINARY_DIR}
|
||||
RESULT_VARIABLE _GENERATE_SUCCEEDED
|
||||
)
|
||||
|
||||
if (NOT _GENERATE_SUCCEEDED EQUAL 0)
|
||||
message (FATAL_ERROR "Failed to generate project files using CMake")
|
||||
endif (NOT _GENERATE_SUCCEEDED EQUAL 0)
|
||||
13
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/glog-config.cmake.in
vendored
Normal file
13
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/glog-config.cmake.in
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
if (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@)
|
||||
message (FATAL_ERROR "CMake >= @glog_CMake_VERSION@ required")
|
||||
endif (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@)
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include (CMakeFindDependencyMacro)
|
||||
include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake)
|
||||
|
||||
@gflags_DEPENDENCY@
|
||||
@Unwind_DEPENDENCY@
|
||||
|
||||
include (${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake)
|
||||
18
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/glog-modules.cmake.in
vendored
Normal file
18
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/glog-modules.cmake.in
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_policy (PUSH)
|
||||
cmake_policy (SET CMP0057 NEW)
|
||||
|
||||
if (CMAKE_VERSION VERSION_LESS 3.3)
|
||||
message (FATAL_ERROR "glog-modules.cmake requires the consumer "
|
||||
"to use CMake 3.3 (or newer)")
|
||||
endif (CMAKE_VERSION VERSION_LESS 3.3)
|
||||
|
||||
set (glog_MODULE_PATH "@glog_FULL_CMake_DATADIR@")
|
||||
list (APPEND CMAKE_MODULE_PATH ${glog_MODULE_PATH})
|
||||
|
||||
if (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH)
|
||||
message (FATAL_ERROR "Cannot add '${glog_MODULE_PATH}' to "
|
||||
"CMAKE_MODULE_PATH. This will cause glog-config.cmake to fail at "
|
||||
"locating required find modules. Make sure CMAKE_MODULE_PATH is not a cache variable.")
|
||||
endif (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH)
|
||||
|
||||
cmake_policy (POP)
|
||||
11
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/libglog.pc.in
vendored
Normal file
11
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/libglog.pc.in
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: libglog
|
||||
Description: Google Log (glog) C++ logging framework
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lglog
|
||||
Libs.private: @glog_libraries_options_for_static_linking@
|
||||
Cflags: -I${includedir}
|
||||
148
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/base/commandlineflags.h
vendored
Normal file
148
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/base/commandlineflags.h
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// ---
|
||||
// This file is a compatibility layer that defines Google's version of
|
||||
// command line flags that are used for configuration.
|
||||
//
|
||||
// We put flags into their own namespace. It is purposefully
|
||||
// named in an opaque way that people should have trouble typing
|
||||
// directly. The idea is that DEFINE puts the flag in the weird
|
||||
// namespace, and DECLARE imports the flag from there into the
|
||||
// current namespace. The net result is to force people to use
|
||||
// DECLARE to get access to a flag, rather than saying
|
||||
// extern bool FLAGS_logtostderr;
|
||||
// or some such instead. We want this so we can put extra
|
||||
// functionality (like sanity-checking) in DECLARE if we want,
|
||||
// and make sure it is picked up everywhere.
|
||||
//
|
||||
// We also put the type of the variable in the namespace, so that
|
||||
// people can't DECLARE_int32 something that they DEFINE_bool'd
|
||||
// elsewhere.
|
||||
#ifndef BASE_COMMANDLINEFLAGS_H__
|
||||
#define BASE_COMMANDLINEFLAGS_H__
|
||||
|
||||
#include "config.h"
|
||||
#include <cstdlib> // for getenv
|
||||
#include <cstring> // for memchr
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_LIB_GFLAGS
|
||||
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#define DECLARE_VARIABLE(type, shorttype, name, tn) \
|
||||
namespace fL##shorttype { \
|
||||
extern GLOG_EXPORT type FLAGS_##name; \
|
||||
} \
|
||||
using fL##shorttype::FLAGS_##name
|
||||
#define DEFINE_VARIABLE(type, shorttype, name, value, meaning, tn) \
|
||||
namespace fL##shorttype { \
|
||||
GLOG_EXPORT type FLAGS_##name(value); \
|
||||
char FLAGS_no##name; \
|
||||
} \
|
||||
using fL##shorttype::FLAGS_##name
|
||||
|
||||
// bool specialization
|
||||
#define DECLARE_bool(name) \
|
||||
DECLARE_VARIABLE(bool, B, name, bool)
|
||||
#define DEFINE_bool(name, value, meaning) \
|
||||
DEFINE_VARIABLE(bool, B, name, value, meaning, bool)
|
||||
|
||||
// int32 specialization
|
||||
#define DECLARE_int32(name) \
|
||||
DECLARE_VARIABLE(GOOGLE_NAMESPACE::int32, I, name, int32)
|
||||
#define DEFINE_int32(name, value, meaning) \
|
||||
DEFINE_VARIABLE(GOOGLE_NAMESPACE::int32, I, name, value, meaning, int32)
|
||||
|
||||
// uint32 specialization
|
||||
#ifndef DECLARE_uint32
|
||||
#define DECLARE_uint32(name) \
|
||||
DECLARE_VARIABLE(GOOGLE_NAMESPACE::uint32, U, name, uint32)
|
||||
#endif // DECLARE_uint64
|
||||
#define DEFINE_uint32(name, value, meaning) \
|
||||
DEFINE_VARIABLE(GOOGLE_NAMESPACE::uint32, U, name, value, meaning, uint32)
|
||||
|
||||
// Special case for string, because we have to specify the namespace
|
||||
// std::string, which doesn't play nicely with our FLAG__namespace hackery.
|
||||
#define DECLARE_string(name) \
|
||||
namespace fLS { \
|
||||
extern GLOG_EXPORT std::string& FLAGS_##name; \
|
||||
} \
|
||||
using fLS::FLAGS_##name
|
||||
#define DEFINE_string(name, value, meaning) \
|
||||
namespace fLS { \
|
||||
std::string FLAGS_##name##_buf(value); \
|
||||
GLOG_EXPORT std::string& FLAGS_##name = FLAGS_##name##_buf; \
|
||||
char FLAGS_no##name; \
|
||||
} \
|
||||
using fLS::FLAGS_##name
|
||||
|
||||
#endif // HAVE_LIB_GFLAGS
|
||||
|
||||
// Define GLOG_DEFINE_* using DEFINE_* . By using these macros, we
|
||||
// have GLOG_* environ variables even if we have gflags installed.
|
||||
//
|
||||
// If both an environment variable and a flag are specified, the value
|
||||
// specified by a flag wins. E.g., if GLOG_v=0 and --v=1, the
|
||||
// verbosity will be 1, not 0.
|
||||
|
||||
#define GLOG_DEFINE_bool(name, value, meaning) \
|
||||
DEFINE_bool(name, EnvToBool("GLOG_" #name, value), meaning)
|
||||
|
||||
#define GLOG_DEFINE_int32(name, value, meaning) \
|
||||
DEFINE_int32(name, EnvToInt("GLOG_" #name, value), meaning)
|
||||
|
||||
#define GLOG_DEFINE_uint32(name, value, meaning) \
|
||||
DEFINE_uint32(name, EnvToUInt("GLOG_" #name, value), meaning)
|
||||
|
||||
#define GLOG_DEFINE_string(name, value, meaning) \
|
||||
DEFINE_string(name, EnvToString("GLOG_" #name, value), meaning)
|
||||
|
||||
// These macros (could be functions, but I don't want to bother with a .cc
|
||||
// file), make it easier to initialize flags from the environment.
|
||||
|
||||
#define EnvToString(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : getenv(envname))
|
||||
|
||||
#define EnvToBool(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) \
|
||||
: memchr("tTyY1\0", getenv(envname)[0], 6) != nullptr)
|
||||
|
||||
#define EnvToInt(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : strtol(getenv(envname), nullptr, 10))
|
||||
|
||||
#define EnvToUInt(envname, dflt) \
|
||||
(!getenv(envname) ? (dflt) : strtoul(getenv(envname), nullptr, 10))
|
||||
|
||||
#endif // BASE_COMMANDLINEFLAGS_H__
|
||||
51
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/base/googleinit.h
vendored
Normal file
51
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/base/googleinit.h
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// ---
|
||||
// Author: Jacob Hoffman-Andrews
|
||||
|
||||
#ifndef _GOOGLEINIT_H
|
||||
#define _GOOGLEINIT_H
|
||||
|
||||
class GoogleInitializer {
|
||||
public:
|
||||
using void_function = void (*)();
|
||||
GoogleInitializer(const char*, void_function f) {
|
||||
f();
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_MODULE_INITIALIZER(name, body) \
|
||||
namespace { \
|
||||
static void google_init_module_##name () { body; } \
|
||||
GoogleInitializer google_initializer_module_##name(#name, \
|
||||
google_init_module_##name); \
|
||||
}
|
||||
|
||||
#endif /* _GOOGLEINIT_H */
|
||||
333
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/base/mutex.h
vendored
Normal file
333
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/base/mutex.h
vendored
Normal file
@@ -0,0 +1,333 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---
|
||||
// Author: Craig Silverstein.
|
||||
//
|
||||
// A simple mutex wrapper, supporting locks and read-write locks.
|
||||
// You should assume the locks are *not* re-entrant.
|
||||
//
|
||||
// To use: you should define the following macros in your configure.ac:
|
||||
// ACX_PTHREAD
|
||||
// AC_RWLOCK
|
||||
// The latter is defined in ../autoconf.
|
||||
//
|
||||
// This class is meant to be internal-only and should be wrapped by an
|
||||
// internal namespace. Before you use this module, please give the
|
||||
// name of your internal namespace for this module. Or, if you want
|
||||
// to expose it, you'll want to move it to the Google namespace. We
|
||||
// cannot put this class in global namespace because there can be some
|
||||
// problems when we have multiple versions of Mutex in each shared object.
|
||||
//
|
||||
// NOTE: by default, we have #ifdef'ed out the TryLock() method.
|
||||
// This is for two reasons:
|
||||
// 1) TryLock() under Windows is a bit annoying (it requires a
|
||||
// #define to be defined very early).
|
||||
// 2) TryLock() is broken for NO_THREADS mode, at least in NDEBUG
|
||||
// mode.
|
||||
// If you need TryLock(), and either these two caveats are not a
|
||||
// problem for you, or you're willing to work around them, then
|
||||
// feel free to #define GMUTEX_TRYLOCK, or to remove the #ifdefs
|
||||
// in the code below.
|
||||
//
|
||||
// CYGWIN NOTE: Cygwin support for rwlock seems to be buggy:
|
||||
// http://www.cygwin.com/ml/cygwin/2008-12/msg00017.html
|
||||
// Because of that, we might as well use windows locks for
|
||||
// cygwin. They seem to be more reliable than the cygwin pthreads layer.
|
||||
//
|
||||
// TRICKY IMPLEMENTATION NOTE:
|
||||
// This class is designed to be safe to use during
|
||||
// dynamic-initialization -- that is, by global constructors that are
|
||||
// run before main() starts. The issue in this case is that
|
||||
// dynamic-initialization happens in an unpredictable order, and it
|
||||
// could be that someone else's dynamic initializer could call a
|
||||
// function that tries to acquire this mutex -- but that all happens
|
||||
// before this mutex's constructor has run. (This can happen even if
|
||||
// the mutex and the function that uses the mutex are in the same .cc
|
||||
// file.) Basically, because Mutex does non-trivial work in its
|
||||
// constructor, it's not, in the naive implementation, safe to use
|
||||
// before dynamic initialization has run on it.
|
||||
//
|
||||
// The solution used here is to pair the actual mutex primitive with a
|
||||
// bool that is set to true when the mutex is dynamically initialized.
|
||||
// (Before that it's false.) Then we modify all mutex routines to
|
||||
// look at the bool, and not try to lock/unlock until the bool makes
|
||||
// it to true (which happens after the Mutex constructor has run.)
|
||||
//
|
||||
// This works because before main() starts -- particularly, during
|
||||
// dynamic initialization -- there are no threads, so a) it's ok that
|
||||
// the mutex operations are a no-op, since we don't need locking then
|
||||
// anyway; and b) we can be quite confident our bool won't change
|
||||
// state between a call to Lock() and a call to Unlock() (that would
|
||||
// require a global constructor in one translation unit to call Lock()
|
||||
// and another global constructor in another translation unit to call
|
||||
// Unlock() later, which is pretty perverse).
|
||||
//
|
||||
// That said, it's tricky, and can conceivably fail; it's safest to
|
||||
// avoid trying to acquire a mutex in a global constructor, if you
|
||||
// can. One way it can fail is that a really smart compiler might
|
||||
// initialize the bool to true at static-initialization time (too
|
||||
// early) rather than at dynamic-initialization time. To discourage
|
||||
// that, we set is_safe_ to true in code (not the constructor
|
||||
// colon-initializer) and set it to true via a function that always
|
||||
// evaluates to true, but that the compiler can't know always
|
||||
// evaluates to true. This should be good enough.
|
||||
|
||||
#ifndef GOOGLE_MUTEX_H_
|
||||
#define GOOGLE_MUTEX_H_
|
||||
|
||||
#include "config.h" // to figure out pthreads support
|
||||
|
||||
#if defined(NO_THREADS)
|
||||
typedef int MutexType; // to keep a lock-count
|
||||
#elif defined(_WIN32) || defined(__CYGWIN__)
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN // We only need minimal includes
|
||||
# endif
|
||||
# ifdef GMUTEX_TRYLOCK
|
||||
// We need Windows NT or later for TryEnterCriticalSection(). If you
|
||||
// don't need that functionality, you can remove these _WIN32_WINNT
|
||||
// lines, and change TryLock() to assert(0) or something.
|
||||
# ifndef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0400
|
||||
# endif
|
||||
# endif
|
||||
// To avoid macro definition of ERROR.
|
||||
# ifndef NOGDI
|
||||
# define NOGDI
|
||||
# endif
|
||||
// To avoid macro definition of min/max.
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
# include <windows.h>
|
||||
typedef CRITICAL_SECTION MutexType;
|
||||
#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
|
||||
// Needed for pthread_rwlock_*. If it causes problems, you could take it
|
||||
// out, but then you'd have to unset HAVE_RWLOCK (at least on linux -- it
|
||||
// *does* cause problems for FreeBSD, or MacOSX, but isn't needed
|
||||
// for locking there.)
|
||||
# ifdef __linux__
|
||||
# ifndef _XOPEN_SOURCE // Some other header might have already set it for us.
|
||||
# define _XOPEN_SOURCE 500 // may be needed to get the rwlock calls
|
||||
# endif
|
||||
# endif
|
||||
# include <pthread.h>
|
||||
using MutexType = pthread_rwlock_t;
|
||||
#elif defined(HAVE_PTHREAD)
|
||||
# include <pthread.h>
|
||||
typedef pthread_mutex_t MutexType;
|
||||
#else
|
||||
# error Need to implement mutex.h for your architecture, or #define NO_THREADS
|
||||
#endif
|
||||
|
||||
// We need to include these header files after defining _XOPEN_SOURCE
|
||||
// as they may define the _XOPEN_SOURCE macro.
|
||||
#include <cassert>
|
||||
#include <cstdlib> // for abort()
|
||||
|
||||
#define MUTEX_NAMESPACE glog_internal_namespace_
|
||||
|
||||
namespace MUTEX_NAMESPACE {
|
||||
|
||||
class Mutex {
|
||||
public:
|
||||
// Create a Mutex that is not held by anybody. This constructor is
|
||||
// typically used for Mutexes allocated on the heap or the stack.
|
||||
// See below for a recommendation for constructing global Mutex
|
||||
// objects.
|
||||
inline Mutex();
|
||||
|
||||
// Destructor
|
||||
inline ~Mutex();
|
||||
|
||||
inline void Lock(); // Block if needed until free then acquire exclusively
|
||||
inline void Unlock(); // Release a lock acquired via Lock()
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
inline bool TryLock(); // If free, Lock() and return true, else return false
|
||||
#endif
|
||||
// Note that on systems that don't support read-write locks, these may
|
||||
// be implemented as synonyms to Lock() and Unlock(). So you can use
|
||||
// these for efficiency, but don't use them anyplace where being able
|
||||
// to do shared reads is necessary to avoid deadlock.
|
||||
inline void ReaderLock(); // Block until free or shared then acquire a share
|
||||
inline void ReaderUnlock(); // Release a read share of this Mutex
|
||||
inline void WriterLock() { Lock(); } // Acquire an exclusive lock
|
||||
inline void WriterUnlock() { Unlock(); } // Release a lock from WriterLock()
|
||||
|
||||
// TODO(hamaji): Do nothing, implement correctly.
|
||||
inline void AssertHeld() {}
|
||||
|
||||
private:
|
||||
MutexType mutex_;
|
||||
// We want to make sure that the compiler sets is_safe_ to true only
|
||||
// when we tell it to, and never makes assumptions is_safe_ is
|
||||
// always true. volatile is the most reliable way to do that.
|
||||
volatile bool is_safe_;
|
||||
|
||||
inline void SetIsSafe() { is_safe_ = true; }
|
||||
|
||||
// Catch the error of writing Mutex when intending MutexLock.
|
||||
explicit Mutex(Mutex * /*ignored*/) {}
|
||||
// Disallow "evil" constructors
|
||||
Mutex(const Mutex &) = delete;
|
||||
void operator=(const Mutex &) = delete;
|
||||
};
|
||||
|
||||
// Now the implementation of Mutex for various systems
|
||||
#if defined(NO_THREADS)
|
||||
|
||||
// When we don't have threads, we can be either reading or writing,
|
||||
// but not both. We can have lots of readers at once (in no-threads
|
||||
// mode, that's most likely to happen in recursive function calls),
|
||||
// but only one writer. We represent this by having mutex_ be -1 when
|
||||
// writing and a number > 0 when reading (and 0 when no lock is held).
|
||||
//
|
||||
// In debug mode, we assert these invariants, while in non-debug mode
|
||||
// we do nothing, for efficiency. That's why everything is in an
|
||||
// assert.
|
||||
|
||||
Mutex::Mutex() : mutex_(0) { }
|
||||
Mutex::~Mutex() { assert(mutex_ == 0); }
|
||||
void Mutex::Lock() { assert(--mutex_ == -1); }
|
||||
void Mutex::Unlock() { assert(mutex_++ == -1); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { if (mutex_) return false; Lock(); return true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { assert(++mutex_ > 0); }
|
||||
void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
|
||||
|
||||
#elif defined(_WIN32) || defined(__CYGWIN__)
|
||||
|
||||
Mutex::Mutex() { InitializeCriticalSection(&mutex_); SetIsSafe(); }
|
||||
Mutex::~Mutex() { DeleteCriticalSection(&mutex_); }
|
||||
void Mutex::Lock() { if (is_safe_) EnterCriticalSection(&mutex_); }
|
||||
void Mutex::Unlock() { if (is_safe_) LeaveCriticalSection(&mutex_); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { return is_safe_ ?
|
||||
TryEnterCriticalSection(&mutex_) != 0 : true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
|
||||
void Mutex::ReaderUnlock() { Unlock(); }
|
||||
|
||||
#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
|
||||
|
||||
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
|
||||
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
|
||||
} while (0)
|
||||
|
||||
Mutex::Mutex() {
|
||||
SetIsSafe();
|
||||
if (is_safe_ && pthread_rwlock_init(&mutex_, nullptr) != 0) abort();
|
||||
}
|
||||
Mutex::~Mutex() { SAFE_PTHREAD(pthread_rwlock_destroy); }
|
||||
void Mutex::Lock() { SAFE_PTHREAD(pthread_rwlock_wrlock); }
|
||||
void Mutex::Unlock() { SAFE_PTHREAD(pthread_rwlock_unlock); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { return is_safe_ ?
|
||||
pthread_rwlock_trywrlock(&mutex_) == 0 :
|
||||
true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { SAFE_PTHREAD(pthread_rwlock_rdlock); }
|
||||
void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock); }
|
||||
#undef SAFE_PTHREAD
|
||||
|
||||
#elif defined(HAVE_PTHREAD)
|
||||
|
||||
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
|
||||
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
|
||||
} while (0)
|
||||
|
||||
Mutex::Mutex() {
|
||||
SetIsSafe();
|
||||
if (is_safe_ && pthread_mutex_init(&mutex_, nullptr) != 0) abort();
|
||||
}
|
||||
Mutex::~Mutex() { SAFE_PTHREAD(pthread_mutex_destroy); }
|
||||
void Mutex::Lock() { SAFE_PTHREAD(pthread_mutex_lock); }
|
||||
void Mutex::Unlock() { SAFE_PTHREAD(pthread_mutex_unlock); }
|
||||
#ifdef GMUTEX_TRYLOCK
|
||||
bool Mutex::TryLock() { return is_safe_ ?
|
||||
pthread_mutex_trylock(&mutex_) == 0 : true; }
|
||||
#endif
|
||||
void Mutex::ReaderLock() { Lock(); }
|
||||
void Mutex::ReaderUnlock() { Unlock(); }
|
||||
#undef SAFE_PTHREAD
|
||||
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Some helper classes
|
||||
|
||||
// MutexLock(mu) acquires mu when constructed and releases it when destroyed.
|
||||
class MutexLock {
|
||||
public:
|
||||
explicit MutexLock(Mutex *mu) : mu_(mu) { mu_->Lock(); }
|
||||
~MutexLock() { mu_->Unlock(); }
|
||||
private:
|
||||
Mutex * const mu_;
|
||||
// Disallow "evil" constructors
|
||||
MutexLock(const MutexLock &) = delete;
|
||||
void operator=(const MutexLock &) = delete;
|
||||
};
|
||||
|
||||
// ReaderMutexLock and WriterMutexLock do the same, for rwlocks
|
||||
class ReaderMutexLock {
|
||||
public:
|
||||
explicit ReaderMutexLock(Mutex *mu) : mu_(mu) { mu_->ReaderLock(); }
|
||||
~ReaderMutexLock() { mu_->ReaderUnlock(); }
|
||||
private:
|
||||
Mutex * const mu_;
|
||||
// Disallow "evil" constructors
|
||||
ReaderMutexLock(const ReaderMutexLock &) = delete;
|
||||
void operator=(const ReaderMutexLock &) = delete;
|
||||
};
|
||||
|
||||
class WriterMutexLock {
|
||||
public:
|
||||
explicit WriterMutexLock(Mutex *mu) : mu_(mu) { mu_->WriterLock(); }
|
||||
~WriterMutexLock() { mu_->WriterUnlock(); }
|
||||
private:
|
||||
Mutex * const mu_;
|
||||
// Disallow "evil" constructors
|
||||
WriterMutexLock(const WriterMutexLock &) = delete;
|
||||
void operator=(const WriterMutexLock &) = delete;
|
||||
};
|
||||
|
||||
// Catch bug where variable name is omitted, e.g. MutexLock (&mu);
|
||||
#define MutexLock(x) COMPILE_ASSERT(0, mutex_lock_decl_missing_var_name)
|
||||
#define ReaderMutexLock(x) COMPILE_ASSERT(0, rmutex_lock_decl_missing_var_name)
|
||||
#define WriterMutexLock(x) COMPILE_ASSERT(0, wmutex_lock_decl_missing_var_name)
|
||||
|
||||
} // namespace MUTEX_NAMESPACE
|
||||
|
||||
using namespace MUTEX_NAMESPACE;
|
||||
|
||||
#undef MUTEX_NAMESPACE
|
||||
|
||||
#endif /* #define GOOGLE_MUTEX_H__ */
|
||||
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/config.h
vendored
Normal file
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/config.h
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
#ifndef GLOG_CONFIG_H
|
||||
#define GLOG_CONFIG_H
|
||||
|
||||
/* Namespace for Google classes */
|
||||
#define GOOGLE_NAMESPACE google
|
||||
|
||||
/* Define if you have the `dladdr' function */
|
||||
#define HAVE_DLADDR
|
||||
|
||||
/* Define if you have the `snprintf' function */
|
||||
#define HAVE_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H
|
||||
|
||||
/* Define if you have the `backtrace' function in <execinfo.h> */
|
||||
#define HAVE_EXECINFO_BACKTRACE
|
||||
|
||||
/* Define if you have the `backtrace_symbols' function in <execinfo.h> */
|
||||
#define HAVE_EXECINFO_BACKTRACE_SYMBOLS
|
||||
|
||||
/* Define if you have the `fcntl' function */
|
||||
#define HAVE_FCNTL
|
||||
|
||||
/* Define to 1 if you have the <glob.h> header file. */
|
||||
#define HAVE_GLOB_H
|
||||
|
||||
/* Define to 1 if you have the `pthread' library (-lpthread). */
|
||||
/* #undef HAVE_LIBPTHREAD */
|
||||
|
||||
/* define if you have google gflags library */
|
||||
/* #undef HAVE_LIB_GFLAGS */
|
||||
|
||||
/* define if you have google gmock library */
|
||||
/* #undef HAVE_LIB_GMOCK */
|
||||
|
||||
/* define if you have google gtest library */
|
||||
/* #undef HAVE_LIB_GTEST */
|
||||
|
||||
/* define if you have dbghelp library */
|
||||
/* #undef HAVE_DBGHELP */
|
||||
|
||||
/* define if you have libunwind */
|
||||
/* #undef HAVE_LIB_UNWIND */
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H
|
||||
|
||||
/* define to disable multithreading support. */
|
||||
/* #undef NO_THREADS */
|
||||
|
||||
/* Define if you have the 'pread' function */
|
||||
#define HAVE_PREAD
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#define HAVE_PTHREAD
|
||||
|
||||
/* Define to 1 if you have the <pwd.h> header file. */
|
||||
#define HAVE_PWD_H
|
||||
|
||||
/* Define if you have the 'pwrite' function */
|
||||
#define HAVE_PWRITE
|
||||
|
||||
/* define if the compiler implements pthread_rwlock_* */
|
||||
#define HAVE_RWLOCK
|
||||
|
||||
/* Define if you have the 'sigaction' function */
|
||||
#define HAVE_SIGACTION
|
||||
|
||||
/* Define if you have the `sigaltstack' function */
|
||||
#define HAVE_SIGALTSTACK
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <syscall.h> header file. */
|
||||
/* #undef HAVE_SYSCALL_H */
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#define HAVE_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/syscall.h> header file. */
|
||||
#define HAVE_SYS_SYSCALL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/ucontext.h> header file. */
|
||||
/* #undef HAVE_SYS_UCONTEXT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/utsname.h> header file. */
|
||||
#define HAVE_SYS_UTSNAME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/wait.h> header file. */
|
||||
#define HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define to 1 if you have the <ucontext.h> header file. */
|
||||
/* #undef HAVE_UCONTEXT_H */
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define if you linking to _Unwind_Backtrace is possible. */
|
||||
#define HAVE__UNWIND_BACKTRACE
|
||||
|
||||
/* Define if you linking to _Unwind_GetIP is possible. */
|
||||
#define HAVE__UNWIND_GETIP
|
||||
|
||||
/* define if your compiler has __attribute__ */
|
||||
#define HAVE___ATTRIBUTE__
|
||||
|
||||
/* define if your compiler has __builtin_expect */
|
||||
#define HAVE___BUILTIN_EXPECT 1
|
||||
|
||||
/* define if your compiler has __sync_val_compare_and_swap */
|
||||
#define HAVE___SYNC_VAL_COMPARE_AND_SWAP
|
||||
|
||||
/* define if symbolize support is available */
|
||||
/* #undef HAVE_SYMBOLIZE */
|
||||
|
||||
/* define if localtime_r is available in time.h */
|
||||
#define HAVE_LOCALTIME_R
|
||||
|
||||
/* define if gmtime_r is available in time.h */
|
||||
/* #undef HAVE_GMTIME_R */
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
/* #undef LT_OBJDIR */
|
||||
|
||||
/* How to access the PC from a struct ucontext */
|
||||
/* #undef PC_FROM_UCONTEXT */
|
||||
|
||||
/* define if we should print file offsets in traces instead of symbolizing. */
|
||||
/* #undef PRINT_UNSYMBOLIZED_STACK_TRACES */
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
/* #undef PTHREAD_CREATE_JOINABLE */
|
||||
|
||||
/* The size of `void *', as computed by sizeof. */
|
||||
#define SIZEOF_VOID_P 8
|
||||
|
||||
/* location of source code */
|
||||
#define TEST_SRC_DIR "/Users/qiuwei/Documents/邱威/语音识别-asr/to_alibaba-damo-academy/FunASR/funasr/runtime/onnxruntime/third_party/glog"
|
||||
|
||||
/* Define if thread-local storage is enabled. */
|
||||
#define GLOG_THREAD_LOCAL_STORAGE
|
||||
|
||||
#ifdef GLOG_BAZEL_BUILD
|
||||
|
||||
/* TODO(rodrigoq): remove this workaround once bazel#3979 is resolved:
|
||||
* https://github.com/bazelbuild/bazel/issues/3979 */
|
||||
#define _START_GOOGLE_NAMESPACE_ namespace GOOGLE_NAMESPACE {
|
||||
|
||||
#define _END_GOOGLE_NAMESPACE_ }
|
||||
|
||||
#else
|
||||
|
||||
/* Stops putting the code inside the Google namespace */
|
||||
#define _END_GOOGLE_NAMESPACE_ }
|
||||
|
||||
/* Puts following code inside the Google namespace */
|
||||
#define _START_GOOGLE_NAMESPACE_ namespace google {
|
||||
|
||||
#endif
|
||||
|
||||
/* Replacement for deprecated syscall(SYS_gettid) on macOS. */
|
||||
#define HAVE_PTHREAD_THREADID_NP 1
|
||||
|
||||
#endif // GLOG_CONFIG_H
|
||||
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/config.h.cmake.in
vendored
Normal file
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/config.h.cmake.in
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
#ifndef GLOG_CONFIG_H
|
||||
#define GLOG_CONFIG_H
|
||||
|
||||
/* Namespace for Google classes */
|
||||
#cmakedefine GOOGLE_NAMESPACE ${GOOGLE_NAMESPACE}
|
||||
|
||||
/* Define if you have the `dladdr' function */
|
||||
#cmakedefine HAVE_DLADDR
|
||||
|
||||
/* Define if you have the `snprintf' function */
|
||||
#cmakedefine HAVE_SNPRINTF
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#cmakedefine HAVE_DLFCN_H
|
||||
|
||||
/* Define if you have the `backtrace' function in <execinfo.h> */
|
||||
#cmakedefine HAVE_EXECINFO_BACKTRACE
|
||||
|
||||
/* Define if you have the `backtrace_symbols' function in <execinfo.h> */
|
||||
#cmakedefine HAVE_EXECINFO_BACKTRACE_SYMBOLS
|
||||
|
||||
/* Define if you have the `fcntl' function */
|
||||
#cmakedefine HAVE_FCNTL
|
||||
|
||||
/* Define to 1 if you have the <glob.h> header file. */
|
||||
#cmakedefine HAVE_GLOB_H
|
||||
|
||||
/* Define to 1 if you have the `pthread' library (-lpthread). */
|
||||
#cmakedefine HAVE_LIBPTHREAD
|
||||
|
||||
/* define if you have google gflags library */
|
||||
#cmakedefine HAVE_LIB_GFLAGS
|
||||
|
||||
/* define if you have google gmock library */
|
||||
#cmakedefine HAVE_LIB_GMOCK
|
||||
|
||||
/* define if you have google gtest library */
|
||||
#cmakedefine HAVE_LIB_GTEST
|
||||
|
||||
/* define if you have dbghelp library */
|
||||
#cmakedefine HAVE_DBGHELP
|
||||
|
||||
/* define if you have libunwind */
|
||||
#cmakedefine HAVE_LIB_UNWIND
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#cmakedefine HAVE_MEMORY_H
|
||||
|
||||
/* define to disable multithreading support. */
|
||||
#cmakedefine NO_THREADS
|
||||
|
||||
/* Define if you have the 'pread' function */
|
||||
#cmakedefine HAVE_PREAD
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#cmakedefine HAVE_PTHREAD
|
||||
|
||||
/* Define to 1 if you have the <pwd.h> header file. */
|
||||
#cmakedefine HAVE_PWD_H
|
||||
|
||||
/* Define if you have the 'pwrite' function */
|
||||
#cmakedefine HAVE_PWRITE
|
||||
|
||||
/* define if the compiler implements pthread_rwlock_* */
|
||||
#cmakedefine HAVE_RWLOCK
|
||||
|
||||
/* Define if you have the 'sigaction' function */
|
||||
#cmakedefine HAVE_SIGACTION
|
||||
|
||||
/* Define if you have the `sigaltstack' function */
|
||||
#cmakedefine HAVE_SIGALTSTACK
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#cmakedefine HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <syscall.h> header file. */
|
||||
#cmakedefine HAVE_SYSCALL_H
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#cmakedefine HAVE_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#cmakedefine HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/syscall.h> header file. */
|
||||
#cmakedefine HAVE_SYS_SYSCALL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
|
||||
|
||||
/* Define to 1 if you have the <sys/ucontext.h> header file. */
|
||||
#cmakedefine HAVE_SYS_UCONTEXT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/utsname.h> header file. */
|
||||
#cmakedefine HAVE_SYS_UTSNAME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/wait.h> header file. */
|
||||
#cmakedefine HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define to 1 if you have the <ucontext.h> header file. */
|
||||
#cmakedefine HAVE_UCONTEXT_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
|
||||
|
||||
/* Define if you linking to _Unwind_Backtrace is possible. */
|
||||
#cmakedefine HAVE__UNWIND_BACKTRACE
|
||||
|
||||
/* Define if you linking to _Unwind_GetIP is possible. */
|
||||
#cmakedefine HAVE__UNWIND_GETIP
|
||||
|
||||
/* define if your compiler has __attribute__ */
|
||||
#cmakedefine HAVE___ATTRIBUTE__
|
||||
|
||||
/* define if your compiler has __builtin_expect */
|
||||
#cmakedefine HAVE___BUILTIN_EXPECT ${HAVE___BUILTIN_EXPECT}
|
||||
|
||||
/* define if your compiler has __sync_val_compare_and_swap */
|
||||
#cmakedefine HAVE___SYNC_VAL_COMPARE_AND_SWAP
|
||||
|
||||
/* define if symbolize support is available */
|
||||
#cmakedefine HAVE_SYMBOLIZE
|
||||
|
||||
/* define if localtime_r is available in time.h */
|
||||
#cmakedefine HAVE_LOCALTIME_R
|
||||
|
||||
/* define if gmtime_r is available in time.h */
|
||||
#cmakedefine HAVE_GMTIME_R
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#cmakedefine LT_OBJDIR
|
||||
|
||||
/* How to access the PC from a struct ucontext */
|
||||
#cmakedefine PC_FROM_UCONTEXT
|
||||
|
||||
/* define if we should print file offsets in traces instead of symbolizing. */
|
||||
#cmakedefine PRINT_UNSYMBOLIZED_STACK_TRACES
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#cmakedefine PTHREAD_CREATE_JOINABLE
|
||||
|
||||
/* The size of `void *', as computed by sizeof. */
|
||||
#cmakedefine SIZEOF_VOID_P ${SIZEOF_VOID_P}
|
||||
|
||||
/* location of source code */
|
||||
#cmakedefine TEST_SRC_DIR ${TEST_SRC_DIR}
|
||||
|
||||
/* Define if thread-local storage is enabled. */
|
||||
#cmakedefine GLOG_THREAD_LOCAL_STORAGE
|
||||
|
||||
#ifdef GLOG_BAZEL_BUILD
|
||||
|
||||
/* TODO(rodrigoq): remove this workaround once bazel#3979 is resolved:
|
||||
* https://github.com/bazelbuild/bazel/issues/3979 */
|
||||
#define _START_GOOGLE_NAMESPACE_ namespace GOOGLE_NAMESPACE {
|
||||
|
||||
#define _END_GOOGLE_NAMESPACE_ }
|
||||
|
||||
#else
|
||||
|
||||
/* Stops putting the code inside the Google namespace */
|
||||
#cmakedefine _END_GOOGLE_NAMESPACE_ ${_END_GOOGLE_NAMESPACE_}
|
||||
|
||||
/* Puts following code inside the Google namespace */
|
||||
#cmakedefine _START_GOOGLE_NAMESPACE_ ${_START_GOOGLE_NAMESPACE_}
|
||||
|
||||
#endif
|
||||
|
||||
/* Replacement for deprecated syscall(SYS_gettid) on macOS. */
|
||||
#cmakedefine HAVE_PTHREAD_THREADID_NP ${HAVE_PTHREAD_THREADID_NP}
|
||||
|
||||
#endif // GLOG_CONFIG_H
|
||||
1310
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/demangle.cc
vendored
Normal file
1310
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/demangle.cc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
85
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/demangle.h
vendored
Normal file
85
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/demangle.h
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Satoru Takabayashi
|
||||
//
|
||||
// An async-signal-safe and thread-safe demangler for Itanium C++ ABI
|
||||
// (aka G++ V3 ABI).
|
||||
|
||||
// The demangler is implemented to be used in async signal handlers to
|
||||
// symbolize stack traces. We cannot use libstdc++'s
|
||||
// abi::__cxa_demangle() in such signal handlers since it's not async
|
||||
// signal safe (it uses malloc() internally).
|
||||
//
|
||||
// Note that this demangler doesn't support full demangling. More
|
||||
// specifically, it doesn't print types of function parameters and
|
||||
// types of template arguments. It just skips them. However, it's
|
||||
// still very useful to extract basic information such as class,
|
||||
// function, constructor, destructor, and operator names.
|
||||
//
|
||||
// See the implementation note in demangle.cc if you are interested.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// | Mangled Name | The Demangler | abi::__cxa_demangle()
|
||||
// |---------------|---------------|-----------------------
|
||||
// | _Z1fv | f() | f()
|
||||
// | _Z1fi | f() | f(int)
|
||||
// | _Z3foo3bar | foo() | foo(bar)
|
||||
// | _Z1fIiEvi | f<>() | void f<int>(int)
|
||||
// | _ZN1N1fE | N::f | N::f
|
||||
// | _ZN3Foo3BarEv | Foo::Bar() | Foo::Bar()
|
||||
// | _Zrm1XS_" | operator%() | operator%(X, X)
|
||||
// | _ZN3FooC1Ev | Foo::Foo() | Foo::Foo()
|
||||
// | _Z1fSs | f() | f(std::basic_string<char,
|
||||
// | | | std::char_traits<char>,
|
||||
// | | | std::allocator<char> >)
|
||||
//
|
||||
// See the unit test for more examples.
|
||||
//
|
||||
// Note: we might want to write demanglers for ABIs other than Itanium
|
||||
// C++ ABI in the future.
|
||||
//
|
||||
|
||||
#ifndef BASE_DEMANGLE_H_
|
||||
#define BASE_DEMANGLE_H_
|
||||
|
||||
#include "config.h"
|
||||
#include <glog/logging.h>
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Demangle "mangled". On success, return true and write the
|
||||
// demangled symbol name to "out". Otherwise, return false.
|
||||
// "out" is modified even if demangling is unsuccessful.
|
||||
bool GLOG_EXPORT Demangle(const char *mangled, char *out, size_t out_size);
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif // BASE_DEMANGLE_H_
|
||||
32
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/fuzz_demangle.cc
vendored
Normal file
32
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/fuzz_demangle.cc
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2023 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "demangle.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data,
|
||||
unsigned Size) {
|
||||
if (Size >= 4095) {
|
||||
return 0;
|
||||
}
|
||||
char Buffer[Size + 1];
|
||||
std::memcpy(Buffer, Data, Size);
|
||||
Buffer[Size] = 0;
|
||||
char demangled[4096];
|
||||
google::Demangle(Buffer, demangled, Size);
|
||||
return 0;
|
||||
}
|
||||
42
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/export.h
vendored
Normal file
42
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/export.h
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
#ifndef GLOG_EXPORT_H
|
||||
#define GLOG_EXPORT_H
|
||||
|
||||
#ifdef GLOG_STATIC_DEFINE
|
||||
# define GLOG_EXPORT
|
||||
# define GLOG_NO_EXPORT
|
||||
#else
|
||||
# ifndef GLOG_EXPORT
|
||||
# ifdef GOOGLE_GLOG_IS_A_DLL
|
||||
/* We are building this library */
|
||||
# define GLOG_EXPORT __attribute__((visibility("default")))
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define GLOG_EXPORT __attribute__((visibility("default")))
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef GLOG_NO_EXPORT
|
||||
# define GLOG_NO_EXPORT __attribute__((visibility("hidden")))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef GLOG_DEPRECATED
|
||||
# define GLOG_DEPRECATED __attribute__ ((__deprecated__))
|
||||
#endif
|
||||
|
||||
#ifndef GLOG_DEPRECATED_EXPORT
|
||||
# define GLOG_DEPRECATED_EXPORT GLOG_EXPORT GLOG_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifndef GLOG_DEPRECATED_NO_EXPORT
|
||||
# define GLOG_DEPRECATED_NO_EXPORT GLOG_NO_EXPORT GLOG_DEPRECATED
|
||||
#endif
|
||||
|
||||
#if 0 /* DEFINE_NO_DEPRECATED */
|
||||
# ifndef GLOG_NO_DEPRECATED
|
||||
# define GLOG_NO_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* GLOG_EXPORT_H */
|
||||
98
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/log_severity.h
vendored
Normal file
98
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/log_severity.h
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2023, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef BASE_LOG_SEVERITY_H__
|
||||
#define BASE_LOG_SEVERITY_H__
|
||||
|
||||
// The recommended semantics of the log levels are as follows:
|
||||
//
|
||||
// INFO:
|
||||
// Use for state changes or other major events, or to aid debugging.
|
||||
// WARNING:
|
||||
// Use for undesired but relatively expected events, which may indicate a
|
||||
// problem
|
||||
// ERROR:
|
||||
// Use for undesired and unexpected events that the program can recover from.
|
||||
// All ERRORs should be actionable - it should be appropriate to file a bug
|
||||
// whenever an ERROR occurs in production.
|
||||
// FATAL:
|
||||
// Use for undesired and unexpected events that the program cannot recover
|
||||
// from.
|
||||
|
||||
// Variables of type LogSeverity are widely taken to lie in the range
|
||||
// [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if
|
||||
// you ever need to change their values or add a new severity.
|
||||
using LogSeverity = int;
|
||||
|
||||
const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3,
|
||||
NUM_SEVERITIES = 4;
|
||||
#ifndef GLOG_NO_ABBREVIATED_SEVERITIES
|
||||
# ifdef ERROR
|
||||
# error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
|
||||
# endif
|
||||
const int INFO = GLOG_INFO, WARNING = GLOG_WARNING,
|
||||
ERROR = GLOG_ERROR, FATAL = GLOG_FATAL;
|
||||
#endif
|
||||
|
||||
// DFATAL is FATAL in debug mode, ERROR in normal mode
|
||||
#ifdef NDEBUG
|
||||
#define DFATAL_LEVEL ERROR
|
||||
#else
|
||||
#define DFATAL_LEVEL FATAL
|
||||
#endif
|
||||
|
||||
extern GLOG_EXPORT const char* const LogSeverityNames[NUM_SEVERITIES];
|
||||
|
||||
// NDEBUG usage helpers related to (RAW_)DCHECK:
|
||||
//
|
||||
// DEBUG_MODE is for small !NDEBUG uses like
|
||||
// if (DEBUG_MODE) foo.CheckThatFoo();
|
||||
// instead of substantially more verbose
|
||||
// #ifndef NDEBUG
|
||||
// foo.CheckThatFoo();
|
||||
// #endif
|
||||
//
|
||||
// IF_DEBUG_MODE is for small !NDEBUG uses like
|
||||
// IF_DEBUG_MODE( string error; )
|
||||
// DCHECK(Foo(&error)) << error;
|
||||
// instead of substantially more verbose
|
||||
// #ifndef NDEBUG
|
||||
// string error;
|
||||
// DCHECK(Foo(&error)) << error;
|
||||
// #endif
|
||||
//
|
||||
#ifdef NDEBUG
|
||||
enum { DEBUG_MODE = 0 };
|
||||
#define IF_DEBUG_MODE(x)
|
||||
#else
|
||||
enum { DEBUG_MODE = 1 };
|
||||
#define IF_DEBUG_MODE(x) x
|
||||
#endif
|
||||
|
||||
#endif // BASE_LOG_SEVERITY_H__
|
||||
1842
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/logging.h
vendored
Normal file
1842
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/logging.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1842
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/logging.h.in
vendored
Normal file
1842
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/logging.h.in
vendored
Normal file
File diff suppressed because it is too large
Load Diff
60
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/platform.h
vendored
Normal file
60
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/platform.h
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Shinichiro Hamaji
|
||||
//
|
||||
// Detect supported platforms.
|
||||
|
||||
#ifndef GLOG_PLATFORM_H
|
||||
#define GLOG_PLATFORM_H
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
#define GLOG_OS_WINDOWS
|
||||
#elif defined(__CYGWIN__) || defined(__CYGWIN32__)
|
||||
#define GLOG_OS_CYGWIN
|
||||
#elif defined(linux) || defined(__linux) || defined(__linux__)
|
||||
#ifndef GLOG_OS_LINUX
|
||||
#define GLOG_OS_LINUX
|
||||
#endif
|
||||
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
|
||||
#define GLOG_OS_MACOSX
|
||||
#elif defined(__FreeBSD__)
|
||||
#define GLOG_OS_FREEBSD
|
||||
#elif defined(__NetBSD__)
|
||||
#define GLOG_OS_NETBSD
|
||||
#elif defined(__OpenBSD__)
|
||||
#define GLOG_OS_OPENBSD
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
#define GLOG_OS_EMSCRIPTEN
|
||||
#else
|
||||
// TODO(hamaji): Add other platforms.
|
||||
#error Platform not supported by glog. Please consider to contribute platform information by submitting a pull request on Github.
|
||||
#endif
|
||||
|
||||
#endif // GLOG_PLATFORM_H
|
||||
179
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/raw_logging.h
vendored
Normal file
179
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/raw_logging.h
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Maxim Lifantsev
|
||||
//
|
||||
// Thread-safe logging routines that do not allocate any memory or
|
||||
// acquire any locks, and can therefore be used by low-level memory
|
||||
// allocation and synchronization code.
|
||||
|
||||
#ifndef GLOG_RAW_LOGGING_H
|
||||
#define GLOG_RAW_LOGGING_H
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace google {
|
||||
|
||||
#include <glog/log_severity.h>
|
||||
#include <glog/logging.h>
|
||||
#include <glog/vlog_is_on.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
||||
#endif
|
||||
|
||||
// This is similar to LOG(severity) << format... and VLOG(level) << format..,
|
||||
// but
|
||||
// * it is to be used ONLY by low-level modules that can't use normal LOG()
|
||||
// * it is desiged to be a low-level logger that does not allocate any
|
||||
// memory and does not need any locks, hence:
|
||||
// * it logs straight and ONLY to STDERR w/o buffering
|
||||
// * it uses an explicit format and arguments list
|
||||
// * it will silently chop off really long message strings
|
||||
// Usage example:
|
||||
// RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
|
||||
// RAW_VLOG(3, "status is %i", status);
|
||||
// These will print an almost standard log lines like this to stderr only:
|
||||
// E20200821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
|
||||
// I20200821 211317 file.cc:142] RAW: status is 20
|
||||
#define RAW_LOG(severity, ...) \
|
||||
do { \
|
||||
switch (google::GLOG_ ## severity) { \
|
||||
case 0: \
|
||||
RAW_LOG_INFO(__VA_ARGS__); \
|
||||
break; \
|
||||
case 1: \
|
||||
RAW_LOG_WARNING(__VA_ARGS__); \
|
||||
break; \
|
||||
case 2: \
|
||||
RAW_LOG_ERROR(__VA_ARGS__); \
|
||||
break; \
|
||||
case 3: \
|
||||
RAW_LOG_FATAL(__VA_ARGS__); \
|
||||
break; \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// The following STRIP_LOG testing is performed in the header file so that it's
|
||||
// possible to completely compile out the logging code and the log messages.
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
||||
#define RAW_VLOG(verboselevel, ...) \
|
||||
do { \
|
||||
if (VLOG_IS_ON(verboselevel)) { \
|
||||
RAW_LOG_INFO(__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG == 0
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
||||
#define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG == 0
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 1
|
||||
#define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG <= 1
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 2
|
||||
#define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG <= 2
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 3
|
||||
#define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_FATAL(...) \
|
||||
do { \
|
||||
google::RawLogStub__(0, __VA_ARGS__); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
#endif // STRIP_LOG <= 3
|
||||
|
||||
// Similar to CHECK(condition) << message,
|
||||
// but for low-level modules: we use only RAW_LOG that does not allocate memory.
|
||||
// We do not want to provide args list here to encourage this usage:
|
||||
// if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
|
||||
// so that the args are not computed when not needed.
|
||||
#define RAW_CHECK(condition, message) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Debug versions of RAW_LOG and RAW_CHECK
|
||||
#ifndef NDEBUG
|
||||
|
||||
#define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
|
||||
#define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
|
||||
|
||||
#else // NDEBUG
|
||||
|
||||
#define RAW_DLOG(severity, ...) \
|
||||
while (false) \
|
||||
RAW_LOG(severity, __VA_ARGS__)
|
||||
#define RAW_DCHECK(condition, message) \
|
||||
while (false) \
|
||||
RAW_CHECK(condition, message)
|
||||
|
||||
#endif // NDEBUG
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// Stub log function used to work around for unused variable warnings when
|
||||
// building with STRIP_LOG > 0.
|
||||
static inline void RawLogStub__(int /* ignored */, ...) {
|
||||
}
|
||||
|
||||
// Helper function to implement RAW_LOG and RAW_VLOG
|
||||
// Logs format... at "severity" level, reporting it
|
||||
// as called from file:line.
|
||||
// This does not allocate memory or acquire locks.
|
||||
GLOG_EXPORT void RawLog__(LogSeverity severity, const char* file, int line,
|
||||
const char* format, ...)
|
||||
__attribute__((__format__(__printf__, 4, 5)));
|
||||
|
||||
}
|
||||
|
||||
#endif // GLOG_RAW_LOGGING_H
|
||||
179
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/raw_logging.h.in
vendored
Normal file
179
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/raw_logging.h.in
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Maxim Lifantsev
|
||||
//
|
||||
// Thread-safe logging routines that do not allocate any memory or
|
||||
// acquire any locks, and can therefore be used by low-level memory
|
||||
// allocation and synchronization code.
|
||||
|
||||
#ifndef GLOG_RAW_LOGGING_H
|
||||
#define GLOG_RAW_LOGGING_H
|
||||
|
||||
#include <ctime>
|
||||
|
||||
@ac_google_start_namespace@
|
||||
|
||||
#include <glog/log_severity.h>
|
||||
#include <glog/logging.h>
|
||||
#include <glog/vlog_is_on.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
||||
#endif
|
||||
|
||||
// This is similar to LOG(severity) << format... and VLOG(level) << format..,
|
||||
// but
|
||||
// * it is to be used ONLY by low-level modules that can't use normal LOG()
|
||||
// * it is desiged to be a low-level logger that does not allocate any
|
||||
// memory and does not need any locks, hence:
|
||||
// * it logs straight and ONLY to STDERR w/o buffering
|
||||
// * it uses an explicit format and arguments list
|
||||
// * it will silently chop off really long message strings
|
||||
// Usage example:
|
||||
// RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
|
||||
// RAW_VLOG(3, "status is %i", status);
|
||||
// These will print an almost standard log lines like this to stderr only:
|
||||
// E20200821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
|
||||
// I20200821 211317 file.cc:142] RAW: status is 20
|
||||
#define RAW_LOG(severity, ...) \
|
||||
do { \
|
||||
switch (@ac_google_namespace@::GLOG_ ## severity) { \
|
||||
case 0: \
|
||||
RAW_LOG_INFO(__VA_ARGS__); \
|
||||
break; \
|
||||
case 1: \
|
||||
RAW_LOG_WARNING(__VA_ARGS__); \
|
||||
break; \
|
||||
case 2: \
|
||||
RAW_LOG_ERROR(__VA_ARGS__); \
|
||||
break; \
|
||||
case 3: \
|
||||
RAW_LOG_FATAL(__VA_ARGS__); \
|
||||
break; \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// The following STRIP_LOG testing is performed in the header file so that it's
|
||||
// possible to completely compile out the logging code and the log messages.
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
||||
#define RAW_VLOG(verboselevel, ...) \
|
||||
do { \
|
||||
if (VLOG_IS_ON(verboselevel)) { \
|
||||
RAW_LOG_INFO(__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG == 0
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG == 0
|
||||
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_INFO, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG == 0
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 1
|
||||
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_WARNING, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG <= 1
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 2
|
||||
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_ERROR, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
|
||||
#endif // STRIP_LOG <= 2
|
||||
|
||||
#if !defined(STRIP_LOG) || STRIP_LOG <= 3
|
||||
#define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_FATAL, \
|
||||
__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define RAW_LOG_FATAL(...) \
|
||||
do { \
|
||||
@ac_google_namespace@::RawLogStub__(0, __VA_ARGS__); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
#endif // STRIP_LOG <= 3
|
||||
|
||||
// Similar to CHECK(condition) << message,
|
||||
// but for low-level modules: we use only RAW_LOG that does not allocate memory.
|
||||
// We do not want to provide args list here to encourage this usage:
|
||||
// if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
|
||||
// so that the args are not computed when not needed.
|
||||
#define RAW_CHECK(condition, message) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Debug versions of RAW_LOG and RAW_CHECK
|
||||
#ifndef NDEBUG
|
||||
|
||||
#define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
|
||||
#define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
|
||||
|
||||
#else // NDEBUG
|
||||
|
||||
#define RAW_DLOG(severity, ...) \
|
||||
while (false) \
|
||||
RAW_LOG(severity, __VA_ARGS__)
|
||||
#define RAW_DCHECK(condition, message) \
|
||||
while (false) \
|
||||
RAW_CHECK(condition, message)
|
||||
|
||||
#endif // NDEBUG
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// Stub log function used to work around for unused variable warnings when
|
||||
// building with STRIP_LOG > 0.
|
||||
static inline void RawLogStub__(int /* ignored */, ...) {
|
||||
}
|
||||
|
||||
// Helper function to implement RAW_LOG and RAW_VLOG
|
||||
// Logs format... at "severity" level, reporting it
|
||||
// as called from file:line.
|
||||
// This does not allocate memory or acquire locks.
|
||||
GLOG_EXPORT void RawLog__(LogSeverity severity, const char* file, int line,
|
||||
const char* format, ...)
|
||||
@ac_cv___attribute___printf_4_5@;
|
||||
|
||||
@ac_google_end_namespace@
|
||||
|
||||
#endif // GLOG_RAW_LOGGING_H
|
||||
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/stl_logging.h
vendored
Normal file
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/stl_logging.h
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
// Copyright (c) 2003, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Stream output operators for STL containers; to be used for logging *only*.
|
||||
// Inclusion of this file lets you do:
|
||||
//
|
||||
// list<string> x;
|
||||
// LOG(INFO) << "data: " << x;
|
||||
// vector<int> v1, v2;
|
||||
// CHECK_EQ(v1, v2);
|
||||
//
|
||||
// If you want to use this header file with hash maps or slist, you
|
||||
// need to define macros before including this file:
|
||||
//
|
||||
// - GLOG_STL_LOGGING_FOR_UNORDERED - <unordered_map> and <unordered_set>
|
||||
// - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - <tr1/unordered_(map|set)>
|
||||
// - GLOG_STL_LOGGING_FOR_EXT_HASH - <ext/hash_(map|set)>
|
||||
// - GLOG_STL_LOGGING_FOR_EXT_SLIST - <ext/slist>
|
||||
//
|
||||
|
||||
#ifndef UTIL_GTL_STL_LOGGING_INL_H_
|
||||
#define UTIL_GTL_STL_LOGGING_INL_H_
|
||||
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// Forward declare these two, and define them after all the container streams
|
||||
// operators so that we can recurse from pair -> container -> container -> pair
|
||||
// properly.
|
||||
template<class First, class Second>
|
||||
std::ostream& operator<<(std::ostream& out, const std::pair<First, Second>& p);
|
||||
|
||||
namespace google {
|
||||
|
||||
template<class Iter>
|
||||
void PrintSequence(std::ostream& out, Iter begin, Iter end);
|
||||
|
||||
}
|
||||
#define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2>& seq) { \
|
||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
OUTPUT_TWO_ARG_CONTAINER(std::vector) OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
||||
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
||||
|
||||
#undef OUTPUT_TWO_ARG_CONTAINER
|
||||
|
||||
#define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2, class T3> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2, T3>& seq) { \
|
||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
OUTPUT_THREE_ARG_CONTAINER(std::set) OUTPUT_THREE_ARG_CONTAINER(
|
||||
std::multiset)
|
||||
|
||||
#undef OUTPUT_THREE_ARG_CONTAINER
|
||||
|
||||
#define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2, class T3, class T4> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2, T3, T4>& seq) { \
|
||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
OUTPUT_FOUR_ARG_CONTAINER(std::map) OUTPUT_FOUR_ARG_CONTAINER(
|
||||
std::multimap) OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set)
|
||||
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset)
|
||||
|
||||
#undef OUTPUT_FOUR_ARG_CONTAINER
|
||||
|
||||
#define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2, class T3, class T4, class T5> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2, T3, T4, T5>& seq) { \
|
||||
google::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
#if defined(GLOG_STL_LOGGING_FOR_UNORDERED) && __cplusplus >= 201103L
|
||||
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map)
|
||||
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap)
|
||||
#endif
|
||||
|
||||
#undef OUTPUT_FIVE_ARG_CONTAINER
|
||||
|
||||
template <class First, class Second>
|
||||
inline std::ostream& operator<<(
|
||||
std::ostream& out,
|
||||
const std::pair<First, Second>& p) {
|
||||
out << '(' << p.first << ", " << p.second << ')';
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace google {
|
||||
|
||||
template<class Iter>
|
||||
inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
|
||||
// Output at most 100 elements -- appropriate if used for logging.
|
||||
for (int i = 0; begin != end && i < 100; ++i, ++begin) {
|
||||
if (i > 0) out << ' ';
|
||||
out << *begin;
|
||||
}
|
||||
if (begin != end) {
|
||||
out << " ...";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Note that this is technically undefined behavior! We are adding things into
|
||||
// the std namespace for a reason though -- we are providing new operations on
|
||||
// types which are themselves defined with this namespace. Without this, these
|
||||
// operator overloads cannot be found via ADL. If these definitions are not
|
||||
// found via ADL, they must be #included before they're used, which requires
|
||||
// this header to be included before apparently independent other headers.
|
||||
//
|
||||
// For example, base/logging.h defines various template functions to implement
|
||||
// CHECK_EQ(x, y) and stream x and y into the log in the event the check fails.
|
||||
// It does so via the function template MakeCheckOpValueString:
|
||||
// template<class T>
|
||||
// void MakeCheckOpValueString(strstream* ss, const T& v) {
|
||||
// (*ss) << v;
|
||||
// }
|
||||
// Because 'glog/logging.h' is included before 'glog/stl_logging.h',
|
||||
// subsequent CHECK_EQ(v1, v2) for vector<...> typed variable v1 and v2 can only
|
||||
// find these operator definitions via ADL.
|
||||
//
|
||||
// Even this solution has problems -- it may pull unintended operators into the
|
||||
// namespace as well, allowing them to also be found via ADL, and creating code
|
||||
// that only works with a particular order of includes. Long term, we need to
|
||||
// move all of the *definitions* into namespace std, bet we need to ensure no
|
||||
// one references them first. This lets us take that step. We cannot define them
|
||||
// in both because that would create ambiguous overloads when both are found.
|
||||
namespace std { using ::operator<<; }
|
||||
|
||||
#endif // UTIL_GTL_STL_LOGGING_INL_H_
|
||||
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/stl_logging.h.in
vendored
Normal file
177
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/stl_logging.h.in
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
// Copyright (c) 2003, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Stream output operators for STL containers; to be used for logging *only*.
|
||||
// Inclusion of this file lets you do:
|
||||
//
|
||||
// list<string> x;
|
||||
// LOG(INFO) << "data: " << x;
|
||||
// vector<int> v1, v2;
|
||||
// CHECK_EQ(v1, v2);
|
||||
//
|
||||
// If you want to use this header file with hash maps or slist, you
|
||||
// need to define macros before including this file:
|
||||
//
|
||||
// - GLOG_STL_LOGGING_FOR_UNORDERED - <unordered_map> and <unordered_set>
|
||||
// - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - <tr1/unordered_(map|set)>
|
||||
// - GLOG_STL_LOGGING_FOR_EXT_HASH - <ext/hash_(map|set)>
|
||||
// - GLOG_STL_LOGGING_FOR_EXT_SLIST - <ext/slist>
|
||||
//
|
||||
|
||||
#ifndef UTIL_GTL_STL_LOGGING_INL_H_
|
||||
#define UTIL_GTL_STL_LOGGING_INL_H_
|
||||
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// Forward declare these two, and define them after all the container streams
|
||||
// operators so that we can recurse from pair -> container -> container -> pair
|
||||
// properly.
|
||||
template<class First, class Second>
|
||||
std::ostream& operator<<(std::ostream& out, const std::pair<First, Second>& p);
|
||||
|
||||
@ac_google_start_namespace@
|
||||
|
||||
template<class Iter>
|
||||
void PrintSequence(std::ostream& out, Iter begin, Iter end);
|
||||
|
||||
@ac_google_end_namespace@
|
||||
#define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2>& seq) { \
|
||||
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
OUTPUT_TWO_ARG_CONTAINER(std::vector) OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
||||
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
||||
|
||||
#undef OUTPUT_TWO_ARG_CONTAINER
|
||||
|
||||
#define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2, class T3> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2, T3>& seq) { \
|
||||
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
OUTPUT_THREE_ARG_CONTAINER(std::set) OUTPUT_THREE_ARG_CONTAINER(
|
||||
std::multiset)
|
||||
|
||||
#undef OUTPUT_THREE_ARG_CONTAINER
|
||||
|
||||
#define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2, class T3, class T4> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2, T3, T4>& seq) { \
|
||||
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
OUTPUT_FOUR_ARG_CONTAINER(std::map) OUTPUT_FOUR_ARG_CONTAINER(
|
||||
std::multimap) OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set)
|
||||
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset)
|
||||
|
||||
#undef OUTPUT_FOUR_ARG_CONTAINER
|
||||
|
||||
#define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
|
||||
template<class T1, class T2, class T3, class T4, class T5> \
|
||||
inline std::ostream& operator<<(std::ostream& out, \
|
||||
const Sequence<T1, T2, T3, T4, T5>& seq) { \
|
||||
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
#if defined(GLOG_STL_LOGGING_FOR_UNORDERED) && __cplusplus >= 201103L
|
||||
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map)
|
||||
OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap)
|
||||
#endif
|
||||
|
||||
#undef OUTPUT_FIVE_ARG_CONTAINER
|
||||
|
||||
template <class First, class Second>
|
||||
inline std::ostream& operator<<(
|
||||
std::ostream& out,
|
||||
const std::pair<First, Second>& p) {
|
||||
out << '(' << p.first << ", " << p.second << ')';
|
||||
return out;
|
||||
}
|
||||
|
||||
@ac_google_start_namespace@
|
||||
|
||||
template<class Iter>
|
||||
inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
|
||||
// Output at most 100 elements -- appropriate if used for logging.
|
||||
for (int i = 0; begin != end && i < 100; ++i, ++begin) {
|
||||
if (i > 0) out << ' ';
|
||||
out << *begin;
|
||||
}
|
||||
if (begin != end) {
|
||||
out << " ...";
|
||||
}
|
||||
}
|
||||
|
||||
@ac_google_end_namespace@
|
||||
|
||||
// Note that this is technically undefined behavior! We are adding things into
|
||||
// the std namespace for a reason though -- we are providing new operations on
|
||||
// types which are themselves defined with this namespace. Without this, these
|
||||
// operator overloads cannot be found via ADL. If these definitions are not
|
||||
// found via ADL, they must be #included before they're used, which requires
|
||||
// this header to be included before apparently independent other headers.
|
||||
//
|
||||
// For example, base/logging.h defines various template functions to implement
|
||||
// CHECK_EQ(x, y) and stream x and y into the log in the event the check fails.
|
||||
// It does so via the function template MakeCheckOpValueString:
|
||||
// template<class T>
|
||||
// void MakeCheckOpValueString(strstream* ss, const T& v) {
|
||||
// (*ss) << v;
|
||||
// }
|
||||
// Because 'glog/logging.h' is included before 'glog/stl_logging.h',
|
||||
// subsequent CHECK_EQ(v1, v2) for vector<...> typed variable v1 and v2 can only
|
||||
// find these operator definitions via ADL.
|
||||
//
|
||||
// Even this solution has problems -- it may pull unintended operators into the
|
||||
// namespace as well, allowing them to also be found via ADL, and creating code
|
||||
// that only works with a particular order of includes. Long term, we need to
|
||||
// move all of the *definitions* into namespace std, bet we need to ensure no
|
||||
// one references them first. This lets us take that step. We cannot define them
|
||||
// in both because that would create ambiguous overloads when both are found.
|
||||
namespace std { using ::operator<<; }
|
||||
|
||||
#endif // UTIL_GTL_STL_LOGGING_INL_H_
|
||||
120
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/vlog_is_on.h
vendored
Normal file
120
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/vlog_is_on.h
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright (c) 2023, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Ray Sidney and many others
|
||||
//
|
||||
// Defines the VLOG_IS_ON macro that controls the variable-verbosity
|
||||
// conditional logging.
|
||||
//
|
||||
// It's used by VLOG and VLOG_IF in logging.h
|
||||
// and by RAW_VLOG in raw_logging.h to trigger the logging.
|
||||
//
|
||||
// It can also be used directly e.g. like this:
|
||||
// if (VLOG_IS_ON(2)) {
|
||||
// // do some logging preparation and logging
|
||||
// // that can't be accomplished e.g. via just VLOG(2) << ...;
|
||||
// }
|
||||
//
|
||||
// The truth value that VLOG_IS_ON(level) returns is determined by
|
||||
// the three verbosity level flags:
|
||||
// --v=<n> Gives the default maximal active V-logging level;
|
||||
// 0 is the default.
|
||||
// Normally positive values are used for V-logging levels.
|
||||
// --vmodule=<str> Gives the per-module maximal V-logging levels to override
|
||||
// the value given by --v.
|
||||
// E.g. "my_module=2,foo*=3" would change the logging level
|
||||
// for all code in source files "my_module.*" and "foo*.*"
|
||||
// ("-inl" suffixes are also disregarded for this matching).
|
||||
//
|
||||
// SetVLOGLevel helper function is provided to do limited dynamic control over
|
||||
// V-logging by overriding the per-module settings given via --vmodule flag.
|
||||
//
|
||||
// CAVEAT: --vmodule functionality is not available in non gcc compilers.
|
||||
//
|
||||
|
||||
#ifndef BASE_VLOG_IS_ON_H_
|
||||
#define BASE_VLOG_IS_ON_H_
|
||||
|
||||
#include <glog/log_severity.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
// We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
|
||||
// (Normally) the first time every VLOG_IS_ON(n) site is hit,
|
||||
// we determine what variable will dynamically control logging at this site:
|
||||
// it's either FLAGS_v or an appropriate internal variable
|
||||
// matching the current source file that represents results of
|
||||
// parsing of --vmodule flag and/or SetVLOGLevel calls.
|
||||
#define VLOG_IS_ON(verboselevel) \
|
||||
__extension__ \
|
||||
({ static google::SiteFlag vlocal__ = {NULL, NULL, 0, NULL}; \
|
||||
google::int32 verbose_level__ = (verboselevel); \
|
||||
(vlocal__.level == NULL ? google::InitVLOG3__(&vlocal__, &FLAGS_v, \
|
||||
__FILE__, verbose_level__) : *vlocal__.level >= verbose_level__); \
|
||||
})
|
||||
#else
|
||||
// GNU extensions not available, so we do not support --vmodule.
|
||||
// Dynamic value of FLAGS_v always controls the logging level.
|
||||
#define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
|
||||
#endif
|
||||
|
||||
// Set VLOG(_IS_ON) level for module_pattern to log_level.
|
||||
// This lets us dynamically control what is normally set by the --vmodule flag.
|
||||
// Returns the level that previously applied to module_pattern.
|
||||
// NOTE: To change the log level for VLOG(_IS_ON) sites
|
||||
// that have already executed after/during InitGoogleLogging,
|
||||
// one needs to supply the exact --vmodule pattern that applied to them.
|
||||
// (If no --vmodule pattern applied to them
|
||||
// the value of FLAGS_v will continue to control them.)
|
||||
extern GLOG_EXPORT int SetVLOGLevel(const char* module_pattern, int log_level);
|
||||
|
||||
// Various declarations needed for VLOG_IS_ON above: =========================
|
||||
|
||||
struct SiteFlag {
|
||||
google::int32* level;
|
||||
const char* base_name;
|
||||
std::size_t base_len;
|
||||
SiteFlag* next;
|
||||
};
|
||||
|
||||
// Helper routine which determines the logging info for a particalur VLOG site.
|
||||
// site_flag is the address of the site-local pointer to the controlling
|
||||
// verbosity level
|
||||
// site_default is the default to use for *site_flag
|
||||
// fname is the current source file name
|
||||
// verbose_level is the argument to VLOG_IS_ON
|
||||
// We will return the return value for VLOG_IS_ON
|
||||
// and if possible set *site_flag appropriately.
|
||||
extern GLOG_EXPORT bool InitVLOG3__(
|
||||
google::SiteFlag* site_flag,
|
||||
google::int32* site_default, const char* fname,
|
||||
google::int32 verbose_level);
|
||||
|
||||
#endif // BASE_VLOG_IS_ON_H_
|
||||
120
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/vlog_is_on.h.in
vendored
Normal file
120
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/glog/vlog_is_on.h.in
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright (c) 2023, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Ray Sidney and many others
|
||||
//
|
||||
// Defines the VLOG_IS_ON macro that controls the variable-verbosity
|
||||
// conditional logging.
|
||||
//
|
||||
// It's used by VLOG and VLOG_IF in logging.h
|
||||
// and by RAW_VLOG in raw_logging.h to trigger the logging.
|
||||
//
|
||||
// It can also be used directly e.g. like this:
|
||||
// if (VLOG_IS_ON(2)) {
|
||||
// // do some logging preparation and logging
|
||||
// // that can't be accomplished e.g. via just VLOG(2) << ...;
|
||||
// }
|
||||
//
|
||||
// The truth value that VLOG_IS_ON(level) returns is determined by
|
||||
// the three verbosity level flags:
|
||||
// --v=<n> Gives the default maximal active V-logging level;
|
||||
// 0 is the default.
|
||||
// Normally positive values are used for V-logging levels.
|
||||
// --vmodule=<str> Gives the per-module maximal V-logging levels to override
|
||||
// the value given by --v.
|
||||
// E.g. "my_module=2,foo*=3" would change the logging level
|
||||
// for all code in source files "my_module.*" and "foo*.*"
|
||||
// ("-inl" suffixes are also disregarded for this matching).
|
||||
//
|
||||
// SetVLOGLevel helper function is provided to do limited dynamic control over
|
||||
// V-logging by overriding the per-module settings given via --vmodule flag.
|
||||
//
|
||||
// CAVEAT: --vmodule functionality is not available in non gcc compilers.
|
||||
//
|
||||
|
||||
#ifndef BASE_VLOG_IS_ON_H_
|
||||
#define BASE_VLOG_IS_ON_H_
|
||||
|
||||
#include <glog/log_severity.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
// We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
|
||||
// (Normally) the first time every VLOG_IS_ON(n) site is hit,
|
||||
// we determine what variable will dynamically control logging at this site:
|
||||
// it's either FLAGS_v or an appropriate internal variable
|
||||
// matching the current source file that represents results of
|
||||
// parsing of --vmodule flag and/or SetVLOGLevel calls.
|
||||
#define VLOG_IS_ON(verboselevel) \
|
||||
__extension__ \
|
||||
({ static @ac_google_namespace@::SiteFlag vlocal__ = {NULL, NULL, 0, NULL}; \
|
||||
@ac_google_namespace@::int32 verbose_level__ = (verboselevel); \
|
||||
(vlocal__.level == NULL ? @ac_google_namespace@::InitVLOG3__(&vlocal__, &FLAGS_v, \
|
||||
__FILE__, verbose_level__) : *vlocal__.level >= verbose_level__); \
|
||||
})
|
||||
#else
|
||||
// GNU extensions not available, so we do not support --vmodule.
|
||||
// Dynamic value of FLAGS_v always controls the logging level.
|
||||
#define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel))
|
||||
#endif
|
||||
|
||||
// Set VLOG(_IS_ON) level for module_pattern to log_level.
|
||||
// This lets us dynamically control what is normally set by the --vmodule flag.
|
||||
// Returns the level that previously applied to module_pattern.
|
||||
// NOTE: To change the log level for VLOG(_IS_ON) sites
|
||||
// that have already executed after/during InitGoogleLogging,
|
||||
// one needs to supply the exact --vmodule pattern that applied to them.
|
||||
// (If no --vmodule pattern applied to them
|
||||
// the value of FLAGS_v will continue to control them.)
|
||||
extern GLOG_EXPORT int SetVLOGLevel(const char* module_pattern, int log_level);
|
||||
|
||||
// Various declarations needed for VLOG_IS_ON above: =========================
|
||||
|
||||
struct SiteFlag {
|
||||
@ac_google_namespace@::int32* level;
|
||||
const char* base_name;
|
||||
std::size_t base_len;
|
||||
SiteFlag* next;
|
||||
};
|
||||
|
||||
// Helper routine which determines the logging info for a particalur VLOG site.
|
||||
// site_flag is the address of the site-local pointer to the controlling
|
||||
// verbosity level
|
||||
// site_default is the default to use for *site_flag
|
||||
// fname is the current source file name
|
||||
// verbose_level is the argument to VLOG_IS_ON
|
||||
// We will return the return value for VLOG_IS_ON
|
||||
// and if possible set *site_flag appropriately.
|
||||
extern GLOG_EXPORT bool InitVLOG3__(
|
||||
@ac_google_namespace@::SiteFlag* site_flag,
|
||||
@ac_google_namespace@::int32* site_default, const char* fname,
|
||||
@ac_google_namespace@::int32 verbose_level);
|
||||
|
||||
#endif // BASE_VLOG_IS_ON_H_
|
||||
2678
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/logging.cc
vendored
Normal file
2678
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/logging.cc
vendored
Normal file
File diff suppressed because it is too large
Load Diff
155
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/mock-log.h
vendored
Normal file
155
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/mock-log.h
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Zhanyong Wan
|
||||
//
|
||||
// Defines the ScopedMockLog class (using Google C++ Mocking
|
||||
// Framework), which is convenient for testing code that uses LOG().
|
||||
|
||||
#ifndef GLOG_SRC_MOCK_LOG_H_
|
||||
#define GLOG_SRC_MOCK_LOG_H_
|
||||
|
||||
// For GOOGLE_NAMESPACE. This must go first so we get _XOPEN_SOURCE.
|
||||
#include "utilities.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
namespace glog_testing {
|
||||
|
||||
// A ScopedMockLog object intercepts LOG() messages issued during its
|
||||
// lifespan. Using this together with Google C++ Mocking Framework,
|
||||
// it's very easy to test how a piece of code calls LOG(). The
|
||||
// typical usage:
|
||||
//
|
||||
// TEST(FooTest, LogsCorrectly) {
|
||||
// ScopedMockLog log;
|
||||
//
|
||||
// // We expect the WARNING "Something bad!" exactly twice.
|
||||
// EXPECT_CALL(log, Log(WARNING, _, "Something bad!"))
|
||||
// .Times(2);
|
||||
//
|
||||
// // We allow foo.cc to call LOG(INFO) any number of times.
|
||||
// EXPECT_CALL(log, Log(INFO, HasSubstr("/foo.cc"), _))
|
||||
// .Times(AnyNumber());
|
||||
//
|
||||
// Foo(); // Exercises the code under test.
|
||||
// }
|
||||
class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
|
||||
public:
|
||||
// When a ScopedMockLog object is constructed, it starts to
|
||||
// intercept logs.
|
||||
ScopedMockLog() { AddLogSink(this); }
|
||||
|
||||
// When the object is destructed, it stops intercepting logs.
|
||||
~ScopedMockLog() override { RemoveLogSink(this); }
|
||||
|
||||
// Implements the mock method:
|
||||
//
|
||||
// void Log(LogSeverity severity, const string& file_path,
|
||||
// const string& message);
|
||||
//
|
||||
// The second argument to Send() is the full path of the source file
|
||||
// in which the LOG() was issued.
|
||||
//
|
||||
// Note, that in a multi-threaded environment, all LOG() messages from a
|
||||
// single thread will be handled in sequence, but that cannot be guaranteed
|
||||
// for messages from different threads. In fact, if the same or multiple
|
||||
// expectations are matched on two threads concurrently, their actions will
|
||||
// be executed concurrently as well and may interleave.
|
||||
MOCK_METHOD3(Log, void(GOOGLE_NAMESPACE::LogSeverity severity,
|
||||
const std::string& file_path,
|
||||
const std::string& message));
|
||||
|
||||
private:
|
||||
// Implements the send() virtual function in class LogSink.
|
||||
// Whenever a LOG() statement is executed, this function will be
|
||||
// invoked with information presented in the LOG().
|
||||
//
|
||||
// The method argument list is long and carries much information a
|
||||
// test usually doesn't care about, so we trim the list before
|
||||
// forwarding the call to Log(), which is much easier to use in
|
||||
// tests.
|
||||
//
|
||||
// We still cannot call Log() directly, as it may invoke other LOG()
|
||||
// messages, either due to Invoke, or due to an error logged in
|
||||
// Google C++ Mocking Framework code, which would trigger a deadlock
|
||||
// since a lock is held during send().
|
||||
//
|
||||
// Hence, we save the message for WaitTillSent() which will be called after
|
||||
// the lock on send() is released, and we'll call Log() inside
|
||||
// WaitTillSent(). Since while a single send() call may be running at a
|
||||
// time, multiple WaitTillSent() calls (along with the one send() call) may
|
||||
// be running simultaneously, we ensure thread-safety of the exchange between
|
||||
// send() and WaitTillSent(), and that for each message, LOG(), send(),
|
||||
// WaitTillSent() and Log() are executed in the same thread.
|
||||
void send(GOOGLE_NAMESPACE::LogSeverity severity, const char* full_filename,
|
||||
const char* /*base_filename*/, int /*line*/,
|
||||
const LogMessageTime& /*logmsgtime*/, const char* message,
|
||||
size_t message_len) override {
|
||||
// We are only interested in the log severity, full file name, and
|
||||
// log message.
|
||||
message_info_.severity = severity;
|
||||
message_info_.file_path = full_filename;
|
||||
message_info_.message = std::string(message, message_len);
|
||||
}
|
||||
|
||||
// Implements the WaitTillSent() virtual function in class LogSink.
|
||||
// It will be executed after send() and after the global logging lock is
|
||||
// released, so calls within it (or rather within the Log() method called
|
||||
// within) may also issue LOG() statements.
|
||||
//
|
||||
// LOG(), send(), WaitTillSent() and Log() will occur in the same thread for
|
||||
// a given log message.
|
||||
void WaitTillSent() override {
|
||||
// First, and very importantly, we save a copy of the message being
|
||||
// processed before calling Log(), since Log() may indirectly call send()
|
||||
// and WaitTillSent() in the same thread again.
|
||||
MessageInfo message_info = message_info_;
|
||||
Log(message_info.severity, message_info.file_path, message_info.message);
|
||||
}
|
||||
|
||||
// All relevant information about a logged message that needs to be passed
|
||||
// from send() to WaitTillSent().
|
||||
struct MessageInfo {
|
||||
GOOGLE_NAMESPACE::LogSeverity severity;
|
||||
std::string file_path;
|
||||
std::string message;
|
||||
};
|
||||
MessageInfo message_info_;
|
||||
};
|
||||
|
||||
} // namespace glog_testing
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif // GLOG_SRC_MOCK_LOG_H_
|
||||
179
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/raw_logging.cc
vendored
Normal file
179
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/raw_logging.cc
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Maxim Lifantsev
|
||||
//
|
||||
// logging_unittest.cc covers the functionality herein
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
#include "utilities.h"
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h> // for close() and write()
|
||||
#endif
|
||||
#include <fcntl.h> // for open()
|
||||
#include <ctime>
|
||||
#include "config.h"
|
||||
#include <glog/logging.h> // To pick up flag settings etc.
|
||||
#include <glog/raw_logging.h>
|
||||
#include "base/commandlineflags.h"
|
||||
|
||||
#ifdef HAVE_STACKTRACE
|
||||
# include "stacktrace.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYSCALL_H)
|
||||
#include <syscall.h> // for syscall()
|
||||
#elif defined(HAVE_SYS_SYSCALL_H)
|
||||
#include <sys/syscall.h> // for syscall()
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)) && \
|
||||
(!(defined(GLOG_OS_MACOSX))) && !defined(GLOG_OS_EMSCRIPTEN)
|
||||
#define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
|
||||
#else
|
||||
// Not so safe, but what can you do?
|
||||
#define safe_write(fd, s, len) write(fd, s, len)
|
||||
#endif
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck) \
|
||||
__attribute__((format(archetype, stringIndex, firstToCheck)))
|
||||
#define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex) \
|
||||
__attribute__((format_arg(stringIndex)))
|
||||
#else
|
||||
#define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck)
|
||||
#define GLOG_ATTRIBUTE_FORMAT_ARG(stringIndex)
|
||||
#endif
|
||||
|
||||
// CAVEAT: vsnprintf called from *DoRawLog below has some (exotic) code paths
|
||||
// that invoke malloc() and getenv() that might acquire some locks.
|
||||
// If this becomes a problem we should reimplement a subset of vsnprintf
|
||||
// that does not need locks and malloc.
|
||||
|
||||
// Helper for RawLog__ below.
|
||||
// *DoRawLog writes to *buf of *size and move them past the written portion.
|
||||
// It returns true iff there was no overflow or error.
|
||||
GLOG_ATTRIBUTE_FORMAT(printf, 3, 4)
|
||||
static bool DoRawLog(char** buf, size_t* size, const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int n = vsnprintf(*buf, *size, format, ap);
|
||||
va_end(ap);
|
||||
if (n < 0 || static_cast<size_t>(n) > *size) return false;
|
||||
*size -= static_cast<size_t>(n);
|
||||
*buf += n;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Helper for RawLog__ below.
|
||||
inline static bool VADoRawLog(char** buf, size_t* size,
|
||||
const char* format, va_list ap) {
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
int n = vsnprintf(*buf, *size, format, ap);
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
if (n < 0 || static_cast<size_t>(n) > *size) return false;
|
||||
*size -= static_cast<size_t>(n);
|
||||
*buf += n;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const int kLogBufSize = 3000;
|
||||
static bool crashed = false;
|
||||
static CrashReason crash_reason;
|
||||
static char crash_buf[kLogBufSize + 1] = { 0 }; // Will end in '\0'
|
||||
|
||||
GLOG_ATTRIBUTE_FORMAT(printf, 4, 5)
|
||||
void RawLog__(LogSeverity severity, const char* file, int line,
|
||||
const char* format, ...) {
|
||||
if (!(FLAGS_logtostdout || FLAGS_logtostderr ||
|
||||
severity >= FLAGS_stderrthreshold || FLAGS_alsologtostderr ||
|
||||
!IsGoogleLoggingInitialized())) {
|
||||
return; // this stderr log message is suppressed
|
||||
}
|
||||
// can't call localtime_r here: it can allocate
|
||||
char buffer[kLogBufSize];
|
||||
char* buf = buffer;
|
||||
size_t size = sizeof(buffer);
|
||||
|
||||
// NOTE: this format should match the specification in base/logging.h
|
||||
DoRawLog(&buf, &size, "%c00000000 00:00:00.000000 %5u %s:%d] RAW: ",
|
||||
LogSeverityNames[severity][0],
|
||||
static_cast<unsigned int>(GetTID()),
|
||||
const_basename(const_cast<char *>(file)), line);
|
||||
|
||||
// Record the position and size of the buffer after the prefix
|
||||
const char* msg_start = buf;
|
||||
const size_t msg_size = size;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
bool no_chop = VADoRawLog(&buf, &size, format, ap);
|
||||
va_end(ap);
|
||||
if (no_chop) {
|
||||
DoRawLog(&buf, &size, "\n");
|
||||
} else {
|
||||
DoRawLog(&buf, &size, "RAW_LOG ERROR: The Message was too long!\n");
|
||||
}
|
||||
// We make a raw syscall to write directly to the stderr file descriptor,
|
||||
// avoiding FILE buffering (to avoid invoking malloc()), and bypassing
|
||||
// libc (to side-step any libc interception).
|
||||
// We write just once to avoid races with other invocations of RawLog__.
|
||||
safe_write(STDERR_FILENO, buffer, strlen(buffer));
|
||||
if (severity == GLOG_FATAL) {
|
||||
if (!sync_val_compare_and_swap(&crashed, false, true)) {
|
||||
crash_reason.filename = file;
|
||||
crash_reason.line_number = line;
|
||||
memcpy(crash_buf, msg_start, msg_size); // Don't include prefix
|
||||
crash_reason.message = crash_buf;
|
||||
#ifdef HAVE_STACKTRACE
|
||||
crash_reason.depth =
|
||||
GetStackTrace(crash_reason.stack, ARRAYSIZE(crash_reason.stack), 1);
|
||||
#else
|
||||
crash_reason.depth = 0;
|
||||
#endif
|
||||
SetCrashReason(&crash_reason);
|
||||
}
|
||||
LogMessage::Fail(); // abort()
|
||||
}
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
412
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/signalhandler.cc
vendored
Normal file
412
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/signalhandler.cc
vendored
Normal file
@@ -0,0 +1,412 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Satoru Takabayashi
|
||||
//
|
||||
// Implementation of InstallFailureSignalHandler().
|
||||
|
||||
#include "utilities.h"
|
||||
#include "stacktrace.h"
|
||||
#include "symbolize.h"
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include <csignal>
|
||||
#include <ctime>
|
||||
#ifdef HAVE_UCONTEXT_H
|
||||
# include <ucontext.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_UCONTEXT_H
|
||||
# include <sys/ucontext.h>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
namespace {
|
||||
|
||||
// We'll install the failure signal handler for these signals. We could
|
||||
// use strsignal() to get signal names, but we don't use it to avoid
|
||||
// introducing yet another #ifdef complication.
|
||||
//
|
||||
// The list should be synced with the comment in signalhandler.h.
|
||||
const struct {
|
||||
int number;
|
||||
const char *name;
|
||||
} kFailureSignals[] = {
|
||||
{ SIGSEGV, "SIGSEGV" },
|
||||
{ SIGILL, "SIGILL" },
|
||||
{ SIGFPE, "SIGFPE" },
|
||||
{ SIGABRT, "SIGABRT" },
|
||||
#if !defined(GLOG_OS_WINDOWS)
|
||||
{ SIGBUS, "SIGBUS" },
|
||||
#endif
|
||||
{ SIGTERM, "SIGTERM" },
|
||||
};
|
||||
|
||||
static bool kFailureSignalHandlerInstalled = false;
|
||||
|
||||
#if !defined(GLOG_OS_WINDOWS)
|
||||
// Returns the program counter from signal context, nullptr if unknown.
|
||||
void* GetPC(void* ucontext_in_void) {
|
||||
#if (defined(HAVE_UCONTEXT_H) || defined(HAVE_SYS_UCONTEXT_H)) && defined(PC_FROM_UCONTEXT)
|
||||
if (ucontext_in_void != nullptr) {
|
||||
ucontext_t *context = reinterpret_cast<ucontext_t *>(ucontext_in_void);
|
||||
return (void*)context->PC_FROM_UCONTEXT;
|
||||
}
|
||||
#else
|
||||
(void)ucontext_in_void;
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
// The class is used for formatting error messages. We don't use printf()
|
||||
// as it's not async signal safe.
|
||||
class MinimalFormatter {
|
||||
public:
|
||||
MinimalFormatter(char *buffer, size_t size)
|
||||
: buffer_(buffer),
|
||||
cursor_(buffer),
|
||||
end_(buffer + size) {
|
||||
}
|
||||
|
||||
// Returns the number of bytes written in the buffer.
|
||||
std::size_t num_bytes_written() const { return static_cast<std::size_t>(cursor_ - buffer_); }
|
||||
|
||||
// Appends string from "str" and updates the internal cursor.
|
||||
void AppendString(const char* str) {
|
||||
ptrdiff_t i = 0;
|
||||
while (str[i] != '\0' && cursor_ + i < end_) {
|
||||
cursor_[i] = str[i];
|
||||
++i;
|
||||
}
|
||||
cursor_ += i;
|
||||
}
|
||||
|
||||
// Formats "number" in "radix" and updates the internal cursor.
|
||||
// Lowercase letters are used for 'a' - 'z'.
|
||||
void AppendUint64(uint64 number, unsigned radix) {
|
||||
unsigned i = 0;
|
||||
while (cursor_ + i < end_) {
|
||||
const uint64 tmp = number % radix;
|
||||
number /= radix;
|
||||
cursor_[i] = static_cast<char>(tmp < 10 ? '0' + tmp : 'a' + tmp - 10);
|
||||
++i;
|
||||
if (number == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Reverse the bytes written.
|
||||
std::reverse(cursor_, cursor_ + i);
|
||||
cursor_ += i;
|
||||
}
|
||||
|
||||
// Formats "number" as hexadecimal number, and updates the internal
|
||||
// cursor. Padding will be added in front if needed.
|
||||
void AppendHexWithPadding(uint64 number, int width) {
|
||||
char* start = cursor_;
|
||||
AppendString("0x");
|
||||
AppendUint64(number, 16);
|
||||
// Move to right and add padding in front if needed.
|
||||
if (cursor_ < start + width) {
|
||||
const int64 delta = start + width - cursor_;
|
||||
std::copy(start, cursor_, start + delta);
|
||||
std::fill(start, start + delta, ' ');
|
||||
cursor_ = start + width;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
char *buffer_;
|
||||
char *cursor_;
|
||||
const char * const end_;
|
||||
};
|
||||
|
||||
// Writes the given data with the size to the standard error.
|
||||
void WriteToStderr(const char* data, size_t size) {
|
||||
if (write(STDERR_FILENO, data, size) < 0) {
|
||||
// Ignore errors.
|
||||
}
|
||||
}
|
||||
|
||||
// The writer function can be changed by InstallFailureWriter().
|
||||
void (*g_failure_writer)(const char* data, size_t size) = WriteToStderr;
|
||||
|
||||
// Dumps time information. We don't dump human-readable time information
|
||||
// as localtime() is not guaranteed to be async signal safe.
|
||||
void DumpTimeInfo() {
|
||||
time_t time_in_sec = time(nullptr);
|
||||
char buf[256]; // Big enough for time info.
|
||||
MinimalFormatter formatter(buf, sizeof(buf));
|
||||
formatter.AppendString("*** Aborted at ");
|
||||
formatter.AppendUint64(static_cast<uint64>(time_in_sec), 10);
|
||||
formatter.AppendString(" (unix time)");
|
||||
formatter.AppendString(" try \"date -d @");
|
||||
formatter.AppendUint64(static_cast<uint64>(time_in_sec), 10);
|
||||
formatter.AppendString("\" if you are using GNU date ***\n");
|
||||
g_failure_writer(buf, formatter.num_bytes_written());
|
||||
}
|
||||
|
||||
// TODO(hamaji): Use signal instead of sigaction?
|
||||
#if defined(HAVE_STACKTRACE) && defined(HAVE_SIGACTION)
|
||||
|
||||
// Dumps information about the signal to STDERR.
|
||||
void DumpSignalInfo(int signal_number, siginfo_t *siginfo) {
|
||||
// Get the signal name.
|
||||
const char* signal_name = nullptr;
|
||||
for (auto kFailureSignal : kFailureSignals) {
|
||||
if (signal_number == kFailureSignal.number) {
|
||||
signal_name = kFailureSignal.name;
|
||||
}
|
||||
}
|
||||
|
||||
char buf[256]; // Big enough for signal info.
|
||||
MinimalFormatter formatter(buf, sizeof(buf));
|
||||
|
||||
formatter.AppendString("*** ");
|
||||
if (signal_name) {
|
||||
formatter.AppendString(signal_name);
|
||||
} else {
|
||||
// Use the signal number if the name is unknown. The signal name
|
||||
// should be known, but just in case.
|
||||
formatter.AppendString("Signal ");
|
||||
formatter.AppendUint64(static_cast<uint64>(signal_number), 10);
|
||||
}
|
||||
formatter.AppendString(" (@0x");
|
||||
formatter.AppendUint64(reinterpret_cast<uintptr_t>(siginfo->si_addr), 16);
|
||||
formatter.AppendString(")");
|
||||
formatter.AppendString(" received by PID ");
|
||||
formatter.AppendUint64(static_cast<uint64>(getpid()), 10);
|
||||
formatter.AppendString(" (TID 0x");
|
||||
// We assume pthread_t is an integral number or a pointer, rather
|
||||
// than a complex struct. In some environments, pthread_self()
|
||||
// returns an uint64 but in some other environments pthread_self()
|
||||
// returns a pointer.
|
||||
pthread_t id = pthread_self();
|
||||
formatter.AppendUint64(
|
||||
reinterpret_cast<uint64>(reinterpret_cast<const char*>(id)), 16);
|
||||
formatter.AppendString(") ");
|
||||
// Only linux has the PID of the signal sender in si_pid.
|
||||
#ifdef GLOG_OS_LINUX
|
||||
formatter.AppendString("from PID ");
|
||||
formatter.AppendUint64(static_cast<uint64>(siginfo->si_pid), 10);
|
||||
formatter.AppendString("; ");
|
||||
#endif
|
||||
formatter.AppendString("stack trace: ***\n");
|
||||
g_failure_writer(buf, formatter.num_bytes_written());
|
||||
}
|
||||
|
||||
#endif // HAVE_SIGACTION
|
||||
|
||||
// Dumps information about the stack frame to STDERR.
|
||||
void DumpStackFrameInfo(const char* prefix, void* pc) {
|
||||
// Get the symbol name.
|
||||
const char *symbol = "(unknown)";
|
||||
char symbolized[1024]; // Big enough for a sane symbol.
|
||||
// Symbolizes the previous address of pc because pc may be in the
|
||||
// next function.
|
||||
if (Symbolize(reinterpret_cast<char *>(pc) - 1,
|
||||
symbolized, sizeof(symbolized))) {
|
||||
symbol = symbolized;
|
||||
}
|
||||
|
||||
char buf[1024]; // Big enough for stack frame info.
|
||||
MinimalFormatter formatter(buf, sizeof(buf));
|
||||
|
||||
formatter.AppendString(prefix);
|
||||
formatter.AppendString("@ ");
|
||||
const int width = 2 * sizeof(void*) + 2; // + 2 for "0x".
|
||||
formatter.AppendHexWithPadding(reinterpret_cast<uintptr_t>(pc), width);
|
||||
formatter.AppendString(" ");
|
||||
formatter.AppendString(symbol);
|
||||
formatter.AppendString("\n");
|
||||
g_failure_writer(buf, formatter.num_bytes_written());
|
||||
}
|
||||
|
||||
// Invoke the default signal handler.
|
||||
void InvokeDefaultSignalHandler(int signal_number) {
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction sig_action;
|
||||
memset(&sig_action, 0, sizeof(sig_action));
|
||||
sigemptyset(&sig_action.sa_mask);
|
||||
sig_action.sa_handler = SIG_DFL;
|
||||
sigaction(signal_number, &sig_action, nullptr);
|
||||
kill(getpid(), signal_number);
|
||||
#elif defined(GLOG_OS_WINDOWS)
|
||||
signal(signal_number, SIG_DFL);
|
||||
raise(signal_number);
|
||||
#endif
|
||||
}
|
||||
|
||||
// This variable is used for protecting FailureSignalHandler() from
|
||||
// dumping stuff while another thread is doing it. Our policy is to let
|
||||
// the first thread dump stuff and let other threads wait.
|
||||
// See also comments in FailureSignalHandler().
|
||||
static pthread_t* g_entered_thread_id_pointer = nullptr;
|
||||
|
||||
// Dumps signal and stack frame information, and invokes the default
|
||||
// signal handler once our job is done.
|
||||
#if defined(GLOG_OS_WINDOWS)
|
||||
void FailureSignalHandler(int signal_number)
|
||||
#else
|
||||
void FailureSignalHandler(int signal_number,
|
||||
siginfo_t *signal_info,
|
||||
void *ucontext)
|
||||
#endif
|
||||
{
|
||||
// First check if we've already entered the function. We use an atomic
|
||||
// compare and swap operation for platforms that support it. For other
|
||||
// platforms, we use a naive method that could lead to a subtle race.
|
||||
|
||||
// We assume pthread_self() is async signal safe, though it's not
|
||||
// officially guaranteed.
|
||||
pthread_t my_thread_id = pthread_self();
|
||||
// NOTE: We could simply use pthread_t rather than pthread_t* for this,
|
||||
// if pthread_self() is guaranteed to return non-zero value for thread
|
||||
// ids, but there is no such guarantee. We need to distinguish if the
|
||||
// old value (value returned from __sync_val_compare_and_swap) is
|
||||
// different from the original value (in this case nullptr).
|
||||
pthread_t* old_thread_id_pointer =
|
||||
glog_internal_namespace_::sync_val_compare_and_swap(
|
||||
&g_entered_thread_id_pointer, static_cast<pthread_t*>(nullptr),
|
||||
&my_thread_id);
|
||||
if (old_thread_id_pointer != nullptr) {
|
||||
// We've already entered the signal handler. What should we do?
|
||||
if (pthread_equal(my_thread_id, *g_entered_thread_id_pointer)) {
|
||||
// It looks the current thread is reentering the signal handler.
|
||||
// Something must be going wrong (maybe we are reentering by another
|
||||
// type of signal?). Kill ourself by the default signal handler.
|
||||
InvokeDefaultSignalHandler(signal_number);
|
||||
}
|
||||
// Another thread is dumping stuff. Let's wait until that thread
|
||||
// finishes the job and kills the process.
|
||||
while (true) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
// This is the first time we enter the signal handler. We are going to
|
||||
// do some interesting stuff from here.
|
||||
// TODO(satorux): We might want to set timeout here using alarm(), but
|
||||
// mixing alarm() and sleep() can be a bad idea.
|
||||
|
||||
// First dump time info.
|
||||
DumpTimeInfo();
|
||||
|
||||
#if !defined(GLOG_OS_WINDOWS)
|
||||
// Get the program counter from ucontext.
|
||||
void *pc = GetPC(ucontext);
|
||||
DumpStackFrameInfo("PC: ", pc);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STACKTRACE
|
||||
// Get the stack traces.
|
||||
void *stack[32];
|
||||
// +1 to exclude this function.
|
||||
const int depth = GetStackTrace(stack, ARRAYSIZE(stack), 1);
|
||||
# ifdef HAVE_SIGACTION
|
||||
DumpSignalInfo(signal_number, signal_info);
|
||||
#elif !defined(GLOG_OS_WINDOWS)
|
||||
(void)signal_info;
|
||||
# endif
|
||||
// Dump the stack traces.
|
||||
for (int i = 0; i < depth; ++i) {
|
||||
DumpStackFrameInfo(" ", stack[i]);
|
||||
}
|
||||
#elif !defined(GLOG_OS_WINDOWS)
|
||||
(void)signal_info;
|
||||
#endif
|
||||
|
||||
// *** TRANSITION ***
|
||||
//
|
||||
// BEFORE this point, all code must be async-termination-safe!
|
||||
// (See WARNING above.)
|
||||
//
|
||||
// AFTER this point, we do unsafe things, like using LOG()!
|
||||
// The process could be terminated or hung at any time. We try to
|
||||
// do more useful things first and riskier things later.
|
||||
|
||||
// Flush the logs before we do anything in case 'anything'
|
||||
// causes problems.
|
||||
FlushLogFilesUnsafe(0);
|
||||
|
||||
// Kill ourself by the default signal handler.
|
||||
InvokeDefaultSignalHandler(signal_number);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace glog_internal_namespace_ {
|
||||
|
||||
bool IsFailureSignalHandlerInstalled() {
|
||||
#ifdef HAVE_SIGACTION
|
||||
// TODO(andschwa): Return kFailureSignalHandlerInstalled?
|
||||
struct sigaction sig_action;
|
||||
memset(&sig_action, 0, sizeof(sig_action));
|
||||
sigemptyset(&sig_action.sa_mask);
|
||||
sigaction(SIGABRT, nullptr, &sig_action);
|
||||
if (sig_action.sa_sigaction == &FailureSignalHandler) {
|
||||
return true;
|
||||
}
|
||||
#elif defined(GLOG_OS_WINDOWS)
|
||||
return kFailureSignalHandlerInstalled;
|
||||
#endif // HAVE_SIGACTION
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace glog_internal_namespace_
|
||||
|
||||
void InstallFailureSignalHandler() {
|
||||
#ifdef HAVE_SIGACTION
|
||||
// Build the sigaction struct.
|
||||
struct sigaction sig_action;
|
||||
memset(&sig_action, 0, sizeof(sig_action));
|
||||
sigemptyset(&sig_action.sa_mask);
|
||||
sig_action.sa_flags |= SA_SIGINFO;
|
||||
sig_action.sa_sigaction = &FailureSignalHandler;
|
||||
|
||||
for (auto kFailureSignal : kFailureSignals) {
|
||||
CHECK_ERR(sigaction(kFailureSignal.number, &sig_action, nullptr));
|
||||
}
|
||||
kFailureSignalHandlerInstalled = true;
|
||||
#elif defined(GLOG_OS_WINDOWS)
|
||||
for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) {
|
||||
CHECK_NE(signal(kFailureSignals[i].number, &FailureSignalHandler),
|
||||
SIG_ERR);
|
||||
}
|
||||
kFailureSignalHandlerInstalled = true;
|
||||
#endif // HAVE_SIGACTION
|
||||
}
|
||||
|
||||
void InstallFailureWriter(void (*writer)(const char* data, size_t size)) {
|
||||
#if defined(HAVE_SIGACTION) || defined(GLOG_OS_WINDOWS)
|
||||
g_failure_writer = writer;
|
||||
#endif // HAVE_SIGACTION
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
61
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace.h
vendored
Normal file
61
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace.h
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2000 - 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Routines to extract the current stack trace. These functions are
|
||||
// thread-safe.
|
||||
|
||||
#ifndef BASE_STACKTRACE_H_
|
||||
#define BASE_STACKTRACE_H_
|
||||
|
||||
#include "config.h"
|
||||
#include <glog/logging.h>
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// This is similar to the GetStackFrames routine, except that it returns
|
||||
// the stack trace only, and not the stack frame sizes as well.
|
||||
// Example:
|
||||
// main() { foo(); }
|
||||
// foo() { bar(); }
|
||||
// bar() {
|
||||
// void* result[10];
|
||||
// int depth = GetStackFrames(result, 10, 1);
|
||||
// }
|
||||
//
|
||||
// This produces:
|
||||
// result[0] foo
|
||||
// result[1] main
|
||||
// .... ...
|
||||
//
|
||||
// "result" must not be nullptr.
|
||||
GLOG_EXPORT int GetStackTrace(void** result, int max_depth, int skip_count);
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif // BASE_STACKTRACE_H_
|
||||
64
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_generic-inl.h
vendored
Normal file
64
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_generic-inl.h
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2000 - 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Portable implementation - just use glibc
|
||||
//
|
||||
// Note: The glibc implementation may cause a call to malloc.
|
||||
// This can cause a deadlock in HeapProfiler.
|
||||
#include <execinfo.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "stacktrace.h"
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// If you change this function, also change GetStackFrames below.
|
||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||
static const int kStackLength = 64;
|
||||
void * stack[kStackLength];
|
||||
int size;
|
||||
|
||||
size = backtrace(stack, kStackLength);
|
||||
skip_count++; // we want to skip the current frame as well
|
||||
int result_count = size - skip_count;
|
||||
if (result_count < 0) {
|
||||
result_count = 0;
|
||||
}
|
||||
if (result_count > max_depth) {
|
||||
result_count = max_depth;
|
||||
}
|
||||
for (int i = 0; i < result_count; i++) {
|
||||
result[i] = stack[i + skip_count];
|
||||
}
|
||||
|
||||
return result_count;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2005 - 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Arun Sharma
|
||||
//
|
||||
// Produce stack trace using libunwind
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
extern "C" {
|
||||
#define UNW_LOCAL_ONLY
|
||||
#include <libunwind.h>
|
||||
}
|
||||
#include <glog/raw_logging.h>
|
||||
#include "stacktrace.h"
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Sometimes, we can try to get a stack trace from within a stack
|
||||
// trace, because libunwind can call mmap (maybe indirectly via an
|
||||
// internal mmap based memory allocator), and that mmap gets trapped
|
||||
// and causes a stack-trace request. If were to try to honor that
|
||||
// recursive request, we'd end up with infinite recursion or deadlock.
|
||||
// Luckily, it's safe to ignore those subsequent traces. In such
|
||||
// cases, we return 0 to indicate the situation.
|
||||
// We can use the GCC __thread syntax here since libunwind is not supported on
|
||||
// Windows.
|
||||
static __thread bool g_tl_entered; // Initialized to false.
|
||||
|
||||
// If you change this function, also change GetStackFrames below.
|
||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||
void *ip;
|
||||
int n = 0;
|
||||
unw_cursor_t cursor;
|
||||
unw_context_t uc;
|
||||
|
||||
if (g_tl_entered) {
|
||||
return 0;
|
||||
}
|
||||
g_tl_entered = true;
|
||||
|
||||
unw_getcontext(&uc);
|
||||
RAW_CHECK(unw_init_local(&cursor, &uc) >= 0, "unw_init_local failed");
|
||||
skip_count++; // Do not include the "GetStackTrace" frame
|
||||
|
||||
while (n < max_depth) {
|
||||
int ret =
|
||||
unw_get_reg(&cursor, UNW_REG_IP, reinterpret_cast<unw_word_t *>(&ip));
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
if (skip_count > 0) {
|
||||
skip_count--;
|
||||
} else {
|
||||
result[n++] = ip;
|
||||
}
|
||||
ret = unw_step(&cursor);
|
||||
if (ret <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_tl_entered = false;
|
||||
return n;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
133
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_powerpc-inl.h
vendored
Normal file
133
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_powerpc-inl.h
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Copyright (c) 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Craig Silverstein
|
||||
//
|
||||
// Produce stack trace. I'm guessing (hoping!) the code is much like
|
||||
// for x86. For apple machines, at least, it seems to be; see
|
||||
// http://developer.apple.com/documentation/mac/runtimehtml/RTArch-59.html
|
||||
// http://www.linux-foundation.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#STACK
|
||||
// Linux has similar code: http://patchwork.ozlabs.org/linuxppc/patch?id=8882
|
||||
|
||||
#include <cstdint> // for uintptr_t
|
||||
#include <cstdio>
|
||||
|
||||
#include "stacktrace.h"
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Given a pointer to a stack frame, locate and return the calling
|
||||
// stackframe, or return nullptr if no stackframe can be found. Perform sanity
|
||||
// checks (the strictness of which is controlled by the boolean parameter
|
||||
// "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned.
|
||||
template<bool STRICT_UNWINDING>
|
||||
static void **NextStackFrame(void **old_sp) {
|
||||
void **new_sp = static_cast<void **>(*old_sp);
|
||||
|
||||
// Check that the transition from frame pointer old_sp to frame
|
||||
// pointer new_sp isn't clearly bogus
|
||||
if (STRICT_UNWINDING) {
|
||||
// With the stack growing downwards, older stack frame must be
|
||||
// at a greater address that the current one.
|
||||
if (new_sp <= old_sp) return nullptr;
|
||||
// Assume stack frames larger than 100,000 bytes are bogus.
|
||||
if ((uintptr_t)new_sp - (uintptr_t)old_sp > 100000) return nullptr;
|
||||
} else {
|
||||
// In the non-strict mode, allow discontiguous stack frames.
|
||||
// (alternate-signal-stacks for example).
|
||||
if (new_sp == old_sp) return nullptr;
|
||||
// And allow frames upto about 1MB.
|
||||
if ((new_sp > old_sp) &&
|
||||
((uintptr_t)new_sp - (uintptr_t)old_sp > 1000000)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if ((uintptr_t)new_sp & (sizeof(void *) - 1)) return nullptr;
|
||||
return new_sp;
|
||||
}
|
||||
|
||||
// This ensures that GetStackTrace stes up the Link Register properly.
|
||||
void StacktracePowerPCDummyFunction() __attribute__((noinline));
|
||||
void StacktracePowerPCDummyFunction() { __asm__ volatile(""); }
|
||||
|
||||
// If you change this function, also change GetStackFrames below.
|
||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||
void **sp;
|
||||
// Apple OS X uses an old version of gnu as -- both Darwin 7.9.0 (Panther)
|
||||
// and Darwin 8.8.1 (Tiger) use as 1.38. This means we have to use a
|
||||
// different asm syntax. I don't know quite the best way to discriminate
|
||||
// systems using the old as from the new one; I've gone with __APPLE__.
|
||||
#ifdef __APPLE__
|
||||
__asm__ volatile ("mr %0,r1" : "=r" (sp));
|
||||
#else
|
||||
__asm__ volatile ("mr %0,1" : "=r" (sp));
|
||||
#endif
|
||||
|
||||
// On PowerPC, the "Link Register" or "Link Record" (LR), is a stack
|
||||
// entry that holds the return address of the subroutine call (what
|
||||
// instruction we run after our function finishes). This is the
|
||||
// same as the stack-pointer of our parent routine, which is what we
|
||||
// want here. While the compiler will always(?) set up LR for
|
||||
// subroutine calls, it may not for leaf functions (such as this one).
|
||||
// This routine forces the compiler (at least gcc) to push it anyway.
|
||||
StacktracePowerPCDummyFunction();
|
||||
|
||||
// The LR save area is used by the callee, so the top entry is bogus.
|
||||
skip_count++;
|
||||
|
||||
int n = 0;
|
||||
while (sp && n < max_depth) {
|
||||
if (skip_count > 0) {
|
||||
skip_count--;
|
||||
} else {
|
||||
// PowerPC has 3 main ABIs, which say where in the stack the
|
||||
// Link Register is. For DARWIN and AIX (used by apple and
|
||||
// linux ppc64), it's in sp[2]. For SYSV (used by linux ppc),
|
||||
// it's in sp[1].
|
||||
#if defined(_CALL_AIX) || defined(_CALL_DARWIN)
|
||||
result[n++] = *(sp+2);
|
||||
#elif defined(_CALL_SYSV)
|
||||
result[n++] = *(sp+1);
|
||||
#elif defined(__APPLE__) || ((defined(__linux) || defined(__linux__)) && defined(__PPC64__))
|
||||
// This check is in case the compiler doesn't define _CALL_AIX/etc.
|
||||
result[n++] = *(sp+2);
|
||||
#elif defined(__linux) || defined(__OpenBSD__)
|
||||
// This check is in case the compiler doesn't define _CALL_SYSV.
|
||||
result[n++] = *(sp+1);
|
||||
#else
|
||||
#error Need to specify the PPC ABI for your archiecture.
|
||||
#endif
|
||||
}
|
||||
// Use strict unwinding rules.
|
||||
sp = NextStackFrame<true>(sp);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
245
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_unittest.cc
vendored
Normal file
245
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_unittest.cc
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
// Copyright (c) 2004, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "config.h"
|
||||
#include "base/commandlineflags.h"
|
||||
#include <glog/logging.h>
|
||||
#include "stacktrace.h"
|
||||
|
||||
#ifdef HAVE_EXECINFO_BACKTRACE_SYMBOLS
|
||||
# include <execinfo.h>
|
||||
#endif
|
||||
|
||||
using namespace GOOGLE_NAMESPACE;
|
||||
|
||||
#ifdef HAVE_STACKTRACE
|
||||
|
||||
// Obtain a backtrace, verify that the expected callers are present in the
|
||||
// backtrace, and maybe print the backtrace to stdout.
|
||||
|
||||
// The sequence of functions whose return addresses we expect to see in the
|
||||
// backtrace.
|
||||
const int BACKTRACE_STEPS = 6;
|
||||
|
||||
struct AddressRange {
|
||||
const void *start, *end;
|
||||
};
|
||||
|
||||
// Expected function [start,end] range.
|
||||
AddressRange expected_range[BACKTRACE_STEPS];
|
||||
|
||||
#if __GNUC__
|
||||
// Using GCC extension: address of a label can be taken with '&&label'.
|
||||
// Start should be a label somewhere before recursive call, end somewhere
|
||||
// after it.
|
||||
#define INIT_ADDRESS_RANGE(fn, start_label, end_label, prange) \
|
||||
do { \
|
||||
(prange)->start = &&start_label; \
|
||||
(prange)->end = &&end_label; \
|
||||
CHECK_LT((prange)->start, (prange)->end); \
|
||||
} while (0)
|
||||
// This macro expands into "unmovable" code (opaque to GCC), and that
|
||||
// prevents GCC from moving a_label up or down in the code.
|
||||
// Without it, there is no code following the 'end' label, and GCC
|
||||
// (4.3.1, 4.4.0) thinks it safe to assign &&end an address that is before
|
||||
// the recursive call.
|
||||
#define DECLARE_ADDRESS_LABEL(a_label) \
|
||||
a_label: do { __asm__ __volatile__(""); } while (0)
|
||||
// Gcc 4.4.0 may split function into multiple chunks, and the chunk
|
||||
// performing recursive call may end up later in the code then the return
|
||||
// instruction (this actually happens with FDO).
|
||||
// Adjust function range from __builtin_return_address.
|
||||
#define ADJUST_ADDRESS_RANGE_FROM_RA(prange) \
|
||||
do { \
|
||||
void *ra = __builtin_return_address(0); \
|
||||
CHECK_LT((prange)->start, ra); \
|
||||
if (ra > (prange)->end) { \
|
||||
printf("Adjusting range from %p..%p to %p..%p\n", \
|
||||
(prange)->start, (prange)->end, \
|
||||
(prange)->start, ra); \
|
||||
(prange)->end = ra; \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
// Assume the Check* functions below are not longer than 256 bytes.
|
||||
#define INIT_ADDRESS_RANGE(fn, start_label, end_label, prange) \
|
||||
do { \
|
||||
(prange)->start = reinterpret_cast<const void *>(&fn); \
|
||||
(prange)->end = reinterpret_cast<const char *>(&fn) + 256; \
|
||||
} while (0)
|
||||
#define DECLARE_ADDRESS_LABEL(a_label) do { } while (0)
|
||||
#define ADJUST_ADDRESS_RANGE_FROM_RA(prange) do { } while (0)
|
||||
#endif // __GNUC__
|
||||
|
||||
//-----------------------------------------------------------------------//
|
||||
|
||||
static void CheckRetAddrIsInFunction(void *ret_addr, const AddressRange &range)
|
||||
{
|
||||
CHECK_GE(ret_addr, range.start);
|
||||
CHECK_LE(ret_addr, range.end);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------//
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wgnu-label-as-value"
|
||||
#endif
|
||||
|
||||
void ATTRIBUTE_NOINLINE CheckStackTrace(int);
|
||||
static void ATTRIBUTE_NOINLINE CheckStackTraceLeaf() {
|
||||
const int STACK_LEN = 10;
|
||||
void *stack[STACK_LEN];
|
||||
int size;
|
||||
|
||||
ADJUST_ADDRESS_RANGE_FROM_RA(&expected_range[1]);
|
||||
INIT_ADDRESS_RANGE(CheckStackTraceLeaf, start, end, &expected_range[0]);
|
||||
DECLARE_ADDRESS_LABEL(start);
|
||||
size = GetStackTrace(stack, STACK_LEN, 0);
|
||||
printf("Obtained %d stack frames.\n", size);
|
||||
CHECK_GE(size, 1);
|
||||
CHECK_LE(size, STACK_LEN);
|
||||
|
||||
if (true) {
|
||||
#ifdef HAVE_EXECINFO_BACKTRACE_SYMBOLS
|
||||
char **strings = backtrace_symbols(stack, size);
|
||||
printf("Obtained %d stack frames.\n", size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
printf("%s %p\n", strings[i], stack[i]);
|
||||
}
|
||||
|
||||
union {
|
||||
void (*p1)(int);
|
||||
void* p2;
|
||||
} p = {&CheckStackTrace};
|
||||
|
||||
printf("CheckStackTrace() addr: %p\n", p.p2);
|
||||
free(strings);
|
||||
#endif
|
||||
}
|
||||
for (int i = 0; i < BACKTRACE_STEPS; i++) {
|
||||
printf("Backtrace %d: expected: %p..%p actual: %p ... ",
|
||||
i, expected_range[i].start, expected_range[i].end, stack[i]);
|
||||
fflush(stdout);
|
||||
CheckRetAddrIsInFunction(stack[i], expected_range[i]);
|
||||
printf("OK\n");
|
||||
}
|
||||
DECLARE_ADDRESS_LABEL(end);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------//
|
||||
|
||||
/* Dummy functions to make the backtrace more interesting. */
|
||||
static void ATTRIBUTE_NOINLINE CheckStackTrace4(int i) {
|
||||
ADJUST_ADDRESS_RANGE_FROM_RA(&expected_range[2]);
|
||||
INIT_ADDRESS_RANGE(CheckStackTrace4, start, end, &expected_range[1]);
|
||||
DECLARE_ADDRESS_LABEL(start);
|
||||
for (int j = i; j >= 0; j--) {
|
||||
CheckStackTraceLeaf();
|
||||
}
|
||||
DECLARE_ADDRESS_LABEL(end);
|
||||
}
|
||||
static void ATTRIBUTE_NOINLINE CheckStackTrace3(int i) {
|
||||
ADJUST_ADDRESS_RANGE_FROM_RA(&expected_range[3]);
|
||||
INIT_ADDRESS_RANGE(CheckStackTrace3, start, end, &expected_range[2]);
|
||||
DECLARE_ADDRESS_LABEL(start);
|
||||
for (int j = i; j >= 0; j--) {
|
||||
CheckStackTrace4(j);
|
||||
}
|
||||
DECLARE_ADDRESS_LABEL(end);
|
||||
}
|
||||
static void ATTRIBUTE_NOINLINE CheckStackTrace2(int i) {
|
||||
ADJUST_ADDRESS_RANGE_FROM_RA(&expected_range[4]);
|
||||
INIT_ADDRESS_RANGE(CheckStackTrace2, start, end, &expected_range[3]);
|
||||
DECLARE_ADDRESS_LABEL(start);
|
||||
for (int j = i; j >= 0; j--) {
|
||||
CheckStackTrace3(j);
|
||||
}
|
||||
DECLARE_ADDRESS_LABEL(end);
|
||||
}
|
||||
static void ATTRIBUTE_NOINLINE CheckStackTrace1(int i) {
|
||||
ADJUST_ADDRESS_RANGE_FROM_RA(&expected_range[5]);
|
||||
INIT_ADDRESS_RANGE(CheckStackTrace1, start, end, &expected_range[4]);
|
||||
DECLARE_ADDRESS_LABEL(start);
|
||||
for (int j = i; j >= 0; j--) {
|
||||
CheckStackTrace2(j);
|
||||
}
|
||||
DECLARE_ADDRESS_LABEL(end);
|
||||
}
|
||||
|
||||
#ifndef __GNUC__
|
||||
// On non-GNU environment, we use the address of `CheckStackTrace` to
|
||||
// guess the address range of this function. This guess is wrong for
|
||||
// non-static function on Windows. This is probably because
|
||||
// `&CheckStackTrace` returns the address of a trampoline like PLT,
|
||||
// not the actual address of `CheckStackTrace`.
|
||||
// See https://github.com/google/glog/issues/421 for the detail.
|
||||
static
|
||||
#endif
|
||||
void ATTRIBUTE_NOINLINE CheckStackTrace(int i) {
|
||||
INIT_ADDRESS_RANGE(CheckStackTrace, start, end, &expected_range[5]);
|
||||
DECLARE_ADDRESS_LABEL(start);
|
||||
for (int j = i; j >= 0; j--) {
|
||||
CheckStackTrace1(j);
|
||||
}
|
||||
DECLARE_ADDRESS_LABEL(end);
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------//
|
||||
|
||||
int main(int, char ** argv) {
|
||||
FLAGS_logtostderr = true;
|
||||
InitGoogleLogging(argv[0]);
|
||||
|
||||
CheckStackTrace(0);
|
||||
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
int main() {
|
||||
|
||||
#ifdef GLOG_BAZEL_BUILD
|
||||
printf("HAVE_STACKTRACE is expected to be defined in Bazel tests\n");
|
||||
exit(EXIT_FAILURE);
|
||||
#endif // GLOG_BAZEL_BUILD
|
||||
|
||||
printf("PASS (no stacktrace support)\n");
|
||||
return 0;
|
||||
}
|
||||
#endif // HAVE_STACKTRACE
|
||||
106
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_unwind-inl.h
vendored
Normal file
106
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_unwind-inl.h
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
// Copyright (c) 2005 - 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Arun Sharma
|
||||
//
|
||||
// Produce stack trace using libgcc
|
||||
|
||||
#include <unwind.h> // ABI defined unwinder
|
||||
|
||||
#include <cstdlib> // for nullptr
|
||||
|
||||
#include "stacktrace.h"
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
struct trace_arg_t {
|
||||
void **result;
|
||||
int max_depth;
|
||||
int skip_count;
|
||||
int count;
|
||||
};
|
||||
|
||||
// Workaround for the malloc() in _Unwind_Backtrace() issue.
|
||||
static _Unwind_Reason_Code nop_backtrace(struct _Unwind_Context */*uc*/, void */*opq*/) {
|
||||
return _URC_NO_REASON;
|
||||
}
|
||||
|
||||
|
||||
// This code is not considered ready to run until
|
||||
// static initializers run so that we are guaranteed
|
||||
// that any malloc-related initialization is done.
|
||||
static bool ready_to_run = false;
|
||||
class StackTraceInit {
|
||||
public:
|
||||
StackTraceInit() {
|
||||
// Extra call to force initialization
|
||||
_Unwind_Backtrace(nop_backtrace, nullptr);
|
||||
ready_to_run = true;
|
||||
}
|
||||
};
|
||||
|
||||
static StackTraceInit module_initializer; // Force initialization
|
||||
|
||||
static _Unwind_Reason_Code GetOneFrame(struct _Unwind_Context *uc, void *opq) {
|
||||
auto *targ = static_cast<trace_arg_t *>(opq);
|
||||
|
||||
if (targ->skip_count > 0) {
|
||||
targ->skip_count--;
|
||||
} else {
|
||||
targ->result[targ->count++] = reinterpret_cast<void *>(_Unwind_GetIP(uc));
|
||||
}
|
||||
|
||||
if (targ->count == targ->max_depth) {
|
||||
return _URC_END_OF_STACK;
|
||||
}
|
||||
|
||||
return _URC_NO_REASON;
|
||||
}
|
||||
|
||||
// If you change this function, also change GetStackFrames below.
|
||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||
if (!ready_to_run) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
trace_arg_t targ;
|
||||
|
||||
skip_count += 1; // Do not include the "GetStackTrace" frame
|
||||
|
||||
targ.result = result;
|
||||
targ.max_depth = max_depth;
|
||||
targ.skip_count = skip_count;
|
||||
targ.count = 0;
|
||||
|
||||
_Unwind_Backtrace(GetOneFrame, &targ);
|
||||
|
||||
return targ.count;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
51
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_windows-inl.h
vendored
Normal file
51
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_windows-inl.h
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2000 - 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Andrew Schwartzmeyer
|
||||
//
|
||||
// Windows implementation - just use CaptureStackBackTrace
|
||||
|
||||
#include "config.h"
|
||||
#include "port.h"
|
||||
#include "stacktrace.h"
|
||||
#include <dbghelp.h>
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||
if (max_depth > 64) {
|
||||
max_depth = 64;
|
||||
}
|
||||
skip_count++; // we want to skip the current frame as well
|
||||
// This API is thread-safe (moreover it walks only the current thread).
|
||||
return CaptureStackBackTrace(static_cast<DWORD>(skip_count),
|
||||
static_cast<DWORD>(max_depth), result, nullptr);
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
159
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_x86-inl.h
vendored
Normal file
159
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/stacktrace_x86-inl.h
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
// Copyright (c) 2000 - 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Produce stack trace
|
||||
|
||||
#include <cstdint> // for uintptr_t
|
||||
|
||||
#include "utilities.h" // for OS_* macros
|
||||
|
||||
#if !defined(GLOG_OS_WINDOWS)
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include <cstdio> // for nullptr
|
||||
|
||||
#include "stacktrace.h"
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Given a pointer to a stack frame, locate and return the calling
|
||||
// stackframe, or return nullptr if no stackframe can be found. Perform sanity
|
||||
// checks (the strictness of which is controlled by the boolean parameter
|
||||
// "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned.
|
||||
template<bool STRICT_UNWINDING>
|
||||
static void **NextStackFrame(void **old_sp) {
|
||||
void **new_sp = static_cast<void **>(*old_sp);
|
||||
|
||||
// Check that the transition from frame pointer old_sp to frame
|
||||
// pointer new_sp isn't clearly bogus
|
||||
if (STRICT_UNWINDING) {
|
||||
// With the stack growing downwards, older stack frame must be
|
||||
// at a greater address that the current one.
|
||||
if (new_sp <= old_sp) return nullptr;
|
||||
// Assume stack frames larger than 100,000 bytes are bogus.
|
||||
if (reinterpret_cast<uintptr_t>(new_sp) -
|
||||
reinterpret_cast<uintptr_t>(old_sp) >
|
||||
100000) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
// In the non-strict mode, allow discontiguous stack frames.
|
||||
// (alternate-signal-stacks for example).
|
||||
if (new_sp == old_sp) return nullptr;
|
||||
// And allow frames upto about 1MB.
|
||||
if ((new_sp > old_sp) && (reinterpret_cast<uintptr_t>(new_sp) -
|
||||
reinterpret_cast<uintptr_t>(old_sp) >
|
||||
1000000)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (reinterpret_cast<uintptr_t>(new_sp) & (sizeof(void *) - 1)) {
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef __i386__
|
||||
// On 64-bit machines, the stack pointer can be very close to
|
||||
// 0xffffffff, so we explicitly check for a pointer into the
|
||||
// last two pages in the address space
|
||||
if ((uintptr_t)new_sp >= 0xffffe000) return nullptr;
|
||||
#endif
|
||||
#if !defined(GLOG_OS_WINDOWS)
|
||||
if (!STRICT_UNWINDING) {
|
||||
// Lax sanity checks cause a crash in 32-bit tcmalloc/crash_reason_test
|
||||
// on AMD-based machines with VDSO-enabled kernels.
|
||||
// Make an extra sanity check to insure new_sp is readable.
|
||||
// Note: NextStackFrame<false>() is only called while the program
|
||||
// is already on its last leg, so it's ok to be slow here.
|
||||
static int page_size = getpagesize();
|
||||
void *new_sp_aligned =
|
||||
reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(new_sp) &
|
||||
static_cast<uintptr_t>(~(page_size - 1)));
|
||||
if (msync(new_sp_aligned, static_cast<size_t>(page_size), MS_ASYNC) == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return new_sp;
|
||||
}
|
||||
|
||||
// If you change this function, also change GetStackFrames below.
|
||||
int GetStackTrace(void** result, int max_depth, int skip_count) {
|
||||
void **sp;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
|
||||
#define USE_BUILTIN_FRAME_ADDRESS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_BUILTIN_FRAME_ADDRESS
|
||||
sp = reinterpret_cast<void**>(__builtin_frame_address(0));
|
||||
#elif defined(__i386__)
|
||||
// Stack frame format:
|
||||
// sp[0] pointer to previous frame
|
||||
// sp[1] caller address
|
||||
// sp[2] first argument
|
||||
// ...
|
||||
sp = (void **)&result - 2;
|
||||
#elif defined(__x86_64__)
|
||||
// __builtin_frame_address(0) can return the wrong address on gcc-4.1.0-k8
|
||||
unsigned long rbp;
|
||||
// Move the value of the register %rbp into the local variable rbp.
|
||||
// We need 'volatile' to prevent this instruction from getting moved
|
||||
// around during optimization to before function prologue is done.
|
||||
// An alternative way to achieve this
|
||||
// would be (before this __asm__ instruction) to call Noop() defined as
|
||||
// static void Noop() __attribute__ ((noinline)); // prevent inlining
|
||||
// static void Noop() { asm(""); } // prevent optimizing-away
|
||||
__asm__ volatile ("mov %%rbp, %0" : "=r" (rbp));
|
||||
// Arguments are passed in registers on x86-64, so we can't just
|
||||
// offset from &result
|
||||
sp = (void **) rbp;
|
||||
#endif
|
||||
|
||||
int n = 0;
|
||||
while (sp && n < max_depth) {
|
||||
if (*(sp + 1) == nullptr) {
|
||||
// In 64-bit code, we often see a frame that
|
||||
// points to itself and has a return address of 0.
|
||||
break;
|
||||
}
|
||||
if (skip_count > 0) {
|
||||
skip_count--;
|
||||
} else {
|
||||
result[n++] = *(sp+1);
|
||||
}
|
||||
// Use strict unwinding rules.
|
||||
sp = NextStackFrame<true>(sp);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
956
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/symbolize.cc
vendored
Normal file
956
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/symbolize.cc
vendored
Normal file
@@ -0,0 +1,956 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Satoru Takabayashi
|
||||
// Stack-footprint reduction work done by Raksit Ashok
|
||||
//
|
||||
// Implementation note:
|
||||
//
|
||||
// We don't use heaps but only use stacks. We want to reduce the
|
||||
// stack consumption so that the symbolizer can run on small stacks.
|
||||
//
|
||||
// Here are some numbers collected with GCC 4.1.0 on x86:
|
||||
// - sizeof(Elf32_Sym) = 16
|
||||
// - sizeof(Elf32_Shdr) = 40
|
||||
// - sizeof(Elf64_Sym) = 24
|
||||
// - sizeof(Elf64_Shdr) = 64
|
||||
//
|
||||
// This implementation is intended to be async-signal-safe but uses
|
||||
// some functions which are not guaranteed to be so, such as memchr()
|
||||
// and memmove(). We assume they are async-signal-safe.
|
||||
//
|
||||
// Additional header can be specified by the GLOG_BUILD_CONFIG_INCLUDE
|
||||
// macro to add platform specific defines (e.g. GLOG_OS_OPENBSD).
|
||||
|
||||
#ifdef GLOG_BUILD_CONFIG_INCLUDE
|
||||
#include GLOG_BUILD_CONFIG_INCLUDE
|
||||
#endif // GLOG_BUILD_CONFIG_INCLUDE
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
#if defined(HAVE_SYMBOLIZE)
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
#include "symbolize.h"
|
||||
#include "demangle.h"
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// We don't use assert() since it's not guaranteed to be
|
||||
// async-signal-safe. Instead we define a minimal assertion
|
||||
// macro. So far, we don't need pretty printing for __FILE__, etc.
|
||||
|
||||
// A wrapper for abort() to make it callable in ? :.
|
||||
static int AssertFail() {
|
||||
abort();
|
||||
return 0; // Should not reach.
|
||||
}
|
||||
|
||||
#define SAFE_ASSERT(expr) ((expr) ? 0 : AssertFail())
|
||||
|
||||
static SymbolizeCallback g_symbolize_callback = nullptr;
|
||||
void InstallSymbolizeCallback(SymbolizeCallback callback) {
|
||||
g_symbolize_callback = callback;
|
||||
}
|
||||
|
||||
static SymbolizeOpenObjectFileCallback g_symbolize_open_object_file_callback =
|
||||
nullptr;
|
||||
void InstallSymbolizeOpenObjectFileCallback(
|
||||
SymbolizeOpenObjectFileCallback callback) {
|
||||
g_symbolize_open_object_file_callback = callback;
|
||||
}
|
||||
|
||||
// This function wraps the Demangle function to provide an interface
|
||||
// where the input symbol is demangled in-place.
|
||||
// To keep stack consumption low, we would like this function to not
|
||||
// get inlined.
|
||||
static ATTRIBUTE_NOINLINE void DemangleInplace(char *out, size_t out_size) {
|
||||
char demangled[256]; // Big enough for sane demangled symbols.
|
||||
if (Demangle(out, demangled, sizeof(demangled))) {
|
||||
// Demangling succeeded. Copy to out if the space allows.
|
||||
size_t len = strlen(demangled);
|
||||
if (len + 1 <= out_size) { // +1 for '\0'.
|
||||
SAFE_ASSERT(len < sizeof(demangled));
|
||||
memmove(out, demangled, len + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#if defined(__ELF__)
|
||||
|
||||
#if defined(HAVE_DLFCN_H)
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#if defined(GLOG_OS_OPENBSD)
|
||||
#include <sys/exec_elf.h>
|
||||
#else
|
||||
#include <elf.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <glog/raw_logging.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "config.h"
|
||||
#include "symbolize.h"
|
||||
|
||||
// Re-runs fn until it doesn't cause EINTR.
|
||||
#define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR)
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Read up to "count" bytes from "offset" in the file pointed by file
|
||||
// descriptor "fd" into the buffer starting at "buf" while handling short reads
|
||||
// and EINTR. On success, return the number of bytes read. Otherwise, return
|
||||
// -1.
|
||||
static ssize_t ReadFromOffset(const int fd, void *buf, const size_t count,
|
||||
const size_t offset) {
|
||||
SAFE_ASSERT(fd >= 0);
|
||||
SAFE_ASSERT(count <= static_cast<size_t>(std::numeric_limits<ssize_t>::max()));
|
||||
char *buf0 = reinterpret_cast<char *>(buf);
|
||||
size_t num_bytes = 0;
|
||||
while (num_bytes < count) {
|
||||
ssize_t len;
|
||||
NO_INTR(len = pread(fd, buf0 + num_bytes, count - num_bytes,
|
||||
static_cast<off_t>(offset + num_bytes)));
|
||||
if (len < 0) { // There was an error other than EINTR.
|
||||
return -1;
|
||||
}
|
||||
if (len == 0) { // Reached EOF.
|
||||
break;
|
||||
}
|
||||
num_bytes += static_cast<size_t>(len);
|
||||
}
|
||||
SAFE_ASSERT(num_bytes <= count);
|
||||
return static_cast<ssize_t>(num_bytes);
|
||||
}
|
||||
|
||||
// Try reading exactly "count" bytes from "offset" bytes in a file
|
||||
// pointed by "fd" into the buffer starting at "buf" while handling
|
||||
// short reads and EINTR. On success, return true. Otherwise, return
|
||||
// false.
|
||||
static bool ReadFromOffsetExact(const int fd, void *buf,
|
||||
const size_t count, const size_t offset) {
|
||||
ssize_t len = ReadFromOffset(fd, buf, count, offset);
|
||||
return static_cast<size_t>(len) == count;
|
||||
}
|
||||
|
||||
// Returns elf_header.e_type if the file pointed by fd is an ELF binary.
|
||||
static int FileGetElfType(const int fd) {
|
||||
ElfW(Ehdr) elf_header;
|
||||
if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) {
|
||||
return -1;
|
||||
}
|
||||
if (memcmp(elf_header.e_ident, ELFMAG, SELFMAG) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return elf_header.e_type;
|
||||
}
|
||||
|
||||
// Read the section headers in the given ELF binary, and if a section
|
||||
// of the specified type is found, set the output to this section header
|
||||
// and return true. Otherwise, return false.
|
||||
// To keep stack consumption low, we would like this function to not get
|
||||
// inlined.
|
||||
static ATTRIBUTE_NOINLINE bool
|
||||
GetSectionHeaderByType(const int fd, ElfW(Half) sh_num, const size_t sh_offset,
|
||||
ElfW(Word) type, ElfW(Shdr) *out) {
|
||||
// Read at most 16 section headers at a time to save read calls.
|
||||
ElfW(Shdr) buf[16];
|
||||
for (size_t i = 0; i < sh_num;) {
|
||||
const size_t num_bytes_left = (sh_num - i) * sizeof(buf[0]);
|
||||
const size_t num_bytes_to_read =
|
||||
(sizeof(buf) > num_bytes_left) ? num_bytes_left : sizeof(buf);
|
||||
const ssize_t len = ReadFromOffset(fd, buf, num_bytes_to_read,
|
||||
sh_offset + i * sizeof(buf[0]));
|
||||
if (len == -1) {
|
||||
return false;
|
||||
}
|
||||
SAFE_ASSERT(static_cast<size_t>(len) % sizeof(buf[0]) == 0);
|
||||
const size_t num_headers_in_buf = static_cast<size_t>(len) / sizeof(buf[0]);
|
||||
SAFE_ASSERT(num_headers_in_buf <= sizeof(buf) / sizeof(buf[0]));
|
||||
for (size_t j = 0; j < num_headers_in_buf; ++j) {
|
||||
if (buf[j].sh_type == type) {
|
||||
*out = buf[j];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i += num_headers_in_buf;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// There is no particular reason to limit section name to 63 characters,
|
||||
// but there has (as yet) been no need for anything longer either.
|
||||
const int kMaxSectionNameLen = 64;
|
||||
|
||||
// name_len should include terminating '\0'.
|
||||
bool GetSectionHeaderByName(int fd, const char *name, size_t name_len,
|
||||
ElfW(Shdr) *out) {
|
||||
ElfW(Ehdr) elf_header;
|
||||
if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ElfW(Shdr) shstrtab;
|
||||
size_t shstrtab_offset =
|
||||
(elf_header.e_shoff + static_cast<size_t>(elf_header.e_shentsize) *
|
||||
static_cast<size_t>(elf_header.e_shstrndx));
|
||||
if (!ReadFromOffsetExact(fd, &shstrtab, sizeof(shstrtab), shstrtab_offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < elf_header.e_shnum; ++i) {
|
||||
size_t section_header_offset = (elf_header.e_shoff +
|
||||
elf_header.e_shentsize * i);
|
||||
if (!ReadFromOffsetExact(fd, out, sizeof(*out), section_header_offset)) {
|
||||
return false;
|
||||
}
|
||||
char header_name[kMaxSectionNameLen];
|
||||
if (sizeof(header_name) < name_len) {
|
||||
RAW_LOG(WARNING, "Section name '%s' is too long (%" PRIuS "); "
|
||||
"section will not be found (even if present).", name, name_len);
|
||||
// No point in even trying.
|
||||
return false;
|
||||
}
|
||||
size_t name_offset = shstrtab.sh_offset + out->sh_name;
|
||||
ssize_t n_read = ReadFromOffset(fd, &header_name, name_len, name_offset);
|
||||
if (n_read == -1) {
|
||||
return false;
|
||||
} else if (static_cast<size_t>(n_read) != name_len) {
|
||||
// Short read -- name could be at end of file.
|
||||
continue;
|
||||
}
|
||||
if (memcmp(header_name, name, name_len) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read a symbol table and look for the symbol containing the
|
||||
// pc. Iterate over symbols in a symbol table and look for the symbol
|
||||
// containing "pc". On success, return true and write the symbol name
|
||||
// to out. Otherwise, return false.
|
||||
// To keep stack consumption low, we would like this function to not get
|
||||
// inlined.
|
||||
static ATTRIBUTE_NOINLINE bool
|
||||
FindSymbol(uint64_t pc, const int fd, char *out, size_t out_size,
|
||||
uint64_t symbol_offset, const ElfW(Shdr) *strtab,
|
||||
const ElfW(Shdr) *symtab) {
|
||||
if (symtab == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const size_t num_symbols = symtab->sh_size / symtab->sh_entsize;
|
||||
for (unsigned i = 0; i < num_symbols;) {
|
||||
size_t offset = symtab->sh_offset + i * symtab->sh_entsize;
|
||||
|
||||
// If we are reading Elf64_Sym's, we want to limit this array to
|
||||
// 32 elements (to keep stack consumption low), otherwise we can
|
||||
// have a 64 element Elf32_Sym array.
|
||||
#if defined(__WORDSIZE) && __WORDSIZE == 64
|
||||
const size_t NUM_SYMBOLS = 32U;
|
||||
#else
|
||||
const size_t NUM_SYMBOLS = 64U;
|
||||
#endif
|
||||
|
||||
// Read at most NUM_SYMBOLS symbols at once to save read() calls.
|
||||
ElfW(Sym) buf[NUM_SYMBOLS];
|
||||
size_t num_symbols_to_read = std::min(NUM_SYMBOLS, num_symbols - i);
|
||||
const ssize_t len =
|
||||
ReadFromOffset(fd, &buf, sizeof(buf[0]) * num_symbols_to_read, offset);
|
||||
SAFE_ASSERT(static_cast<size_t>(len) % sizeof(buf[0]) == 0);
|
||||
const size_t num_symbols_in_buf = static_cast<size_t>(len) / sizeof(buf[0]);
|
||||
SAFE_ASSERT(num_symbols_in_buf <= num_symbols_to_read);
|
||||
for (unsigned j = 0; j < num_symbols_in_buf; ++j) {
|
||||
const ElfW(Sym)& symbol = buf[j];
|
||||
uint64_t start_address = symbol.st_value;
|
||||
start_address += symbol_offset;
|
||||
uint64_t end_address = start_address + symbol.st_size;
|
||||
if (symbol.st_value != 0 && // Skip null value symbols.
|
||||
symbol.st_shndx != 0 && // Skip undefined symbols.
|
||||
start_address <= pc && pc < end_address) {
|
||||
ssize_t len1 = ReadFromOffset(fd, out, out_size,
|
||||
strtab->sh_offset + symbol.st_name);
|
||||
if (len1 <= 0 || memchr(out, '\0', out_size) == nullptr) {
|
||||
memset(out, 0, out_size);
|
||||
return false;
|
||||
}
|
||||
return true; // Obtained the symbol name.
|
||||
}
|
||||
}
|
||||
i += num_symbols_in_buf;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the symbol name of "pc" from the file pointed by "fd". Process
|
||||
// both regular and dynamic symbol tables if necessary. On success,
|
||||
// write the symbol name to "out" and return true. Otherwise, return
|
||||
// false.
|
||||
static bool GetSymbolFromObjectFile(const int fd,
|
||||
uint64_t pc,
|
||||
char* out,
|
||||
size_t out_size,
|
||||
uint64_t base_address) {
|
||||
// Read the ELF header.
|
||||
ElfW(Ehdr) elf_header;
|
||||
if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ElfW(Shdr) symtab, strtab;
|
||||
|
||||
// Consult a regular symbol table first.
|
||||
if (GetSectionHeaderByType(fd, elf_header.e_shnum, elf_header.e_shoff,
|
||||
SHT_SYMTAB, &symtab)) {
|
||||
if (!ReadFromOffsetExact(fd, &strtab, sizeof(strtab), elf_header.e_shoff +
|
||||
symtab.sh_link * sizeof(symtab))) {
|
||||
return false;
|
||||
}
|
||||
if (FindSymbol(pc, fd, out, out_size, base_address, &strtab, &symtab)) {
|
||||
return true; // Found the symbol in a regular symbol table.
|
||||
}
|
||||
}
|
||||
|
||||
// If the symbol is not found, then consult a dynamic symbol table.
|
||||
if (GetSectionHeaderByType(fd, elf_header.e_shnum, elf_header.e_shoff,
|
||||
SHT_DYNSYM, &symtab)) {
|
||||
if (!ReadFromOffsetExact(fd, &strtab, sizeof(strtab), elf_header.e_shoff +
|
||||
symtab.sh_link * sizeof(symtab))) {
|
||||
return false;
|
||||
}
|
||||
if (FindSymbol(pc, fd, out, out_size, base_address, &strtab, &symtab)) {
|
||||
return true; // Found the symbol in a dynamic symbol table.
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
// Thin wrapper around a file descriptor so that the file descriptor
|
||||
// gets closed for sure.
|
||||
struct FileDescriptor {
|
||||
const int fd_;
|
||||
explicit FileDescriptor(int fd) : fd_(fd) {}
|
||||
~FileDescriptor() {
|
||||
if (fd_ >= 0) {
|
||||
close(fd_);
|
||||
}
|
||||
}
|
||||
int get() { return fd_; }
|
||||
|
||||
private:
|
||||
FileDescriptor(const FileDescriptor &) = delete;
|
||||
void operator=(const FileDescriptor &) = delete;
|
||||
};
|
||||
|
||||
// Helper class for reading lines from file.
|
||||
//
|
||||
// Note: we don't use ProcMapsIterator since the object is big (it has
|
||||
// a 5k array member) and uses async-unsafe functions such as sscanf()
|
||||
// and snprintf().
|
||||
class LineReader {
|
||||
public:
|
||||
explicit LineReader(int fd, char *buf, size_t buf_len, size_t offset)
|
||||
: fd_(fd),
|
||||
buf_(buf),
|
||||
buf_len_(buf_len),
|
||||
offset_(offset),
|
||||
bol_(buf),
|
||||
eol_(buf),
|
||||
eod_(buf) {}
|
||||
|
||||
// Read '\n'-terminated line from file. On success, modify "bol"
|
||||
// and "eol", then return true. Otherwise, return false.
|
||||
//
|
||||
// Note: if the last line doesn't end with '\n', the line will be
|
||||
// dropped. It's an intentional behavior to make the code simple.
|
||||
bool ReadLine(const char **bol, const char **eol) {
|
||||
if (BufferIsEmpty()) { // First time.
|
||||
const ssize_t num_bytes = ReadFromOffset(fd_, buf_, buf_len_, offset_);
|
||||
if (num_bytes <= 0) { // EOF or error.
|
||||
return false;
|
||||
}
|
||||
offset_ += static_cast<size_t>(num_bytes);
|
||||
eod_ = buf_ + num_bytes;
|
||||
bol_ = buf_;
|
||||
} else {
|
||||
bol_ = eol_ + 1; // Advance to the next line in the buffer.
|
||||
SAFE_ASSERT(bol_ <= eod_); // "bol_" can point to "eod_".
|
||||
if (!HasCompleteLine()) {
|
||||
const auto incomplete_line_length = static_cast<size_t>(eod_ - bol_);
|
||||
// Move the trailing incomplete line to the beginning.
|
||||
memmove(buf_, bol_, incomplete_line_length);
|
||||
// Read text from file and append it.
|
||||
char * const append_pos = buf_ + incomplete_line_length;
|
||||
const size_t capacity_left = buf_len_ - incomplete_line_length;
|
||||
const ssize_t num_bytes =
|
||||
ReadFromOffset(fd_, append_pos, capacity_left, offset_);
|
||||
if (num_bytes <= 0) { // EOF or error.
|
||||
return false;
|
||||
}
|
||||
offset_ += static_cast<size_t>(num_bytes);
|
||||
eod_ = append_pos + num_bytes;
|
||||
bol_ = buf_;
|
||||
}
|
||||
}
|
||||
eol_ = FindLineFeed();
|
||||
if (eol_ == nullptr) { // '\n' not found. Malformed line.
|
||||
return false;
|
||||
}
|
||||
*eol_ = '\0'; // Replace '\n' with '\0'.
|
||||
|
||||
*bol = bol_;
|
||||
*eol = eol_;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Beginning of line.
|
||||
const char *bol() {
|
||||
return bol_;
|
||||
}
|
||||
|
||||
// End of line.
|
||||
const char *eol() {
|
||||
return eol_;
|
||||
}
|
||||
|
||||
private:
|
||||
LineReader(const LineReader &) = delete;
|
||||
void operator=(const LineReader &) = delete;
|
||||
|
||||
char *FindLineFeed() {
|
||||
return reinterpret_cast<char *>(memchr(bol_, '\n', static_cast<size_t>(eod_ - bol_)));
|
||||
}
|
||||
|
||||
bool BufferIsEmpty() {
|
||||
return buf_ == eod_;
|
||||
}
|
||||
|
||||
bool HasCompleteLine() {
|
||||
return !BufferIsEmpty() && FindLineFeed() != nullptr;
|
||||
}
|
||||
|
||||
const int fd_;
|
||||
char * const buf_;
|
||||
const size_t buf_len_;
|
||||
size_t offset_;
|
||||
char *bol_;
|
||||
char *eol_;
|
||||
const char *eod_; // End of data in "buf_".
|
||||
};
|
||||
} // namespace
|
||||
|
||||
// Place the hex number read from "start" into "*hex". The pointer to
|
||||
// the first non-hex character or "end" is returned.
|
||||
static char *GetHex(const char *start, const char *end, uint64_t *hex) {
|
||||
*hex = 0;
|
||||
const char *p;
|
||||
for (p = start; p < end; ++p) {
|
||||
int ch = *p;
|
||||
if ((ch >= '0' && ch <= '9') ||
|
||||
(ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) {
|
||||
*hex = (*hex << 4U) | (ch < 'A' ? static_cast<uint64_t>(ch - '0') : (ch & 0xF) + 9U);
|
||||
} else { // Encountered the first non-hex character.
|
||||
break;
|
||||
}
|
||||
}
|
||||
SAFE_ASSERT(p <= end);
|
||||
return const_cast<char *>(p);
|
||||
}
|
||||
|
||||
// Searches for the object file (from /proc/self/maps) that contains
|
||||
// the specified pc. If found, sets |start_address| to the start address
|
||||
// of where this object file is mapped in memory, sets the module base
|
||||
// address into |base_address|, copies the object file name into
|
||||
// |out_file_name|, and attempts to open the object file. If the object
|
||||
// file is opened successfully, returns the file descriptor. Otherwise,
|
||||
// returns -1. |out_file_name_size| is the size of the file name buffer
|
||||
// (including the null-terminator).
|
||||
static ATTRIBUTE_NOINLINE int
|
||||
OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc,
|
||||
uint64_t &start_address,
|
||||
uint64_t &base_address,
|
||||
char *out_file_name,
|
||||
size_t out_file_name_size) {
|
||||
int object_fd;
|
||||
|
||||
int maps_fd;
|
||||
NO_INTR(maps_fd = open("/proc/self/maps", O_RDONLY));
|
||||
FileDescriptor wrapped_maps_fd(maps_fd);
|
||||
if (wrapped_maps_fd.get() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mem_fd;
|
||||
NO_INTR(mem_fd = open("/proc/self/mem", O_RDONLY));
|
||||
FileDescriptor wrapped_mem_fd(mem_fd);
|
||||
if (wrapped_mem_fd.get() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Iterate over maps and look for the map containing the pc. Then
|
||||
// look into the symbol tables inside.
|
||||
char buf[1024]; // Big enough for line of sane /proc/self/maps
|
||||
unsigned num_maps = 0;
|
||||
LineReader reader(wrapped_maps_fd.get(), buf, sizeof(buf), 0);
|
||||
while (true) {
|
||||
num_maps++;
|
||||
const char *cursor;
|
||||
const char *eol;
|
||||
if (!reader.ReadLine(&cursor, &eol)) { // EOF or malformed line.
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Start parsing line in /proc/self/maps. Here is an example:
|
||||
//
|
||||
// 08048000-0804c000 r-xp 00000000 08:01 2142121 /bin/cat
|
||||
//
|
||||
// We want start address (08048000), end address (0804c000), flags
|
||||
// (r-xp) and file name (/bin/cat).
|
||||
|
||||
// Read start address.
|
||||
cursor = GetHex(cursor, eol, &start_address);
|
||||
if (cursor == eol || *cursor != '-') {
|
||||
return -1; // Malformed line.
|
||||
}
|
||||
++cursor; // Skip '-'.
|
||||
|
||||
// Read end address.
|
||||
uint64_t end_address;
|
||||
cursor = GetHex(cursor, eol, &end_address);
|
||||
if (cursor == eol || *cursor != ' ') {
|
||||
return -1; // Malformed line.
|
||||
}
|
||||
++cursor; // Skip ' '.
|
||||
|
||||
// Read flags. Skip flags until we encounter a space or eol.
|
||||
const char * const flags_start = cursor;
|
||||
while (cursor < eol && *cursor != ' ') {
|
||||
++cursor;
|
||||
}
|
||||
// We expect at least four letters for flags (ex. "r-xp").
|
||||
if (cursor == eol || cursor < flags_start + 4) {
|
||||
return -1; // Malformed line.
|
||||
}
|
||||
|
||||
// Determine the base address by reading ELF headers in process memory.
|
||||
ElfW(Ehdr) ehdr;
|
||||
// Skip non-readable maps.
|
||||
if (flags_start[0] == 'r' &&
|
||||
ReadFromOffsetExact(mem_fd, &ehdr, sizeof(ElfW(Ehdr)), start_address) &&
|
||||
memcmp(ehdr.e_ident, ELFMAG, SELFMAG) == 0) {
|
||||
switch (ehdr.e_type) {
|
||||
case ET_EXEC:
|
||||
base_address = 0;
|
||||
break;
|
||||
case ET_DYN:
|
||||
// Find the segment containing file offset 0. This will correspond
|
||||
// to the ELF header that we just read. Normally this will have
|
||||
// virtual address 0, but this is not guaranteed. We must subtract
|
||||
// the virtual address from the address where the ELF header was
|
||||
// mapped to get the base address.
|
||||
//
|
||||
// If we fail to find a segment for file offset 0, use the address
|
||||
// of the ELF header as the base address.
|
||||
base_address = start_address;
|
||||
for (unsigned i = 0; i != ehdr.e_phnum; ++i) {
|
||||
ElfW(Phdr) phdr;
|
||||
if (ReadFromOffsetExact(
|
||||
mem_fd, &phdr, sizeof(phdr),
|
||||
start_address + ehdr.e_phoff + i * sizeof(phdr)) &&
|
||||
phdr.p_type == PT_LOAD && phdr.p_offset == 0) {
|
||||
base_address = start_address - phdr.p_vaddr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// ET_REL or ET_CORE. These aren't directly executable, so they don't
|
||||
// affect the base address.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check start and end addresses.
|
||||
if (!(start_address <= pc && pc < end_address)) {
|
||||
continue; // We skip this map. PC isn't in this map.
|
||||
}
|
||||
|
||||
// Check flags. We are only interested in "r*x" maps.
|
||||
if (flags_start[0] != 'r' || flags_start[2] != 'x') {
|
||||
continue; // We skip this map.
|
||||
}
|
||||
++cursor; // Skip ' '.
|
||||
|
||||
// Read file offset.
|
||||
uint64_t file_offset;
|
||||
cursor = GetHex(cursor, eol, &file_offset);
|
||||
if (cursor == eol || *cursor != ' ') {
|
||||
return -1; // Malformed line.
|
||||
}
|
||||
++cursor; // Skip ' '.
|
||||
|
||||
// Skip to file name. "cursor" now points to dev. We need to
|
||||
// skip at least two spaces for dev and inode.
|
||||
int num_spaces = 0;
|
||||
while (cursor < eol) {
|
||||
if (*cursor == ' ') {
|
||||
++num_spaces;
|
||||
} else if (num_spaces >= 2) {
|
||||
// The first non-space character after skipping two spaces
|
||||
// is the beginning of the file name.
|
||||
break;
|
||||
}
|
||||
++cursor;
|
||||
}
|
||||
if (cursor == eol) {
|
||||
return -1; // Malformed line.
|
||||
}
|
||||
|
||||
// Finally, "cursor" now points to file name of our interest.
|
||||
NO_INTR(object_fd = open(cursor, O_RDONLY));
|
||||
if (object_fd < 0) {
|
||||
// Failed to open object file. Copy the object file name to
|
||||
// |out_file_name|.
|
||||
strncpy(out_file_name, cursor, out_file_name_size);
|
||||
// Making sure |out_file_name| is always null-terminated.
|
||||
out_file_name[out_file_name_size - 1] = '\0';
|
||||
return -1;
|
||||
}
|
||||
return object_fd;
|
||||
}
|
||||
}
|
||||
|
||||
// POSIX doesn't define any async-signal safe function for converting
|
||||
// an integer to ASCII. We'll have to define our own version.
|
||||
// itoa_r() converts an (unsigned) integer to ASCII. It returns "buf", if the
|
||||
// conversion was successful or nullptr otherwise. It never writes more than
|
||||
// "sz" bytes. Output will be truncated as needed, and a NUL character is always
|
||||
// appended.
|
||||
// NOTE: code from sandbox/linux/seccomp-bpf/demo.cc.
|
||||
static char *itoa_r(uintptr_t i, char *buf, size_t sz, unsigned base, size_t padding) {
|
||||
// Make sure we can write at least one NUL byte.
|
||||
size_t n = 1;
|
||||
if (n > sz) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (base < 2 || base > 16) {
|
||||
buf[0] = '\000';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char *start = buf;
|
||||
|
||||
// Loop until we have converted the entire number. Output at least one
|
||||
// character (i.e. '0').
|
||||
char *ptr = start;
|
||||
do {
|
||||
// Make sure there is still enough space left in our output buffer.
|
||||
if (++n > sz) {
|
||||
buf[0] = '\000';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Output the next digit.
|
||||
*ptr++ = "0123456789abcdef"[i % base];
|
||||
i /= base;
|
||||
|
||||
if (padding > 0) {
|
||||
padding--;
|
||||
}
|
||||
} while (i > 0 || padding > 0);
|
||||
|
||||
// Terminate the output with a NUL character.
|
||||
*ptr = '\000';
|
||||
|
||||
// Conversion to ASCII actually resulted in the digits being in reverse
|
||||
// order. We can't easily generate them in forward order, as we can't tell
|
||||
// the number of characters needed until we are done converting.
|
||||
// So, now, we reverse the string (except for the possible "-" sign).
|
||||
while (--ptr > start) {
|
||||
char ch = *ptr;
|
||||
*ptr = *start;
|
||||
*start++ = ch;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Safely appends string |source| to string |dest|. Never writes past the
|
||||
// buffer size |dest_size| and guarantees that |dest| is null-terminated.
|
||||
static void SafeAppendString(const char* source, char* dest, size_t dest_size) {
|
||||
size_t dest_string_length = strlen(dest);
|
||||
SAFE_ASSERT(dest_string_length < dest_size);
|
||||
dest += dest_string_length;
|
||||
dest_size -= dest_string_length;
|
||||
strncpy(dest, source, dest_size);
|
||||
// Making sure |dest| is always null-terminated.
|
||||
dest[dest_size - 1] = '\0';
|
||||
}
|
||||
|
||||
// Converts a 64-bit value into a hex string, and safely appends it to |dest|.
|
||||
// Never writes past the buffer size |dest_size| and guarantees that |dest| is
|
||||
// null-terminated.
|
||||
static void SafeAppendHexNumber(uint64_t value, char* dest, size_t dest_size) {
|
||||
// 64-bit numbers in hex can have up to 16 digits.
|
||||
char buf[17] = {'\0'};
|
||||
SafeAppendString(itoa_r(value, buf, sizeof(buf), 16, 0), dest, dest_size);
|
||||
}
|
||||
|
||||
// The implementation of our symbolization routine. If it
|
||||
// successfully finds the symbol containing "pc" and obtains the
|
||||
// symbol name, returns true and write the symbol name to "out".
|
||||
// Otherwise, returns false. If Callback function is installed via
|
||||
// InstallSymbolizeCallback(), the function is also called in this function,
|
||||
// and "out" is used as its output.
|
||||
// To keep stack consumption low, we would like this function to not
|
||||
// get inlined.
|
||||
static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
|
||||
size_t out_size) {
|
||||
auto pc0 = reinterpret_cast<uintptr_t>(pc);
|
||||
uint64_t start_address = 0;
|
||||
uint64_t base_address = 0;
|
||||
int object_fd = -1;
|
||||
|
||||
if (out_size < 1) {
|
||||
return false;
|
||||
}
|
||||
out[0] = '\0';
|
||||
SafeAppendString("(", out, out_size);
|
||||
|
||||
if (g_symbolize_open_object_file_callback) {
|
||||
object_fd = g_symbolize_open_object_file_callback(pc0, start_address,
|
||||
base_address, out + 1,
|
||||
out_size - 1);
|
||||
} else {
|
||||
object_fd = OpenObjectFileContainingPcAndGetStartAddress(pc0, start_address,
|
||||
base_address,
|
||||
out + 1,
|
||||
out_size - 1);
|
||||
}
|
||||
|
||||
FileDescriptor wrapped_object_fd(object_fd);
|
||||
|
||||
#if defined(PRINT_UNSYMBOLIZED_STACK_TRACES)
|
||||
{
|
||||
#else
|
||||
// Check whether a file name was returned.
|
||||
if (object_fd < 0) {
|
||||
#endif
|
||||
if (out[1]) {
|
||||
// The object file containing PC was determined successfully however the
|
||||
// object file was not opened successfully. This is still considered
|
||||
// success because the object file name and offset are known and tools
|
||||
// like asan_symbolize.py can be used for the symbolization.
|
||||
out[out_size - 1] = '\0'; // Making sure |out| is always null-terminated.
|
||||
SafeAppendString("+0x", out, out_size);
|
||||
SafeAppendHexNumber(pc0 - base_address, out, out_size);
|
||||
SafeAppendString(")", out, out_size);
|
||||
return true;
|
||||
}
|
||||
// Failed to determine the object file containing PC. Bail out.
|
||||
return false;
|
||||
}
|
||||
int elf_type = FileGetElfType(wrapped_object_fd.get());
|
||||
if (elf_type == -1) {
|
||||
return false;
|
||||
}
|
||||
if (g_symbolize_callback) {
|
||||
// Run the call back if it's installed.
|
||||
// Note: relocation (and much of the rest of this code) will be
|
||||
// wrong for prelinked shared libraries and PIE executables.
|
||||
uint64_t relocation = (elf_type == ET_DYN) ? start_address : 0;
|
||||
int num_bytes_written = g_symbolize_callback(wrapped_object_fd.get(),
|
||||
pc, out, out_size,
|
||||
relocation);
|
||||
if (num_bytes_written > 0) {
|
||||
out += static_cast<size_t>(num_bytes_written);
|
||||
out_size -= static_cast<size_t>(num_bytes_written);
|
||||
}
|
||||
}
|
||||
if (!GetSymbolFromObjectFile(wrapped_object_fd.get(), pc0,
|
||||
out, out_size, base_address)) {
|
||||
if (out[1] && !g_symbolize_callback) {
|
||||
// The object file containing PC was opened successfully however the
|
||||
// symbol was not found. The object may have been stripped. This is still
|
||||
// considered success because the object file name and offset are known
|
||||
// and tools like asan_symbolize.py can be used for the symbolization.
|
||||
out[out_size - 1] = '\0'; // Making sure |out| is always null-terminated.
|
||||
SafeAppendString("+0x", out, out_size);
|
||||
SafeAppendHexNumber(pc0 - base_address, out, out_size);
|
||||
SafeAppendString(")", out, out_size);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Symbolization succeeded. Now we try to demangle the symbol.
|
||||
DemangleInplace(out, out_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#elif defined(GLOG_OS_MACOSX) && defined(HAVE_DLADDR)
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <cstring>
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
|
||||
size_t out_size) {
|
||||
Dl_info info;
|
||||
if (dladdr(pc, &info)) {
|
||||
if (info.dli_sname) {
|
||||
if (strlen(info.dli_sname) < out_size) {
|
||||
strcpy(out, info.dli_sname);
|
||||
// Symbolization succeeded. Now we try to demangle the symbol.
|
||||
DemangleInplace(out, out_size);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#elif defined(GLOG_OS_WINDOWS) || defined(GLOG_OS_CYGWIN)
|
||||
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "dbghelp")
|
||||
#endif
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
class SymInitializer {
|
||||
public:
|
||||
HANDLE process;
|
||||
bool ready;
|
||||
SymInitializer() : process(nullptr), ready(false) {
|
||||
// Initialize the symbol handler.
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680344(v=vs.85).aspx
|
||||
process = GetCurrentProcess();
|
||||
// Defer symbol loading.
|
||||
// We do not request undecorated symbols with SYMOPT_UNDNAME
|
||||
// because the mangling library calls UnDecorateSymbolName.
|
||||
SymSetOptions(SYMOPT_DEFERRED_LOADS);
|
||||
if (SymInitialize(process, nullptr, true)) {
|
||||
ready = true;
|
||||
}
|
||||
}
|
||||
~SymInitializer() {
|
||||
SymCleanup(process);
|
||||
// We do not need to close `HANDLE process` because it's a "pseudo handle."
|
||||
}
|
||||
private:
|
||||
SymInitializer(const SymInitializer&);
|
||||
SymInitializer& operator=(const SymInitializer&);
|
||||
};
|
||||
|
||||
static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
|
||||
size_t out_size) {
|
||||
const static SymInitializer symInitializer;
|
||||
if (!symInitializer.ready) {
|
||||
return false;
|
||||
}
|
||||
// Resolve symbol information from address.
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680578(v=vs.85).aspx
|
||||
char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
|
||||
SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(buf);
|
||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
symbol->MaxNameLen = MAX_SYM_NAME;
|
||||
// We use the ANSI version to ensure the string type is always `char *`.
|
||||
// This could break if a symbol has Unicode in it.
|
||||
BOOL ret = SymFromAddr(symInitializer.process,
|
||||
reinterpret_cast<DWORD64>(pc), 0, symbol);
|
||||
if (ret == 1 && static_cast<ssize_t>(symbol->NameLen) < out_size) {
|
||||
// `NameLen` does not include the null terminating character.
|
||||
strncpy(out, symbol->Name, static_cast<size_t>(symbol->NameLen) + 1);
|
||||
out[static_cast<size_t>(symbol->NameLen)] = '\0';
|
||||
// Symbolization succeeded. Now we try to demangle the symbol.
|
||||
DemangleInplace(out, out_size);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#else
|
||||
# error BUG: HAVE_SYMBOLIZE was wrongly set
|
||||
#endif
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
bool Symbolize(void *pc, char *out, size_t out_size) {
|
||||
return SymbolizeAndDemangle(pc, out, out_size);
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#else /* HAVE_SYMBOLIZE */
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// TODO: Support other environments.
|
||||
bool Symbolize(void* /*pc*/, char* /*out*/, size_t /*out_size*/) {
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif
|
||||
152
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/symbolize.h
vendored
Normal file
152
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/symbolize.h
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
// Copyright (c) 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Satoru Takabayashi
|
||||
//
|
||||
// This library provides Symbolize() function that symbolizes program
|
||||
// counters to their corresponding symbol names on linux platforms.
|
||||
// This library has a minimal implementation of an ELF symbol table
|
||||
// reader (i.e. it doesn't depend on libelf, etc.).
|
||||
//
|
||||
// The algorithm used in Symbolize() is as follows.
|
||||
//
|
||||
// 1. Go through a list of maps in /proc/self/maps and find the map
|
||||
// containing the program counter.
|
||||
//
|
||||
// 2. Open the mapped file and find a regular symbol table inside.
|
||||
// Iterate over symbols in the symbol table and look for the symbol
|
||||
// containing the program counter. If such a symbol is found,
|
||||
// obtain the symbol name, and demangle the symbol if possible.
|
||||
// If the symbol isn't found in the regular symbol table (binary is
|
||||
// stripped), try the same thing with a dynamic symbol table.
|
||||
//
|
||||
// Note that Symbolize() is originally implemented to be used in
|
||||
// FailureSignalHandler() in base/google.cc. Hence it doesn't use
|
||||
// malloc() and other unsafe operations. It should be both
|
||||
// thread-safe and async-signal-safe.
|
||||
|
||||
#ifndef BASE_SYMBOLIZE_H_
|
||||
#define BASE_SYMBOLIZE_H_
|
||||
|
||||
#include "utilities.h"
|
||||
#include "config.h"
|
||||
#include <glog/logging.h>
|
||||
|
||||
#ifdef HAVE_SYMBOLIZE
|
||||
|
||||
#if defined(__ELF__) // defined by gcc
|
||||
#if defined(__OpenBSD__)
|
||||
#include <sys/exec_elf.h>
|
||||
#else
|
||||
#include <elf.h>
|
||||
#endif
|
||||
|
||||
#if !defined(ANDROID)
|
||||
#include <link.h> // For ElfW() macro.
|
||||
#endif
|
||||
|
||||
// For systems where SIZEOF_VOID_P is not defined, determine it
|
||||
// based on __LP64__ (defined by gcc on 64-bit systems)
|
||||
#if !defined(SIZEOF_VOID_P)
|
||||
# if defined(__LP64__)
|
||||
# define SIZEOF_VOID_P 8
|
||||
# else
|
||||
# define SIZEOF_VOID_P 4
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// If there is no ElfW macro, let's define it by ourself.
|
||||
#ifndef ElfW
|
||||
# if SIZEOF_VOID_P == 4
|
||||
# define ElfW(type) Elf32_##type
|
||||
# elif SIZEOF_VOID_P == 8
|
||||
# define ElfW(type) Elf64_##type
|
||||
# else
|
||||
# error "Unknown sizeof(void *)"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Gets the section header for the given name, if it exists. Returns true on
|
||||
// success. Otherwise, returns false.
|
||||
bool GetSectionHeaderByName(int fd, const char *name, size_t name_len,
|
||||
ElfW(Shdr) *out);
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif /* __ELF__ */
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Restrictions on the callbacks that follow:
|
||||
// - The callbacks must not use heaps but only use stacks.
|
||||
// - The callbacks must be async-signal-safe.
|
||||
|
||||
// Installs a callback function, which will be called right before a symbol name
|
||||
// is printed. The callback is intended to be used for showing a file name and a
|
||||
// line number preceding a symbol name.
|
||||
// "fd" is a file descriptor of the object file containing the program
|
||||
// counter "pc". The callback function should write output to "out"
|
||||
// and return the size of the output written. On error, the callback
|
||||
// function should return -1.
|
||||
using SymbolizeCallback = int (*)(int, void *, char *, size_t, uint64_t);
|
||||
GLOG_EXPORT
|
||||
void InstallSymbolizeCallback(SymbolizeCallback callback);
|
||||
|
||||
// Installs a callback function, which will be called instead of
|
||||
// OpenObjectFileContainingPcAndGetStartAddress. The callback is expected
|
||||
// to searches for the object file (from /proc/self/maps) that contains
|
||||
// the specified pc. If found, sets |start_address| to the start address
|
||||
// of where this object file is mapped in memory, sets the module base
|
||||
// address into |base_address|, copies the object file name into
|
||||
// |out_file_name|, and attempts to open the object file. If the object
|
||||
// file is opened successfully, returns the file descriptor. Otherwise,
|
||||
// returns -1. |out_file_name_size| is the size of the file name buffer
|
||||
// (including the null-terminator).
|
||||
using SymbolizeOpenObjectFileCallback = int (*)(uint64_t, uint64_t &,
|
||||
uint64_t &, char *, size_t);
|
||||
void InstallSymbolizeOpenObjectFileCallback(
|
||||
SymbolizeOpenObjectFileCallback callback);
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
// Symbolizes a program counter. On success, returns true and write the
|
||||
// symbol name to "out". The symbol name is demangled if possible
|
||||
// (supports symbols generated by GCC 3.x or newer). Otherwise,
|
||||
// returns false.
|
||||
GLOG_EXPORT bool Symbolize(void* pc, char* out, size_t out_size);
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif // BASE_SYMBOLIZE_H_
|
||||
400
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/utilities.cc
vendored
Normal file
400
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/utilities.cc
vendored
Normal file
@@ -0,0 +1,400 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Shinichiro Hamaji
|
||||
|
||||
#include "config.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <csignal>
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#include <ctime>
|
||||
#if defined(HAVE_SYSCALL_H)
|
||||
#include <syscall.h> // for syscall()
|
||||
#elif defined(HAVE_SYS_SYSCALL_H)
|
||||
#include <sys/syscall.h> // for syscall()
|
||||
#endif
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
# include <syslog.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h> // For geteuid.
|
||||
#endif
|
||||
#ifdef HAVE_PWD_H
|
||||
# include <pwd.h>
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#include "base/googleinit.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
static const char* g_program_invocation_short_name = nullptr;
|
||||
|
||||
bool IsGoogleLoggingInitialized() {
|
||||
return g_program_invocation_short_name != nullptr;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
// The following APIs are all internal.
|
||||
#ifdef HAVE_STACKTRACE
|
||||
|
||||
#include "stacktrace.h"
|
||||
#include "symbolize.h"
|
||||
#include "base/commandlineflags.h"
|
||||
|
||||
GLOG_DEFINE_bool(symbolize_stacktrace, true,
|
||||
"Symbolize the stack trace in the tombstone");
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
using DebugWriter = void(const char*, void*);
|
||||
|
||||
// The %p field width for printf() functions is two characters per byte.
|
||||
// For some environments, add two extra bytes for the leading "0x".
|
||||
static const int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*);
|
||||
|
||||
static void DebugWriteToStderr(const char* data, void *) {
|
||||
// This one is signal-safe.
|
||||
if (write(STDERR_FILENO, data, strlen(data)) < 0) {
|
||||
// Ignore errors.
|
||||
}
|
||||
#if defined(__ANDROID__)
|
||||
// ANDROID_LOG_FATAL as fatal error occurred and now is dumping call stack.
|
||||
__android_log_write(ANDROID_LOG_FATAL,
|
||||
glog_internal_namespace_::ProgramInvocationShortName(),
|
||||
data);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void DebugWriteToString(const char* data, void *arg) {
|
||||
reinterpret_cast<string*>(arg)->append(data);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYMBOLIZE
|
||||
// Print a program counter and its symbol name.
|
||||
static void DumpPCAndSymbol(DebugWriter *writerfn, void *arg, void *pc,
|
||||
const char * const prefix) {
|
||||
char tmp[1024];
|
||||
const char *symbol = "(unknown)";
|
||||
// Symbolizes the previous address of pc because pc may be in the
|
||||
// next function. The overrun happens when the function ends with
|
||||
// a call to a function annotated noreturn (e.g. CHECK).
|
||||
if (Symbolize(reinterpret_cast<char *>(pc) - 1, tmp, sizeof(tmp))) {
|
||||
symbol = tmp;
|
||||
}
|
||||
char buf[1024];
|
||||
snprintf(buf, sizeof(buf), "%s@ %*p %s\n",
|
||||
prefix, kPrintfPointerFieldWidth, pc, symbol);
|
||||
writerfn(buf, arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void DumpPC(DebugWriter *writerfn, void *arg, void *pc,
|
||||
const char * const prefix) {
|
||||
char buf[100];
|
||||
snprintf(buf, sizeof(buf), "%s@ %*p\n",
|
||||
prefix, kPrintfPointerFieldWidth, pc);
|
||||
writerfn(buf, arg);
|
||||
}
|
||||
|
||||
// Dump current stack trace as directed by writerfn
|
||||
static void DumpStackTrace(int skip_count, DebugWriter *writerfn, void *arg) {
|
||||
// Print stack trace
|
||||
void* stack[32];
|
||||
int depth = GetStackTrace(stack, ARRAYSIZE(stack), skip_count+1);
|
||||
for (int i = 0; i < depth; i++) {
|
||||
#if defined(HAVE_SYMBOLIZE)
|
||||
if (FLAGS_symbolize_stacktrace) {
|
||||
DumpPCAndSymbol(writerfn, arg, stack[i], " ");
|
||||
} else {
|
||||
DumpPC(writerfn, arg, stack[i], " ");
|
||||
}
|
||||
#else
|
||||
DumpPC(writerfn, arg, stack[i], " ");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
__attribute__((noreturn))
|
||||
#endif
|
||||
static void
|
||||
DumpStackTraceAndExit() {
|
||||
DumpStackTrace(1, DebugWriteToStderr, nullptr);
|
||||
|
||||
// TODO(hamaji): Use signal instead of sigaction?
|
||||
if (IsFailureSignalHandlerInstalled()) {
|
||||
// Set the default signal handler for SIGABRT, to avoid invoking our
|
||||
// own signal handler installed by InstallFailureSignalHandler().
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction sig_action;
|
||||
memset(&sig_action, 0, sizeof(sig_action));
|
||||
sigemptyset(&sig_action.sa_mask);
|
||||
sig_action.sa_handler = SIG_DFL;
|
||||
sigaction(SIGABRT, &sig_action, nullptr);
|
||||
#elif defined(GLOG_OS_WINDOWS)
|
||||
signal(SIGABRT, SIG_DFL);
|
||||
#endif // HAVE_SIGACTION
|
||||
}
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
#endif // HAVE_STACKTRACE
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
namespace glog_internal_namespace_ {
|
||||
|
||||
const char* ProgramInvocationShortName() {
|
||||
if (g_program_invocation_short_name != nullptr) {
|
||||
return g_program_invocation_short_name;
|
||||
} else {
|
||||
// TODO(hamaji): Use /proc/self/cmdline and so?
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GLOG_OS_WINDOWS
|
||||
struct timeval {
|
||||
long tv_sec, tv_usec;
|
||||
};
|
||||
|
||||
// Based on: http://www.google.com/codesearch/p?hl=en#dR3YEbitojA/os_win32.c&q=GetSystemTimeAsFileTime%20license:bsd
|
||||
// See COPYING for copyright information.
|
||||
static int gettimeofday(struct timeval *tv, void* /*tz*/) {
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wlong-long"
|
||||
#endif
|
||||
#define EPOCHFILETIME (116444736000000000ULL)
|
||||
FILETIME ft;
|
||||
ULARGE_INTEGER li;
|
||||
uint64 tt;
|
||||
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
li.LowPart = ft.dwLowDateTime;
|
||||
li.HighPart = ft.dwHighDateTime;
|
||||
tt = (li.QuadPart - EPOCHFILETIME) / 10;
|
||||
tv->tv_sec = tt / 1000000;
|
||||
tv->tv_usec = tt % 1000000;
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int64 CycleClock_Now() {
|
||||
// TODO(hamaji): temporary impementation - it might be too slow.
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
return static_cast<int64>(tv.tv_sec) * 1000000 + tv.tv_usec;
|
||||
}
|
||||
|
||||
int64 UsecToCycles(int64 usec) {
|
||||
return usec;
|
||||
}
|
||||
|
||||
WallTime WallTime_Now() {
|
||||
// Now, cycle clock is retuning microseconds since the epoch.
|
||||
return CycleClock_Now() * 0.000001;
|
||||
}
|
||||
|
||||
static int32 g_main_thread_pid = getpid();
|
||||
int32 GetMainThreadPid() {
|
||||
return g_main_thread_pid;
|
||||
}
|
||||
|
||||
bool PidHasChanged() {
|
||||
int32 pid = getpid();
|
||||
if (g_main_thread_pid == pid) {
|
||||
return false;
|
||||
}
|
||||
g_main_thread_pid = pid;
|
||||
return true;
|
||||
}
|
||||
|
||||
pid_t GetTID() {
|
||||
// On Linux and MacOSX, we try to use gettid().
|
||||
#if defined GLOG_OS_LINUX || defined GLOG_OS_MACOSX
|
||||
#ifndef __NR_gettid
|
||||
#ifdef GLOG_OS_MACOSX
|
||||
#define __NR_gettid SYS_gettid
|
||||
#elif ! defined __i386__
|
||||
#error "Must define __NR_gettid for non-x86 platforms"
|
||||
#else
|
||||
#define __NR_gettid 224
|
||||
#endif
|
||||
#endif
|
||||
static bool lacks_gettid = false;
|
||||
if (!lacks_gettid) {
|
||||
#if (defined(GLOG_OS_MACOSX) && defined(HAVE_PTHREAD_THREADID_NP))
|
||||
uint64_t tid64;
|
||||
const int error = pthread_threadid_np(nullptr, &tid64);
|
||||
pid_t tid = error ? -1 : static_cast<pid_t>(tid64);
|
||||
#else
|
||||
auto tid = static_cast<pid_t>(syscall(__NR_gettid));
|
||||
#endif
|
||||
if (tid != -1) {
|
||||
return tid;
|
||||
}
|
||||
// Technically, this variable has to be volatile, but there is a small
|
||||
// performance penalty in accessing volatile variables and there should
|
||||
// not be any serious adverse effect if a thread does not immediately see
|
||||
// the value change to "true".
|
||||
lacks_gettid = true;
|
||||
}
|
||||
#endif // GLOG_OS_LINUX || GLOG_OS_MACOSX
|
||||
|
||||
// If gettid() could not be used, we use one of the following.
|
||||
#if defined GLOG_OS_LINUX
|
||||
return getpid(); // Linux: getpid returns thread ID when gettid is absent
|
||||
#elif defined GLOG_OS_WINDOWS && !defined GLOG_OS_CYGWIN
|
||||
return static_cast<pid_t>(GetCurrentThreadId());
|
||||
#elif defined(HAVE_PTHREAD)
|
||||
// If none of the techniques above worked, we use pthread_self().
|
||||
return (pid_t)(uintptr_t)pthread_self();
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* const_basename(const char* filepath) {
|
||||
const char* base = strrchr(filepath, '/');
|
||||
#ifdef GLOG_OS_WINDOWS // Look for either path separator in Windows
|
||||
if (!base)
|
||||
base = strrchr(filepath, '\\');
|
||||
#endif
|
||||
return base ? (base+1) : filepath;
|
||||
}
|
||||
|
||||
static string g_my_user_name;
|
||||
const string& MyUserName() {
|
||||
return g_my_user_name;
|
||||
}
|
||||
static void MyUserNameInitializer() {
|
||||
// TODO(hamaji): Probably this is not portable.
|
||||
#if defined(GLOG_OS_WINDOWS)
|
||||
const char* user = getenv("USERNAME");
|
||||
#else
|
||||
const char* user = getenv("USER");
|
||||
#endif
|
||||
if (user != nullptr) {
|
||||
g_my_user_name = user;
|
||||
} else {
|
||||
#if defined(HAVE_PWD_H) && defined(HAVE_UNISTD_H)
|
||||
struct passwd pwd;
|
||||
struct passwd* result = nullptr;
|
||||
char buffer[1024] = {'\0'};
|
||||
uid_t uid = geteuid();
|
||||
int pwuid_res = getpwuid_r(uid, &pwd, buffer, sizeof(buffer), &result);
|
||||
if (pwuid_res == 0 && result) {
|
||||
g_my_user_name = pwd.pw_name;
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "uid%d", uid);
|
||||
g_my_user_name = buffer;
|
||||
}
|
||||
#endif
|
||||
if (g_my_user_name.empty()) {
|
||||
g_my_user_name = "invalid-user";
|
||||
}
|
||||
}
|
||||
}
|
||||
REGISTER_MODULE_INITIALIZER(utilities, MyUserNameInitializer())
|
||||
|
||||
#ifdef HAVE_STACKTRACE
|
||||
void DumpStackTraceToString(string* stacktrace) {
|
||||
DumpStackTrace(1, DebugWriteToString, stacktrace);
|
||||
}
|
||||
#endif
|
||||
|
||||
// We use an atomic operation to prevent problems with calling CrashReason
|
||||
// from inside the Mutex implementation (potentially through RAW_CHECK).
|
||||
static const CrashReason* g_reason = nullptr;
|
||||
|
||||
void SetCrashReason(const CrashReason* r) {
|
||||
sync_val_compare_and_swap(&g_reason,
|
||||
reinterpret_cast<const CrashReason*>(0),
|
||||
r);
|
||||
}
|
||||
|
||||
void InitGoogleLoggingUtilities(const char* argv0) {
|
||||
CHECK(!IsGoogleLoggingInitialized())
|
||||
<< "You called InitGoogleLogging() twice!";
|
||||
const char* slash = strrchr(argv0, '/');
|
||||
#ifdef GLOG_OS_WINDOWS
|
||||
if (!slash) slash = strrchr(argv0, '\\');
|
||||
#endif
|
||||
g_program_invocation_short_name = slash ? slash + 1 : argv0;
|
||||
|
||||
#ifdef HAVE_STACKTRACE
|
||||
InstallFailureFunction(&DumpStackTraceAndExit);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShutdownGoogleLoggingUtilities() {
|
||||
CHECK(IsGoogleLoggingInitialized())
|
||||
<< "You called ShutdownGoogleLogging() without calling InitGoogleLogging() first!";
|
||||
g_program_invocation_short_name = nullptr;
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
closelog();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace glog_internal_namespace_
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
// Make an implementation of stacktrace compiled.
|
||||
#ifdef STACKTRACE_H
|
||||
# include STACKTRACE_H
|
||||
# if 0
|
||||
// For include scanners which can't handle macro expansions.
|
||||
# include "stacktrace_libunwind-inl.h"
|
||||
# include "stacktrace_x86-inl.h"
|
||||
# include "stacktrace_x86_64-inl.h"
|
||||
# include "stacktrace_powerpc-inl.h"
|
||||
# include "stacktrace_generic-inl.h"
|
||||
# endif
|
||||
#endif
|
||||
217
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/utilities.h
vendored
Normal file
217
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/utilities.h
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
// Copyright (c) 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Shinichiro Hamaji
|
||||
//
|
||||
// Define utilties for glog internal usage.
|
||||
|
||||
#ifndef UTILITIES_H__
|
||||
#define UTILITIES_H__
|
||||
|
||||
// printf macros for size_t, in the style of inttypes.h
|
||||
#ifdef _LP64
|
||||
#define __PRIS_PREFIX "z"
|
||||
#else
|
||||
#define __PRIS_PREFIX
|
||||
#endif
|
||||
|
||||
// Use these macros after a % in a printf format string
|
||||
// to get correct 32/64 bit behavior, like this:
|
||||
// size_t size = records.size();
|
||||
// printf("%"PRIuS"\n", size);
|
||||
|
||||
#define PRIdS __PRIS_PREFIX "d"
|
||||
#define PRIxS __PRIS_PREFIX "x"
|
||||
#define PRIuS __PRIS_PREFIX "u"
|
||||
#define PRIXS __PRIS_PREFIX "X"
|
||||
#define PRIoS __PRIS_PREFIX "o"
|
||||
|
||||
#include "base/mutex.h" // This must go first so we get _XOPEN_SOURCE
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#if defined(GLOG_OS_WINDOWS)
|
||||
# include "port.h"
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
|
||||
// There are three different ways we can try to get the stack trace:
|
||||
//
|
||||
// 1) The libunwind library. This is still in development, and as a
|
||||
// separate library adds a new dependency, but doesn't need a frame
|
||||
// pointer. It also doesn't call malloc.
|
||||
//
|
||||
// 2) Our hand-coded stack-unwinder. This depends on a certain stack
|
||||
// layout, which is used by gcc (and those systems using a
|
||||
// gcc-compatible ABI) on x86 systems, at least since gcc 2.95.
|
||||
// It uses the frame pointer to do its work.
|
||||
//
|
||||
// 3) The gdb unwinder -- also the one used by the c++ exception code.
|
||||
// It's obviously well-tested, but has a fatal flaw: it can call
|
||||
// malloc() from the unwinder. This is a problem because we're
|
||||
// trying to use the unwinder to instrument malloc().
|
||||
//
|
||||
// 4) The Windows API CaptureStackTrace.
|
||||
//
|
||||
// Note: if you add a new implementation here, make sure it works
|
||||
// correctly when GetStackTrace() is called with max_depth == 0.
|
||||
// Some code may do that.
|
||||
|
||||
#if defined(HAVE_LIB_UNWIND)
|
||||
# define STACKTRACE_H "stacktrace_libunwind-inl.h"
|
||||
#elif defined(HAVE__UNWIND_BACKTRACE) && defined(HAVE__UNWIND_GETIP)
|
||||
# define STACKTRACE_H "stacktrace_unwind-inl.h"
|
||||
#elif !defined(NO_FRAME_POINTER)
|
||||
# if defined(__i386__) && __GNUC__ >= 2
|
||||
# define STACKTRACE_H "stacktrace_x86-inl.h"
|
||||
# elif (defined(__ppc__) || defined(__PPC__)) && __GNUC__ >= 2
|
||||
# define STACKTRACE_H "stacktrace_powerpc-inl.h"
|
||||
# elif defined(GLOG_OS_WINDOWS)
|
||||
# define STACKTRACE_H "stacktrace_windows-inl.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(STACKTRACE_H) && defined(HAVE_EXECINFO_BACKTRACE)
|
||||
# define STACKTRACE_H "stacktrace_generic-inl.h"
|
||||
#endif
|
||||
|
||||
#if defined(STACKTRACE_H)
|
||||
# define HAVE_STACKTRACE
|
||||
#endif
|
||||
|
||||
#ifndef GLOG_NO_SYMBOLIZE_DETECTION
|
||||
#ifndef HAVE_SYMBOLIZE
|
||||
// defined by gcc
|
||||
#if defined(__ELF__) && defined(GLOG_OS_LINUX)
|
||||
# define HAVE_SYMBOLIZE
|
||||
#elif defined(GLOG_OS_MACOSX) && defined(HAVE_DLADDR)
|
||||
// Use dladdr to symbolize.
|
||||
# define HAVE_SYMBOLIZE
|
||||
#elif defined(GLOG_OS_WINDOWS)
|
||||
// Use DbgHelp to symbolize
|
||||
# define HAVE_SYMBOLIZE
|
||||
#endif
|
||||
#endif // !defined(HAVE_SYMBOLIZE)
|
||||
#endif // !defined(GLOG_NO_SYMBOLIZE_DETECTION)
|
||||
|
||||
#ifndef ARRAYSIZE
|
||||
// There is a better way, but this is good enough for our purpose.
|
||||
# define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
|
||||
#endif
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
namespace glog_internal_namespace_ {
|
||||
|
||||
#ifdef HAVE___ATTRIBUTE__
|
||||
# define ATTRIBUTE_NOINLINE __attribute__ ((noinline))
|
||||
# define HAVE_ATTRIBUTE_NOINLINE
|
||||
#elif defined(GLOG_OS_WINDOWS)
|
||||
# define ATTRIBUTE_NOINLINE __declspec(noinline)
|
||||
# define HAVE_ATTRIBUTE_NOINLINE
|
||||
#else
|
||||
# define ATTRIBUTE_NOINLINE
|
||||
#endif
|
||||
|
||||
const char* ProgramInvocationShortName();
|
||||
|
||||
int64 CycleClock_Now();
|
||||
|
||||
int64 UsecToCycles(int64 usec);
|
||||
WallTime WallTime_Now();
|
||||
|
||||
int32 GetMainThreadPid();
|
||||
bool PidHasChanged();
|
||||
|
||||
pid_t GetTID();
|
||||
|
||||
const std::string& MyUserName();
|
||||
|
||||
// Get the part of filepath after the last path separator.
|
||||
// (Doesn't modify filepath, contrary to basename() in libgen.h.)
|
||||
const char* const_basename(const char* filepath);
|
||||
|
||||
// Wrapper of __sync_val_compare_and_swap. If the GCC extension isn't
|
||||
// defined, we try the CPU specific logics (we only support x86 and
|
||||
// x86_64 for now) first, then use a naive implementation, which has a
|
||||
// race condition.
|
||||
template<typename T>
|
||||
inline T sync_val_compare_and_swap(T* ptr, T oldval, T newval) {
|
||||
#if defined(HAVE___SYNC_VAL_COMPARE_AND_SWAP)
|
||||
return __sync_val_compare_and_swap(ptr, oldval, newval);
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
T ret;
|
||||
__asm__ __volatile__("lock; cmpxchg %1, (%2);"
|
||||
:"=a"(ret)
|
||||
// GCC may produces %sil or %dil for
|
||||
// constraint "r", but some of apple's gas
|
||||
// dosn't know the 8 bit registers.
|
||||
// We use "q" to avoid these registers.
|
||||
:"q"(newval), "q"(ptr), "a"(oldval)
|
||||
:"memory", "cc");
|
||||
return ret;
|
||||
#else
|
||||
T ret = *ptr;
|
||||
if (ret == oldval) {
|
||||
*ptr = newval;
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
void DumpStackTraceToString(std::string* stacktrace);
|
||||
|
||||
struct CrashReason {
|
||||
CrashReason() = default;
|
||||
|
||||
const char* filename{nullptr};
|
||||
int line_number{0};
|
||||
const char* message{nullptr};
|
||||
|
||||
// We'll also store a bit of stack trace context at the time of crash as
|
||||
// it may not be available later on.
|
||||
void* stack[32];
|
||||
int depth{0};
|
||||
};
|
||||
|
||||
void SetCrashReason(const CrashReason* r);
|
||||
|
||||
void InitGoogleLoggingUtilities(const char* argv0);
|
||||
void ShutdownGoogleLoggingUtilities();
|
||||
|
||||
} // namespace glog_internal_namespace_
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
||||
using namespace GOOGLE_NAMESPACE::glog_internal_namespace_;
|
||||
|
||||
#endif // UTILITIES_H__
|
||||
294
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/vlog_is_on.cc
vendored
Normal file
294
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/vlog_is_on.cc
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
// Copyright (c) 1999, 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: Ray Sidney and many others
|
||||
//
|
||||
// Broken out from logging.cc by Soren Lassen
|
||||
// logging_unittest.cc covers the functionality herein
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include "base/commandlineflags.h"
|
||||
#include <glog/logging.h>
|
||||
#include <glog/raw_logging.h>
|
||||
#include "base/googleinit.h"
|
||||
|
||||
// glog doesn't have annotation
|
||||
#define ANNOTATE_BENIGN_RACE(address, description)
|
||||
|
||||
using std::string;
|
||||
|
||||
GLOG_DEFINE_int32(v, 0, "Show all VLOG(m) messages for m <= this."
|
||||
" Overridable by --vmodule.");
|
||||
|
||||
GLOG_DEFINE_string(vmodule, "", "per-module verbose level."
|
||||
" Argument is a comma-separated list of <module name>=<log level>."
|
||||
" <module name> is a glob pattern, matched against the filename base"
|
||||
" (that is, name ignoring .cc/.h./-inl.h)."
|
||||
" <log level> overrides any value given by --v.");
|
||||
|
||||
_START_GOOGLE_NAMESPACE_
|
||||
|
||||
namespace glog_internal_namespace_ {
|
||||
|
||||
// Used by logging_unittests.cc so can't make it static here.
|
||||
GLOG_EXPORT bool SafeFNMatch_(const char* pattern, size_t patt_len,
|
||||
const char* str, size_t str_len);
|
||||
|
||||
// Implementation of fnmatch that does not need 0-termination
|
||||
// of arguments and does not allocate any memory,
|
||||
// but we only support "*" and "?" wildcards, not the "[...]" patterns.
|
||||
// It's not a static function for the unittest.
|
||||
GLOG_EXPORT bool SafeFNMatch_(const char* pattern, size_t patt_len,
|
||||
const char* str, size_t str_len) {
|
||||
size_t p = 0;
|
||||
size_t s = 0;
|
||||
while (true) {
|
||||
if (p == patt_len && s == str_len) return true;
|
||||
if (p == patt_len) return false;
|
||||
if (s == str_len) return p+1 == patt_len && pattern[p] == '*';
|
||||
if (pattern[p] == str[s] || pattern[p] == '?') {
|
||||
p += 1;
|
||||
s += 1;
|
||||
continue;
|
||||
}
|
||||
if (pattern[p] == '*') {
|
||||
if (p+1 == patt_len) return true;
|
||||
do {
|
||||
if (SafeFNMatch_(pattern+(p+1), patt_len-(p+1), str+s, str_len-s)) {
|
||||
return true;
|
||||
}
|
||||
s += 1;
|
||||
} while (s != str_len);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glog_internal_namespace_
|
||||
|
||||
using glog_internal_namespace_::SafeFNMatch_;
|
||||
|
||||
// List of per-module log levels from FLAGS_vmodule.
|
||||
// Once created each element is never deleted/modified
|
||||
// except for the vlog_level: other threads will read VModuleInfo blobs
|
||||
// w/o locks and we'll store pointers to vlog_level at VLOG locations
|
||||
// that will never go away.
|
||||
// We can't use an STL struct here as we wouldn't know
|
||||
// when it's safe to delete/update it: other threads need to use it w/o locks.
|
||||
struct VModuleInfo {
|
||||
string module_pattern;
|
||||
mutable int32 vlog_level; // Conceptually this is an AtomicWord, but it's
|
||||
// too much work to use AtomicWord type here
|
||||
// w/o much actual benefit.
|
||||
const VModuleInfo* next;
|
||||
};
|
||||
|
||||
// This protects the following global variables.
|
||||
static Mutex vmodule_lock;
|
||||
// Pointer to head of the VModuleInfo list.
|
||||
// It's a map from module pattern to logging level for those module(s).
|
||||
static VModuleInfo* vmodule_list = nullptr;
|
||||
static SiteFlag* cached_site_list = nullptr;
|
||||
|
||||
// Boolean initialization flag.
|
||||
static bool inited_vmodule = false;
|
||||
|
||||
// L >= vmodule_lock.
|
||||
static void VLOG2Initializer() {
|
||||
vmodule_lock.AssertHeld();
|
||||
// Can now parse --vmodule flag and initialize mapping of module-specific
|
||||
// logging levels.
|
||||
inited_vmodule = false;
|
||||
const char* vmodule = FLAGS_vmodule.c_str();
|
||||
const char* sep;
|
||||
VModuleInfo* head = nullptr;
|
||||
VModuleInfo* tail = nullptr;
|
||||
while ((sep = strchr(vmodule, '=')) != nullptr) {
|
||||
string pattern(vmodule, static_cast<size_t>(sep - vmodule));
|
||||
int module_level;
|
||||
if (sscanf(sep, "=%d", &module_level) == 1) {
|
||||
auto* info = new VModuleInfo;
|
||||
info->module_pattern = pattern;
|
||||
info->vlog_level = module_level;
|
||||
if (head) {
|
||||
tail->next = info;
|
||||
} else {
|
||||
head = info;
|
||||
}
|
||||
tail = info;
|
||||
}
|
||||
// Skip past this entry
|
||||
vmodule = strchr(sep, ',');
|
||||
if (vmodule == nullptr) break;
|
||||
vmodule++; // Skip past ","
|
||||
}
|
||||
if (head) { // Put them into the list at the head:
|
||||
tail->next = vmodule_list;
|
||||
vmodule_list = head;
|
||||
}
|
||||
inited_vmodule = true;
|
||||
}
|
||||
|
||||
// This can be called very early, so we use SpinLock and RAW_VLOG here.
|
||||
int SetVLOGLevel(const char* module_pattern, int log_level) {
|
||||
int result = FLAGS_v;
|
||||
size_t const pattern_len = strlen(module_pattern);
|
||||
bool found = false;
|
||||
{
|
||||
MutexLock l(&vmodule_lock); // protect whole read-modify-write
|
||||
for (const VModuleInfo* info = vmodule_list; info != nullptr;
|
||||
info = info->next) {
|
||||
if (info->module_pattern == module_pattern) {
|
||||
if (!found) {
|
||||
result = info->vlog_level;
|
||||
found = true;
|
||||
}
|
||||
info->vlog_level = log_level;
|
||||
} else if (!found &&
|
||||
SafeFNMatch_(info->module_pattern.c_str(),
|
||||
info->module_pattern.size(),
|
||||
module_pattern, pattern_len)) {
|
||||
result = info->vlog_level;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
auto* info = new VModuleInfo;
|
||||
info->module_pattern = module_pattern;
|
||||
info->vlog_level = log_level;
|
||||
info->next = vmodule_list;
|
||||
vmodule_list = info;
|
||||
|
||||
SiteFlag** item_ptr = &cached_site_list;
|
||||
SiteFlag* item = cached_site_list;
|
||||
|
||||
// We traverse the list fully because the pattern can match several items
|
||||
// from the list.
|
||||
while (item) {
|
||||
if (SafeFNMatch_(module_pattern, pattern_len, item->base_name,
|
||||
item->base_len)) {
|
||||
// Redirect the cached value to its module override.
|
||||
item->level = &info->vlog_level;
|
||||
*item_ptr = item->next; // Remove the item from the list.
|
||||
} else {
|
||||
item_ptr = &item->next;
|
||||
}
|
||||
item = *item_ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
RAW_VLOG(1, "Set VLOG level for \"%s\" to %d", module_pattern, log_level);
|
||||
return result;
|
||||
}
|
||||
|
||||
// NOTE: Individual VLOG statements cache the integer log level pointers.
|
||||
// NOTE: This function must not allocate memory or require any locks.
|
||||
bool InitVLOG3__(SiteFlag* site_flag, int32* level_default,
|
||||
const char* fname, int32 verbose_level) {
|
||||
MutexLock l(&vmodule_lock);
|
||||
bool read_vmodule_flag = inited_vmodule;
|
||||
if (!read_vmodule_flag) {
|
||||
VLOG2Initializer();
|
||||
}
|
||||
|
||||
// protect the errno global in case someone writes:
|
||||
// VLOG(..) << "The last error was " << strerror(errno)
|
||||
int old_errno = errno;
|
||||
|
||||
// site_default normally points to FLAGS_v
|
||||
int32* site_flag_value = level_default;
|
||||
|
||||
// Get basename for file
|
||||
const char* base = strrchr(fname, '/');
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!base) {
|
||||
base = strrchr(fname, '\\');
|
||||
}
|
||||
#endif
|
||||
|
||||
base = base ? (base+1) : fname;
|
||||
const char* base_end = strchr(base, '.');
|
||||
size_t base_length =
|
||||
base_end ? static_cast<size_t>(base_end - base) : strlen(base);
|
||||
|
||||
// Trim out trailing "-inl" if any
|
||||
if (base_length >= 4 && (memcmp(base+base_length-4, "-inl", 4) == 0)) {
|
||||
base_length -= 4;
|
||||
}
|
||||
|
||||
// TODO: Trim out _unittest suffix? Perhaps it is better to have
|
||||
// the extra control and just leave it there.
|
||||
|
||||
// find target in vector of modules, replace site_flag_value with
|
||||
// a module-specific verbose level, if any.
|
||||
for (const VModuleInfo* info = vmodule_list; info != nullptr;
|
||||
info = info->next) {
|
||||
if (SafeFNMatch_(info->module_pattern.c_str(), info->module_pattern.size(),
|
||||
base, base_length)) {
|
||||
site_flag_value = &info->vlog_level;
|
||||
// value at info->vlog_level is now what controls
|
||||
// the VLOG at the caller site forever
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cache the vlog value pointer if --vmodule flag has been parsed.
|
||||
ANNOTATE_BENIGN_RACE(site_flag,
|
||||
"*site_flag may be written by several threads,"
|
||||
" but the value will be the same");
|
||||
if (read_vmodule_flag) {
|
||||
site_flag->level = site_flag_value;
|
||||
// If VLOG flag has been cached to the default site pointer,
|
||||
// we want to add to the cached list in order to invalidate in case
|
||||
// SetVModule is called afterwards with new modules.
|
||||
// The performance penalty here is neglible, because InitVLOG3__ is called
|
||||
// once per site.
|
||||
if (site_flag_value == level_default && !site_flag->base_name) {
|
||||
site_flag->base_name = base;
|
||||
site_flag->base_len = base_length;
|
||||
site_flag->next = cached_site_list;
|
||||
cached_site_list = site_flag;
|
||||
}
|
||||
}
|
||||
|
||||
// restore the errno in case something recoverable went wrong during
|
||||
// the initialization of the VLOG mechanism (see above note "protect the..")
|
||||
errno = old_errno;
|
||||
return *site_flag_value >= verbose_level;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
1145
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/windows/dirent.h
vendored
Normal file
1145
modules/python/vendors/FunASR/runtime/onnxruntime/third_party/glog/src/windows/dirent.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user