Skip to content

Commit 5ac16e5

Browse files
authored
Merge pull request #845 from wangkuiyi/glog-gflags-bazel
Add dependency to gflags and related tests
2 parents be734a6 + 35ccf9c commit 5ac16e5

File tree

10 files changed

+222
-5
lines changed

10 files changed

+222
-5
lines changed

WORKSPACE

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ http_archive(
33
name="protobuf",
44
url="http://github.com/google/protobuf/archive/v3.1.0.tar.gz",
55
sha256="0a0ae63cbffc274efb573bdde9a253e3f32e458c41261df51c5dbc5ad541e8f7",
6-
strip_prefix="protobuf-3.1.0", )
6+
strip_prefix="protobuf-3.1.0")
77

88
# External dependency to gtest 1.7.0. This method comes from
99
# https://www.bazel.io/versions/master/docs/tutorial/cpp.html.
@@ -12,4 +12,20 @@ new_http_archive(
1212
url="https://github.com/google/googletest/archive/release-1.7.0.zip",
1313
sha256="b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0",
1414
build_file="third_party/gtest.BUILD",
15-
strip_prefix="googletest-release-1.7.0", )
15+
strip_prefix="googletest-release-1.7.0")
16+
17+
# External dependency to gflags. This method comes from
18+
# https://github.com/gflags/example/blob/master/WORKSPACE.
19+
new_git_repository(
20+
name="gflags",
21+
tag="v2.2.0",
22+
remote="https://github.com/gflags/gflags.git",
23+
build_file="third_party/gflags.BUILD")
24+
25+
# External dependency to glog. This method comes from
26+
# https://github.com/reyoung/bazel_playground/blob/master/WORKSPACE
27+
new_git_repository(
28+
name="glog",
29+
remote="https://github.com/google/glog.git",
30+
commit="b6a5e0524c28178985f0d228e9eaa43808dbec3c",
31+
build_file="third_party/glog.BUILD")

paddle/cuda/src/hl_cuda_device.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
// clang-format off
16-
// Because clang-format 4.X and clang-format 3.8+ format
16+
// Because clang-format 4.X and clang-format 3.8+ format
1717
// following lines in different. So disable clang-format.
1818
#include "hl_cuda.h"
1919
#include <cuda_profiler_api.h>
@@ -22,6 +22,7 @@ limitations under the License. */
2222
#include <sys/time.h>
2323
#include <unistd.h>
2424
#include <mutex>
25+
#include "hl_cuda.h"
2526
#include "hl_cuda.ph"
2627
#include "hl_dso_loader.h"
2728
#include "hl_thread.ph"

