forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter_project_bundle.h" | ||
|
||
#include <filesystem> | ||
|
||
#include "flutter/shell/platform/common/path_utils.h" | ||
#include "flutter/shell/platform/tizen/tizen_log.h" | ||
|
||
namespace flutter { | ||
|
||
FlutterProjectBundle::FlutterProjectBundle( | ||
const FlutterDesktopEngineProperties& properties) | ||
: assets_path_(properties.assets_path), | ||
icu_path_(properties.icu_data_path) { | ||
if (properties.aot_library_path != nullptr) { | ||
aot_library_path_ = std::filesystem::path(properties.aot_library_path); | ||
} | ||
|
||
// Resolve any relative paths. | ||
if (assets_path_.is_relative() || icu_path_.is_relative() || | ||
(!aot_library_path_.empty() && aot_library_path_.is_relative())) { | ||
std::filesystem::path executable_location = GetExecutableDirectory(); | ||
if (executable_location.empty()) { | ||
FT_LOGE("Unable to find executable location to resolve resource paths."); | ||
assets_path_ = std::filesystem::path(); | ||
icu_path_ = std::filesystem::path(); | ||
} else { | ||
assets_path_ = std::filesystem::path(executable_location) / assets_path_; | ||
icu_path_ = std::filesystem::path(executable_location) / icu_path_; | ||
if (!aot_library_path_.empty()) { | ||
aot_library_path_ = | ||
std::filesystem::path(executable_location) / aot_library_path_; | ||
} | ||
} | ||
} | ||
|
||
switches_.insert(switches_.end(), properties.switches, | ||
properties.switches + properties.switches_count); | ||
} | ||
|
||
bool FlutterProjectBundle::HasValidPaths() { | ||
return !assets_path_.empty() && !icu_path_.empty(); | ||
} | ||
|
||
// Attempts to load AOT data from the given path, which must be absolute and | ||
// non-empty. Logs and returns nullptr on failure. | ||
UniqueAotDataPtr FlutterProjectBundle::LoadAotData( | ||
const FlutterEngineProcTable& engine_procs) { | ||
if (aot_library_path_.empty()) { | ||
FT_LOGE( | ||
"Attempted to load AOT data, but no aot_library_path was provided."); | ||
return UniqueAotDataPtr(nullptr, nullptr); | ||
} | ||
if (!std::filesystem::exists(aot_library_path_)) { | ||
FT_LOGE("Can't load AOT data from %s; no such file.", | ||
aot_library_path_.u8string().c_str()); | ||
return UniqueAotDataPtr(nullptr, nullptr); | ||
} | ||
std::string path_string = aot_library_path_.u8string(); | ||
FlutterEngineAOTDataSource source = {}; | ||
source.type = kFlutterEngineAOTDataSourceTypeElfPath; | ||
source.elf_path = path_string.c_str(); | ||
FlutterEngineAOTData data = nullptr; | ||
auto result = engine_procs.CreateAOTData(&source, &data); | ||
if (result != kSuccess) { | ||
FT_LOGE("Failed to load AOT data from: %s", path_string.c_str()); | ||
return UniqueAotDataPtr(nullptr, nullptr); | ||
} | ||
return UniqueAotDataPtr(data, engine_procs.CollectAOTData); | ||
} | ||
|
||
FlutterProjectBundle::~FlutterProjectBundle() {} | ||
|
||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef EMBEDDER_FLUTTER_PROJECT_BUNDLE_H_ | ||
#define EMBEDDER_FLUTTER_PROJECT_BUNDLE_H_ | ||
|
||
#include <filesystem> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "flutter/shell/platform/embedder/embedder.h" | ||
#include "flutter/shell/platform/tizen/public/flutter_tizen.h" | ||
|
||
namespace flutter { | ||
|
||
using UniqueAotDataPtr = | ||
std::unique_ptr<_FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr>; | ||
|
||
// The data associated with a Flutter project needed to run it in an engine. | ||
class FlutterProjectBundle { | ||
public: | ||
// Creates a new project bundle from the given properties. | ||
// | ||
// Treats any relative paths as relative to the directory of this executable. | ||
explicit FlutterProjectBundle( | ||
const FlutterDesktopEngineProperties& properties); | ||
|
||
~FlutterProjectBundle(); | ||
|
||
// Whether or not the bundle is valid. This does not check that the paths | ||
// exist, or contain valid data, just that paths were able to be constructed. | ||
bool HasValidPaths(); | ||
|
||
// Returns the path to the assets directory. | ||
const std::filesystem::path& assets_path() { return assets_path_; } | ||
|
||
// Returns the path to the ICU data file. | ||
const std::filesystem::path& icu_path() { return icu_path_; } | ||
|
||
// Returns any switches that should be passed to the engine. | ||
const std::vector<std::string> switches() { return switches_; } | ||
|
||
// Attempts to load AOT data for this bundle. The returned data must be | ||
// retained until any engine instance it is passed to has been shut down. | ||
// | ||
// Logs and returns nullptr on failure. | ||
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable& engine_procs); | ||
|
||
private: | ||
std::filesystem::path assets_path_; | ||
std::filesystem::path icu_path_; | ||
std::vector<std::string> switches_; | ||
|
||
// Path to the AOT library file, if any. | ||
std::filesystem::path aot_library_path_; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // EMBEDDER_FLUTTER_PROJECT_BUNDLE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters