forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fl_dart_project.cc
116 lines (93 loc) · 3.76 KB
/
fl_dart_project.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// 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/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
#include <gmodule.h>
struct _FlDartProject {
GObject parent_instance;
gchar* aot_library_path;
gchar* assets_path;
gchar* icu_data_path;
gchar** dart_entrypoint_args;
};
G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
// Gets the directory the current executable is in.
static gchar* get_executable_dir() {
g_autoptr(GError) error = nullptr;
g_autofree gchar* exe_path = g_file_read_link("/proc/self/exe", &error);
if (exe_path == nullptr) {
g_critical("Failed to determine location of executable: %s",
error->message);
return nullptr;
}
return g_path_get_dirname(exe_path);
}
static void fl_dart_project_dispose(GObject* object) {
FlDartProject* self = FL_DART_PROJECT(object);
g_clear_pointer(&self->aot_library_path, g_free);
g_clear_pointer(&self->assets_path, g_free);
g_clear_pointer(&self->icu_data_path, g_free);
g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
}
static void fl_dart_project_class_init(FlDartProjectClass* klass) {
G_OBJECT_CLASS(klass)->dispose = fl_dart_project_dispose;
}
static void fl_dart_project_init(FlDartProject* self) {}
G_MODULE_EXPORT FlDartProject* fl_dart_project_new() {
FlDartProject* self =
FL_DART_PROJECT(g_object_new(fl_dart_project_get_type(), nullptr));
g_autofree gchar* executable_dir = get_executable_dir();
self->aot_library_path =
g_build_filename(executable_dir, "lib", "libapp.so", nullptr);
self->assets_path =
g_build_filename(executable_dir, "data", "flutter_assets", nullptr);
self->icu_data_path =
g_build_filename(executable_dir, "data", "icudtl.dat", nullptr);
return self;
}
G_MODULE_EXPORT void fl_dart_project_set_aot_library_path(FlDartProject* self,
const gchar* path) {
g_return_if_fail(FL_IS_DART_PROJECT(self));
g_clear_pointer(&self->aot_library_path, g_free);
self->aot_library_path = g_strdup(path);
}
G_MODULE_EXPORT const gchar* fl_dart_project_get_aot_library_path(
FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->aot_library_path;
}
G_MODULE_EXPORT void fl_dart_project_set_assets_path(FlDartProject* self,
gchar* path) {
g_return_if_fail(FL_IS_DART_PROJECT(self));
g_clear_pointer(&self->assets_path, g_free);
self->assets_path = g_strdup(path);
}
G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->assets_path;
}
G_MODULE_EXPORT void fl_dart_project_set_icu_data_path(FlDartProject* self,
gchar* path) {
g_return_if_fail(FL_IS_DART_PROJECT(self));
g_clear_pointer(&self->icu_data_path, g_free);
self->icu_data_path = g_strdup(path);
}
G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->icu_data_path;
}
G_MODULE_EXPORT gchar** fl_dart_project_get_dart_entrypoint_arguments(
FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->dart_entrypoint_args;
}
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(
FlDartProject* self,
char** argv) {
g_return_if_fail(FL_IS_DART_PROJECT(self));
g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
self->dart_entrypoint_args = g_strdupv(argv);
}