Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make headers self-contained #1030

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ jobs:
run: |
cd build_${{matrix.build_type}}
gcovr -r .. . -s --xml coverage.xml
cd ..

- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ jobs:
if: matrix.build_type == 'Debug'
run: |
cd build_${{matrix.build_type}}
rm -r Tests/
gcovr -r .. . -s --cobertura coverage.xml
cd ..

- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ jobs:
run: |
cd build_${{matrix.build_type}}
gcovr -r .. . -s --cobertura coverage.xml
cd ..

- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
Expand Down
79 changes: 69 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ set (GLOG_PUBLIC_H
src/glog/platform.h
src/glog/raw_logging.h
src/glog/stl_logging.h
src/glog/types.h
src/glog/flags.h
src/glog/vlog_is_on.h
)

Expand All @@ -363,6 +365,7 @@ set (GLOG_SRCS
src/base/googleinit.h
src/demangle.cc
src/demangle.h
src/flags.cc
src/logging.cc
src/raw_logging.cc
src/signalhandler.cc
Expand Down Expand Up @@ -787,10 +790,6 @@ if (BUILD_TESTING)
PROPERTIES WILL_FAIL ON
)

set (_glog_TEST_ENVIRONMENT
glog_ROOT=${glog_BINARY_DIR}
)

add_test (NAME log_severity_constants COMMAND ${CMAKE_CTEST_COMMAND}
--build-config $<CONFIG>
--build-and-test
Expand All @@ -804,9 +803,9 @@ if (BUILD_TESTING)
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-Dglog_DIR=${glog_BINARY_DIR}
)
set_tests_properties (log_severity_constants PROPERTIES
ENVIRONMENT "${_glog_TEST_ENVIRONMENT}"
PASS_REGULAR_EXPRESSION "COMPACT_GOOGLE_LOG_[1-3]"
)

Expand All @@ -823,9 +822,7 @@ if (BUILD_TESTING)
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
)
set_tests_properties (log_severity_conversion PROPERTIES
ENVIRONMENT "${_glog_TEST_ENVIRONMENT}"
-Dglog_DIR=${glog_BINARY_DIR}
)

if (CMAKE_COMPILER_IS_GNUCXX)
Expand All @@ -842,13 +839,75 @@ if (BUILD_TESTING)
)
else (CMAKE_COMPILER_IS_GNUCXX)
message (AUTHOR_WARNING
"Unsuuported C++ compiler ${CMAKE_CXX_COMPILER_ID}: "
"Unsupported C++ compiler ${CMAKE_CXX_COMPILER_ID}: "
"log_severity_conversion test will be disabled"
)
set_tests_properties (log_severity_conversion DISABLED ON)
endif (CMAKE_COMPILER_IS_GNUCXX)

unset (_glog_TEST_ENVIRONMENT)
add_test (NAME includes_logging COMMAND ${CMAKE_CTEST_COMMAND}
--build-config $<CONFIG>
--build-and-test
"${glog_SOURCE_DIR}/src/includes_unittest"
"${glog_BINARY_DIR}/Tests/includes_logging"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-target glog_includes_logging
--build-options
-DCMAKE_BUILD_TYPE=$<CONFIG>
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-Dglog_DIR=${glog_BINARY_DIR}
)

add_test (NAME includes_vlog_is_on COMMAND ${CMAKE_CTEST_COMMAND}
--build-config $<CONFIG>
--build-and-test
"${glog_SOURCE_DIR}/src/includes_unittest"
"${glog_BINARY_DIR}/Tests/includes_vlog_is_on"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-target glog_includes_vlog_is_on
--build-options
-DCMAKE_BUILD_TYPE=$<CONFIG>
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-Dglog_DIR=${glog_BINARY_DIR}
)

add_test (NAME includes_raw_logging COMMAND ${CMAKE_CTEST_COMMAND}
--build-config $<CONFIG>
--build-and-test
"${glog_SOURCE_DIR}/src/includes_unittest"
"${glog_BINARY_DIR}/Tests/includes_raw_logging"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-target glog_includes_raw_logging
--build-options
-DCMAKE_BUILD_TYPE=$<CONFIG>
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-Dglog_DIR=${glog_BINARY_DIR}
)

add_test (NAME includes_stl_logging COMMAND ${CMAKE_CTEST_COMMAND}
--build-config $<CONFIG>
--build-and-test
"${glog_SOURCE_DIR}/src/includes_unittest"
"${glog_BINARY_DIR}/Tests/includes_stl_logging"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-target glog_includes_stl_logging
--build-options
-DCMAKE_BUILD_TYPE=$<CONFIG>
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-Dglog_DIR=${glog_BINARY_DIR}
)
endif (BUILD_TESTING)

