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 #include <iostream>
9 
10 #include "flutter/shell/platform/common/engine_switches.h" // nogncheck
11 #include "flutter/shell/platform/common/path_utils.h"
12 
13 namespace 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  for (int i = 0; i < properties.dart_entrypoint_argc; i++) {
24  dart_entrypoint_arguments_.push_back(
25  std::string(properties.dart_entrypoint_argv[i]));
26  }
27 
28  // Resolve any relative paths.
29  if (assets_path_.is_relative() || icu_path_.is_relative() ||
30  (!aot_library_path_.empty() && aot_library_path_.is_relative())) {
31  std::filesystem::path executable_location = GetExecutableDirectory();
32  if (executable_location.empty()) {
33  std::cerr
34  << "Unable to find executable location to resolve resource paths."
35  << std::endl;
36  assets_path_ = std::filesystem::path();
37  icu_path_ = std::filesystem::path();
38  } else {
39  assets_path_ = std::filesystem::path(executable_location) / assets_path_;
40  icu_path_ = std::filesystem::path(executable_location) / icu_path_;
41  if (!aot_library_path_.empty()) {
42  aot_library_path_ =
43  std::filesystem::path(executable_location) / aot_library_path_;
44  }
45  }
46  }
47 }
48 
50  return !assets_path_.empty() && !icu_path_.empty();
51 }
52 
53 // Attempts to load AOT data from the given path, which must be absolute and
54 // non-empty. Logs and returns nullptr on failure.
56  const FlutterEngineProcTable& engine_procs) {
57  if (aot_library_path_.empty()) {
58  std::cerr
59  << "Attempted to load AOT data, but no aot_library_path was provided."
60  << std::endl;
61  return UniqueAotDataPtr(nullptr, nullptr);
62  }
63  if (!std::filesystem::exists(aot_library_path_)) {
64  std::cerr << "Can't load AOT data from " << aot_library_path_.u8string()
65  << "; no such file." << std::endl;
66  return UniqueAotDataPtr(nullptr, nullptr);
67  }
68  std::string path_string = aot_library_path_.u8string();
69  FlutterEngineAOTDataSource source = {};
71  source.elf_path = path_string.c_str();
72  FlutterEngineAOTData data = nullptr;
73  auto result = engine_procs.CreateAOTData(&source, &data);
74  if (result != kSuccess) {
75  std::cerr << "Failed to load AOT data from: " << path_string << std::endl;
76  return UniqueAotDataPtr(nullptr, nullptr);
77  }
78  return UniqueAotDataPtr(data, engine_procs.CollectAOTData);
79 }
80 
82 
84  const std::vector<std::string>& switches) {
85  engine_switches_ = switches;
86 }
87 
88 const std::vector<std::string> FlutterProjectBundle::GetSwitches() {
89 #if WINUWP
90  return engine_switches_;
91 #else
93 #endif
94 }
95 
96 } // namespace flutter
FlutterProjectBundle(const FlutterDesktopEngineProperties &properties)
void SetSwitches(const std::vector< std::string > &switches)
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
FlutterEngineCollectAOTDataFnPtr CollectAOTData
Definition: embedder.h:2377
std::filesystem::path GetExecutableDirectory()
Definition: path_utils.cc:16
Function-pointer-based versions of the APIs above.
Definition: embedder.h:2372
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable &engine_procs)
GAsyncResult * result
const std::vector< std::string > GetSwitches()
std::vector< std::string > GetSwitchesFromEnvironment()
FlutterEngineCreateAOTDataFnPtr CreateAOTData
Definition: embedder.h:2376
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1326
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1329
std::unique_ptr< _FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr > UniqueAotDataPtr