Skip to content

Commit fca69a7

Browse files
committed
Merge branch 'dev' into bugfix/integration-tests-mac-openssl-error
2 parents aa7281b + f5995b4 commit fca69a7

25 files changed

+384
-197
lines changed

.github/workflows/cpp-packaging.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
preserveIntermediateArtifacts:
1212
description: 'preserve intermediate artifacts?'
1313
default: 0
14+
verboseBuild:
15+
description: 'verbose build?'
16+
default: 0
1417
skipIntegrationTests:
1518
description: 'skip integration tests?'
1619
default: 0
@@ -60,6 +63,12 @@ jobs:
6063
github.event.inputs.downloadPublicVersion == '' && github.event.inputs.downloadPreviousRun == ''
6164
run: echo "::warning ::Intermediate artifacts will be preserved."
6265

66+
- name: log if verbose build enabled
67+
if: |
68+
github.event.inputs.verboseBuild != 0 && github.event.inputs.verboseBuild != '' &&
69+
github.event.inputs.downloadPublicVersion == '' && github.event.inputs.downloadPreviousRun == ''
70+
run: echo "::warning ::Verbose build enabled."
71+
6372
build_tools:
6473
name: build-tools-${{ matrix.tools_platform }}
6574
runs-on: ${{ matrix.os }}
@@ -320,7 +329,11 @@ jobs:
320329
- name: Build desktop SDK
321330
shell: bash
322331
run: |
323-
python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --linux_abi "${{ matrix.linux_abi }}" --build_dir out-${{ env.SDK_NAME }} ${{ matrix.additional_build_flags }}
332+
verbose_flag=
333+
if [[ -n "${{ github.event.inputs.verboseBuild }}" && "${{ github.event.inputs.verboseBuild }}" -ne 0 ]]; then
334+
verbose_flag=--verbose
335+
fi
336+
python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --linux_abi "${{ matrix.linux_abi }}" --build_dir out-${{ env.SDK_NAME }} ${verbose_flag} ${{ matrix.additional_build_flags }}
324337
# Make a list of all the source files, for debugging purposes.
325338
cd out-${{ env.SDK_NAME }}
326339
find .. -type f -print > src_file_list.txt
@@ -433,12 +446,30 @@ jobs:
433446
else
434447
tools_platform=darwin
435448
fi
449+
verbose_flag=
450+
if [[ -n "${{ github.event.inputs.verboseBuild }}" && "${{ github.event.inputs.verboseBuild }}" -ne 0 ]]; then
451+
verbose_flag=-v
452+
fi
453+
declare -a additional_flags
436454
tar -xvzf artifacts/packaging-tools-${tools_platform}/packaging-tools.tgz -C bin
437455
chmod -R u+x bin
438456
for pkg in artifacts/firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix }}*-build/*.tgz; do
439457
# determine the build variant based on the artifact filename
440458
variant=$(sdk-src/build_scripts/desktop/get_variant.sh "${pkg}")
441-
sdk-src/build_scripts/desktop/package.sh -b ${pkg} -o firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix }}-package -p ${{ matrix.sdk_platform }} -t bin -d ${variant} -P python3 -j
459+
additional_flags=(${verbose_flag})
460+
# Several build targets require explicitly-set binutils format to be passed
461+
# to package.sh (and thus, to merge_libraries).
462+
if [[ "${{ matrix.sdk_platform }}" == "darwin" && "${variant}" == "arm64" ]]; then
463+
# MacOS ARM
464+
additional_flags+=(-f mach-o-arm64)
465+
elif [[ "${{ matrix.sdk_platform }}" == "windows" && "${variant}" == *"/x64/"* ]]; then
466+
# Windows x64
467+
additional_flags+=(-f pe-x86-64,pe-bigobj-x86-64)
468+
elif [[ "${{ matrix.sdk_platform }}" == "windows" && "${variant}" == *"/x86/"* ]]; then
469+
# Windows x86
470+
additional_flags+=(-f pe-i386,pe-bigobj-i386)
471+
fi
472+
sdk-src/build_scripts/desktop/package.sh -b ${pkg} -o firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix }}-package -p ${{ matrix.sdk_platform }} -t bin -d ${variant} -P python3 -j ${additional_flags[*]}
442473
done
443474
if [[ "${{ matrix.sdk_platform }}" == "darwin" ]]; then
444475
# Darwin has a final step after all the variants are done,
@@ -672,7 +703,7 @@ jobs:
672703
python scripts/gha/restore_secrets.py --passphrase "${{ secrets.TEST_SECRET }}"
673704
- name: Build integration tests
674705
run: |
675-
python scripts/gha/build_testapps.py --t ${{ env.apis }} --p ${{ matrix.target_platform }} --sdk_dir firebase_cpp_sdk --output_directory "${{ github.workspace }}" --noadd_timestamp
706+
python scripts/gha/build_testapps.py --t ${{ env.apis }} --p ${{ matrix.target_platform }} --packaged_sdk firebase_cpp_sdk --output_directory "${{ github.workspace }}" --noadd_timestamp
676707
677708
- name: Run desktop integration tests
678709
if: matrix.target_platform == 'Desktop' && !cancelled()

.github/workflows/integration_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
if [[ "${{ matrix.ssl_variant }}" == "boringssl" ]]; then
137137
ssl_option=--cmake_flag=-DFIREBASE_USE_BORINGSSL=ON
138138
fi
139-
python scripts/gha/build_testapps.py --t ${{ github.event.inputs.apis }} --p ${{ matrix.target_platform }} --output_directory "${{ github.workspace }}" --use_vcpkg --noadd_timestamp ${ssl_option}
139+
python scripts/gha/build_testapps.py --t ${{ github.event.inputs.apis }} --p ${{ matrix.target_platform }} --output_directory "${{ github.workspace }}" --noadd_timestamp ${ssl_option}
140140
141141
- name: Run desktop integration tests
142142
if: matrix.target_platform == 'Desktop' && !cancelled()

app/instance_id/instance_id_desktop_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ bool InstanceIdDesktopImpl::FetchServerToken(const char* scope, bool* retry) {
721721
size_t component_start = 0;
722722
size_t component_end;
723723
do {
724-
component_end = error.find(":", component_start);
724+
component_end = error.find(':', component_start);
725725
std::string error_component =
726726
error.substr(component_start, component_end - component_start);
727727
if (error_component == kPhoneRegistrationError) {

app/src/locale.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ std::string GetLocale() {
6969
// Some of the environment variables have a "." after the name to specify the
7070
// terminal encoding, e.g. "en_US.UTF-8", so we want to cut the string on the
7171
// ".".
72-
size_t cut = output.find(".");
72+
size_t cut = output.find('.');
7373
if (cut != std::string::npos) {
7474
output = output.substr(0, cut);
7575
}
7676
// Do the same with a "@" which some locales also have.
77-
cut = output.find("@");
77+
cut = output.find('@');
7878
if (cut != std::string::npos) {
7979
output = output.substr(0, cut);
8080
}

app/tests/locale_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST_F(LocaleTest, TestGetLocale) {
4949
// Make sure this looks like a locale, e.g. has at least 5 characters and
5050
// contains an underscore.
5151
EXPECT_GE(loc.size(), 5);
52-
EXPECT_NE(loc.find("_"), std::string::npos);
52+
EXPECT_NE(loc.find('_'), std::string::npos);
5353
}
5454

5555
} // namespace internal

auth/src/desktop/rpcs/error_codes.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ AuthError GetAuthErrorCode(const std::string& error,
225225
// Couldn't find it, check again with just the first word.
226226
// Sometimes the backend will return the error code along with
227227
// some explanatory text (see kAuthErrorNoSuchProvider above).
228-
size_t space = error.find(" ");
228+
size_t space = error.find(' ');
229229
if (space != std::string::npos) {
230230
std::string first_word = error.substr(0, space);
231231
found = find_error(first_word);

build_scripts/desktop/package.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ options:
1313
-m, merge_libraries.py path default: <script dir>/../../scripts/merge_libraries.py
1414
-P, python command default: python
1515
-t, packaging tools directory default: ~/bin
16+
-f, binutils format default: [auto-detect]
1617
-j, run merge_libraries jobs in parallel
1718
-v, enable verbose mode
1819
example:
@@ -29,6 +30,7 @@ root_dir=$(cd $(dirname $0)/../..; pwd -P)
2930
merge_libraries_script=${root_dir}/scripts/merge_libraries.py
3031
tools_path=~/bin
3132
built_sdk_tarfile=
33+
binutils_format=
3234
temp_dir=
3335
run_in_parallel=0
3436

@@ -44,8 +46,11 @@ abspath(){
4446
fi
4547
}
4648

47-
while getopts "b:o:p:d:m:P:t:hjv" opt; do
49+
while getopts "f:b:o:p:d:m:P:t:hjv" opt; do
4850
case $opt in
51+
f)
52+
binutils_format=$OPTARG
53+
;;
4954
b)
5055
built_sdk_path=$OPTARG
5156
;;
@@ -252,6 +257,11 @@ fi
252257
if [[ ${verbose} -eq 1 ]]; then
253258
merge_libraries_params+=(--verbosity=3)
254259
fi
260+
if [[ -n "${binutils_format}" ]]; then
261+
merge_libraries_params+=(--force_binutils_target="${binutils_format}")
262+
fi
263+
264+
255265

256266
if [[ ! -x "${binutils_objcopy}" || ! -x "${binutils_ar}" || ! -x "${binutils_nm}" ]]; then
257267
echo "Packaging tools not found at path '${tools_path}'."
@@ -327,12 +337,12 @@ for product in ${product_list[*]}; do
327337
rm -f "${outfile}"
328338
if [[ ${verbose} -eq 1 ]]; then
329339
echo "${python_cmd}" "${merge_libraries_script}" \
330-
${merge_libraries_params[*]} \
340+
${merge_libraries_params[*]} \
331341
${cache_param} \
332-
--output="${outfile}" \
333-
--scan_libs="${allfiles}" \
334-
--hide_c_symbols="${deps_hidden}" \
335-
${libfile_src} ${deps[*]}
342+
--output="${outfile}" \
343+
--scan_libs="${allfiles}" \
344+
--hide_c_symbols="${deps_hidden}" \
345+
${libfile_src} ${deps[*]}
336346
fi
337347
# Place the merge command in a script so we can optionally run them in parallel.
338348
echo "#!/bin/bash -e" > "${merge_libraries_tmp}/merge_${product}.sh"
@@ -342,7 +352,7 @@ for product in ${product_list[*]}; do
342352
echo "echo \"${libfile_out}\"" >> "${merge_libraries_tmp}/merge_${product}.sh"
343353
fi
344354
if [[ ! -z ${deps_basenames[*]} ]]; then
345-
echo -n >> "${merge_libraries_tmp}/merge_${product}.sh"
355+
echo -n >> "${merge_libraries_tmp}/merge_${product}.sh"
346356
fi
347357
echo >> "${merge_libraries_tmp}/merge_${product}.sh"
348358
echo "\"${python_cmd}\" \\

cmake/external_rules.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ function(build_external_dependencies)
148148
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}")
149149
endif()
150150

151+
if (CMAKE_VERBOSE_MAKEFILE)
152+
# If verbose mode was enabled, pass it on
153+
set(CMAKE_SUB_CONFIGURE_OPTIONS ${CMAKE_SUB_CONFIGURE_OPTIONS}
154+
"-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE}")
155+
endif()
156+
151157
if(APPLE)
152158
# Propagate MacOS build flags.
153159
if(CMAKE_OSX_ARCHITECTURES)

firestore/src/android/firestore_android.cc

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,24 @@ class JavaFirestoreMap {
178178
jni::Global<jni::HashMap> firestores_;
179179
};
180180

181-
// Governed by init_mutex_below as well.
182-
JavaFirestoreMap* java_firestores_ = nullptr;
181+
// init_mutex protects all the globals below.
182+
Mutex init_mutex; // NOLINT
183+
int initialize_count = 0;
184+
Loader* global_loader = nullptr;
185+
186+
JavaFirestoreMap* java_firestores = nullptr;
187+
188+
// The initial value for setLoggingEnabled.
189+
enum class InitialLogState {
190+
kUnset,
191+
kSetEnabled,
192+
kSetDisabled,
193+
} initial_log_state = InitialLogState::kUnset;
183194

184195
} // namespace
185196

186197
const char kApiIdentifier[] = "Firestore";
187198

188-
Mutex FirestoreInternal::init_mutex_; // NOLINT
189-
int FirestoreInternal::initialize_count_ = 0;
190-
Loader* FirestoreInternal::loader_ = nullptr;
191-
192199
FirestoreInternal::FirestoreInternal(App* app) {
193200
FIREBASE_ASSERT(app != nullptr);
194201
if (!Initialize(app)) return;
@@ -200,7 +207,7 @@ FirestoreInternal::FirestoreInternal(App* app) {
200207
FIREBASE_ASSERT(java_firestore.get() != nullptr);
201208
obj_ = java_firestore;
202209

203-
java_firestores_->Put(env, java_firestore, this);
210+
java_firestores->Put(env, java_firestore, this);
204211

205212
// Mainly for enabling TimestampsInSnapshotsEnabled. The rest comes from the
206213
// default in native SDK. The C++ implementation relies on that for reading
@@ -218,21 +225,22 @@ FirestoreInternal::FirestoreInternal(App* app) {
218225

219226
/* static */
220227
bool FirestoreInternal::Initialize(App* app) {
221-
MutexLock init_lock(init_mutex_);
222-
if (initialize_count_ == 0) {
228+
MutexLock init_lock(init_mutex);
229+
if (initialize_count == 0) {
223230
jni::Initialize(app->java_vm());
224231

225-
FIREBASE_DEV_ASSERT(java_firestores_ == nullptr);
226-
java_firestores_ = new JavaFirestoreMap();
232+
FIREBASE_DEV_ASSERT(java_firestores == nullptr);
233+
java_firestores = new JavaFirestoreMap();
227234

235+
Env env = GetEnv();
228236
Loader loader(app);
229237
loader.AddEmbeddedFile(::firebase_firestore::firestore_resources_filename,
230238
::firebase_firestore::firestore_resources_data,
231239
::firebase_firestore::firestore_resources_size);
232240
loader.CacheEmbeddedFiles();
233241

234242
jni::Object::Initialize(loader);
235-
243+
jni::String::Initialize(env, loader);
236244
jni::ArrayList::Initialize(loader);
237245
jni::Boolean::Initialize(loader);
238246
jni::Collection::Initialize(loader);
@@ -272,32 +280,42 @@ bool FirestoreInternal::Initialize(App* app) {
272280
TransactionInternal::Initialize(loader);
273281
WriteBatchInternal::Initialize(loader);
274282
if (!loader.ok()) {
275-
ReleaseClasses(app);
283+
ReleaseClassesLocked(env);
276284
return false;
277285
}
278286

279-
FIREBASE_DEV_ASSERT(loader_ == nullptr);
280-
loader_ = new Loader(Move(loader));
287+
FIREBASE_DEV_ASSERT(global_loader == nullptr);
288+
global_loader = new Loader(Move(loader));
289+
290+
if (initial_log_state != InitialLogState::kUnset) {
291+
bool enabled = initial_log_state == InitialLogState::kSetEnabled;
292+
env.Call(kSetLoggingEnabled, enabled);
293+
}
281294
}
282-
initialize_count_++;
295+
initialize_count++;
283296
return true;
284297
}
285298

286299
/* static */
287-
void FirestoreInternal::ReleaseClasses(App* app) {
288-
delete loader_;
289-
loader_ = nullptr;
300+
void FirestoreInternal::ReleaseClassesLocked(Env& env) {
301+
// Assumes `init_mutex` is held.
302+
String::Terminate(env);
303+
304+
delete global_loader;
305+
global_loader = nullptr;
290306
}
291307

292308
/* static */
293309
void FirestoreInternal::Terminate(App* app) {
294-
MutexLock init_lock(init_mutex_);
295-
FIREBASE_ASSERT(initialize_count_ > 0);
296-
initialize_count_--;
297-
if (initialize_count_ == 0) {
298-
ReleaseClasses(app);
299-
delete java_firestores_;
300-
java_firestores_ = nullptr;
310+
MutexLock init_lock(init_mutex);
311+
FIREBASE_ASSERT(initialize_count > 0);
312+
initialize_count--;
313+
if (initialize_count == 0) {
314+
Env env(app->GetJNIEnv());
315+
ReleaseClassesLocked(env);
316+
317+
delete java_firestores;
318+
java_firestores = nullptr;
301319
}
302320
}
303321

@@ -316,7 +334,7 @@ FirestoreInternal::~FirestoreInternal() {
316334

317335
future_manager_.ReleaseFutureApi(this);
318336

319-
java_firestores_->Remove(env, obj_);
337+
java_firestores->Remove(env, obj_);
320338

321339
Terminate(app_);
322340
app_ = nullptr;
@@ -512,13 +530,28 @@ void Firestore::set_log_level(LogLevel log_level) {
512530
// "Info", "warning", "error", and "assert" map to logging disabled.
513531
bool logging_enabled = log_level < LogLevel::kLogLevelInfo;
514532

533+
{
534+
MutexLock lock(init_mutex);
535+
536+
// Set the initial_log_state on every invocation, just in case Firestore
537+
// is terminated for long enough to unload the Firestore classes within
538+
// the JVM.
539+
initial_log_state = logging_enabled ? InitialLogState::kSetEnabled
540+
: InitialLogState::kSetDisabled;
541+
542+
if (initialize_count < 1) {
543+
// Avoid invoking Java methods before Firestore has been initialized.
544+
return;
545+
}
546+
}
547+
515548
Env env = FirestoreInternal::GetEnv();
516549
env.Call(kSetLoggingEnabled, logging_enabled);
517550
}
518551

519552
FirestoreInternal* FirestoreInternal::RecoverFirestore(
520553
Env& env, const Object& java_firestore) {
521-
return java_firestores_->Get(env, java_firestore);
554+
return java_firestores->Get(env, java_firestore);
522555
}
523556

524557
void FirestoreInternal::SetClientLanguage(const std::string& language_token) {

firestore/src/android/firestore_android.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,9 @@ class FirestoreInternal {
178178
void ShutdownUserCallbackExecutor(jni::Env& env);
179179

180180
static bool Initialize(App* app);
181-
static void ReleaseClasses(App* app);
181+
static void ReleaseClassesLocked(jni::Env& env);
182182
static void Terminate(App* app);
183183

184-
static Mutex init_mutex_;
185-
static int initialize_count_;
186-
static jni::Loader* loader_;
187-
188184
jni::Global<jni::Object> user_callback_executor_;
189185

190186
App* app_ = nullptr;

0 commit comments

Comments
 (0)