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 ()
 
UniqueAotDataPtr LoadAotData ()
 

Detailed Description

Definition at line 25 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, 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  // Resolve any relative paths.
24  if (assets_path_.is_relative() || icu_path_.is_relative() ||
25  (!aot_library_path_.empty() && aot_library_path_.is_relative())) {
26  std::filesystem::path executable_location = GetExecutableDirectory();
27  if (executable_location.empty()) {
28  std::cerr
29  << "Unable to find executable location to resolve resource paths."
30  << std::endl;
31  assets_path_ = std::filesystem::path();
32  icu_path_ = std::filesystem::path();
33  } else {
34  assets_path_ = std::filesystem::path(executable_location) / assets_path_;
35  icu_path_ = std::filesystem::path(executable_location) / icu_path_;
36  if (!aot_library_path_.empty()) {
37  aot_library_path_ =
38  std::filesystem::path(executable_location) / aot_library_path_;
39  }
40  }
41  }
42 }
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 75 of file flutter_project_bundle.cc.

75 {}

Member Function Documentation

◆ assets_path()

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

Definition at line 40 of file flutter_project_bundle.h.

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

40 { return assets_path_; }

◆ GetSwitches()

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

Definition at line 77 of file flutter_project_bundle.cc.

References flutter::GetSwitchesFromEnvironment().

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

77  {
79 }
std::vector< std::string > GetSwitchesFromEnvironment()

◆ HasValidPaths()

bool flutter::FlutterProjectBundle::HasValidPaths ( )

Definition at line 44 of file flutter_project_bundle.cc.

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

44  {
45  return !assets_path_.empty() && !icu_path_.empty();
46 }

◆ icu_path()

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

Definition at line 43 of file flutter_project_bundle.h.

References LoadAotData(), and flutter::path.

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

43 { return icu_path_; }

◆ LoadAotData()

UniqueAotDataPtr flutter::FlutterProjectBundle::LoadAotData ( )

Definition at line 50 of file flutter_project_bundle.cc.

References FlutterEngineAOTDataSource::elf_path, FlutterEngineCreateAOTData(), kFlutterEngineAOTDataSourceTypeElfPath, flutter::kSuccess, and FlutterEngineAOTDataSource::type.

50  {
51  if (aot_library_path_.empty()) {
52  std::cerr
53  << "Attempted to load AOT data, but no aot_library_path was provided."
54  << std::endl;
55  return nullptr;
56  }
57  if (!std::filesystem::exists(aot_library_path_)) {
58  std::cerr << "Can't load AOT data from " << aot_library_path_.u8string()
59  << "; no such file." << std::endl;
60  return nullptr;
61  }
62  std::string path_string = aot_library_path_.u8string();
63  FlutterEngineAOTDataSource source = {};
65  source.elf_path = path_string.c_str();
66  FlutterEngineAOTData data = nullptr;
67  auto result = FlutterEngineCreateAOTData(&source, &data);
68  if (result != kSuccess) {
69  std::cerr << "Failed to load AOT data from: " << path_string << std::endl;
70  return nullptr;
71  }
72  return UniqueAotDataPtr(data);
73 }
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1122
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1125
std::unique_ptr< _FlutterEngineAOTData, AotDataDeleter > UniqueAotDataPtr
FlutterEngineResult FlutterEngineCreateAOTData(const FlutterEngineAOTDataSource *source, FlutterEngineAOTData *data_out)
Creates the necessary data structures to launch a Flutter Dart application in AOT mode...
Definition: embedder.cc:597

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