Flutter Engine
The Flutter Engine
flutter_project_bundle.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/shell/platform/windows/flutter_project_bundle.h"
6
7#include <filesystem>
8
9#include "flutter/fml/logging.h"
10#include "flutter/shell/platform/common/engine_switches.h" // nogncheck
11#include "flutter/shell/platform/common/path_utils.h"
12
13namespace flutter {
14
16 const FlutterDesktopEngineProperties& properties)
17 : assets_path_(properties.assets_path),
18 icu_path_(properties.icu_data_path) {
19 if (properties.aot_library_path != nullptr) {
20 aot_library_path_ = std::filesystem::path(properties.aot_library_path);
21 }
22
23 if (properties.dart_entrypoint && properties.dart_entrypoint[0] != '\0') {
24 dart_entrypoint_ = properties.dart_entrypoint;
25 }
26
27 for (int i = 0; i < properties.dart_entrypoint_argc; i++) {
28 dart_entrypoint_arguments_.push_back(
29 std::string(properties.dart_entrypoint_argv[i]));
30 }
31
32 // Resolve any relative paths.
33 if (assets_path_.is_relative() || icu_path_.is_relative() ||
34 (!aot_library_path_.empty() && aot_library_path_.is_relative())) {
35 std::filesystem::path executable_location = GetExecutableDirectory();
36 if (executable_location.empty()) {
38 << "Unable to find executable location to resolve resource paths.";
39 assets_path_ = std::filesystem::path();
40 icu_path_ = std::filesystem::path();
41 } else {
42 assets_path_ = std::filesystem::path(executable_location) / assets_path_;
43 icu_path_ = std::filesystem::path(executable_location) / icu_path_;
44 if (!aot_library_path_.empty()) {
45 aot_library_path_ =
46 std::filesystem::path(executable_location) / aot_library_path_;
47 }
48 }
49 }
50}
51
53 return !assets_path_.empty() && !icu_path_.empty();
54}
55
56// Attempts to load AOT data from the given path, which must be absolute and
57// non-empty. Logs and returns nullptr on failure.
59 const FlutterEngineProcTable& engine_procs) {
60 if (aot_library_path_.empty()) {
62 << "Attempted to load AOT data, but no aot_library_path was provided.";
63 return UniqueAotDataPtr(nullptr, nullptr);
64 }
65 if (!std::filesystem::exists(aot_library_path_)) {
66 FML_LOG(ERROR) << "Can't load AOT data from "
67 << aot_library_path_.u8string() << "; no such file.";
68 return UniqueAotDataPtr(nullptr, nullptr);
69 }
70 std::string path_string = aot_library_path_.u8string();
73 source.elf_path = path_string.c_str();
74 FlutterEngineAOTData data = nullptr;
75 auto result = engine_procs.CreateAOTData(&source, &data);
76 if (result != kSuccess) {
77 FML_LOG(ERROR) << "Failed to load AOT data from: " << path_string;
78 return UniqueAotDataPtr(nullptr, nullptr);
79 }
80 return UniqueAotDataPtr(data, engine_procs.CollectAOTData);
81}
82
84
86 const std::vector<std::string>& switches) {
87 engine_switches_ = switches;
88}
89
90const std::vector<std::string> FlutterProjectBundle::GetSwitches() {
91 if (engine_switches_.size() == 0) {
93 }
94 std::vector<std::string> switches;
95 switches.insert(switches.end(), engine_switches_.begin(),
96 engine_switches_.end());
97
98 auto env_switches = GetSwitchesFromEnvironment();
99 switches.insert(switches.end(), env_switches.begin(), env_switches.end());
100
101 return switches;
102}
103
104} // namespace flutter
const std::vector< std::string > GetSwitches()
FlutterProjectBundle(const FlutterDesktopEngineProperties &properties)
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable &engine_procs)
void SetSwitches(const std::vector< std::string > &switches)
@ kFlutterEngineAOTDataSourceTypeElfPath
Definition: embedder.h:2110
@ kSuccess
Definition: embedder.h:73
SkBitmap source
Definition: examples.cpp:28
GAsyncResult * result
#define FML_LOG(severity)
Definition: logging.h:82
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
std::vector< std::string > GetSwitchesFromEnvironment()
std::filesystem::path GetExecutableDirectory()
Definition: path_utils.cc:16
std::unique_ptr< _FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr > UniqueAotDataPtr
Function-pointer-based versions of the APIs above.
Definition: embedder.h:3319
FlutterEngineCreateAOTDataFnPtr CreateAOTData
Definition: embedder.h:3323
FlutterEngineCollectAOTDataFnPtr CollectAOTData
Definition: embedder.h:3324
#define ERROR(message)
Definition: elf_loader.cc:260