Skip to content

Commit

Permalink
feat(windows): add platform logging for core, auth, firestore and sto…
Browse files Browse the repository at this point in the history
…rage (#11790)

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>
  • Loading branch information
cynthiajoan and russellwheatley committed Nov 1, 2023
1 parent 30c8abc commit e7d428d
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 5 deletions.
21 changes: 21 additions & 0 deletions packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -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.
Expand Down
Expand Up @@ -20,6 +20,7 @@
#include <mutex>
#include <sstream>

#include "cloud_firestore/plugin_version.h"
#include "firebase/app.h"
#include "firebase/firestore.h"
#include "firebase/firestore/filter.h"
Expand All @@ -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) {
Expand All @@ -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(
Expand Down
@@ -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
21 changes: 21 additions & 0 deletions packages/firebase_auth/firebase_auth/windows/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -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.
Expand Down
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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() {
Expand Down
13 changes: 13 additions & 0 deletions 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
24 changes: 23 additions & 1 deletion packages/firebase_core/firebase_core/windows/CMakeLists.txt
Expand Up @@ -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
)


Expand All @@ -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)
Expand Down Expand Up @@ -117,4 +139,4 @@ target_link_libraries(${PLUGIN_NAME} PUBLIC flutter flutter_wrapper_plugin)
set(firebase_core_bundled_libraries
""
PARENT_SCOPE
)
)
Expand Up @@ -8,6 +8,7 @@
#include <windows.h>

#include "firebase/app.h"
#include "firebase_core/plugin_version.h"
#include "messages.g.h"

// For getPlatformVersion; remove unless needed for your plugin implementation.
Expand All @@ -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) {
Expand All @@ -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() {}
Expand Down
13 changes: 13 additions & 0 deletions 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
21 changes: 21 additions & 0 deletions packages/firebase_storage/firebase_storage/windows/CMakeLists.txt
Expand Up @@ -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
)


Expand All @@ -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.
Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -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";
Expand All @@ -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() {}
Expand Down
@@ -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
Expand Up @@ -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';
Expand All @@ -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
Expand Down

0 comments on commit e7d428d

Please sign in to comment.