Flutter Windows Embedder
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 
6 
7 #include <filesystem>
8 
9 #include "flutter/fml/logging.h"
10 #include "flutter/fml/string_conversion.h"
13 
14 namespace flutter {
15 
17  const FlutterDesktopEngineProperties& properties)
18  : assets_path_(properties.assets_path),
19  icu_path_(properties.icu_data_path) {
20  if (properties.aot_library_path != nullptr) {
21  aot_library_path_ = std::filesystem::path(properties.aot_library_path);
22  }
23 
24  if (properties.dart_entrypoint && properties.dart_entrypoint[0] != '\0') {
25  dart_entrypoint_ = properties.dart_entrypoint;
26  }
27 
28  for (int i = 0; i < properties.dart_entrypoint_argc; i++) {
29  dart_entrypoint_arguments_.push_back(
30  std::string(properties.dart_entrypoint_argv[i]));
31  }
32 
33  gpu_preference_ =
34  static_cast<FlutterGpuPreference>(properties.gpu_preference);
35 
36  ui_thread_policy_ =
37  static_cast<FlutterUIThreadPolicy>(properties.ui_thread_policy);
38 
39  // Resolve any relative paths.
40  if (assets_path_.is_relative() || icu_path_.is_relative() ||
41  (!aot_library_path_.empty() && aot_library_path_.is_relative())) {
42  std::filesystem::path executable_location = GetExecutableDirectory();
43  if (executable_location.empty()) {
44  FML_LOG(ERROR)
45  << "Unable to find executable location to resolve resource paths.";
46  assets_path_ = std::filesystem::path();
47  icu_path_ = std::filesystem::path();
48  } else {
49  assets_path_ = std::filesystem::path(executable_location) / assets_path_;
50  icu_path_ = std::filesystem::path(executable_location) / icu_path_;
51  if (!aot_library_path_.empty()) {
52  aot_library_path_ =
53  std::filesystem::path(executable_location) / aot_library_path_;
54  }
55  }
56  }
57 }
58 
60  return !assets_path_.empty() && !icu_path_.empty();
61 }
62 
63 // Attempts to load AOT data from the given path, which must be absolute and
64 // non-empty. Logs and returns nullptr on failure.
66  const FlutterEngineProcTable& engine_procs) {
67  if (aot_library_path_.empty()) {
68  FML_LOG(ERROR)
69  << "Attempted to load AOT data, but no aot_library_path was provided.";
70  return UniqueAotDataPtr(nullptr, nullptr);
71  }
72  if (!std::filesystem::exists(aot_library_path_)) {
73  FML_LOG(ERROR) << "Can't load AOT data from " << aot_library_path_
74  << "; no such file.";
75  return UniqueAotDataPtr(nullptr, nullptr);
76  }
77  std::string path_string = fml::PathToUtf8(aot_library_path_);
78  FlutterEngineAOTDataSource source = {};
79  source.type = kFlutterEngineAOTDataSourceTypeElfPath;
80  source.elf_path = path_string.c_str();
81  FlutterEngineAOTData data = nullptr;
82  auto result = engine_procs.CreateAOTData(&source, &data);
83  if (result != kSuccess) {
84  FML_LOG(ERROR) << "Failed to load AOT data from: " << path_string;
85  return UniqueAotDataPtr(nullptr, nullptr);
86  }
87  return UniqueAotDataPtr(data, engine_procs.CollectAOTData);
88 }
89 
91 
93  const std::vector<std::string>& switches) {
94  engine_switches_ = switches;
95 }
96 
97 const std::vector<std::string> FlutterProjectBundle::GetSwitches() {
98  if (engine_switches_.size() == 0) {
100  }
101  std::vector<std::string> switches;
102  switches.insert(switches.end(), engine_switches_.begin(),
103  engine_switches_.end());
104 
105  auto env_switches = GetSwitchesFromEnvironment();
106  switches.insert(switches.end(), env_switches.begin(), env_switches.end());
107 
108  return switches;
109 }
110 
111 } // 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)
std::vector< std::string > GetSwitchesFromEnvironment()
std::filesystem::path GetExecutableDirectory()
Definition: path_utils.cc:16
std::unique_ptr< _FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr > UniqueAotDataPtr
FlutterDesktopUIThreadPolicy ui_thread_policy
FlutterDesktopGpuPreference gpu_preference