From f06e2e43e190ecc26d8f3020d4061f0d1379f411 Mon Sep 17 00:00:00 2001 From: hyiso Date: Thu, 13 Jun 2024 20:24:54 +0800 Subject: [PATCH] =?UTF-8?q?ohos=20=E4=BA=A7=E7=89=A9=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hyiso --- README.en.md | 8 ++--- README.md | 8 ++--- packages/flutter_tools/lib/src/cache.dart | 31 ++++++++++++++++++- .../flutter_tools/lib/src/flutter_cache.dart | 30 ++---------------- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/README.en.md b/README.en.md index 87cae944be..9c48fc0488 100644 --- a/README.en.md +++ b/README.en.md @@ -34,10 +34,9 @@ This repository is a compatible extension of Flutter SDK for the OpenHarmony pla ```sh export PATH=/bin:$PATH - # Flutter pub domestic mirror + # Domestic mirror export PUB_HOSTED_URL=https://pub.flutter-io.cn - # Flutter openharmony mirror - export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn ``` 3. The application build relies on [Flutter Engine](https://github.com/flutter/engine) to build products: `ohos_debug_unopt_arm64` and `ohos_release_arm64`. Please add: `--local-engine= in the Flutter Tools command running parameters. --local-engine=src/out/`. Can be downloaded at this path [Compiled product](https://docs.qq.com/sheet/DUnljRVBYUWZKZEtF?tab=BB08J2) @@ -47,8 +46,7 @@ This repository is a compatible extension of Flutter SDK for the OpenHarmony pla ``` # Domestic mirror export PUB_HOSTED_URL=https://pub.flutter-io.cn - # Flutter openharmony mirror - export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn # The flutter_flutter directory pulled from Gitee export PATH=/home//ohos/flutter_flutter/bin:$PATH diff --git a/README.md b/README.md index 8364b14485..54bd3f5a2e 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,8 @@ Flutter SDK 仓库 ```sh export PATH=/bin:$PATH - - # Flutter pub国内镜像 export PUB_HOSTED_URL=https://pub.flutter-io.cn - # Flutter 鸿蒙镜像 - export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn ``` 3. 应用构建依赖[Flutter Engine](https://github.com/flutter/engine)构建产物:`ohos_debug_unopt_arm64` 与 `ohos_release_arm64`,请在Flutter Tools指令运行参数中添加:`--local-engine=src/out/` 可在该路径下载[编译产物](https://docs.qq.com/sheet/DUnljRVBYUWZKZEtF?tab=BB08J2),engine路径指向需带上`src/out`目录 @@ -46,8 +43,7 @@ Flutter SDK 仓库 ```sh # 国内镜像 export PUB_HOSTED_URL=https://pub.flutter-io.cn - # Flutter 鸿蒙镜像 - export FLUTTER_STORAGE_BASE_URL=https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com + export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn # 拉取下来的flutter_flutter/bin目录 export PATH=/home//ohos/flutter_flutter/bin:$PATH diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 0b49c4ceee..0102b3ea08 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -197,6 +197,7 @@ class Cache { httpClient: HttpClient(), allowedBaseUrls: [ storageBaseUrl, + ohosStorageBaseUrl, cipdBaseUrl, ], ); @@ -478,6 +479,32 @@ class Cache { return overrideUrl; } + /// The base for URLs that store Flutter engine ohos artifacts that are fetched + /// during the installation of the Flutter SDK. + /// + /// By default the base URL is https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com. However, if + /// `FLUTTER_OHOS_STORAGE_BASE_URL` environment variable is provided, the + /// environment variable value is returned instead. + /// + /// See also: + /// + /// * [cipdBaseUrl], which determines how CIPD artifacts are fetched. + /// * [Cache] class-level dartdocs that explain how artifact mirrors work. + String get ohosStorageBaseUrl { + final String? overrideUrl = _platform.environment['FLUTTER_OHOS_STORAGE_BASE_URL']; + if (overrideUrl == null) { + return 'https://flutter-ohos.obs.cn-south-1.myhuaweicloud.com'; + } + // verify that this is a valid URI. + try { + Uri.parse(overrideUrl); + } on FormatException catch (err) { + throwToolExit('"FLUTTER_OHOS_STORAGE_BASE_URL" contains an invalid URI:\n$err'); + } + _maybeWarnAboutStorageOverride(overrideUrl); + return overrideUrl; + } + /// The base for URLs that store Flutter engine artifacts in CIPD. /// /// For some platforms, such as Web and Fuchsia, CIPD artifacts are fetched @@ -865,6 +892,8 @@ abstract class EngineCachedArtifact extends CachedArtifact { /// A list of the dart package directories to download. List getPackageDirs(); + String get storageBaseUrl => cache.storageBaseUrl; + @override bool isUpToDateInner(FileSystem fileSystem) { final Directory pkgDir = cache.getCacheDir('pkg'); @@ -897,7 +926,7 @@ abstract class EngineCachedArtifact extends CachedArtifact { FileSystem fileSystem, OperatingSystemUtils operatingSystemUtils, ) async { - final String url = '${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/'; + final String url = '$storageBaseUrl/flutter_infra_release/flutter/$version/'; final Directory pkgDir = cache.getCacheDir('pkg'); for (final String pkgName in getPackageDirs()) { diff --git a/packages/flutter_tools/lib/src/flutter_cache.dart b/packages/flutter_tools/lib/src/flutter_cache.dart index 7c8ae99be9..1521557317 100644 --- a/packages/flutter_tools/lib/src/flutter_cache.dart +++ b/packages/flutter_tools/lib/src/flutter_cache.dart @@ -556,19 +556,7 @@ class OHOSGenSnapshotArtifacts extends EngineCachedArtifact { String? get version => cache.getVersionFor('engine.ohos'); @override - Future updateInner( - ArtifactUpdater artifactUpdater, - FileSystem fileSystem, - OperatingSystemUtils operatingSystemUtils, - ) async { - if (!await checkForArtifacts(version)) { - throwToolExit( - 'do not have remote artifacts for ohos, please check your FLUTTER_STORAGE_BASE_URL.', - ); - return; - } - await super.updateInner(artifactUpdater, fileSystem, operatingSystemUtils); - } + String get storageBaseUrl => cache.ohosStorageBaseUrl; } class OHOSInternalBuildArtifacts extends EngineCachedArtifact { @@ -594,22 +582,10 @@ class OHOSInternalBuildArtifacts extends EngineCachedArtifact { } @override - String? get version => cache.getVersionFor('engine.ohos'); + String get storageBaseUrl => cache.ohosStorageBaseUrl; @override - Future updateInner( - ArtifactUpdater artifactUpdater, - FileSystem fileSystem, - OperatingSystemUtils operatingSystemUtils, - ) async { - if (!await checkForArtifacts(version)) { - throwToolExit( - 'do not have remote artifacts for ohos, please check your FLUTTER_STORAGE_BASE_URL.', - ); - return; - } - await super.updateInner(artifactUpdater, fileSystem, operatingSystemUtils); - } + String? get version => cache.getVersionFor('engine.ohos'); } /// A cached artifact containing Gradle Wrapper scripts and binaries. -- Gitee