third_party/gflags.BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Bazel (http://bazel.io/) BUILD file for gflags.
2+
#
3+
# See INSTALL.md for instructions for adding gflags to a Bazel workspace.
4+
5+
licenses(["notice"])
6+
7+
exports_files(["src/gflags_complections.sh", "COPYING.txt"])
8+
9+
load(":bazel/gflags.bzl", "gflags_sources", "gflags_library")
10+
(hdrs, srcs) = gflags_sources(namespace=["google", "gflags"])
11+
gflags_library(hdrs=hdrs, srcs=srcs, threads=0)
12+
gflags_library(hdrs=hdrs, srcs=srcs, threads=1)

third_party/gflags_test/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
licenses(["notice"]) # Apache 2.0
2+
3+
cc_test(
4+
name="gflags_test",
5+
srcs=["gflags_test.cc"],
6+
copts=["-Iexternal/gtest/include"],
7+
deps=[
8+
"@gtest//:gtest",
9+
"@gflags//:gflags",
10+
], )
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
#include "gflags/gflags.h"
5+
#include "gtest/gtest.h"
6+
7+
DEFINE_bool(verbose, false, "Display program name before message");
8+
DEFINE_string(message, "Hello world!", "Message to print");
9+
10+
static bool IsNonEmptyMessage(const char *flagname, const std::string &value) {
11+
return value[0] != '\0';
12+
}
13+
DEFINE_validator(message, &IsNonEmptyMessage);
14+
15+
namespace third_party {
16+
namespace gflags_test {
17+
18+
TEST(GflagsTest, ParseAndPrint) {
19+
gflags::SetUsageMessage("some usage message");
20+
gflags::SetVersionString("1.0.0");
21+
int argc = 1;
22+
char program_name[] = "gflags_test";
23+
char **argv = new char *[2];
24+
argv[0] = program_name;
25+
argv[1] = NULL;
26+
gflags::ParseCommandLineFlags(&argc, reinterpret_cast<char ***>(&argv), true);
27+
EXPECT_EQ("gflags_test", std::string(gflags::ProgramInvocationShortName()));
28+
EXPECT_EQ("Hello world!", FLAGS_message);
29+
gflags::ShutDownCommandLineFlags();
30+
}
31+
32+
} // namespace gflags_test
33+
} // namespace third_party

third_party/glog.BUILD

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
licenses(["notice"])
2+
3+
cc_library(
4+
visibility=["//visibility:public"],
5+
name="glog",
6+
includes=[
7+
".",
8+
"src",
9+
],
10+
copts=[
11+
"-D_START_GOOGLE_NAMESPACE_='namespace google {'",
12+
"-D_END_GOOGLE_NAMESPACE_='}'",
13+
"-DGOOGLE_NAMESPACE='google'",
14+
"-DGOOGLE_GLOG_DLL_DECL=''",
15+
"-DHAVE_DLADDR",
16+
"-DHAVE_SNPRINTF",
17+
"-DHAVE_DLFCN_H",
18+
"-DHAVE_FCNTL",
19+
"-DHAVE_GLOB_H",
20+
"-DHAVE_INTTYPES_H",
21+
"-DHAVE_LIBPTHREAD",
22+
"-DHAVE_SYS_SYSCALL_H",
23+
"-DHAVE_MEMORY_H",
24+
"-DHAVE_NAMESPACES",
25+
"-DHAVE_PREAD",
26+
"-DHAVE_PTHREAD",
27+
"-DHAVE_PWD_H",
28+
"-DHAVE_PWRITE",
29+
"-DHAVE_RWLOCK",
30+
"-DHAVE_SIGACTION",
31+
"-DHAVE_SIGALTSTACK",
32+
"-DHAVE_STDINT_H",
33+
"-DHAVE_STRING_H",
34+
"-DHAVE_SYS_TIME_H",
35+
"-DHAVE_SYS_TYPES_H",
36+
"-DHAVE_SYS_UCONTEXT_H",
37+
"-DHAVE_SYS_UTSNAME_H",
38+
"-DHAVE_UNISTD_H",
39+
"-DHAVE_USING_OPERATOR",
40+
"-DHAVE_HAVE___ATTRIBUTE___",
41+
"-DHAVE_HAVE___BUILTIN_EXPECT",
42+
#"-DNO_FRAME_POINTER",
43+
"-D_GNU_SOURCE",
44+
#"-fno-sanitize=thread",
45+
#"-fno-sanitize=address",
46+
"-Iexternal/glog/src",
47+
],
48+
srcs=[
49+
"src/demangle.cc",
50+
"src/logging.cc",
51+
"src/raw_logging.cc",
52+
"src/signalhandler.cc",
53+
"src/symbolize.cc",
54+
"src/utilities.cc",
55+
"src/vlog_is_on.cc",
56+
":config_h",
57+
":logging_h",
58+
":raw_logging_h",
59+
":stl_logging_h",
60+
":vlog_is_on_h",
61+
],
62+
hdrs=[
63+
"src/demangle.h",
64+
"src/mock-log.h",
65+
"src/stacktrace.h",
66+
"src/symbolize.h",
67+
"src/utilities.h",
68+
"src/base/commandlineflags.h",
69+
"src/base/googleinit.h",
70+
"src/base/mutex.h",
71+
"src/glog/log_severity.h",
72+
])
73+
74+
genrule(
75+
name="config_h",
76+
srcs=["src/config.h.cmake.in"],
77+
outs=["config.h"],
78+
cmd="awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $(<) > $(@)",
79+
)
80+
81+
genrule(
82+
name="logging_h",
83+
srcs=["src/glog/logging.h.in"],
84+
outs=["glog/logging.h"],
85+
cmd="$(location :gen_sh) < $(<) > $(@)",
86+
tools=[":gen_sh"])
87+
88+
genrule(
89+
name="raw_logging_h",
90+
srcs=["src/glog/raw_logging.h.in"],
91+
outs=["glog/raw_logging.h"],
92+
cmd="$(location :gen_sh) < $(<) > $(@)",
93+
tools=[":gen_sh"])
94+
95+
genrule(
96+
name="stl_logging_h",
97+
srcs=["src/glog/stl_logging.h.in"],
98+
outs=["glog/stl_logging.h"],
99+
cmd="$(location :gen_sh) < $(<) > $(@)",
100+
tools=[":gen_sh"])
101+
102+
genrule(
103+
name="vlog_is_on_h",
104+
srcs=["src/glog/vlog_is_on.h.in"],
105+
outs=["glog/vlog_is_on.h"],
106+
cmd="$(location :gen_sh) < $(<) > $(@)",
107+
tools=[":gen_sh"])
108+
109+
genrule(
110+
name="gen_sh",
111+
outs=["gen.sh"],
112+
cmd="""
113+
cat > $@ <<"EOF"
114+
#! /bin/sh
115+
sed -e 's/@ac_cv_have_unistd_h@/1/g' \
116+
-e 's/@ac_cv_have_stdint_h@/1/g' \
117+
-e 's/@ac_cv_have_systypes_h@/1/g' \
118+
-e 's/@ac_cv_have_libgflags_h@/1/g' \
119+
-e 's/@ac_cv_have_uint16_t@/1/g' \
120+
-e 's/@ac_cv_have___builtin_expect@/1/g' \
121+
-e 's/@ac_cv_have_.*@/0/g' \
122+
-e 's/@ac_google_start_namespace@/namespace google {/g' \
123+
-e 's/@ac_google_end_namespace@/}/g' \
124+
-e 's/@ac_google_namespace@/google/g' \
125+
-e 's/@ac_cv___attribute___noinline@/__attribute__((noinline))/g' \
126+
-e 's/@ac_cv___attribute___noreturn@/__attribute__((noreturn))/g' \
127+
-e 's/@ac_cv___attribute___printf_4_5@/__attribute__((__format__ (__printf__, 4, 5)))/g'
128+
EOF""")

third_party/glog_test/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
licenses(["notice"]) # Apache 2.0
2+
3+
cc_test(
4+
name="glog_test",
5+
srcs=["glog_test.cc"],
6+
copts=["-Iexternal/gtest/include"],
7+
deps=[
8+
"@gtest//:gtest",
9+
"@glog//:glog",
10+
], )

third_party/glog_test/glog_test.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
#include "glog/logging.h"
5+
#include "gtest/gtest.h"
6+
7+
TEST(GlogTest, Logging) { LOG(INFO) << "Hello world"; }

third_party/gtest.BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cc_library(
2-
name="main",
2+
name="gtest",
33
srcs=glob(
44
["src/*.cc"], exclude=["src/gtest-all.cc"]),
55
hdrs=glob(["include/**/*.h", "src/*.h"]),

third_party/protobuf_test/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ cc_test(
1919
srcs=["example_lib_test.cc"],
2020
copts=["-Iexternal/gtest/include"],
2121
deps=[
22-
"@gtest//:main",
22+
"@gtest//:gtest",
2323
":example_lib",
2424
], )

0 commit comments

Comments
 (0)