Skip to content

Commit 5f922b7

Browse files
committed
- Changes gtest from new_http_archive to new_git_repository
with latest 1.8 (closes #11). - Updates cpp test with main entrypoint. - Updates readme in relation to #10. - Bump to v0.5.1.
1 parent 08284e0 commit 5f922b7

File tree

6 files changed

+140
-24
lines changed

6 files changed

+140
-24
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,38 @@ Build label: 0.3.1
5959
6060
# Quick Start
6161

62-
Require these rules your `WORKSPACE`:
62+
## WORKSPACE
63+
64+
1. Add rules_go to your workspace
65+
66+
Note about golang: this project uses [rules-go][rules_go] for
67+
`go_library`, `go_binary`, and `go_test`. Even if you're not using go
68+
support in rules_protobuf, it is a current requirement for your
69+
WORKSPACE file (see issue #10).
6370

6471
```python
6572
git_repository(
66-
name = "org_pubref_rules_protobuf",
67-
remote = "https://github.com/pubref/rules_protobuf",
68-
tag = "v0.5.0",
73+
name = "io_bazel_rules_go",
74+
tag = "0.0.4",
75+
remote = "https://github.com/bazelbuild/rules_go.git",
6976
)
77+
load("@io_bazel_rules_go//go:def.bzl", "go_repositories")
78+
go_repositories()
7079
```
7180

72-
Trigger loading of external dependencies. Specify the language(s)
73-
you'd like support for.
74-
81+
2. Require these rules your `WORKSPACE` and trigger loading of
82+
external dependencies. Specify the language(s) you'd like support
83+
for.:
7584

7685
```python
86+
git_repository(
87+
name = "org_pubref_rules_protobuf",
88+
remote = "https://github.com/pubref/rules_protobuf",
89+
tag = "v0.5.1",
90+
)
91+
7792
load("@org_pubref_rules_protobuf//bzl:rules.bzl", "protobuf_repositories")
93+
7894
protobuf_repositories(
7995
with_go = True,
8096
with_java = True,
@@ -86,6 +102,8 @@ protobuf_repositories(
86102
> the set of external dependencies that will be loaded into your
87103
> project.
88104
105+
## BUILD
106+
89107
Build a java-based gRPC library:
90108

91109
```python

bzl/build_file/gtest.BUILD

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,105 @@
1+
# Adapted from https://github.com/mzhaom/trunk/blob/master/third_party/gtest/BUILD
2+
licenses(["notice"])
3+
14
cc_library(
2-
name = "main",
3-
srcs = glob(
4-
["src/*.cc"],
5-
exclude = ["src/gtest-all.cc"],
6-
),
7-
hdrs = glob([
8-
"include/**/*.h",
9-
"src/*.h",
10-
]),
11-
copts = ["-Iexternal/gtest/include"],
12-
linkopts = ["-pthread"],
5+
name = "gtest",
6+
testonly = 1,
137
visibility = ["//visibility:public"],
8+
includes = [
9+
"googletest/include",
10+
],
11+
hdrs = [
12+
"googletest/include/gtest/gtest-death-test.h",
13+
"googletest/include/gtest/gtest-message.h",
14+
"googletest/include/gtest/gtest_pred_impl.h",
15+
"googletest/include/gtest/gtest-test-part.h",
16+
"googletest/include/gtest/gtest.h",
17+
"googletest/include/gtest/gtest-param-test.h",
18+
"googletest/include/gtest/gtest-printers.h",
19+
"googletest/include/gtest/gtest-spi.h",
20+
"googletest/include/gtest/gtest-typed-test.h"
21+
],
22+
srcs = glob([
23+
"googletest/include/gtest/internal/**/*.h"
24+
]) + [
25+
"googletest/src/gtest-internal-inl.h",
26+
"googletest/src/gtest-death-test.cc",
27+
"googletest/src/gtest-filepath.cc",
28+
"googletest/src/gtest-port.cc",
29+
"googletest/src/gtest-printers.cc",
30+
"googletest/src/gtest-test-part.cc",
31+
"googletest/src/gtest-typed-test.cc",
32+
"googletest/src/gtest.cc",
33+
],
34+
copts = [
35+
"-Iexternal/gtest/googletest"
36+
],
37+
deps = [
38+
":gtest_prod",
39+
],
40+
)
41+
42+
cc_library(
43+
name = "gtest_main",
44+
testonly = 1,
45+
visibility = ["//visibility:public"],
46+
deps = [
47+
":gtest",
48+
],
49+
srcs = [
50+
"googletest/src/gtest_main.cc",
51+
],
52+
)
53+
54+
cc_library(
55+
name = "gtest_prod",
56+
visibility = ["//visibility:public"],
57+
hdrs = [
58+
"googletest/include/gtest/gtest_prod.h",
59+
],
60+
)
61+
62+
cc_library(
63+
name = "googlemock",
64+
testonly = 1,
65+
visibility = ["//visibility:public"],
66+
hdrs = [
67+
"googlemock/include/gmock/gmock-actions.h",
68+
"googlemock/include/gmock/gmock-cardinalities.h",
69+
"googlemock/include/gmock/gmock-generated-actions.h",
70+
"googlemock/include/gmock/gmock-generated-function-mockers.h",
71+
"googlemock/include/gmock/gmock-generated-matchers.h",
72+
"googlemock/include/gmock/gmock-generated-nice-strict.h",
73+
"googlemock/include/gmock/gmock.h",
74+
"googlemock/include/gmock/gmock-matchers.h",
75+
"googlemock/include/gmock/gmock-more-actions.h",
76+
"googlemock/include/gmock/gmock-more-matchers.h",
77+
"googlemock/include/gmock/gmock-spec-builders.h",
78+
],
79+
srcs = glob([
80+
"googlemock/include/gmock/internal/**/*.h"
81+
]) + [
82+
"googlemock/src/gmock-cardinalities.cc",
83+
"googlemock/src/gmock.cc",
84+
"googlemock/src/gmock-internal-utils.cc",
85+
"googlemock/src/gmock-matchers.cc",
86+
"googlemock/src/gmock-spec-builders.cc",
87+
],
88+
deps = [
89+
":gtest",
90+
],
91+
includes = [
92+
"googlemock/include",
93+
],
94+
)
95+
96+
cc_library(
97+
name = "gmock_main",
98+
visibility = ["//visibility:public"],
99+
deps = [
100+
":gmock",
101+
],
102+
srcs = [
103+
"googlemock/src/gmock_main.cc",
104+
],
14105
)

bzl/repositories.bzl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,11 @@ REPOSITORIES = {
139139

140140
# GTest is for our own internal cc tests.
141141
"gtest": {
142-
"kind": "new_http_archive",
142+
"kind": "new_git_repository",
143143
"name": "gtest",
144-
"url": "https://googletest.googlecode.com/files/gtest-1.7.0.zip",
145-
"sha256": "247ca18dd83f53deb1328be17e4b1be31514cedfc1e3424f672bf11fd7e0d60d",
144+
"remote": "https://github.com/google/googletest.git",
145+
"commit": "ed9d1e1ff92ce199de5ca2667a667cd0a368482a",
146146
"build_file": str(Label("//bzl:build_file/gtest.BUILD")),
147-
"strip_prefix": "gtest-1.7.0",
148147
},
149148

150149
# ****************************************************************

bzl/util.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def require(target, context):
119119
# for ext in requires:
120120
# require(ext, opts)
121121

122+
if not hasattr(native, kind):
123+
fail("No native workspace rule named '%s' in dependency %s" % (kind, name))
124+
122125
rule = getattr(native, kind)
123126
if not rule:
124127
fail("During require (%s), kind '%s' has no matching native rule" % (target, dep.kind))

examples/helloworld/cpp/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cc_test(
1313
tags = ["exclusive"],
1414
deps = [
1515
":clientlib",
16-
"@gtest//:main",
16+
"@gtest//:gtest",
1717
],
1818
)
1919

examples/helloworld/cpp/greeter_client_test.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ class GreeterClientTest : public ::testing::Test {
5757
// so at some level, even if we can run a test that does nothing is a
5858
// success.
5959

60-
6160
TEST_F(GreeterClientTest, testHello) {
6261
GreeterClient greeter(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()));
6362
std::string user("world");
6463
std::string reply = ("Hello world");
6564
//std::string reply = greeter.SayHello(user);
6665
EXPECT_EQ("Hello world", reply);
6766
}
67+
68+
69+
int main(int ac, char* av[]) {
70+
testing::InitGoogleTest(&ac, av);
71+
return RUN_ALL_TESTS();
72+
}

0 commit comments

Comments
 (0)