Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit f8cba72

Browse files
committed
support ndk r25
1 parent c515e1a commit f8cba72

File tree

14 files changed

+148
-72
lines changed

14 files changed

+148
-72
lines changed

.github/workflows/android.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
defaults:
1010
run:
1111
shell: bash
12+
env:
13+
NDK_VERSION: 25.0.8775105
1214
strategy:
1315
fail-fast: true
1416
matrix:
@@ -29,19 +31,26 @@ jobs:
2931
run: |
3032
echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV
3133
34+
- name: Setup NDK
35+
env:
36+
ANDROID_SDK_ROOT: /usr/local/lib/android/sdk
37+
run: |
38+
echo 'y' | ${{env.ANDROID_SDK_ROOT}}/cmdline-tools/latest/bin/sdkmanager --install 'ndk;${{env.NDK_VERSION}}'
39+
3240
- name: Configure
3341
env:
3442
CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}}
3543
run: |
3644
cmake -S . -B build_${{matrix.abi}} \
37-
-DANDROID_ABI=${{matrix.abi}} \
38-
-DANDROID_NATIVE_API_LEVEL=28 \
39-
-DANDROID_STL=c++_shared \
45+
-DCMAKE_ANDROID_API=28 \
46+
-DCMAKE_ANDROID_ARCH_ABI=${{matrix.abi}} \
47+
-DCMAKE_ANDROID_NDK=/usr/local/lib/android/sdk/ndk/${{env.NDK_VERSION}} \
48+
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
4049
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
4150
-DCMAKE_CXX_EXTENSIONS=OFF \
4251
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
4352
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
44-
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
53+
-DCMAKE_SYSTEM_NAME=Android \
4554
-G Ninja \
4655
-Werror
4756

.github/workflows/macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push, pull_request]
55
jobs:
66
build-macos:
77
name: AppleClang-C++${{matrix.std}}-${{matrix.build_type}}
8-
runs-on: macos-10.15
8+
runs-on: macos-12
99
strategy:
1010
fail-fast: true
1111
matrix:

CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required (VERSION 3.16)
22
project (glog
3-
VERSION 0.6.0
3+
VERSION 0.7.0
44
DESCRIPTION "C++ implementation of the Google logging module"
55
HOMEPAGE_URL https://github.com/google/glog
66
LANGUAGES CXX
@@ -101,7 +101,6 @@ else (Unwind_FOUND)
101101
endif (Unwind_FOUND)
102102

103103
check_include_file_cxx (dlfcn.h HAVE_DLFCN_H)
104-
check_include_file_cxx (execinfo.h HAVE_EXECINFO_H)
105104
check_include_file_cxx (glob.h HAVE_GLOB_H)
106105
check_include_file_cxx (inttypes.h HAVE_INTTYPES_H)
107106
check_include_file_cxx (memory.h HAVE_MEMORY_H)
@@ -128,6 +127,8 @@ check_include_file_cxx ("unordered_map" HAVE_UNORDERED_MAP)
128127
check_include_file_cxx ("unordered_set" HAVE_UNORDERED_SET)
129128

130129
check_type_size ("unsigned __int16" HAVE___UINT16 LANGUAGE CXX)
130+
check_type_size (mode_t HAVE_MODE_T LANGUAGE CXX)
131+
check_type_size (ssize_t HAVE_SSIZE_T LANGUAGE CXX)
131132
check_type_size (u_int16_t HAVE_U_INT16_T LANGUAGE CXX)
132133
check_type_size (uint16_t HAVE_UINT16_T LANGUAGE CXX)
133134

@@ -138,6 +139,10 @@ check_function_exists (pwrite HAVE_PWRITE)
138139
check_function_exists (sigaction HAVE_SIGACTION)
139140
check_function_exists (sigaltstack HAVE_SIGALTSTACK)
140141

142+
check_cxx_symbol_exists (backtrace execinfo.h HAVE_EXECINFO_BACKTRACE)
143+
check_cxx_symbol_exists (backtrace_symbols execinfo.h
144+
HAVE_EXECINFO_BACKTRACE_SYMBOLS)
145+
141146
# NOTE gcc does not fail if you pass a non-existent -Wno-* option as an
142147
# argument. However, it will happily fail if you pass the corresponding -W*
143148
# option. So, we check whether options that disable warnings exist by testing
@@ -389,6 +394,18 @@ else (HAVE_UINT16_T)
389394
set (ac_cv_have_uint16_t 0)
390395
endif (HAVE_UINT16_T)
391396

397+
if (HAVE_SSIZE_T)
398+
set (ac_cv_have_ssize_t 1)
399+
else (HAVE_SSIZE_T)
400+
set (ac_cv_have_ssize_t 0)
401+
endif (HAVE_SSIZE_T)
402+
403+
if (HAVE_MODE_T)
404+
set (ac_cv_have_mode_t 1)
405+
else (HAVE_MODE_T)
406+
set (ac_cv_have_mode_t 0)
407+
endif (HAVE_MODE_T)
408+
392409
if (HAVE_UNISTD_H)
393410
set (ac_cv_have_unistd_h 1)
394411
else (HAVE_UNISTD_H)
@@ -438,9 +455,9 @@ else (HAVE_CXX11_NULLPTR_T)
438455
set (ac_cv_cxx11_nullptr_t 0)
439456
endif (HAVE_CXX11_NULLPTR_T)
440457

441-
if (HAVE_EXECINFO_H)
458+
if (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS)
442459
set (HAVE_STACKTRACE 1)
443-
endif (HAVE_EXECINFO_H)
460+
endif (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS)
444461

445462
if (HAVE_CXX11_ATOMIC)
446463
set (ac_cv_cxx11_atomic 1)
@@ -844,6 +861,9 @@ if (BUILD_TESTING)
844861
add_test (NAME logging COMMAND logging_unittest)
845862

846863
set_tests_properties (logging PROPERTIES TIMEOUT 30)
864+
# MacOS diff is not deterministic: use the output to determine whether the
865+
# test passed.
866+
set_tests_properties (logging PROPERTIES PASS_REGULAR_EXPRESSION ".*\nPASS\n.*")
847867

848868
# FIXME: Skip flaky test
849869
set_tests_properties (logging PROPERTIES SKIP_REGULAR_EXPRESSION

bazel/glog.bzl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,33 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
232232
}
233233

234234
posix_config = dict_union(common_config, {
235-
"@ac_cv_have_unistd_h@": "1",
236-
"@ac_cv_have_stdint_h@": "1",
237-
"@ac_cv_have_systypes_h@": "1",
238-
"@ac_cv_have_uint16_t@": "1",
239-
"@ac_cv_have___uint16@": "0",
240-
"@ac_cv_have___builtin_expect@": "1",
241-
"@ac_cv_have_libgflags@": "1" if with_gflags else "0",
242235
"@ac_cv___attribute___noinline@": "__attribute__((noinline))",
243236
"@ac_cv___attribute___noreturn@": "__attribute__((noreturn))",
244237
"@ac_cv___attribute___printf_4_5@": "__attribute__((__format__(__printf__, 4, 5)))",
238+
"@ac_cv_have___builtin_expect@": "1",
239+
"@ac_cv_have___uint16@": "0",
240+
"@ac_cv_have_libgflags@": "1" if with_gflags else "0",
241+
"@ac_cv_have_mode_t@": "1",
242+
"@ac_cv_have_ssize_t@": "1",
243+
"@ac_cv_have_stdint_h@": "1",
244+
"@ac_cv_have_systypes_h@": "1",
245+
"@ac_cv_have_uint16_t@": "1",
246+
"@ac_cv_have_unistd_h@": "1",
245247
})
246248

247249
windows_config = dict_union(common_config, {
248-
"@ac_cv_have_unistd_h@": "0",
249-
"@ac_cv_have_stdint_h@": "0",
250-
"@ac_cv_have_systypes_h@": "0",
251-
"@ac_cv_have_uint16_t@": "0",
252-
"@ac_cv_have___uint16@": "1",
253-
"@ac_cv_have___builtin_expect@": "0",
254-
"@ac_cv_have_libgflags@": "0",
255250
"@ac_cv___attribute___noinline@": "",
256251
"@ac_cv___attribute___noreturn@": "__declspec(noreturn)",
257252
"@ac_cv___attribute___printf_4_5@": "",
253+
"@ac_cv_have___builtin_expect@": "0",
254+
"@ac_cv_have___uint16@": "1",
255+
"@ac_cv_have_libgflags@": "0",
256+
"@ac_cv_have_mode_t@": "0",
257+
"@ac_cv_have_ssize_t@": "0",
258+
"@ac_cv_have_stdint_h@": "0",
259+
"@ac_cv_have_systypes_h@": "0",
260+
"@ac_cv_have_uint16_t@": "0",
261+
"@ac_cv_have_unistd_h@": "0",
258262
})
259263

260264
[

src/config.h.cmake.in

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
/* Define to 1 if you have the <dlfcn.h> header file. */
1717
#cmakedefine HAVE_DLFCN_H
1818

19-
/* Define to 1 if you have the <execinfo.h> header file. */
20-
#cmakedefine HAVE_EXECINFO_H
19+
/* Define if you have the `backtrace' function in <execinfo.h> */
20+
#cmakedefine HAVE_EXECINFO_BACKTRACE
21+
22+
/* Define if you have the `backtrace_symbols' function in <execinfo.h> */
23+
#cmakedefine HAVE_EXECINFO_BACKTRACE_SYMBOLS
2124

2225
/* Define if you have the `fcntl' function */
2326
#cmakedefine HAVE_FCNTL

src/demangle.cc

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ static const AbbrevPair kSubstitutionList[] = {
149149

150150
// State needed for demangling.
151151
typedef struct {
152-
const char *mangled_cur; // Cursor of mangled name.
153-
char *out_cur; // Cursor of output string.
154-
const char *out_begin; // Beginning of output string.
155-
const char *out_end; // End of output string.
156-
const char *prev_name; // For constructors/destructors.
157-
int prev_name_length; // For constructors/destructors.
158-
short nest_level; // For nested names.
159-
bool append; // Append flag.
160-
bool overflowed; // True if output gets overflowed.
152+
const char *mangled_cur; // Cursor of mangled name.
153+
char *out_cur; // Cursor of output string.
154+
const char *out_begin; // Beginning of output string.
155+
const char *out_end; // End of output string.
156+
const char *prev_name; // For constructors/destructors.
157+
ssize_t prev_name_length; // For constructors/destructors.
158+
short nest_level; // For nested names.
159+
bool append; // Append flag.
160+
bool overflowed; // True if output gets overflowed.
161161
} State;
162162

163163
// We don't use strlen() in libc since it's not guaranteed to be async
@@ -172,8 +172,8 @@ static size_t StrLen(const char *str) {
172172
}
173173

174174
// Returns true if "str" has at least "n" characters remaining.
175-
static bool AtLeastNumCharsRemaining(const char *str, int n) {
176-
for (int i = 0; i < n; ++i) {
175+
static bool AtLeastNumCharsRemaining(const char *str, ssize_t n) {
176+
for (ssize_t i = 0; i < n; ++i) {
177177
if (str[i] == '\0') {
178178
return false;
179179
}
@@ -269,9 +269,8 @@ static bool ZeroOrMore(ParseFunc parse_func, State *state) {
269269
// Append "str" at "out_cur". If there is an overflow, "overflowed"
270270
// is set to true for later use. The output string is ensured to
271271
// always terminate with '\0' as long as there is no overflow.
272-
static void Append(State *state, const char * const str, const int length) {
273-
int i;
274-
for (i = 0; i < length; ++i) {
272+
static void Append(State *state, const char * const str, ssize_t length) {
273+
for (ssize_t i = 0; i < length; ++i) {
275274
if (state->out_cur + 1 < state->out_end) { // +1 for '\0'
276275
*state->out_cur = str[i];
277276
++state->out_cur;
@@ -327,7 +326,7 @@ static bool IsFunctionCloneSuffix(const char *str) {
327326
// Append "str" with some tweaks, iff "append" state is true.
328327
// Returns true so that it can be placed in "if" conditions.
329328
static void MaybeAppendWithLength(State *state, const char * const str,
330-
const int length) {
329+
ssize_t length) {
331330
if (state->append && length > 0) {
332331
// Append a space if the output buffer ends with '<' and "str"
333332
// starts with '<' to avoid <<<.
@@ -347,8 +346,8 @@ static void MaybeAppendWithLength(State *state, const char * const str,
347346
// A convenient wrapper arount MaybeAppendWithLength().
348347
static bool MaybeAppend(State *state, const char * const str) {
349348
if (state->append) {
350-
int length = StrLen(str);
351-
MaybeAppendWithLength(state, str, length);
349+
size_t length = StrLen(str);
350+
MaybeAppendWithLength(state, str, static_cast<ssize_t>(length));
352351
}
353352
return true;
354353
}
@@ -402,10 +401,10 @@ static void MaybeCancelLastSeparator(State *state) {
402401

403402
// Returns true if the identifier of the given length pointed to by
404403
// "mangled_cur" is anonymous namespace.
405-
static bool IdentifierIsAnonymousNamespace(State *state, int length) {
404+
static bool IdentifierIsAnonymousNamespace(State *state, ssize_t length) {
406405
static const char anon_prefix[] = "_GLOBAL__N_";
407-
return (length >
408-
static_cast<int>(sizeof(anon_prefix)) - 1 && // Should be longer.
406+
return (length > static_cast<ssize_t>(sizeof(anon_prefix)) -
407+
1 && // Should be longer.
409408
StrPrefix(state->mangled_cur, anon_prefix));
410409
}
411410

@@ -423,7 +422,7 @@ static bool ParseLocalSourceName(State *state);
423422
static bool ParseNumber(State *state, int *number_out);
424423
static bool ParseFloatNumber(State *state);
425424
static bool ParseSeqId(State *state);
426-
static bool ParseIdentifier(State *state, int length);
425+
static bool ParseIdentifier(State *state, ssize_t length);
427426
static bool ParseAbiTags(State *state);
428427
static bool ParseAbiTag(State *state);
429428
static bool ParseOperatorName(State *state);
@@ -692,7 +691,7 @@ static bool ParseSeqId(State *state) {
692691
}
693692

694693
// <identifier> ::= <unqualified source code identifier> (of given length)
695-
static bool ParseIdentifier(State *state, int length) {
694+
static bool ParseIdentifier(State *state, ssize_t length) {
696695
if (length == -1 ||
697696
!AtLeastNumCharsRemaining(state->mangled_cur, length)) {
698697
return false;
@@ -892,7 +891,7 @@ static bool ParseCtorDtorName(State *state) {
892891
if (ParseOneCharToken(state, 'C') &&
893892
ParseCharClass(state, "123")) {
894893
const char * const prev_name = state->prev_name;
895-
const int prev_name_length = state->prev_name_length;
894+
const ssize_t prev_name_length = state->prev_name_length;
896895
MaybeAppendWithLength(state, prev_name, prev_name_length);
897896
return true;
898897
}
@@ -901,7 +900,7 @@ static bool ParseCtorDtorName(State *state) {
901900
if (ParseOneCharToken(state, 'D') &&
902901
ParseCharClass(state, "012")) {
903902
const char * const prev_name = state->prev_name;
904-
const int prev_name_length = state->prev_name_length;
903+
const ssize_t prev_name_length = state->prev_name_length;
905904
MaybeAppend(state, "~");
906905
MaybeAppendWithLength(state, prev_name, prev_name_length);
907906
return true;

src/glog/logging.h.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ typedef unsigned __int64 uint64;
116116
#error Do not know how to define a 32-bit integer quantity on your system
117117
#endif
118118

119+
#if !(@ac_cv_have_ssize_t@)
120+
typedef ptrdiff_t ssize_t;
121+
#endif
122+
123+
#if !(@ac_cv_have_mode_t@)
124+
typedef int mode_t;
125+
#endif
126+
119127
typedef double WallTime;
120128

121129
struct GLOG_EXPORT LogMessageTime {

src/logging.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ bool LogFileObject::CreateLogfile(const string& time_pid_string) {
10501050
//demand that the file is unique for our timestamp (fail if it exists).
10511051
flags = flags | O_EXCL;
10521052
}
1053-
int fd = open(filename, flags, FLAGS_logfile_mode);
1053+
int fd = open(filename, flags, static_cast<mode_t>(FLAGS_logfile_mode));
10541054
if (fd == -1) return false;
10551055
#ifdef HAVE_FCNTL
10561056
// Mark the file close-on-exec. We don't really care if this fails
@@ -1319,7 +1319,8 @@ void LogFileObject::Write(bool force_flush,
13191319
// 'posix_fadvise' introduced in API 21:
13201320
// * https://android.googlesource.com/platform/bionic/+/6880f936173081297be0dc12f687d341b86a4cfa/libc/libc.map.txt#732
13211321
# else
1322-
posix_fadvise(fileno(file_), dropped_mem_length_, this_drop_length,
1322+
posix_fadvise(fileno(file_), static_cast<off_t>(dropped_mem_length_),
1323+
static_cast<off_t>(this_drop_length),
13231324
POSIX_FADV_DONTNEED);
13241325
# endif
13251326
dropped_mem_length_ = total_drop_length;

src/signalhandler.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void DumpTimeInfo() {
174174
}
175175

176176
// TODO(hamaji): Use signal instead of sigaction?
177-
#ifdef HAVE_SIGACTION
177+
#if defined(HAVE_STACKTRACE) && defined(HAVE_SIGACTION)
178178

179179
// Dumps information about the signal to STDERR.
180180
void DumpSignalInfo(int signal_number, siginfo_t *siginfo) {
@@ -332,11 +332,15 @@ void FailureSignalHandler(int signal_number,
332332
const int depth = GetStackTrace(stack, ARRAYSIZE(stack), 1);
333333
# ifdef HAVE_SIGACTION
334334
DumpSignalInfo(signal_number, signal_info);
335+
#elif !defined(GLOG_OS_WINDOWS)
336+
(void)signal_info;
335337
# endif
336338
// Dump the stack traces.
337339
for (int i = 0; i < depth; ++i) {
338340
DumpStackFrameInfo(" ", stack[i]);
339341
}
342+
#elif !defined(GLOG_OS_WINDOWS)
343+
(void)signal_info;
340344
#endif
341345

342346
// *** TRANSITION ***

src/stacktrace_unittest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <glog/logging.h>
3737
#include "stacktrace.h"
3838

39-
#ifdef HAVE_EXECINFO_H
39+
#ifdef HAVE_EXECINFO_BACKTRACE_SYMBOLS
4040
# include <execinfo.h>
4141
#endif
4242

@@ -131,7 +131,7 @@ static void ATTRIBUTE_NOINLINE CheckStackTraceLeaf(void) {
131131
CHECK_LE(size, STACK_LEN);
132132

133133
if (1) {
134-
#ifdef HAVE_EXECINFO_H
134+
#ifdef HAVE_EXECINFO_BACKTRACE_SYMBOLS
135135
char **strings = backtrace_symbols(stack, size);
136136
printf("Obtained %d stack frames.\n", size);
137137
for (int i = 0; i < size; i++) {

0 commit comments

Comments
 (0)