From e7d428d14be1535a2d579d4b2d376fbb81f06742 Mon Sep 17 00:00:00 2001 From: Cynthia J Date: Wed, 1 Nov 2023 07:29:44 -0700 Subject: [PATCH] feat(windows): add platform logging for core, auth, firestore and storage (#11790) Co-authored-by: Russell Wheatley --- .../cloud_firestore/windows/CMakeLists.txt | 21 ++++++++++++++++ .../windows/cloud_firestore_plugin.cpp | 6 +++++ .../windows/plugin_version.h.in | 13 ++++++++++ .../firebase_auth/windows/CMakeLists.txt | 21 ++++++++++++++++ .../windows/firebase_auth_plugin.cpp | 7 ++++++ .../firebase_auth/windows/plugin_version.h.in | 13 ++++++++++ .../firebase_core/windows/CMakeLists.txt | 24 ++++++++++++++++++- .../windows/firebase_core_plugin.cpp | 7 ++++++ .../firebase_core/windows/plugin_version.h.in | 13 ++++++++++ .../firebase_storage/windows/CMakeLists.txt | 21 ++++++++++++++++ .../windows/firebase_storage_plugin.cpp | 7 ++++-- .../windows/plugin_version.h.in | 13 ++++++++++ .../firebase_storage_e2e_test.dart | 8 +++++-- 13 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 packages/cloud_firestore/cloud_firestore/windows/plugin_version.h.in create mode 100644 packages/firebase_auth/firebase_auth/windows/plugin_version.h.in create mode 100644 packages/firebase_core/firebase_core/windows/plugin_version.h.in create mode 100644 packages/firebase_storage/firebase_storage/windows/plugin_version.h.in diff --git a/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt b/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt index 5440c40427ab..0fa1da05e299 100644 --- a/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt +++ b/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt @@ -22,12 +22,31 @@ list(APPEND PLUGIN_SOURCES "firestore_codec.h" ) +# Read version from pubspec.yaml +file(STRINGS "../pubspec.yaml" pubspec_content) +foreach(line ${pubspec_content}) + string(FIND ${line} "version: " has_version) + + if("${has_version}" STREQUAL "0") + string(FIND ${line} ": " version_start_pos) + math(EXPR version_start_pos "${version_start_pos} + 2") + string(LENGTH ${line} version_end_pos) + math(EXPR len "${version_end_pos} - ${version_start_pos}") + string(SUBSTRING ${line} ${version_start_pos} ${len} PLUGIN_VERSION) + break() + endif() +endforeach(line) + +configure_file(plugin_version.h.in ${CMAKE_BINARY_DIR}/generated/cloud_firestore/plugin_version.h) +include_directories(${CMAKE_BINARY_DIR}/generated/) + # Define the plugin library target. Its name must not be changed (see comment # on PLUGIN_NAME above). add_library(${PLUGIN_NAME} STATIC "include/cloud_firestore/cloud_firestore_plugin_c_api.h" "cloud_firestore_plugin_c_api.cpp" ${PLUGIN_SOURCES} + ${CMAKE_BINARY_DIR}/generated/cloud_firestore/plugin_version.h ) # Apply a standard set of build settings that are configured in the @@ -41,6 +60,8 @@ apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PUBLIC FLUTTER_PLUGIN_IMPL) +# Enable firebase-cpp-sdk's platform logging api. +target_compile_definitions(${PLUGIN_NAME} PRIVATE -DINTERNAL_EXPERIMENTAL=1) # Source include directories and library dependencies. Add any plugin-specific # dependencies here. diff --git a/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp b/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp index 296cc72adfa9..b11febd56d16 100644 --- a/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp +++ b/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp @@ -20,6 +20,7 @@ #include #include +#include "cloud_firestore/plugin_version.h" #include "firebase/app.h" #include "firebase/firestore.h" #include "firebase/firestore/filter.h" @@ -38,6 +39,7 @@ using flutter::EncodableValue; namespace cloud_firestore_windows { +static std::string kLibraryName = "flutter-fire-fst"; // static void CloudFirestorePlugin::RegisterWithRegistrar( flutter::PluginRegistrarWindows* registrar) { @@ -53,6 +55,10 @@ void CloudFirestorePlugin::RegisterWithRegistrar( FirebaseFirestoreHostApi::SetUp(registrar->messenger(), plugin.get()); registrar->AddPlugin(std::move(plugin)); + + // Register for platform logging + App::RegisterLibrary(kLibraryName.c_str(), getPluginVersion().c_str(), + nullptr); } firebase::firestore::FieldValue CloudFirestorePlugin::ConvertToFieldValue( diff --git a/packages/cloud_firestore/cloud_firestore/windows/plugin_version.h.in b/packages/cloud_firestore/cloud_firestore/windows/plugin_version.h.in new file mode 100644 index 000000000000..c2b22b3d8abe --- /dev/null +++ b/packages/cloud_firestore/cloud_firestore/windows/plugin_version.h.in @@ -0,0 +1,13 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#ifndef PLUGIN_VERSION_CONFIG_H +#define PLUGIN_VERSION_CONFIG_H + +namespace cloud_firestore_windows { + +std::string getPluginVersion() { return "@PLUGIN_VERSION@"; } +} // namespace cloud_firestore_windows + +#endif // PLUGIN_VERSION_CONFIG_H diff --git a/packages/firebase_auth/firebase_auth/windows/CMakeLists.txt b/packages/firebase_auth/firebase_auth/windows/CMakeLists.txt index 6dae01cf2593..74c8f9abd4e5 100644 --- a/packages/firebase_auth/firebase_auth/windows/CMakeLists.txt +++ b/packages/firebase_auth/firebase_auth/windows/CMakeLists.txt @@ -20,12 +20,31 @@ list(APPEND PLUGIN_SOURCES "messages.g.h" ) +# Read version from pubspec.yaml +file(STRINGS "../pubspec.yaml" pubspec_content) +foreach(line ${pubspec_content}) + string(FIND ${line} "version: " has_version) + + if("${has_version}" STREQUAL "0") + string(FIND ${line} ": " version_start_pos) + math(EXPR version_start_pos "${version_start_pos} + 2") + string(LENGTH ${line} version_end_pos) + math(EXPR len "${version_end_pos} - ${version_start_pos}") + string(SUBSTRING ${line} ${version_start_pos} ${len} PLUGIN_VERSION) + break() + endif() +endforeach(line) + +configure_file(plugin_version.h.in ${CMAKE_BINARY_DIR}/generated/firebase_auth/plugin_version.h) +include_directories(${CMAKE_BINARY_DIR}/generated/) + # Define the plugin library target. Its name must not be changed (see comment # on PLUGIN_NAME above). add_library(${PLUGIN_NAME} STATIC "include/firebase_auth/firebase_auth_plugin_c_api.h" "firebase_auth_plugin_c_api.cpp" ${PLUGIN_SOURCES} + ${CMAKE_BINARY_DIR}/generated/firebase_auth/plugin_version.h ) # Apply a standard set of build settings that are configured in the @@ -39,6 +58,8 @@ apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PUBLIC FLUTTER_PLUGIN_IMPL) +# Enable firebase-cpp-sdk's platform logging api. +target_compile_definitions(${PLUGIN_NAME} PRIVATE -DINTERNAL_EXPERIMENTAL=1) # Source include directories and library dependencies. Add any plugin-specific # dependencies here. diff --git a/packages/firebase_auth/firebase_auth/windows/firebase_auth_plugin.cpp b/packages/firebase_auth/firebase_auth/windows/firebase_auth_plugin.cpp index 5de13ba8009d..553c9e6ca90b 100644 --- a/packages/firebase_auth/firebase_auth/windows/firebase_auth_plugin.cpp +++ b/packages/firebase_auth/firebase_auth/windows/firebase_auth_plugin.cpp @@ -16,6 +16,7 @@ #include "firebase/log.h" #include "firebase/util.h" #include "firebase/variant.h" +#include "firebase_auth/plugin_version.h" #include "firebase_core/firebase_core_plugin_c_api.h" #include "messages.g.h" @@ -39,6 +40,8 @@ using ::firebase::App; using ::firebase::auth::Auth; namespace firebase_auth_windows { + +static std::string kLibraryName = "flutter-fire-auth"; flutter::BinaryMessenger* FirebaseAuthPlugin::binaryMessenger = nullptr; // static @@ -52,6 +55,10 @@ void FirebaseAuthPlugin::RegisterWithRegistrar( registrar->AddPlugin(std::move(plugin)); binaryMessenger = registrar->messenger(); + + // Register for platform logging + App::RegisterLibrary(kLibraryName.c_str(), getPluginVersion().c_str(), + nullptr); } FirebaseAuthPlugin::FirebaseAuthPlugin() { diff --git a/packages/firebase_auth/firebase_auth/windows/plugin_version.h.in b/packages/firebase_auth/firebase_auth/windows/plugin_version.h.in new file mode 100644 index 000000000000..3a8915c42544 --- /dev/null +++ b/packages/firebase_auth/firebase_auth/windows/plugin_version.h.in @@ -0,0 +1,13 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#ifndef PLUGIN_VERSION_CONFIG_H +#define PLUGIN_VERSION_CONFIG_H + +namespace firebase_auth_windows { + +std::string getPluginVersion() { return "@PLUGIN_VERSION@"; } +} // namespace firebase_auth_windows + +#endif // PLUGIN_VERSION_CONFIG_H diff --git a/packages/firebase_core/firebase_core/windows/CMakeLists.txt b/packages/firebase_core/firebase_core/windows/CMakeLists.txt index c9f3405e6f34..06c477b32068 100644 --- a/packages/firebase_core/firebase_core/windows/CMakeLists.txt +++ b/packages/firebase_core/firebase_core/windows/CMakeLists.txt @@ -63,12 +63,31 @@ list(APPEND PLUGIN_SOURCES "messages.g.h" ) +# Read version from pubspec.yaml +file(STRINGS "../pubspec.yaml" pubspec_content) +foreach(line ${pubspec_content}) + string(FIND ${line} "version: " has_version) + + if("${has_version}" STREQUAL "0") + string(FIND ${line} ": " version_start_pos) + math(EXPR version_start_pos "${version_start_pos} + 2") + string(LENGTH ${line} version_end_pos) + math(EXPR len "${version_end_pos} - ${version_start_pos}") + string(SUBSTRING ${line} ${version_start_pos} ${len} PLUGIN_VERSION) + break() + endif() +endforeach(line) + +configure_file(plugin_version.h.in ${CMAKE_BINARY_DIR}/generated/firebase_core/plugin_version.h) +include_directories(${CMAKE_BINARY_DIR}/generated/) + # Define the plugin library target. Its name must not be changed (see comment # on PLUGIN_NAME above). add_library(${PLUGIN_NAME} STATIC "include/firebase_core/firebase_core_plugin_c_api.h" "firebase_core_plugin_c_api.cpp" ${PLUGIN_SOURCES} + ${CMAKE_BINARY_DIR}/generated/firebase_core/plugin_version.h ) @@ -84,6 +103,9 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PUBLIC FLUTTER_PLUGIN_IMPL) +# Enable firebase-cpp-sdk's platform logging api. +target_compile_definitions(${PLUGIN_NAME} PRIVATE -DINTERNAL_EXPERIMENTAL=1) + # Source include directories and library dependencies. Add any plugin-specific # dependencies here. if(NOT MSVC_RUNTIME_MODE) @@ -117,4 +139,4 @@ target_link_libraries(${PLUGIN_NAME} PUBLIC flutter flutter_wrapper_plugin) set(firebase_core_bundled_libraries "" PARENT_SCOPE -) \ No newline at end of file +) diff --git a/packages/firebase_core/firebase_core/windows/firebase_core_plugin.cpp b/packages/firebase_core/firebase_core/windows/firebase_core_plugin.cpp index fb66dc621010..2f4951c86050 100644 --- a/packages/firebase_core/firebase_core/windows/firebase_core_plugin.cpp +++ b/packages/firebase_core/firebase_core/windows/firebase_core_plugin.cpp @@ -8,6 +8,7 @@ #include #include "firebase/app.h" +#include "firebase_core/plugin_version.h" #include "messages.g.h" // For getPlatformVersion; remove unless needed for your plugin implementation. @@ -29,6 +30,8 @@ using ::firebase::App; namespace firebase_core_windows { +static std::string kLibraryName = "flutter-fire-core"; + // static void FirebaseCorePlugin::RegisterWithRegistrar( flutter::PluginRegistrarWindows *registrar) { @@ -38,6 +41,10 @@ void FirebaseCorePlugin::RegisterWithRegistrar( FirebaseAppHostApi::SetUp(registrar->messenger(), plugin.get()); registrar->AddPlugin(std::move(plugin)); + + // Register for platform logging + App::RegisterLibrary(kLibraryName.c_str(), getPluginVersion().c_str(), + nullptr); } FirebaseCorePlugin::FirebaseCorePlugin() {} diff --git a/packages/firebase_core/firebase_core/windows/plugin_version.h.in b/packages/firebase_core/firebase_core/windows/plugin_version.h.in new file mode 100644 index 000000000000..5d669c2f50c0 --- /dev/null +++ b/packages/firebase_core/firebase_core/windows/plugin_version.h.in @@ -0,0 +1,13 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#ifndef PLUGIN_VERSION_CONFIG_H +#define PLUGIN_VERSION_CONFIG_H + +namespace firebase_core_windows { + +std::string getPluginVersion() { return "@PLUGIN_VERSION@"; } +} // namespace firebase_core_windows + +#endif // PLUGIN_VERSION_CONFIG_H diff --git a/packages/firebase_storage/firebase_storage/windows/CMakeLists.txt b/packages/firebase_storage/firebase_storage/windows/CMakeLists.txt index 9077990143f8..36c1303e159b 100644 --- a/packages/firebase_storage/firebase_storage/windows/CMakeLists.txt +++ b/packages/firebase_storage/firebase_storage/windows/CMakeLists.txt @@ -21,12 +21,31 @@ list(APPEND PLUGIN_SOURCES "messages.g.h" ) +# Read version from pubspec.yaml +file(STRINGS "../pubspec.yaml" pubspec_content) +foreach(line ${pubspec_content}) + string(FIND ${line} "version: " has_version) + + if("${has_version}" STREQUAL "0") + string(FIND ${line} ": " version_start_pos) + math(EXPR version_start_pos "${version_start_pos} + 2") + string(LENGTH ${line} version_end_pos) + math(EXPR len "${version_end_pos} - ${version_start_pos}") + string(SUBSTRING ${line} ${version_start_pos} ${len} PLUGIN_VERSION) + break() + endif() +endforeach(line) + +configure_file(plugin_version.h.in ${CMAKE_BINARY_DIR}/generated/firebase_storage/plugin_version.h) +include_directories(${CMAKE_BINARY_DIR}/generated/) + # Define the plugin library target. Its name must not be changed (see comment # on PLUGIN_NAME above). add_library(${PLUGIN_NAME} STATIC "include/firebase_storage/firebase_storage_plugin_c_api.h" "firebase_storage_plugin_c_api.cpp" ${PLUGIN_SOURCES} + ${CMAKE_BINARY_DIR}/generated/firebase_storage/plugin_version.h ) @@ -41,6 +60,8 @@ apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PUBLIC FLUTTER_PLUGIN_IMPL) +# Enable firebase-cpp-sdk's platform logging api. +target_compile_definitions(${PLUGIN_NAME} PRIVATE -DINTERNAL_EXPERIMENTAL=1) # Source include directories and library dependencies. Add any plugin-specific # dependencies here. diff --git a/packages/firebase_storage/firebase_storage/windows/firebase_storage_plugin.cpp b/packages/firebase_storage/firebase_storage/windows/firebase_storage_plugin.cpp index ce4236bfe584..578e71bebc16 100644 --- a/packages/firebase_storage/firebase_storage/windows/firebase_storage_plugin.cpp +++ b/packages/firebase_storage/firebase_storage/windows/firebase_storage_plugin.cpp @@ -9,13 +9,13 @@ #include "firebase/app.h" #include "firebase/future.h" -#include "firebase/log.h" #include "firebase/storage.h" #include "firebase/storage/controller.h" #include "firebase/storage/listener.h" #include "firebase/storage/metadata.h" #include "firebase/storage/storage_reference.h" #include "firebase_core/firebase_core_plugin_c_api.h" +#include "firebase_storage/plugin_version.h" #include "messages.g.h" // For getPlatformVersion; remove unless needed for your plugin implementation. @@ -48,6 +48,7 @@ using flutter::EncodableValue; namespace firebase_storage_windows { +static std::string kLibraryName = "flutter-fire-gcs"; static std::string kStorageMethodChannelName = "plugins.flutter.io/firebase_storage"; static std::string kStorageTaskEventName = "taskEvent"; @@ -58,7 +59,9 @@ void FirebaseStoragePlugin::RegisterWithRegistrar( messenger_ = registrar->messenger(); FirebaseStorageHostApi::SetUp(registrar->messenger(), plugin.get()); registrar->AddPlugin(std::move(plugin)); - firebase::SetLogLevel(firebase::kLogLevelVerbose); + // Register for platform logging + App::RegisterLibrary(kLibraryName.c_str(), getPluginVersion().c_str(), + nullptr); } FirebaseStoragePlugin::FirebaseStoragePlugin() {} diff --git a/packages/firebase_storage/firebase_storage/windows/plugin_version.h.in b/packages/firebase_storage/firebase_storage/windows/plugin_version.h.in new file mode 100644 index 000000000000..4a2022b5e862 --- /dev/null +++ b/packages/firebase_storage/firebase_storage/windows/plugin_version.h.in @@ -0,0 +1,13 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#ifndef PLUGIN_VERSION_CONFIG_H +#define PLUGIN_VERSION_CONFIG_H + +namespace firebase_storage_windows { + +std::string getPluginVersion() { return "@PLUGIN_VERSION@"; } +} // namespace firebase_storage_windows + +#endif // PLUGIN_VERSION_CONFIG_H diff --git a/tests/integration_test/firebase_storage/firebase_storage_e2e_test.dart b/tests/integration_test/firebase_storage/firebase_storage_e2e_test.dart index c6604d35931b..b9e0e80a2927 100644 --- a/tests/integration_test/firebase_storage/firebase_storage_e2e_test.dart +++ b/tests/integration_test/firebase_storage/firebase_storage_e2e_test.dart @@ -7,6 +7,7 @@ import 'package:firebase_storage/firebase_storage.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:tests/firebase_options.dart'; +import 'package:flutter/foundation.dart'; import 'instance_e2e.dart'; import 'list_result_e2e.dart'; @@ -22,8 +23,11 @@ void main() { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); - await FirebaseStorage.instance - .useStorageEmulator(testEmulatorHost, testEmulatorPort); + if (defaultTargetPlatform != TargetPlatform.windows) { + // windows don't support emulator yet + await FirebaseStorage.instance + .useStorageEmulator(testEmulatorHost, testEmulatorPort); + } // Add a write only file await FirebaseStorage.instance