Skip to content

Commit 1e40913

Browse files
xiaowei-guanswift-kim
authored andcommitted
Support dart entrypoint (#149)
* Support dart entrypoint * Copy dart_entrypoint_argv to FlutterProjectArgs.dart_entrypoint.argv. * Add description for RunEngine. * Update unittest code * Fix build error
1 parent ea75b5b commit 1e40913

7 files changed

+53
-13
lines changed

shell/platform/tizen/flutter_project_bundle.cc

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ FlutterProjectBundle::FlutterProjectBundle(
4343
aot_library_path_ = std::filesystem::path(properties.aot_library_path);
4444
}
4545

46+
for (int i = 0; i < properties.dart_entrypoint_argc; i++) {
47+
dart_entrypoint_arguments_.push_back(
48+
std::string(properties.dart_entrypoint_argv[i]));
49+
}
50+
4651
// Resolve any relative paths.
4752
if (assets_path_.is_relative() || icu_path_.is_relative() ||
4853
(!aot_library_path_.empty() && aot_library_path_.is_relative())) {

shell/platform/tizen/flutter_project_bundle.h

+9
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,22 @@ class FlutterProjectBundle {
4848
// Logs and returns nullptr on failure.
4949
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable& engine_procs);
5050

51+
// Returns the command line arguments to be passed through to the Dart
52+
// entrypoint.
53+
const std::vector<std::string>& dart_entrypoint_arguments() const {
54+
return dart_entrypoint_arguments_;
55+
}
56+
5157
private:
5258
std::filesystem::path assets_path_;
5359
std::filesystem::path icu_path_;
5460
std::vector<std::string> switches_ = {};
5561

5662
// Path to the AOT library file, if any.
5763
std::filesystem::path aot_library_path_;
64+
65+
// Dart entrypoint arguments.
66+
std::vector<std::string> dart_entrypoint_arguments_;
5867
};
5968

6069
} // namespace flutter

