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/cpp/engine_switches.h"
11 #include "flutter/shell/platform/common/cpp/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  // 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 }
43 
45  return !assets_path_.empty() && !icu_path_.empty();
46 }
47 
48 // Attempts to load AOT data from the given path, which must be absolute and
49 // non-empty. Logs and returns nullptr on failure.
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 }
74 
76 
77 const std::vector<std::string> FlutterProjectBundle::GetSwitches() {
79 }
80 
81 } // namespace flutter
FlutterProjectBundle(const FlutterDesktopEngineProperties &properties)
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
std::filesystem::path GetExecutableDirectory()
Definition: path_utils.cc:16
const std::vector< std::string > GetSwitches()
std::vector< std::string > GetSwitchesFromEnvironment()
FlutterEngineAOTDataSourceType type
Definition: embedder.h:1126
const char * elf_path
Absolute path to an ELF library file.
Definition: embedder.h:1129
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