install (TARGETS glog
Expand Down
6 changes: 6 additions & 0 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def glog_library(with_gflags = 1, **kwargs):
"src/base/googleinit.h",
"src/demangle.cc",
"src/demangle.h",
"src/flags.cc",
"src/logging.cc",
"src/raw_logging.cc",
"src/signalhandler.cc",
Expand All @@ -184,11 +185,13 @@ def glog_library(with_gflags = 1, **kwargs):
"//conditions:default": [],
}),
hdrs = [
"src/glog/flags.h",
"src/glog/log_severity.h",
"src/glog/logging.h",
"src/glog/platform.h",
"src/glog/raw_logging.h",
"src/glog/stl_logging.h",
"src/glog/types.h",
"src/glog/vlog_is_on.h",
],
# https://github.com/google/glog/issues/837: Replacing
Expand Down Expand Up @@ -251,10 +254,13 @@ def glog_library(with_gflags = 1, **kwargs):
native.cc_library(
name = "strip_include_prefix_hack",
hdrs = [
"src/glog/flags.h",
"src/glog/log_severity.h",
"src/glog/logging.h",
"src/glog/platform.h",
"src/glog/raw_logging.h",
"src/glog/stl_logging.h",
"src/glog/types.h",
"src/glog/vlog_is_on.h",
],
)
Expand Down
1 change: 1 addition & 0 deletions gcovr.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
exclude = src/.*_unittest\.cc
exclude = src/googletest\.h
exclude = src/mock-log\.h
exclude-directories = Tests/
exclude-throw-branches = yes
exclude-unreachable-branches = yes
filter = .*/glog/.*\.h
Expand Down
157 changes: 157 additions & 0 deletions src/flags.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// Copyright (c) 2024, 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 "glog/flags.h"

#include <cstdlib>
#include <cstring>

#include "base/commandlineflags.h"
#include "glog/log_severity.h"

namespace {

// Compute the default value for --log_dir
static const char* DefaultLogDir() {
constexpr const char* const names[]{"GOOGLE_LOG_DIR", "TEST_TMPDIR"};
for (const char* const name : names) {
const char* const env = std::getenv(name);
if (env != nullptr && env[0] != '\0') {
return env;
}
}
return "";
}

bool BoolFromEnv(const char* varname, bool defval) {
const char* const valstr = getenv(varname);
if (!valstr) {
return defval;
}
return std::memchr("tTyY1\0", valstr[0], 6) != nullptr;
}

} // namespace

GLOG_DEFINE_bool(timestamp_in_logfile_name,
BoolFromEnv("GOOGLE_TIMESTAMP_IN_LOGFILE_NAME", true),
"put a timestamp at the end of the log file name");
GLOG_DEFINE_bool(logtostderr, BoolFromEnv("GOOGLE_LOGTOSTDERR", false),
"log messages go to stderr instead of logfiles");
GLOG_DEFINE_bool(alsologtostderr, BoolFromEnv("GOOGLE_ALSOLOGTOSTDERR", false),
"log messages go to stderr in addition to logfiles");
GLOG_DEFINE_bool(colorlogtostderr, false,
"color messages logged to stderr (if supported by terminal)");
GLOG_DEFINE_bool(colorlogtostdout, false,
"color messages logged to stdout (if supported by terminal)");
GLOG_DEFINE_bool(logtostdout, BoolFromEnv("GOOGLE_LOGTOSTDOUT", false),
"log messages go to stdout instead of logfiles");
#ifdef GLOG_OS_LINUX
GLOG_DEFINE_bool(
drop_log_memory, true,
"Drop in-memory buffers of log contents. "
"Logs can grow very quickly and they are rarely read before they "
"need to be evicted from memory. Instead, drop them from memory "
"as soon as they are flushed to disk.");
#endif

// By default, errors (including fatal errors) get logged to stderr as
// well as the file.
//
// The default is ERROR instead of FATAL so that users can see problems
// when they run a program without having to look in another file.
DEFINE_int32(stderrthreshold, google::GLOG_ERROR,
"log messages at or above this level are copied to stderr in "
"addition to logfiles. This flag obsoletes --alsologtostderr.");

GLOG_DEFINE_string(alsologtoemail, "",
"log messages go to these email addresses "
"in addition to logfiles");
GLOG_DEFINE_bool(log_file_header, true,
"Write the file header at the start of each log file");
GLOG_DEFINE_bool(log_prefix, true,
"Prepend the log prefix to the start of each log line");
GLOG_DEFINE_bool(log_year_in_prefix, true,
"Include the year in the log prefix");
GLOG_DEFINE_int32(minloglevel, 0,
"Messages logged at a lower level than this don't "
"actually get logged anywhere");
GLOG_DEFINE_int32(logbuflevel, 0,
"Buffer log messages logged at this level or lower"
" (-1 means don't buffer; 0 means buffer INFO only;"
" ...)");
GLOG_DEFINE_int32(logbufsecs, 30,
"Buffer log messages for at most this many seconds");

GLOG_DEFINE_int32(logcleansecs, 60 * 5, // every 5 minutes
"Clean overdue logs every this many seconds");

GLOG_DEFINE_int32(logemaillevel, 999,
"Email log messages logged at this level or higher"
" (0 means email all; 3 means email FATAL only;"
" ...)");
GLOG_DEFINE_string(logmailer, "", "Mailer used to send logging email");

GLOG_DEFINE_int32(logfile_mode, 0664, "Log file mode/permissions.");

GLOG_DEFINE_string(
log_dir, DefaultLogDir(),
"If specified, logfiles are written into this directory instead "
"of the default logging directory.");
GLOG_DEFINE_string(log_link, "",
"Put additional links to the log "
"files in this directory");

GLOG_DEFINE_uint32(max_log_size, 1800,
"approx. maximum log file size (in MB). A value of 0 will "
"be silently overridden to 1.");

GLOG_DEFINE_bool(stop_logging_if_full_disk, false,
"Stop attempting to log to disk if the disk is full.");

GLOG_DEFINE_string(log_backtrace_at, "",
"Emit a backtrace when logging at file:linenum.");

GLOG_DEFINE_bool(log_utc_time, false, "Use UTC time for logging.");

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.");

GLOG_DEFINE_bool(symbolize_stacktrace, true,
"Symbolize the stack trace in the tombstone");
Loading