shell/platform/tizen/flutter_tizen.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ FlutterDesktopEngineRef FlutterDesktopRunEngine(
4040
window_properties.height, window_properties.transparent,
4141
window_properties.focusable);
4242
}
43-
if (!engine->RunEngine()) {
43+
if (!engine->RunEngine(engine_properties.entry_point)) {
4444
FT_LOG(Error) << "Failed to start the Flutter engine.";
4545
return nullptr;
4646
}

shell/platform/tizen/flutter_tizen_engine.cc

+16-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void FlutterTizenEngine::InitializeRenderer(int32_t x,
111111
#endif
112112
}
113113

114-
bool FlutterTizenEngine::RunEngine() {
114+
bool FlutterTizenEngine::RunEngine(const char* entrypoint) {
115115
if (engine_ != nullptr) {
116116
FT_LOG(Error) << "The engine has already started.";
117117
return false;
@@ -149,6 +149,14 @@ bool FlutterTizenEngine::RunEngine() {
149149
Logger::SetLoggingLevel(kLogLevelDebug);
150150
}
151151

152+
const std::vector<std::string>& entrypoint_args =
153+
project_->dart_entrypoint_arguments();
154+
std::vector<const char*> entrypoint_argv;
155+
std::transform(
156+
entrypoint_args.begin(), entrypoint_args.end(),
157+
std::back_inserter(entrypoint_argv),
158+
[](const std::string& arg) -> const char* { return arg.c_str(); });
159+
152160
// Configure task runners.
153161
FlutterTaskRunnerDescription platform_task_runner = {};
154162
platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
@@ -190,6 +198,9 @@ bool FlutterTizenEngine::RunEngine() {
190198
args.icu_data_path = icu_path_string.c_str();
191199
args.command_line_argc = static_cast<int>(argv.size());
192200
args.command_line_argv = argv.size() > 0 ? argv.data() : nullptr;
201+
args.dart_entrypoint_argc = static_cast<int>(entrypoint_argv.size());
202+
args.dart_entrypoint_argv =
203+
entrypoint_argv.size() > 0 ? entrypoint_argv.data() : nullptr;
193204
args.platform_message_callback =
194205
[](const FlutterPlatformMessage* engine_message, void* user_data) {
195206
if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
@@ -215,6 +226,10 @@ bool FlutterTizenEngine::RunEngine() {
215226
args.aot_data = aot_data_.get();
216227
}
217228

229+
if (entrypoint) {
230+
args.custom_dart_entrypoint = entrypoint;
231+
}
232+
218233
FlutterRendererConfig renderer_config = GetRendererConfig();
219234

220235
auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,

shell/platform/tizen/flutter_tizen_engine.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ class FlutterTizenEngine : public TizenRenderer::Delegate {
6666
bool transparent,
6767
bool focusable);
6868

69-
// Starts running the engine.
70-
bool RunEngine();
69+
// Starts running the engine with the given entrypoint. If null, defaults to
70+
// main().
71+
//
72+
// Returns false if the engine couldn't be started.
73+
bool RunEngine(const char* entrypoint);
7174

7275
// Stops the engine.
7376
bool StopEngine();

shell/platform/tizen/flutter_tizen_engine_unittest.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,37 @@ class FlutterTizenEngineTestHeaded : public FlutterTizenEngineTest {
5050

5151
TEST_F(FlutterTizenEngineTest, Run) {
5252
EXPECT_TRUE(engine_ != nullptr);
53-
EXPECT_TRUE(engine_->RunEngine());
53+
EXPECT_TRUE(engine_->RunEngine(nullptr));
5454
}
5555

5656
TEST_F(FlutterTizenEngineTest, Run_Twice) {
57-
EXPECT_TRUE(engine_->RunEngine());
58-
EXPECT_FALSE(engine_->RunEngine());
57+
EXPECT_TRUE(engine_->RunEngine(nullptr));
58+
EXPECT_FALSE(engine_->RunEngine(nullptr));
5959
}
6060

6161
TEST_F(FlutterTizenEngineTest, Stop) {
62-
EXPECT_TRUE(engine_->RunEngine());
62+
EXPECT_TRUE(engine_->RunEngine(nullptr));
6363
EXPECT_TRUE(engine_->StopEngine());
6464
}
6565

6666
TEST_F(FlutterTizenEngineTest, Stop_Twice) {
67-
EXPECT_TRUE(engine_->RunEngine());
67+
EXPECT_TRUE(engine_->RunEngine(nullptr));
6868
EXPECT_TRUE(engine_->StopEngine());
6969
EXPECT_FALSE(engine_->StopEngine());
7070
}
7171

7272
TEST_F(FlutterTizenEngineTest, GetPluginRegistrar) {
73-
EXPECT_TRUE(engine_->RunEngine());
73+
EXPECT_TRUE(engine_->RunEngine(nullptr));
7474
EXPECT_TRUE(engine_->GetPluginRegistrar() != nullptr);
7575
}
7676

7777
TEST_F(FlutterTizenEngineTest, GetTextureRegistrar) {
78-
EXPECT_TRUE(engine_->RunEngine());
78+
EXPECT_TRUE(engine_->RunEngine(nullptr));
7979
EXPECT_TRUE(engine_->GetTextureRegistrar() == nullptr);
8080
}
8181

8282
TEST_F(FlutterTizenEngineTestHeaded, GetTextureRegistrar) {
83-
EXPECT_TRUE(engine_->RunEngine());
83+
EXPECT_TRUE(engine_->RunEngine(nullptr));
8484
EXPECT_TRUE(engine_->GetTextureRegistrar() != nullptr);
8585
}
8686

@@ -134,7 +134,7 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) {
134134
return kSuccess;
135135
}));
136136

137-
engine_->RunEngine();
137+
engine_->RunEngine(nullptr);
138138

139139
EXPECT_TRUE(run_called);
140140
EXPECT_TRUE(update_locales_called);

shell/platform/tizen/public/flutter_tizen.h

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ typedef struct {
5555
const char** switches;
5656
// The number of elements in |switches|.
5757
size_t switches_count;
58+
// The optional entry point in the Dart project, if the entry point is null,
59+
// defaults to main().
60+
const char* entry_point;
61+
// Number of elements in the array passed in as dart_entrypoint_argv.
62+
int dart_entrypoint_argc;
63+
// Array of Dart entrypoint arguments. This is deep copied during the call
64+
// to FlutterDesktopEngineCreate.
65+
const char** dart_entrypoint_argv;
5866
} FlutterDesktopEngineProperties;
5967

6068
// Runs an instance of a Flutter engine with the given properties.

0 commit comments

Comments
 (0)