未验证 提交 710f738d 编写于 作者: S stuartmorgan 提交者: GitHub

Allow relative resource paths in GLFW embedding (#16944)

Currently every Linux runner has this code to allow relative resource paths; this moves it into the framework so that any embedder can get this behavior without that code needing to be in the template.

Rolls buildroot to pick up std::filesystem support in our libc++
上级 c85f3f06
......@@ -75,6 +75,7 @@ group("flutter") {
"//flutter/lib/ui:ui_unittests",
"//flutter/runtime:runtime_unittests",
"//flutter/shell/common:shell_unittests",
"//flutter/shell/platform/common/cpp:common_cpp_core_unittests",
"//flutter/shell/platform/common/cpp/client_wrapper:client_wrapper_unittests",
"//flutter/shell/platform/embedder:embedder_unittests",
"//flutter/shell/platform/glfw/client_wrapper:client_wrapper_glfw_unittests",
......
......@@ -137,7 +137,7 @@ allowed_hosts = [
]
deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'd14f3c708fb132381f7053b4ee9e628be915ed96',
'src': 'https://github.com/flutter/buildroot.git' + '@' + '4489a78bf94bb9d8ea6a127106f85b7710d57f70',
# Fuchsia compatibility
#
......
......@@ -798,6 +798,9 @@ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/standard_message
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/standard_method_codec_unittests.cc
FILE: ../../../flutter/shell/platform/common/cpp/incoming_message_dispatcher.cc
FILE: ../../../flutter/shell/platform/common/cpp/incoming_message_dispatcher.h
FILE: ../../../flutter/shell/platform/common/cpp/path_utils.cc
FILE: ../../../flutter/shell/platform/common/cpp/path_utils.h
FILE: ../../../flutter/shell/platform/common/cpp/path_utils_unittests.cc
FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_export.h
FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_messenger.h
FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_plugin_registrar.h
......
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//flutter/testing/testing.gni")
config("desktop_library_implementation") {
defines = [ "FLUTTER_DESKTOP_LIBRARY" ]
}
......@@ -49,6 +51,10 @@ source_set("common_cpp") {
"//flutter/shell/platform/embedder:embedder_with_symbol_prefix",
]
public_deps = [
":common_cpp_core",
]
# TODO: Remove once text input model refactor lands, at which point this code
# won't have a JSON dependency.
defines = [ "USE_RAPID_JSON" ]
......@@ -60,6 +66,41 @@ source_set("common_cpp") {
}
}
# The portion of common_cpp that has no dependencies on the public/
# headers. This division should be revisited once the Linux GTK
# embedding is futher along and it's clearer how much, if any, shared
# API surface there will be.
source_set("common_cpp_core") {
public = [
"path_utils.h",
]
sources = [
"path_utils.cc",
]
}
test_fixtures("common_cpp_core_fixtures") {
fixtures = []
}
executable("common_cpp_core_unittests") {
testonly = true
sources = [
"path_utils_unittests.cc",
]
deps = [
":common_cpp_core",
":common_cpp_core_fixtures",
"//flutter/testing",
"//third_party/dart/runtime:libdart_jit",
]
public_configs = [ "//flutter:config" ]
}
copy("publish_headers") {
sources = _public_headers
outputs = [
......
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/common/cpp/path_utils.h"
#if defined(_WIN32)
#include <windows.h>
#elif defined(__linux__)
#include <linux/limits.h>
#include <unistd.h>
#endif
namespace flutter {
std::filesystem::path GetExecutableDirectory() {
#if defined(_WIN32)
wchar_t buffer[MAX_PATH];
if (GetModuleFileName(nullptr, buffer, MAX_PATH) == 0) {
return std::filesystem::path();
}
std::filesystem::path executable_path(buffer);
return executable_path.remove_filename();
#elif defined(__linux__)
char buffer[PATH_MAX + 1];
ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer));
if (length > PATH_MAX) {
return std::filesystem::path();
}
std::filesystem::path executable_path(std::string(buffer, length));
return executable_path.remove_filename();
#else
return std::filesystem::path();
#endif
}
} // namespace flutter
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_
#define FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_
#include <filesystem>
namespace flutter {
// Returns the path of the directory containing this executable, or an empty
// path if the directory cannot be found.
std::filesystem::path GetExecutableDirectory();
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/common/cpp/path_utils.h"
#include "gtest/gtest.h"
namespace flutter {
// Tests that GetExecutableDirectory returns a valid, absolute path.
TEST(PathUtilsTest, ExecutableDirector) {
std::filesystem::path exe_directory = GetExecutableDirectory();
#if defined(__linux__) || defined(_WIN32)
EXPECT_EQ(exe_directory.empty(), false);
EXPECT_EQ(exe_directory.is_absolute(), true);
#else
// On platforms where it's not implemented, it should indicate that
// by returning an empty path.
EXPECT_EQ(exe_directory.empty(), true);
#endif
}
} // namespace flutter
......@@ -10,10 +10,12 @@
#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h"
#include "flutter/shell/platform/common/cpp/path_utils.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/glfw/glfw_event_loop.h"
#include "flutter/shell/platform/glfw/key_event_handler.h"
......@@ -507,6 +509,25 @@ static FLUTTER_API_SYMBOL(FlutterEngine)
&engine_properties.switches[engine_properties.switches_count]);
}
std::filesystem::path assets_path =
std::filesystem::u8path(engine_properties.assets_path);
std::filesystem::path icu_path =
std::filesystem::u8path(engine_properties.icu_data_path);
if (assets_path.is_relative() || icu_path.is_relative()) {
// Treat relative paths as relative to the directory of this executable.
std::filesystem::path executable_location =
flutter::GetExecutableDirectory();
if (executable_location.empty()) {
std::cerr << "Unable to find executable location to resolve paths."
<< std::endl;
return nullptr;
}
assets_path = std::filesystem::path(executable_location) / assets_path;
icu_path = std::filesystem::path(executable_location) / icu_path;
}
std::string assets_path_string = assets_path.u8string();
std::string icu_path_string = assets_path.u8string();
FlutterRendererConfig config = {};
if (window == nullptr) {
config.type = kOpenGL;
......@@ -528,8 +549,8 @@ static FLUTTER_API_SYMBOL(FlutterEngine)
}
FlutterProjectArgs args = {};
args.struct_size = sizeof(FlutterProjectArgs);
args.assets_path = engine_properties.assets_path;
args.icu_data_path = engine_properties.icu_data_path;
args.assets_path = assets_path_string.c_str();
args.icu_data_path = icu_path_string.c_str();
args.command_line_argc = static_cast<int>(argv.size());
args.command_line_argv = &argv[0];
args.platform_message_callback = GLFWOnFlutterPlatformMessage;
......
......@@ -38,8 +38,12 @@ typedef struct {
// Properties for configuring a Flutter engine instance.
typedef struct {
// The path to the flutter_assets folder for the application to be run.
// This can either be an absolute path, or on Windows or Linux, a path
// relative to the directory containing the executable.
const char* assets_path;
// The path to the icudtl.dat file for the version of Flutter you are using.
// This can either be an absolute path, or on Windows or Linux, a path
// relative to the directory containing the executable.
const char* icu_data_path;
// The switches to pass to the Flutter engine.
//
......
......@@ -108,6 +108,8 @@ def RunCCTests(build_dir, filter):
RunEngineExecutable(build_dir, 'client_wrapper_glfw_unittests', filter, shuffle_flags)
RunEngineExecutable(build_dir, 'common_cpp_core_unittests', filter, shuffle_flags)
RunEngineExecutable(build_dir, 'client_wrapper_unittests', filter, shuffle_flags)
# https://github.com/flutter/flutter/issues/36294
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册