Skip to content

Commit 4b51b42

Browse files
authored
Merge d35bab3 into afa0cdd
2 parents afa0cdd + d35bab3 commit 4b51b42

File tree

8 files changed

+181
-122
lines changed

8 files changed

+181
-122
lines changed

firestore/CONTRIBUTING.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Overview
2+
3+
This describes how to Firestore CPP SDK works on supported platforms, and how to
4+
contribute this Firestore CPP SDK.
5+
6+
Please read `README.md` and `CONTRIBUTING.md` from the repository root first.
7+
8+
# Prerequisites
9+
10+
There is no specific prerequisites for Firestore, `README.md` from the root directory
11+
should have everything you need.
12+
13+
One slight enhancement is to use [https://github.com/pyenv/pyenv][pyenv] to manage
14+
your python versions, if you work on multiple projects with different python
15+
requirements.
16+
17+
For CPP SDK to compile, you generally need your `pyenv which python` to point to
18+
a Python3 installation.
19+
20+
# Architecture
21+
22+
It is easier to work this Firestore CPP SDK by keeping a high level archetecture in mind:
23+
24+
![architecture.png](architecture.png)
25+
26+
To summarize, the C++ Code in this directory is an adapting layer on top of the underlying
27+
SDKs: Firestore Android SDK for Android, and C++ Core SDK for everything else.
28+
29+
These dependencies live within different github repos, so understanding where and which versions
30+
of the dependencies being used is critical to troubleshooting, should the issues stem from
31+
those dependencies or the interop layer.
32+
33+
# Desktop building and testing
34+
35+
Desktop builds of the Firestore SDK uses `CMAKE` to build and test. The complete set
36+
of tests lives under `${REPO_ROOT}/firestore/integration_test_internal`. To build
37+
the Firestore CPP SDK and its test suites:
38+
39+
```shell
40+
# from ${REPO_ROOT}/firestore/integration_test_internal
41+
mkdir cmake-build-debug
42+
cd cmake-build-debug
43+
44+
# Generate build files
45+
cmake .. # Or OPENSSL_ROOT_DIR=${PATH_TO_OPENSSL} cmake ..
46+
# Build SDK and tests
47+
cmake --build . -j
48+
```
49+
50+
Once above steps are successful, there should be a `integration_test` under the current directory:
51+
```shell
52+
./integration_test # Run all tests against Firestore Prod Backend
53+
54+
USE_FIRESTORE_EMULATOR=yes ./integration_test # Run all tests against Firestore Emulator
55+
56+
# Run all tests against Firestore Emulator on a custom port
57+
USE_FIRESTORE_EMULATOR=yes FIRESTORE_EMULATOR_PORT=9999 ./integration_test
58+
59+
./integration_test --gtest_filter="*Query*" # Run a subset of tests
60+
```
61+
62+
It is also possible to change where we get the underlying C++ Core SDK living under
63+
`firebase-ios-sdk` by providing a custom cmake flag `FIRESTORE_DEP_SOURCE`:
64+
```shell
65+
# Default behavior when not specified, getting the Core SDK the last C++ SDK release
66+
# was released with.
67+
cmake -DFIRESTORE_DEP_SOURCE=RELEASED ..
68+
69+
# Clones the origin/master branch of `firebase-ios-sdk` to get the Core SDK.
70+
cmake -DFIRESTORE_DEP_SOURCE=TIP ..
71+
72+
# Clones the origin/master branch of `firebase-ios-sdk` to get the Core SDK.
73+
cmake -DFIRESTORE_DEP_SOURCE=origin/master ..
74+
75+
# Clones commit '555555' of `firebase-ios-sdk`.
76+
cmake -DFIRESTORE_DEP_SOURCE=555555 ..
77+
```
78+
79+
## IDE Integration
80+
81+
Open up the repo root directory from `CLion` should load all symbols for the SDK itsel should
82+
load all symbols for the SDK itself. Once loaded, you can right load on
83+
`firestore/integration_test_internal/CMakeLists.txt` and `load project` to load the tests into
84+
the IDE.
85+
86+
# Android building and testing
87+
# iOS building and testing
88+

firestore/README.md

Lines changed: 0 additions & 90 deletions
This file was deleted.

firestore/architecture.png

106 KB
Loading

firestore/integration_test_internal/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ set(FIREBASE_INTEGRATION_TEST_PORTABLE_SUPPORT_SRCS
140140
src/firestore_integration_test.cc
141141
src/util/bundle_builder.cc
142142
src/util/future_test_util.cc
143+
src/util/locate_emulator.cc
143144
src/util/integration_test_util.cc
144145
)
145146

firestore/integration_test_internal/src/firestore_integration_test.cc

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "android/util_autoid.h"
3030
#endif // !defined(__ANDROID__)
3131
#include "app_framework.h"
32+
#include "util/locate_emulator.h"
3233

3334
namespace firebase {
3435
namespace firestore {
@@ -38,37 +39,6 @@ namespace {
3839
// non-default app to avoid data ending up in the cache before tests run.
3940
static const char* kBootstrapAppName = "bootstrap";
4041

41-
// Set Firestore up to use Firestore Emulator via USE_FIRESTORE_EMULATOR
42-
void LocateEmulator(Firestore* db) {
43-
// Use emulator as long as this env variable is set, regardless its value.
44-
if (std::getenv("USE_FIRESTORE_EMULATOR") == nullptr) {
45-
LogDebug("Using Firestore Prod for testing.");
46-
return;
47-
}
48-
49-
#if defined(__ANDROID__)
50-
// Special IP to access the hosting OS from Android Emulator.
51-
std::string local_host = "10.0.2.2";
52-
#else
53-
std::string local_host = "localhost";
54-
#endif // defined(__ANDROID__)
55-
56-
// Use FIRESTORE_EMULATOR_PORT if it is set to non empty string,
57-
// otherwise use the default port.
58-
std::string port = std::getenv("FIRESTORE_EMULATOR_PORT")
59-
? std::getenv("FIRESTORE_EMULATOR_PORT")
60-
: "8080";
61-
std::string address =
62-
port.empty() ? (local_host + ":8080") : (local_host + ":" + port);
63-
64-
LogInfo("Using Firestore Emulator (%s) for testing.", address.c_str());
65-
auto settings = db->settings();
66-
settings.set_host(address);
67-
// Emulator does not support ssl yet.
68-
settings.set_ssl_enabled(false);
69-
db->set_settings(settings);
70-
}
71-
7242
} // namespace
7343

7444
std::string ToFirestoreErrorCodeName(int error_code) {
@@ -163,7 +133,7 @@ Firestore* FirestoreIntegrationTest::TestFirestoreWithProjectId(
163133
Firestore* db = new Firestore(CreateTestFirestoreInternal(app));
164134
firestores_[db] = FirestoreInfo(name, std::unique_ptr<Firestore>(db));
165135

166-
LocateEmulator(db);
136+
firestore::LocateEmulator(db);
167137
return db;
168138
}
169139

firestore/integration_test_internal/src/integration_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "firebase/auth.h"
4444
#include "firebase/firestore.h"
4545
#include "firebase_test_framework.h" // NOLINT
46+
#include "util/locate_emulator.h"
4647

4748
// The TO_STRING macro is useful for command line defined strings as the quotes
4849
// get stripped.
@@ -253,6 +254,8 @@ void FirebaseFirestoreBasicTest::InitializeFirestore() {
253254
ASSERT_EQ(initializer.InitializeLastResult().error(), 0)
254255
<< initializer.InitializeLastResult().error_message();
255256

257+
LocateEmulator(firestore_);
258+
256259
LogDebug("Successfully initialized Firebase Firestore.");
257260

258261
initialized_ = true;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "util/locate_emulator.h"
17+
18+
#include <string>
19+
20+
#include "app/src/assert.h"
21+
22+
namespace firebase {
23+
namespace firestore {
24+
25+
// Set Firestore up to use Firestore Emulator via USE_FIRESTORE_EMULATOR
26+
void LocateEmulator(Firestore* db) {
27+
// Use emulator as long as this env variable is set, regardless its value.
28+
if (std::getenv("USE_FIRESTORE_EMULATOR") == nullptr) {
29+
LogDebug("Using Firestore Prod for testing.");
30+
return;
31+
}
32+
33+
#if defined(__ANDROID__)
34+
// Special IP to access the hosting OS from Android Emulator.
35+
std::string local_host = "10.0.2.2";
36+
#else
37+
std::string local_host = "localhost";
38+
#endif // defined(__ANDROID__)
39+
40+
// Use FIRESTORE_EMULATOR_PORT if it is set to non empty string,
41+
// otherwise use the default port.
42+
std::string port = std::getenv("FIRESTORE_EMULATOR_PORT")
43+
? std::getenv("FIRESTORE_EMULATOR_PORT")
44+
: "8080";
45+
std::string address =
46+
port.empty() ? (local_host + ":8080") : (local_host + ":" + port);
47+
48+
LogInfo("Using Firestore Emulator (%s) for testing.", address.c_str());
49+
auto settings = db->settings();
50+
settings.set_host(address);
51+
// Emulator does not support ssl yet.
52+
settings.set_ssl_enabled(false);
53+
db->set_settings(settings);
54+
}
55+
56+
} // namespace firestore
57+
} // namespace firebase
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef FIREBASE_FIRESTORE_INTEGRATION_TEST_INTERNAL_SRC_UTIL_LOCATE_EMULATOR_H_
17+
#define FIREBASE_FIRESTORE_INTEGRATION_TEST_INTERNAL_SRC_UTIL_LOCATE_EMULATOR_H_
18+
19+
#include "firestore/src/include/firebase/firestore.h"
20+
21+
namespace firebase {
22+
namespace firestore {
23+
24+
// Set Firestore up to use Firestore Emulator via USE_FIRESTORE_EMULATOR
25+
void LocateEmulator(Firestore* db);
26+
27+
} // namespace firestore
28+
} // namespace firebase
29+
30+
#endif // FIREBASE_FIRESTORE_INTEGRATION_TEST_INTERNAL_SRC_UTIL_LOCATE_EMULATOR_H_

0 commit comments

Comments
 (0)