[linux] Allow overriding asset, ICU data path (#38296)
Support setting a custom asset directory and ICU data path.
Fixes: https://github.com/flutter/flutter/issues/117103
Issue: https://github.com/flutter/flutter/issues/117102
diff --git a/shell/platform/linux/fl_dart_project.cc b/shell/platform/linux/fl_dart_project.cc
index 3a8de3f..fb749d3 100644
--- a/shell/platform/linux/fl_dart_project.cc
+++ b/shell/platform/linux/fl_dart_project.cc
@@ -88,12 +88,26 @@
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);
diff --git a/shell/platform/linux/fl_dart_project_test.cc b/shell/platform/linux/fl_dart_project_test.cc
index 7b37ced..03a16f5 100644
--- a/shell/platform/linux/fl_dart_project_test.cc
+++ b/shell/platform/linux/fl_dart_project_test.cc
@@ -38,6 +38,22 @@
G_GNUC_END_IGNORE_DEPRECATIONS
}
+TEST(FlDartProjectTest, OverrideAssetsPath) {
+ g_autoptr(FlDartProject) project = fl_dart_project_new();
+
+ char assets_path[] = "/normal/tuesday/night/for/shia/labeouf";
+ fl_dart_project_set_assets_path(project, assets_path);
+ EXPECT_STREQ(fl_dart_project_get_assets_path(project), assets_path);
+}
+
+TEST(FlDartProjectTest, OverrideIcuDataPath) {
+ g_autoptr(FlDartProject) project = fl_dart_project_new();
+
+ char icu_data_path[] = "/living/in/the/woods/icudtl.dat";
+ fl_dart_project_set_icu_data_path(project, icu_data_path);
+ EXPECT_STREQ(fl_dart_project_get_icu_data_path(project), icu_data_path);
+}
+
TEST(FlDartProjectTest, DartEntrypointArgs) {
g_autoptr(FlDartProject) project = fl_dart_project_new();
diff --git a/shell/platform/linux/public/flutter_linux/fl_dart_project.h b/shell/platform/linux/public/flutter_linux/fl_dart_project.h
index 1b56e24..d54b8b7 100644
--- a/shell/platform/linux/public/flutter_linux/fl_dart_project.h
+++ b/shell/platform/linux/public/flutter_linux/fl_dart_project.h
@@ -74,6 +74,17 @@
const gchar* fl_dart_project_get_aot_library_path(FlDartProject* project);
/**
+ * fl_dart_project_set_assets_path:
+ * @project: an #FlDartProject.
+ * @path: the absolute path to the assets directory.
+ *
+ * Sets the path to the directory containing the assets used in the Flutter
+ * application. By default, this is the data/flutter_assets subdirectory
+ * relative to the executable directory.
+ */
+void fl_dart_project_set_assets_path(FlDartProject* project, gchar* path);
+
+/**
* fl_dart_project_get_assets_path:
* @project: an #FlDartProject.
*
@@ -86,6 +97,16 @@
const gchar* fl_dart_project_get_assets_path(FlDartProject* project);
/**
+ * fl_dart_project_set_icu_data_path:
+ * @project: an #FlDartProject.
+ * @path: the absolute path to the ICU data file.
+ *
+ * Sets the path to the ICU data file used in the Flutter application. By
+ * default, this is data/icudtl.dat relative to the executable directory.
+ */
+void fl_dart_project_set_icu_data_path(FlDartProject* project, gchar* path);
+
+/**
* fl_dart_project_get_icu_data_path:
* @project: an #FlDartProject.
*