Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart_project.h
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#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
7
8#include <string>
9#include <vector>
10
11namespace flutter {
12
13// A set of Flutter and Dart assets used to initialize a Flutter engine.
15 public:
16 // Creates a DartProject from a series of absolute paths.
17 // The three paths are:
18 // - assets_path: Path to the assets directory as built by the Flutter tool.
19 // - icu_data_path: Path to the icudtl.dat file.
20 // - aot_library_path: Path to the AOT snapshot file.
21 //
22 // The paths may either be absolute or relative to the directory containing
23 // the running executable.
24 explicit DartProject(const std::wstring& assets_path,
25 const std::wstring& icu_data_path,
26 const std::wstring& aot_library_path) {
27 assets_path_ = assets_path;
28 icu_data_path_ = icu_data_path;
29 aot_library_path_ = aot_library_path;
30 }
31
32 // Creates a DartProject from a directory path. The directory should contain
33 // the following top-level items:
34 // - icudtl.dat (provided as a resource by the Flutter tool)
35 // - flutter_assets (as built by the Flutter tool)
36 // - app.so, for an AOT build (as built by the Flutter tool)
37 //
38 // The path can either be absolute, or relative to the directory containing
39 // the running executable.
40 explicit DartProject(const std::wstring& path) {
41 assets_path_ = path + L"\\flutter_assets";
42 icu_data_path_ = path + L"\\icudtl.dat";
43 aot_library_path_ = path + L"\\app.so";
44 }
45
46 ~DartProject() = default;
47
48 // Sets the Dart entrypoint to the specified value.
49 //
50 // If not set, the default entrypoint (main) is used. Custom Dart entrypoints
51 // must be decorated with `@pragma('vm:entry-point')`.
52 void set_dart_entrypoint(const std::string& entrypoint) {
53 if (entrypoint.empty()) {
54 return;
55 }
56 dart_entrypoint_ = entrypoint;
57 }
58
59 // Returns the Dart entrypoint.
60 const std::string& dart_entrypoint() const { return dart_entrypoint_; }
61
62 // Sets the command line arguments that should be passed to the Dart
63 // entrypoint.
64 void set_dart_entrypoint_arguments(std::vector<std::string> arguments) {
65 dart_entrypoint_arguments_ = std::move(arguments);
66 }
67
68 // Returns any command line arguments that should be passed to the Dart
69 // entrypoint.
70 const std::vector<std::string>& dart_entrypoint_arguments() const {
71 return dart_entrypoint_arguments_;
72 }
73
74 private:
75 // Accessors for internals are private, so that they can be changed if more
76 // flexible options for project structures are needed later without it
77 // being a breaking change. Provide access to internal classes that need
78 // them.
79 friend class FlutterEngine;
81 friend class DartProjectTest;
82
83 const std::wstring& assets_path() const { return assets_path_; }
84 const std::wstring& icu_data_path() const { return icu_data_path_; }
85 const std::wstring& aot_library_path() const { return aot_library_path_; }
86
87 // The path to the assets directory.
88 std::wstring assets_path_;
89 // The path to the ICU data.
90 std::wstring icu_data_path_;
91 // The path to the AOT library. This will always return a path, but non-AOT
92 // builds will not be expected to actually have a library at that path.
93 std::wstring aot_library_path_;
94 // The Dart entrypoint to launch.
95 std::string dart_entrypoint_;
96 // The list of arguments to pass through to the Dart entrypoint.
97 std::vector<std::string> dart_entrypoint_arguments_;
98};
99
100} // namespace flutter
101
102#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
void set_dart_entrypoint(const std::string &entrypoint)
DartProject(const std::wstring &assets_path, const std::wstring &icu_data_path, const std::wstring &aot_library_path)
const std::vector< std::string > & dart_entrypoint_arguments() const
const std::string & dart_entrypoint() const
DartProject(const std::wstring &path)
void set_dart_entrypoint_arguments(std::vector< std::string > arguments)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57