From 0a6e2b7f43ba99603ac9f78ad4e40e41ee044150 Mon Sep 17 00:00:00 2001 From: Anh Date: Tue, 28 May 2024 15:02:36 +0700 Subject: [PATCH] Remove FLUTTER_CACHE_FOLDER and FLUTTER_DATA_FOLDER --- docs/custom-tasks.md | 18 -- flutter/android/android-docker.mk | 2 - flutter/android/android.mk | 6 +- flutter/flutter.mk | 16 +- flutter/lib/app_constants.dart | 4 - flutter/lib/l10n/app_en.arb | 9 - flutter/lib/resources/resource_manager.dart | 25 +-- flutter/lib/store.dart | 16 -- flutter/lib/ui/settings/data_folder_type.dart | 17 -- .../lib/ui/settings/task_config_section.dart | 190 ++---------------- flutter/windows/windows.mk | 3 +- 11 files changed, 22 insertions(+), 284 deletions(-) delete mode 100644 flutter/lib/ui/settings/data_folder_type.dart diff --git a/docs/custom-tasks.md b/docs/custom-tasks.md index 6e7a0b8f8..4dee16be2 100644 --- a/docs/custom-tasks.md +++ b/docs/custom-tasks.md @@ -55,24 +55,6 @@ Data directory can be changed in settings, except for iOS, and its possible loca You can specify the full path, which will not depend on the data folder. Absolute path is only available for the task config path. All local resources in the task config must point to the data folder. -## Overriding default folders - -You can change the data folder without using graphical interface. - -Use `--dart-define=FLUTTER_DATA_FOLDER=` to specify the folder you want to use. -It will still be possible to choose a different folder via UI but the app will use specified folder by default. - -If you build the app using makefile commands, use `FLUTTER_DATA_FOLDER` environment variable. For example: `make flutter/test/integration FLUTTER_CACHE_FOLDER=/my/folder/path` - -You can also override app cache folder. -Use `--dart-define=FLUTTER_CACHE_FOLDER=` for manual build or `FLUTTER_CACHE_FOLDER` env for makefile script. -Note that it's impossible to change the cache folder from the UI. - -These options are intended for CI use, and possibly for internal testing. -Never use them for any public builds. - -These options are not available on iOS. - ## Using external resources on an iPhone On iOS an application resource folder can be found in `On My iPhone` -> ``. diff --git a/flutter/android/android-docker.mk b/flutter/android/android-docker.mk index a77fbe28d..21b03d649 100644 --- a/flutter/android/android-docker.mk +++ b/flutter/android/android-docker.mk @@ -46,8 +46,6 @@ flutter_common_docker_flags= \ --env FIREBASE_CRASHLYTICS_ENABLED=${FIREBASE_CRASHLYTICS_ENABLED} \ --env FLUTTER_BUILD_NUMBER=${FLUTTER_BUILD_NUMBER} \ --env FLUTTER_FORCE_PUB_GET=1 \ - --env FLUTTER_DATA_FOLDER=${FLUTTER_DATA_FOLDER} \ - --env FLUTTER_CACHE_FOLDER=${FLUTTER_CACHE_FOLDER} \ ${proxy_docker_args} \ ${backend_qti_flutter_docker_args} \ ${backend_samsung_docker_args} \ diff --git a/flutter/android/android.mk b/flutter/android/android.mk index 57a6f717a..effa10ab0 100644 --- a/flutter/android/android.mk +++ b/flutter/android/android.mk @@ -74,8 +74,7 @@ flutter/android/apk: cd flutter && ${_start_args} flutter --no-version-check build apk \ ${flutter_official_build_arg} \ ${flutter_firebase_crashlytics_arg} \ - ${flutter_build_number_arg} \ - ${flutter_folder_args} + ${flutter_build_number_arg} cp -f flutter/build/app/outputs/flutter-apk/app-release.apk ${flutter_android_apk_release_path}.apk .PHONY: flutter/android/appbundle flutter/android/appbundle: @@ -83,8 +82,7 @@ flutter/android/appbundle: cd flutter && ${_start_args} flutter --no-version-check build appbundle \ ${flutter_official_build_arg} \ ${flutter_firebase_crashlytics_arg} \ - ${flutter_build_number_arg} \ - ${flutter_folder_args} + ${flutter_build_number_arg} cp -f flutter/build/app/outputs/bundle/release/app-release.aab ${flutter_android_apk_release_path}.aab FLUTTER_ANDROID_APK_TEST_MAIN?=test-main.apk diff --git a/flutter/flutter.mk b/flutter/flutter.mk index eaf1f5166..414f6fbbe 100644 --- a/flutter/flutter.mk +++ b/flutter/flutter.mk @@ -51,18 +51,6 @@ flutter/check/build-number: @[ -n "$$FLUTTER_BUILD_NUMBER" ] \ || (echo FLUTTER_BUILD_NUMBER env must be explicitly set; exit 1) -ifneq (${FLUTTER_DATA_FOLDER},) -flutter_data_folder_arg="--dart-define=FLUTTER_DATA_FOLDER=${FLUTTER_DATA_FOLDER}" -else -flutter_data_folder_arg= -endif -ifneq (${FLUTTER_CACHE_FOLDER},) -flutter_cache_folder_arg="--dart-define=FLUTTER_CACHE_FOLDER=${FLUTTER_CACHE_FOLDER}" -else -flutter_cache_folder_arg= -endif -flutter_folder_args=${flutter_data_folder_arg} ${flutter_cache_folder_arg} - FIREBASE_CRASHLYTICS_ENABLED?=false flutter_firebase_crashlytics_arg="--dart-define=FIREBASE_CRASHLYTICS_ENABLED=${FIREBASE_CRASHLYTICS_ENABLED}" @@ -180,15 +168,13 @@ flutter/test/integration: ${flutter_test_device_arg} \ ${flutter_official_build_arg} \ ${flutter_firebase_crashlytics_arg} \ - ${flutter_perf_test_arg} \ - ${flutter_folder_args} + ${flutter_perf_test_arg} .PHONY: flutter/run flutter/run: cd flutter && ${_start_args} \ flutter --no-version-check \ run \ - ${flutter_folder_args} \ ${flutter_test_device_arg} \ ${flutter_official_build_arg} \ ${flutter_firebase_crashlytics_arg} diff --git a/flutter/lib/app_constants.dart b/flutter/lib/app_constants.dart index e71c1a462..b75f56778 100644 --- a/flutter/lib/app_constants.dart +++ b/flutter/lib/app_constants.dart @@ -7,10 +7,6 @@ class DartDefine { bool.fromEnvironment('FIREBASE_CRASHLYTICS_ENABLED', defaultValue: false); static const isFastMode = bool.fromEnvironment('FAST_MODE', defaultValue: false); - static const defaultCacheFolder = - String.fromEnvironment('FLUTTER_CACHE_FOLDER'); - static const defaultDataFolder = - String.fromEnvironment('FLUTTER_DATA_FOLDER'); } class WidgetKeys { diff --git a/flutter/lib/l10n/app_en.arb b/flutter/lib/l10n/app_en.arb index 53d46a22c..8eb04d97c 100644 --- a/flutter/lib/l10n/app_en.arb +++ b/flutter/lib/l10n/app_en.arb @@ -77,15 +77,6 @@ "settingsTaskConfigLocalResource": "local", "settingsTaskConfigError": "Path to config is invalid:", "settingsTaskDataFolderTitle": "Data folder", - "settingsTaskDataFolderDesc": "Task config may contain non-downloadable files that must be managed manually.", - "settingsTaskDataFolderDefault": "Default", - "settingsTaskDataFolderApp": "Application folder", - "settingsTaskDataFolderCustom": "Custom folder", - "settingsTaskDataFolderSelected": "Selected data folder", - "settingsTaskDataFolderWarning": "Folder does not exist or is not accessible", - "settingsTaskCacheFolderTitle": "Cache folder", - "settingsTaskCacheFolderDesc": "Cache folder contains downloadable data.\nThis folder can only be changed during build.", - "settingsTaskCacheFolderDefault": "Default", "settingsClearCache": "Clear cache", "settingsClearCacheConfirm": "All loaded resources will be deleted and downloaded again. Continue?", "settingsUnableSpecifyConfiguration": "Could not specify until benchmarks is running or content is loading", diff --git a/flutter/lib/resources/resource_manager.dart b/flutter/lib/resources/resource_manager.dart index ea316545b..cddb84a14 100644 --- a/flutter/lib/resources/resource_manager.dart +++ b/flutter/lib/resources/resource_manager.dart @@ -5,13 +5,11 @@ import 'package:flutter/foundation.dart'; import 'package:crypto/crypto.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:mlperfbench/app_constants.dart'; import 'package:mlperfbench/resources/cache_manager.dart'; import 'package:mlperfbench/resources/resource.dart'; import 'package:mlperfbench/resources/result_manager.dart'; import 'package:mlperfbench/resources/utils.dart'; import 'package:mlperfbench/store.dart'; -import 'package:mlperfbench/ui/settings/data_folder_type.dart'; class ResourceManager { static const _dataPrefix = 'local://'; @@ -60,18 +58,11 @@ class ResourceManager { } String getDataFolder() { - switch (parseDataFolderType(store.dataFolderType)) { - case DataFolderType.default_: - if (DartDefine.defaultDataFolder.isNotEmpty) { - return DartDefine.defaultDataFolder; - } else { - return applicationDirectory; - } - case DataFolderType.appFolder: - return applicationDirectory; - case DataFolderType.custom: - return store.customDataFolder; - } + return applicationDirectory; + } + + String getDataPrefix() { + return _dataPrefix; } Future isResourceExist(String? uri) async { @@ -152,11 +143,7 @@ class ResourceManager { Future initSystemPaths() async { applicationDirectory = await getApplicationDirectory(); await Directory(applicationDirectory).create(recursive: true); - if (DartDefine.defaultCacheFolder.isNotEmpty) { - _loadedResourcesDir = DartDefine.defaultCacheFolder; - } else { - _loadedResourcesDir = '$applicationDirectory/$_loadedResourcesDirName'; - } + _loadedResourcesDir = '$applicationDirectory/$_loadedResourcesDirName'; await Directory(_loadedResourcesDir).create(); cacheManager = CacheManager(_loadedResourcesDir); diff --git a/flutter/lib/store.dart b/flutter/lib/store.dart index 93139dcc3..b4b0d0100 100644 --- a/flutter/lib/store.dart +++ b/flutter/lib/store.dart @@ -106,20 +106,6 @@ class Store extends ChangeNotifier { notifyListeners(); } - String get dataFolderType => _getString(StoreConstants.dataFolderType); - - set dataFolderType(String value) { - _storeFromDisk.setString(StoreConstants.dataFolderType, value); - notifyListeners(); - } - - String get customDataFolder => _getString(StoreConstants.customDataFolder); - - set customDataFolder(String value) { - _storeFromDisk.setString(StoreConstants.customDataFolder, value); - notifyListeners(); - } - String get taskSelection => _getString(StoreConstants.taskSelection); set taskSelection(String value) { @@ -152,8 +138,6 @@ class StoreConstants { static const previousExtendedResult = 'previous extended result'; static const previousAppVersion = 'previous app version'; static const keepLogs = 'keep_logs'; - static const dataFolderType = 'data folder type'; - static const customDataFolder = 'custom data folder'; static const taskSelection = 'disabled_tasks'; static const testMinDuration = 'test min duration'; static const testCooldownDuration = 'test cooldown duration'; diff --git a/flutter/lib/ui/settings/data_folder_type.dart b/flutter/lib/ui/settings/data_folder_type.dart deleted file mode 100644 index f0f57c8a0..000000000 --- a/flutter/lib/ui/settings/data_folder_type.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:mlperfbench/app_constants.dart'; - -enum DataFolderType { default_, appFolder, custom } - -DataFolderType parseDataFolderType(String value) { - if (value == DataFolderType.appFolder.name && - DartDefine.defaultDataFolder.isNotEmpty) { - // if defaultDataFolder is empty then default_ and appFolder value means the same, - // so it doesn't make sense to have them as separate values - return DataFolderType.appFolder; - } - if (value == DataFolderType.custom.name) { - return DataFolderType.custom; - } - - return DataFolderType.default_; -} diff --git a/flutter/lib/ui/settings/task_config_section.dart b/flutter/lib/ui/settings/task_config_section.dart index fb745d70e..428238bce 100644 --- a/flutter/lib/ui/settings/task_config_section.dart +++ b/flutter/lib/ui/settings/task_config_section.dart @@ -2,148 +2,13 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:file_picker/file_picker.dart'; import 'package:provider/provider.dart'; -import 'package:mlperfbench/app_constants.dart'; import 'package:mlperfbench/benchmark/state.dart'; import 'package:mlperfbench/localizations/app_localizations.dart'; import 'package:mlperfbench/resources/config_manager.dart'; import 'package:mlperfbench/store.dart'; -import 'package:mlperfbench/ui/app_styles.dart'; import 'package:mlperfbench/ui/error_dialog.dart'; -import 'package:mlperfbench/ui/settings/data_folder_type.dart'; - -class _DataFolderSelectorHelper { - final AppLocalizations l10n; - final Store store; - final DataFolderType selectedOption; - - _DataFolderSelectorHelper(BuildContext context) - : l10n = AppLocalizations.of(context)!, - store = context.watch(), - selectedOption = - parseDataFolderType(context.read().dataFolderType); - - Widget build() { - final items = []; - - final dataFolderTitle = ListTile( - title: Padding( - padding: const EdgeInsets.only(bottom: 5), - child: Text( - l10n.settingsTaskDataFolderTitle, - ), - ), - subtitle: Text(l10n.settingsTaskDataFolderDesc), - ); - items.add(dataFolderTitle); - - items.add(_makeDefaultOption()); - if (DartDefine.defaultDataFolder.isNotEmpty) { - items.add(_makeAppFolderOption()); - } - items.add(_makeCustomOption()); - - return Column( - children: items, - ); - } - - void setValue(DataFolderType? value) { - if (value == null) return; - if (value == selectedOption) return; - store.dataFolderType = value.name; - } - - Widget _makeDefaultOption() { - late final String defaultOptionSubtitle; - if (DartDefine.defaultDataFolder.isEmpty) { - defaultOptionSubtitle = l10n.settingsTaskDataFolderApp; - } else { - defaultOptionSubtitle = DartDefine.defaultDataFolder; - } - return ListTile( - title: Text(l10n.settingsTaskDataFolderDefault), - subtitle: Text(defaultOptionSubtitle), - leading: Radio( - value: DataFolderType.default_, - groupValue: selectedOption, - onChanged: setValue, - ), - onTap: () => setValue(DataFolderType.default_), - ); - } - - Widget _makeAppFolderOption() { - return ListTile( - title: Text(l10n.settingsTaskDataFolderApp), - leading: Radio( - value: DataFolderType.appFolder, - groupValue: selectedOption, - onChanged: setValue, - ), - onTap: () => setValue(DataFolderType.appFolder), - ); - } - - Widget _makeCustomOption() { - final pickFolder = () async { - final dir = await FilePicker.platform.getDirectoryPath( - lockParentWindow: true, - ); - if (dir != null) { - store.customDataFolder = dir; - setValue(DataFolderType.custom); - } - }; - final pathField = Row( - children: [ - Expanded( - child: Text(store.customDataFolder), - ), - ElevatedButton( - onPressed: pickFolder, - child: const Icon(Icons.folder), - ) - ], - ); - Widget dirWarning = const SizedBox.shrink(); - if (store.customDataFolder.isNotEmpty) { - dirWarning = FutureBuilder( - future: Directory(store.customDataFolder).exists(), - builder: (context, AsyncSnapshot snapshot) { - if (!snapshot.hasData) { - return const SizedBox.shrink(); - } - final dirExists = snapshot.data!; - if (!dirExists) { - return Text( - l10n.settingsTaskDataFolderWarning - .replaceFirst('', store.customDataFolder), - style: const TextStyle(color: AppColors.errorText), - ); - } - return const SizedBox.shrink(); - }, - ); - } - return ListTile( - title: Text(l10n.settingsTaskDataFolderCustom), - subtitle: Column( - children: [pathField, dirWarning], - ), - leading: Radio( - value: DataFolderType.custom, - groupValue: selectedOption, - onChanged: setValue, - ), - onTap: () async { - await pickFolder(); - }, - ); - } -} class TaskConfigSection extends StatelessWidget { final List _configs; @@ -167,21 +32,19 @@ class TaskConfigSection extends StatelessWidget { (c) => _getConfigChoice(context, c, store.chosenConfigurationName), ), ); - // On ios you need to properly request access to a folder outside of the app folder - // but file_picker plugin doesn't do it. - // see the following link for details: - // https://github.com/mlcommons/mobile_app_open/pull/562#discussion_r992167655 - if (!Platform.isIOS) { - items.addAll([ - _makeCacheFolderNotice(l10n), - _DataFolderSelectorHelper(context).build(), - const Divider(), - ListTile( - title: Text(l10n.settingsTaskDataFolderSelected), - subtitle: Text(state.resourceManager.getDataFolder())), - ]); + String dataFolder; + if (Platform.isIOS) { + dataFolder = 'Files/MLPerf/'; + } else { + dataFolder = state.resourceManager.getDataFolder(); } - + final subtitle = '${state.resourceManager.getDataPrefix()} = $dataFolder'; + items.addAll([ + const Divider(), + ListTile( + title: Text(l10n.settingsTaskDataFolderTitle), + subtitle: Text(subtitle)), + ]); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: items, @@ -224,35 +87,6 @@ class TaskConfigSection extends StatelessWidget { ), ); } - - Widget _makeCacheFolderNotice(AppLocalizations l10n) { - if (DartDefine.defaultCacheFolder.isEmpty) { - return const SizedBox.shrink(); - } - return Column( - children: [ - ListTile( - title: Padding( - padding: const EdgeInsets.only(bottom: 5), - child: Text( - l10n.settingsTaskCacheFolderTitle, - ), - ), - subtitle: Text(l10n.settingsTaskCacheFolderDesc), - ), - ListTile( - enabled: false, - title: Text(l10n.settingsTaskCacheFolderDefault), - subtitle: const Text(DartDefine.defaultCacheFolder), - leading: const Radio( - value: true, - groupValue: true, - onChanged: null, - ), - ) - ], - ); - } } class TaskConfigErrorScreen extends StatelessWidget { diff --git a/flutter/windows/windows.mk b/flutter/windows/windows.mk index cceff0f59..85967ad8a 100644 --- a/flutter/windows/windows.mk +++ b/flutter/windows/windows.mk @@ -66,8 +66,7 @@ flutter/windows/release/build: cd flutter && ${_start_args} flutter --no-version-check build windows --no-pub \ ${flutter_official_build_arg} \ ${flutter_firebase_crashlytics_arg} \ - ${flutter_build_number_arg} \ - ${flutter_folder_args} + ${flutter_build_number_arg} .PHONY: flutter/windows/release/name flutter/windows/release/name: