Flutter Engine
flutter::FlutterProjectBundle Class Reference

#include <flutter_project_bundle.h>

Public Member Functions

 FlutterProjectBundle (const FlutterDesktopEngineProperties &properties)
 
 ~FlutterProjectBundle ()
 
bool HasValidPaths ()
 
const std::filesystem::path & assets_path ()
 
const std::filesystem::path & icu_path ()
 
const std::vector< std::string > GetSwitches ()
 
void SetSwitches (const std::vector< std::string > &switches)
 
UniqueAotDataPtr LoadAotData (const FlutterEngineProcTable &engine_procs)
 
const std::vector< std::string > & dart_entrypoint_arguments () const
 

Detailed Description

Definition at line 21 of file flutter_project_bundle.h.

Constructor & Destructor Documentation

◆ FlutterProjectBundle()

flutter::FlutterProjectBundle::FlutterProjectBundle ( const FlutterDesktopEngineProperties properties)
explicit

Definition at line 15 of file flutter_project_bundle.cc.

References FlutterDesktopEngineProperties::aot_library_path, FlutterDesktopEngineProperties::dart_entrypoint_argc, FlutterDesktopEngineProperties::dart_entrypoint_argv, flutter::GetExecutableDirectory(), and flutter::path.

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 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
std::filesystem::path GetExecutableDirectory()
Definition: path_utils.cc:16

◆ ~FlutterProjectBundle()

flutter::FlutterProjectBundle::~FlutterProjectBundle ( )

Definition at line 81 of file flutter_project_bundle.cc.

81 {}

Member Function Documentation

◆ assets_path()

const std::filesystem::path& flutter::FlutterProjectBundle::assets_path ( )
inline

Definition at line 36 of file flutter_project_bundle.h.

Referenced by flutter::testing::TEST().

36 { return assets_path_; }

◆ dart_entrypoint_arguments()

const std::vector<std::string>& flutter::FlutterProjectBundle::dart_entrypoint_arguments ( ) const
inline

Definition at line 55 of file flutter_project_bundle.h.

References flutter::path.

Referenced by flutter::testing::TEST().

55  {
56  return dart_entrypoint_arguments_;
57  }

◆ GetSwitches()

const std::vector< std::string > flutter::FlutterProjectBundle::GetSwitches ( )

Definition at line 88 of file flutter_project_bundle.cc.

References flutter::GetSwitchesFromEnvironment().

Referenced by icu_path(), and flutter::testing::TEST().

88  {
89 #if WINUWP
90  return engine_switches_;
91 #else
93 #endif
94 }
std::vector< std::string > GetSwitchesFromEnvironment()

◆ HasValidPaths()

bool flutter::FlutterProjectBundle::HasValidPaths ( )

Definition at line 49 of file flutter_project_bundle.cc.

Referenced by flutter::testing::TEST().

49  {
50  return !assets_path_.empty() && !icu_path_.empty();
51 }

◆ icu_path()

const std::filesystem::path& flutter::FlutterProjectBundle::icu_path ( )
inline

Definition at line 39 of file flutter_project_bundle.h.

References GetSwitches(), LoadAotData(), and SetSwitches().

Referenced by flutter::testing::TEST().

39 { return icu_path_; }

◆ LoadAotData()

UniqueAotDataPtr flutter::FlutterProjectBundle::LoadAotData ( const FlutterEngineProcTable engine_procs)

Definition at line 55 of file flutter_project_bundle.cc.

References FlutterEngineProcTable::CollectAOTData, FlutterEngineProcTable::CreateAOTData, FlutterEngineAOTDataSource::elf_path, kFlutterEngineAOTDataSourceTypeElfPath, flutter::kSuccess, result, and FlutterEngineAOTDataSource::type.

Referenced by icu_path().

56  {
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 }
FlutterEngineCollectAOTDataFnPtr CollectAOTData
Definition: embedder.h:2377
GAsyncResult * result
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

◆ SetSwitches()

void flutter::FlutterProjectBundle::SetSwitches ( const std::vector< std::string > &  switches)

Definition at line 83 of file flutter_project_bundle.cc.

Referenced by icu_path().

84  {
85  engine_switches_ = switches;
86 }

The documentation for this class was generated from the following files: