Skip to content

Commit 274fe52

Browse files
authored
cmake build fixes (firebase#770)
* Fix nanopb (in cmake build) Look for binaries in the src dir (since that's where we build now.) This error would be masked if a previous build had completed prior to switching nanopb to build out of src. Also, don't patch the protoc path multiple times. This could be triggered by (eg) 'make && make clean && make'. * Add resource_path.{h,cc} to the cmake build * Fix signed/unsigned int comparison warnings * Ensure FieldValue tag_ is initialized during cp/mv ctor. Otherwise, the assignment operator attempts to deallocate based on the (uninitialized) tag_ variable, posssibly leading to segfaults. * Fix tests that throw exceptions. The (previous) tests checked to ensure that an abort() occurs, but if ABSL_HAVE_EXCEPTIONS is defined on non-macos (which is currently the default) then the assertions will throw a std::logic_error rather than abort()ing. On macos, an exception is thrown too, but the exception doesn't derrive from std::exception, so ASSERT_DEATH_* doesn't catch it (hence why ASSERT_DEATH_* actually works.) To resolve this, I've switched to ASSERT_ANY_THROW.
1 parent ecef4aa commit 274fe52

11 files changed

Lines changed: 48 additions & 39 deletions

File tree

Firestore/core/src/firebase/firestore/model/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ cc_library(
2222
field_path.h
2323
field_value.cc
2424
field_value.h
25+
resource_path.cc
26+
resource_path.h
2527
timestamp.cc
2628
timestamp.h
2729
DEPENDS

Firestore/core/src/firebase/firestore/model/base_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class BasePath {
166166
}
167167
BasePath(std::initializer_list<std::string> list) : segments_{list} {
168168
}
169-
BasePath(SegmentsT&& segments) : segments_{std::move(segments)} {
169+
explicit BasePath(SegmentsT&& segments) : segments_{std::move(segments)} {
170170
}
171171

172172
private:

Firestore/core/src/firebase/firestore/model/field_path.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool IsValidIdentifier(const std::string& segment) {
5151
(first < 'A' || first > 'Z')) {
5252
return false;
5353
}
54-
for (int i = 1; i != segment.size(); ++i) {
54+
for (size_t i = 1; i != segment.size(); ++i) {
5555
const unsigned char c = segment[i];
5656
if (c != '_' && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') &&
5757
(c < '0' || c > '9')) {
@@ -93,7 +93,7 @@ FieldPath FieldPath::FromServerFormat(const absl::string_view path) {
9393

9494
// Inside backticks, dots are treated literally.
9595
bool inside_backticks = false;
96-
int i = 0;
96+
size_t i = 0;
9797
while (i < path.size()) {
9898
const char c = path[i];
9999
// std::string (and string_view) may contain embedded nulls. For full

Firestore/core/src/firebase/firestore/model/field_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class FieldPath : public impl::BasePath<FieldPath> {
8282
}
8383

8484
private:
85-
FieldPath(SegmentsT&& segments) : BasePath{std::move(segments)} {
85+
explicit FieldPath(SegmentsT&& segments) : BasePath{std::move(segments)} {
8686
}
8787

8888
// So that methods of base can construct FieldPath using the private

Firestore/core/src/firebase/firestore/model/field_value.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class FieldValue {
6969
// position instead, see the doc comment above.
7070
};
7171

72-
FieldValue() : tag_(Type::Null) {
72+
FieldValue() {
7373
}
7474

7575
// Do not inline these ctor/dtor below, which contain call to non-trivial
@@ -123,7 +123,7 @@ class FieldValue {
123123
*/
124124
void SwitchTo(const Type type);
125125

126-
Type tag_;
126+
Type tag_ = Type::Null;
127127
union {
128128
// There is no null type as tag_ alone is enough for Null FieldValue.
129129
bool boolean_value_;

Firestore/core/src/firebase/firestore/model/resource_path.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <algorithm>
2020
#include <utility>
21+
#include <vector>
2122

2223
#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"
2324
#include "absl/strings/str_join.h"

Firestore/core/src/firebase/firestore/model/resource_path.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <initializer_list>
2121
#include <string>
22+
#include <utility>
2223

2324
#include "Firestore/core/src/firebase/firestore/model/base_path.h"
2425
#include "absl/strings/string_view.h"
@@ -69,7 +70,7 @@ class ResourcePath : public impl::BasePath<ResourcePath> {
6970
}
7071

7172
private:
72-
ResourcePath(SegmentsT&& segments) : BasePath{std::move(segments)} {
73+
explicit ResourcePath(SegmentsT&& segments) : BasePath{std::move(segments)} {
7374
}
7475

7576
// So that methods of base can construct ResourcePath using the private
@@ -81,4 +82,4 @@ class ResourcePath : public impl::BasePath<ResourcePath> {
8182
} // namespace firestore
8283
} // namespace firebase
8384

84-
#endif
85+
#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_RESOURCE_PATH_H_

Firestore/core/test/firebase/firestore/model/field_path_test.cc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ namespace model {
2929
TEST(FieldPath, Constructors) {
3030
const FieldPath empty_path;
3131
EXPECT_TRUE(empty_path.empty());
32-
EXPECT_EQ(0, empty_path.size());
32+
EXPECT_EQ(0u, empty_path.size());
3333
EXPECT_TRUE(empty_path.begin() == empty_path.end());
3434

3535
const FieldPath path_from_list = {"rooms", "Eros", "messages"};
3636
EXPECT_FALSE(path_from_list.empty());
37-
EXPECT_EQ(3, path_from_list.size());
37+
EXPECT_EQ(3u, path_from_list.size());
3838
EXPECT_TRUE(path_from_list.begin() + 3 == path_from_list.end());
3939

4040
std::vector<std::string> segments{"rooms", "Eros", "messages"};
4141
const FieldPath path_from_segments{segments.begin(), segments.end()};
4242
EXPECT_FALSE(path_from_segments.empty());
43-
EXPECT_EQ(3, path_from_segments.size());
43+
EXPECT_EQ(3u, path_from_segments.size());
4444
EXPECT_TRUE(path_from_segments.begin() + 3 == path_from_segments.end());
4545

4646
FieldPath copied = path_from_list;
@@ -168,13 +168,13 @@ TEST(FieldPath, IsPrefixOf) {
168168

169169
TEST(FieldPath, AccessFailures) {
170170
const FieldPath path;
171-
ASSERT_DEATH_IF_SUPPORTED(path.first_segment(), "");
172-
ASSERT_DEATH_IF_SUPPORTED(path.last_segment(), "");
173-
ASSERT_DEATH_IF_SUPPORTED(path[0], "");
174-
ASSERT_DEATH_IF_SUPPORTED(path[1], "");
175-
ASSERT_DEATH_IF_SUPPORTED(path.PopFirst(), "");
176-
ASSERT_DEATH_IF_SUPPORTED(path.PopFirst(2), "");
177-
ASSERT_DEATH_IF_SUPPORTED(path.PopLast(), "");
171+
ASSERT_ANY_THROW(path.first_segment());
172+
ASSERT_ANY_THROW(path.last_segment());
173+
ASSERT_ANY_THROW(path[0]);
174+
ASSERT_ANY_THROW(path[1]);
175+
ASSERT_ANY_THROW(path.PopFirst());
176+
ASSERT_ANY_THROW(path.PopFirst(2));
177+
ASSERT_ANY_THROW(path.PopLast());
178178
}
179179

180180
TEST(FieldPath, Parsing) {
@@ -201,7 +201,7 @@ TEST(FieldPath, Parsing) {
201201

202202
const auto path_with_dot = FieldPath::FromServerFormat(R"(foo\.bar)");
203203
EXPECT_EQ(path_with_dot.CanonicalString(), "`foo.bar`");
204-
EXPECT_EQ(path_with_dot.size(), 1);
204+
EXPECT_EQ(path_with_dot.size(), 1u);
205205
}
206206

207207
// This is a special case in C++: std::string may contain embedded nulls. To
@@ -213,22 +213,22 @@ TEST(FieldPath, ParseEmbeddedNull) {
213213
str += ".bar";
214214

215215
const auto path = FieldPath::FromServerFormat(str);
216-
EXPECT_EQ(path.size(), 1);
216+
EXPECT_EQ(path.size(), 1u);
217217
EXPECT_EQ(path.CanonicalString(), "foo");
218218
}
219219

220220
TEST(FieldPath, ParseFailures) {
221-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat(""), "");
222-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat("."), "");
223-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat(".."), "");
224-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat("foo."), "");
225-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat(".bar"), "");
226-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat("foo..bar"), "");
227-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat(R"(foo\)"), "");
228-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat(R"(foo.\)"), "");
229-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat("foo`"), "");
230-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat("foo```"), "");
231-
ASSERT_DEATH_IF_SUPPORTED(FieldPath::FromServerFormat("`foo"), "");
221+
ASSERT_ANY_THROW(FieldPath::FromServerFormat(""));
222+
ASSERT_ANY_THROW(FieldPath::FromServerFormat("."));
223+
ASSERT_ANY_THROW(FieldPath::FromServerFormat(".."));
224+
ASSERT_ANY_THROW(FieldPath::FromServerFormat("foo."));
225+
ASSERT_ANY_THROW(FieldPath::FromServerFormat(".bar"));
226+
ASSERT_ANY_THROW(FieldPath::FromServerFormat("foo..bar"));
227+
ASSERT_ANY_THROW(FieldPath::FromServerFormat(R"(foo\)"));
228+
ASSERT_ANY_THROW(FieldPath::FromServerFormat(R"(foo.\)"));
229+
ASSERT_ANY_THROW(FieldPath::FromServerFormat("foo`"));
230+
ASSERT_ANY_THROW(FieldPath::FromServerFormat("foo```"));
231+
ASSERT_ANY_THROW(FieldPath::FromServerFormat("`foo"));
232232
}
233233

234234
TEST(FieldPath, CanonicalStringOfSubstring) {

Firestore/core/test/firebase/firestore/model/resource_path_test.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ namespace model {
2929
TEST(ResourcePath, Constructor) {
3030
const ResourcePath empty_path;
3131
EXPECT_TRUE(empty_path.empty());
32-
EXPECT_EQ(0, empty_path.size());
32+
EXPECT_EQ(0u, empty_path.size());
3333
EXPECT_TRUE(empty_path.begin() == empty_path.end());
3434

3535
const ResourcePath path_from_list{{"rooms", "Eros", "messages"}};
3636
EXPECT_FALSE(path_from_list.empty());
37-
EXPECT_EQ(3, path_from_list.size());
37+
EXPECT_EQ(3u, path_from_list.size());
3838
EXPECT_TRUE(path_from_list.begin() + 3 == path_from_list.end());
3939

4040
std::vector<std::string> segments{"rooms", "Eros", "messages"};
4141
const ResourcePath path_from_segments{segments.begin(), segments.end()};
4242
EXPECT_FALSE(path_from_segments.empty());
43-
EXPECT_EQ(3, path_from_segments.size());
43+
EXPECT_EQ(3u, path_from_segments.size());
4444
EXPECT_TRUE(path_from_segments.begin() + 3 == path_from_segments.end());
4545

4646
ResourcePath copied = path_from_list;
@@ -96,8 +96,8 @@ TEST(ResourcePath, Parsing) {
9696
}
9797

9898
TEST(ResourcePath, ParseFailures) {
99-
ASSERT_DEATH_IF_SUPPORTED(ResourcePath::Parse("//"), "");
100-
ASSERT_DEATH_IF_SUPPORTED(ResourcePath::Parse("foo//bar"), "");
99+
ASSERT_ANY_THROW(ResourcePath::Parse("//"));
100+
ASSERT_ANY_THROW(ResourcePath::Parse("foo//bar"));
101101
}
102102

103103
} // namespace model

cmake/FindNanopb.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ find_path(
1010
find_library(
1111
NANOPB_LIBRARY
1212
NAMES protobuf-nanopb protobuf-nanopbd
13-
HINTS ${BINARY_DIR}/src/nanopb-build
13+
HINTS ${BINARY_DIR}/src/nanopb
1414
)
1515

1616
find_package_handle_standard_args(

0 commit comments

Comments
 (0)