From 1ee011111b4558647a3ad16130bbeb567add26f3 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Wed, 18 Dec 2024 13:54:22 +0100 Subject: [PATCH] [native_assets_builder] Use ` package:file`s `FileSystem` abstraction --- pkgs/native_assets_builder/CHANGELOG.md | 2 + .../lib/src/build_runner/build_planner.dart | 2 +- .../lib/src/build_runner/build_runner.dart | 56 ++++++++++--------- .../dependencies_hash_file.dart | 13 +++-- .../lib/src/locking/locking.dart | 13 +++-- .../src/package_layout/package_layout.dart | 35 +++++++----- .../lib/src/utils/file.dart | 19 +++---- .../lib/src/utils/uri.dart | 14 +++-- pkgs/native_assets_builder/pubspec.yaml | 1 + .../test/build_runner/build_planner_test.dart | 13 +++-- .../build_runner_reusability_test.dart | 2 + .../test/build_runner/build_runner_test.dart | 4 +- .../concurrency_shared_test_helper.dart | 2 + .../build_runner/concurrency_test_helper.dart | 2 + .../test/build_runner/helpers.dart | 4 ++ .../build_runner/package_layout_test.dart | 5 +- .../dependencies_hash_file_test.dart | 18 +++--- .../test/locking/locking_test_helper.dart | 7 ++- 18 files changed, 127 insertions(+), 85 deletions(-) diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index d10ec539d..366b75828 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -4,6 +4,8 @@ - Various fixes to caching. - **Breaking change** `BuildConfig.targetOS` is now only provided if `buildAssetTypes` contains the code asset. +- **Breaking change** `NativeAssetsBuildRunner` and `PackageLayout` now take a + `FileSystem` from `package:file/file.dart`s. ## 0.9.0 diff --git a/pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart b/pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart index 7b6d93780..96aff79a8 100644 --- a/pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart +++ b/pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:convert'; -import 'dart:io'; +import 'dart:io' show Process; import 'package:graphs/graphs.dart' as graphs; import 'package:logging/logging.dart'; diff --git a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart index 8f86b49f9..4e5e571d8 100644 --- a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart +++ b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart @@ -4,8 +4,9 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; +import 'dart:io' show Platform; +import 'package:file/file.dart'; import 'package:logging/logging.dart'; import 'package:native_assets_cli/native_assets_cli_internal.dart'; import 'package:package_config/package_config.dart'; @@ -63,6 +64,7 @@ typedef ApplicationAssetValidator = Future Function( /// [BuildConfig] and [LinkConfig]! For more info see: /// https://github.com/dart-lang/native/issues/1319 class NativeAssetsBuildRunner { + final FileSystem _fileSystem; final Logger logger; final Uri dartExecutable; final Duration singleHookTimeout; @@ -70,8 +72,10 @@ class NativeAssetsBuildRunner { NativeAssetsBuildRunner({ required this.logger, required this.dartExecutable, + required FileSystem fileSystem, Duration? singleHookTimeout, - }) : singleHookTimeout = singleHookTimeout ?? const Duration(minutes: 5); + }) : _fileSystem = fileSystem, + singleHookTimeout = singleHookTimeout ?? const Duration(minutes: 5); /// [workingDirectory] is expected to contain `.dart_tool`. /// @@ -98,7 +102,8 @@ class NativeAssetsBuildRunner { required List buildAssetTypes, required bool linkingEnabled, }) async { - packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); + packageLayout ??= + await PackageLayout.fromRootPackageRoot(_fileSystem, workingDirectory); final (buildPlan, packageGraph) = await _makePlan( hook: Hook.build, @@ -203,7 +208,8 @@ class NativeAssetsBuildRunner { required List buildAssetTypes, required BuildResult buildResult, }) async { - packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); + packageLayout ??= + await PackageLayout.fromRootPackageRoot(_fileSystem, workingDirectory); final (buildPlan, packageGraph) = await _makePlan( hook: Hook.link, @@ -231,9 +237,9 @@ class NativeAssetsBuildRunner { File? resourcesFile; if (resourceIdentifiers != null) { - resourcesFile = File.fromUri(buildDirUri.resolve('resources.json')); + resourcesFile = _fileSystem.file(buildDirUri.resolve('resources.json')); await resourcesFile.create(); - await File.fromUri(resourceIdentifiers).copy(resourcesFile.path); + await _fileSystem.file(resourceIdentifiers).copy(resourcesFile.path); } configBuilder.setupLinkRunConfig( outputDirectory: outDirUri, @@ -291,14 +297,14 @@ class NativeAssetsBuildRunner { final buildDirUri = packageLayout.dartToolNativeAssetsBuilder.resolve('$buildDirName/'); final outDirUri = buildDirUri.resolve('out/'); - final outDir = Directory.fromUri(outDirUri); + final outDir = _fileSystem.directory(outDirUri); if (!await outDir.exists()) { // TODO(https://dartbug.com/50565): Purge old or unused folders. await outDir.create(recursive: true); } final outDirSharedUri = packageLayout.dartToolNativeAssetsBuilder .resolve('shared/${package.name}/$hook/'); - final outDirShared = Directory.fromUri(outDirSharedUri); + final outDirShared = _fileSystem.directory(outDirSharedUri); if (!await outDirShared.exists()) { // TODO(https://dartbug.com/50565): Purge old or unused folders. await outDirShared.create(recursive: true); @@ -318,9 +324,10 @@ class NativeAssetsBuildRunner { final environment = _filteredEnvironment(_environmentVariablesFilter); final outDir = config.outputDirectory; return await runUnderDirectoriesLock( + _fileSystem, [ - Directory.fromUri(config.outputDirectoryShared.parent), - Directory.fromUri(config.outputDirectory.parent), + _fileSystem.directory(config.outputDirectoryShared).parent, + _fileSystem.directory(config.outputDirectory).parent, ], timeout: singleHookTimeout, logger: logger, @@ -338,13 +345,13 @@ class NativeAssetsBuildRunner { final (hookKernelFile, hookHashes) = hookCompileResult; final buildOutputFile = - File.fromUri(config.outputDirectory.resolve(hook.outputName)); - final dependenciesHashFile = File.fromUri( + _fileSystem.file(config.outputDirectory.resolve(hook.outputName)); + final dependenciesHashFile = _fileSystem.file( config.outputDirectory .resolve('../dependencies.dependencies_hash_file.json'), ); final dependenciesHashes = - DependenciesHashFile(file: dependenciesHashFile); + DependenciesHashFile(_fileSystem, file: dependenciesHashFile); final lastModifiedCutoffTime = DateTime.now(); if (buildOutputFile.existsSync() && dependenciesHashFile.existsSync()) { late final HookOutput output; @@ -446,9 +453,9 @@ ${e.message} final configFileContents = const JsonEncoder.withIndent(' ').convert(config.json); logger.info('config.json contents: $configFileContents'); - await File.fromUri(configFile).writeAsString(configFileContents); + await _fileSystem.file(configFile).writeAsString(configFileContents); final hookOutputUri = config.outputDirectory.resolve(hook.outputName); - final hookOutputFile = File.fromUri(hookOutputUri); + final hookOutputFile = _fileSystem.file(hookOutputUri); if (await hookOutputFile.exists()) { // Ensure we'll never read outdated build results. await hookOutputFile.delete(); @@ -472,7 +479,8 @@ ${e.message} var deleteOutputIfExists = false; try { if (result.exitCode != 0) { - final printWorkingDir = workingDirectory != Directory.current.uri; + final printWorkingDir = + workingDirectory != _fileSystem.currentDirectory.uri; final commandString = [ if (printWorkingDir) '(cd ${workingDirectory.toFilePath()};', dartExecutable.toFilePath(), @@ -558,16 +566,17 @@ ${e.message} ) async { // Don't invalidate cache with environment changes. final environmentForCaching = {}; - final kernelFile = File.fromUri( + final kernelFile = _fileSystem.file( outputDirectory.resolve('../hook.dill'), ); - final depFile = File.fromUri( + final depFile = _fileSystem.file( outputDirectory.resolve('../hook.dill.d'), ); - final dependenciesHashFile = File.fromUri( + final dependenciesHashFile = _fileSystem.file( outputDirectory.resolve('../hook.dependencies_hash_file.json'), ); - final dependenciesHashes = DependenciesHashFile(file: dependenciesHashFile); + final dependenciesHashes = + DependenciesHashFile(_fileSystem, file: dependenciesHashFile); final lastModifiedCutoffTime = DateTime.now(); var mustCompile = false; if (!await dependenciesHashFile.exists()) { @@ -641,7 +650,8 @@ ${e.message} ); var success = true; if (compileResult.exitCode != 0) { - final printWorkingDir = workingDirectory != Directory.current.uri; + final printWorkingDir = + workingDirectory != _fileSystem.currentDirectory.uri; final commandString = [ if (printWorkingDir) '(cd ${workingDirectory.toFilePath()};', dartExecutable.toFilePath(), @@ -780,10 +790,6 @@ ${compileResult.stdout} } } -extension on Uri { - Uri get parent => File(toFilePath()).parent.uri; -} - /// Parses depfile contents. /// /// Format: `path/to/my.dill: path/to/my.dart, path/to/more.dart` diff --git a/pkgs/native_assets_builder/lib/src/dependencies_hash_file/dependencies_hash_file.dart b/pkgs/native_assets_builder/lib/src/dependencies_hash_file/dependencies_hash_file.dart index 94449bf04..681e14586 100644 --- a/pkgs/native_assets_builder/lib/src/dependencies_hash_file/dependencies_hash_file.dart +++ b/pkgs/native_assets_builder/lib/src/dependencies_hash_file/dependencies_hash_file.dart @@ -3,19 +3,22 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:convert'; -import 'dart:io'; +import 'dart:io' show Platform; import 'dart:typed_data'; import 'package:crypto/crypto.dart'; +import 'package:file/file.dart'; import '../utils/file.dart'; import '../utils/uri.dart'; class DependenciesHashFile { - DependenciesHashFile({ + DependenciesHashFile( + this._fileSystem, { required this.file, }); + final FileSystem _fileSystem; final File file; FileSystemHashes _hashes = FileSystemHashes(); @@ -51,7 +54,7 @@ class DependenciesHashFile { Uri? modifiedAfterTimeStamp; for (final uri in fileSystemEntities) { int hash; - if ((await uri.fileSystemEntity.lastModified()) + if ((await _fileSystem.fileSystemEntity(uri).lastModified(_fileSystem)) .isAfter(fileSystemValidBeforeLastModified)) { hash = _hashLastModifiedAfterCutoff; modifiedAfterTimeStamp = uri; @@ -124,7 +127,7 @@ class DependenciesHashFile { } Future _hashFile(Uri uri) async { - final file = File.fromUri(uri); + final file = _fileSystem.file(uri); if (!await file.exists()) { return _hashNotExists; } @@ -132,7 +135,7 @@ class DependenciesHashFile { } Future _hashDirectory(Uri uri) async { - final directory = Directory.fromUri(uri); + final directory = _fileSystem.directory(uri); if (!await directory.exists()) { return _hashNotExists; } diff --git a/pkgs/native_assets_builder/lib/src/locking/locking.dart b/pkgs/native_assets_builder/lib/src/locking/locking.dart index c4b1d7ac3..f2351233f 100644 --- a/pkgs/native_assets_builder/lib/src/locking/locking.dart +++ b/pkgs/native_assets_builder/lib/src/locking/locking.dart @@ -3,11 +3,13 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; -import 'dart:io'; +import 'dart:io' show Platform, pid; +import 'package:file/file.dart'; import 'package:logging/logging.dart'; Future runUnderDirectoriesLock( + FileSystem fileSystem, List directories, Future Function() callback, { Duration? timeout, @@ -17,8 +19,10 @@ Future runUnderDirectoriesLock( return await callback(); } return await runUnderDirectoryLock( + fileSystem, directories.first, () => runUnderDirectoriesLock( + fileSystem, directories.skip(1).toList(), callback, timeout: timeout, @@ -41,13 +45,14 @@ Future runUnderDirectoriesLock( /// If provided, the [logger] streams information on the the locking status, and /// also streams error messages. Future runUnderDirectoryLock( + FileSystem fileSystem, Directory directory, Future Function() callback, { Duration? timeout, Logger? logger, }) async { const lockFileName = '.lock'; - final lockFile = _fileInDir(directory, lockFileName); + final lockFile = _fileInDir(fileSystem, directory, lockFileName); return _runUnderFileLock( lockFile, callback, @@ -56,11 +61,11 @@ Future runUnderDirectoryLock( ); } -File _fileInDir(Directory path, String filename) { +File _fileInDir(FileSystem fileSystem, Directory path, String filename) { final dirPath = path.path; var separator = Platform.pathSeparator; if (dirPath.endsWith(separator)) separator = ''; - return File('$dirPath$separator$filename'); + return fileSystem.file('$dirPath$separator$filename'); } /// Run [callback] with this Dart process having exclusive access to [file]. diff --git a/pkgs/native_assets_builder/lib/src/package_layout/package_layout.dart b/pkgs/native_assets_builder/lib/src/package_layout/package_layout.dart index 85cbf1ccf..8e8c19871 100644 --- a/pkgs/native_assets_builder/lib/src/package_layout/package_layout.dart +++ b/pkgs/native_assets_builder/lib/src/package_layout/package_layout.dart @@ -2,8 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:io'; - +import 'package:file/file.dart'; import 'package:native_assets_cli/native_assets_cli_internal.dart'; import 'package:package_config/package_config.dart'; @@ -15,6 +14,8 @@ import 'package:package_config/package_config.dart'; /// The directory layout follows pub's convention for caching: /// https://dart.dev/tools/pub/package-layout#project-specific-caching-for-tools class PackageLayout { + final FileSystem _fileSystem; + /// The root folder of the current dart invocation root package. /// /// `$rootPackageRoot`. @@ -29,26 +30,30 @@ class PackageLayout { final Uri packageConfigUri; - PackageLayout._( - this.rootPackageRoot, this.packageConfig, this.packageConfigUri); + PackageLayout._(this._fileSystem, this.rootPackageRoot, this.packageConfig, + this.packageConfigUri); factory PackageLayout.fromPackageConfig( + FileSystem fileSystem, PackageConfig packageConfig, Uri packageConfigUri, ) { - assert(File.fromUri(packageConfigUri).existsSync()); + assert(fileSystem.file(packageConfigUri).existsSync()); packageConfigUri = packageConfigUri.normalizePath(); final rootPackageRoot = packageConfigUri.resolve('../'); - return PackageLayout._(rootPackageRoot, packageConfig, packageConfigUri); + return PackageLayout._( + fileSystem, rootPackageRoot, packageConfig, packageConfigUri); } - static Future fromRootPackageRoot(Uri rootPackageRoot) async { + static Future fromRootPackageRoot( + FileSystem fileSystem, Uri rootPackageRoot) async { rootPackageRoot = rootPackageRoot.normalizePath(); final packageConfigUri = rootPackageRoot.resolve('.dart_tool/package_config.json'); - assert(await File.fromUri(packageConfigUri).exists()); + assert(await fileSystem.file(packageConfigUri).exists()); final packageConfig = await loadPackageConfigUri(packageConfigUri); - return PackageLayout._(rootPackageRoot, packageConfig, packageConfigUri); + return PackageLayout._( + fileSystem, rootPackageRoot, packageConfig, packageConfigUri); } /// The .dart_tool directory is used to store built artifacts and caches. @@ -107,12 +112,12 @@ class PackageLayout { for (final package in packageConfig.packages) { final packageRoot = package.root; if (packageRoot.scheme == 'file') { - if (await File.fromUri( - packageRoot.resolve('hook/').resolve(hook.scriptName), - ).exists() || - await File.fromUri( - packageRoot.resolve(hook.scriptName), - ).exists()) { + if (await _fileSystem + .file(packageRoot.resolve('hook/').resolve(hook.scriptName)) + .exists() || + await _fileSystem + .file(packageRoot.resolve(hook.scriptName)) + .exists()) { result.add(package); } } diff --git a/pkgs/native_assets_builder/lib/src/utils/file.dart b/pkgs/native_assets_builder/lib/src/utils/file.dart index 00f418eb6..ecec21969 100644 --- a/pkgs/native_assets_builder/lib/src/utils/file.dart +++ b/pkgs/native_assets_builder/lib/src/utils/file.dart @@ -2,12 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:io'; +import 'package:file/file.dart'; extension FileSystemEntityExtension on FileSystemEntity { - Future lastModified() async { + Future lastModified(FileSystem fileSystem) async { final this_ = this; - if (this_ is Link || await FileSystemEntity.isLink(this_.path)) { + + if (this_ is Link || await fileSystem.isLink(this_.path)) { // Don't follow links. return DateTime.fromMicrosecondsSinceEpoch(0); } @@ -18,17 +19,15 @@ extension FileSystemEntityExtension on FileSystemEntity { } return await this_.lastModified(); } - assert(this_ is Directory); - this_ as Directory; - return await this_.lastModified(); + return await (this_ as Directory).lastModified(fileSystem); } } extension FileSystemEntityIterable on Iterable { - Future lastModified() async { + Future lastModified(FileSystem fileSystem) async { var last = DateTime.fromMillisecondsSinceEpoch(0); for (final entity in this) { - final entityTimestamp = await entity.lastModified(); + final entityTimestamp = await entity.lastModified(fileSystem); if (entityTimestamp.isAfter(last)) { last = entityTimestamp; } @@ -38,10 +37,10 @@ extension FileSystemEntityIterable on Iterable { } extension DirectoryExtension on Directory { - Future lastModified() async { + Future lastModified(FileSystem fileSystem) async { var last = DateTime.fromMillisecondsSinceEpoch(0); await for (final entity in list()) { - final entityTimestamp = await entity.lastModified(); + final entityTimestamp = await entity.lastModified(fileSystem); if (entityTimestamp.isAfter(last)) { last = entityTimestamp; } diff --git a/pkgs/native_assets_builder/lib/src/utils/uri.dart b/pkgs/native_assets_builder/lib/src/utils/uri.dart index 95e2274c4..357371687 100644 --- a/pkgs/native_assets_builder/lib/src/utils/uri.dart +++ b/pkgs/native_assets_builder/lib/src/utils/uri.dart @@ -2,13 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:io'; +import 'dart:io' show Platform; -extension UriExtension on Uri { - FileSystemEntity get fileSystemEntity { - if (path.endsWith(Platform.pathSeparator) || path.endsWith('/')) { - return Directory.fromUri(this); +import 'package:file/file.dart'; + +extension UriExtension on FileSystem { + FileSystemEntity fileSystemEntity(Uri uri) { + if (uri.path.endsWith(Platform.pathSeparator) || uri.path.endsWith('/')) { + return directory(uri); } - return File.fromUri(this); + return file(uri); } } diff --git a/pkgs/native_assets_builder/pubspec.yaml b/pkgs/native_assets_builder/pubspec.yaml index e050da08c..fc54cd545 100644 --- a/pkgs/native_assets_builder/pubspec.yaml +++ b/pkgs/native_assets_builder/pubspec.yaml @@ -12,6 +12,7 @@ environment: dependencies: collection: ^1.18.0 crypto: ^3.0.6 + file: ^7.0.1 graphs: ^2.3.1 logging: ^1.2.0 # native_assets_cli: ^0.9.0 diff --git a/pkgs/native_assets_builder/test/build_runner/build_planner_test.dart b/pkgs/native_assets_builder/test/build_runner/build_planner_test.dart index f4027b229..67780467c 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_planner_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_planner_test.dart @@ -4,6 +4,7 @@ import 'dart:io'; +import 'package:file/local.dart'; import 'package:native_assets_builder/native_assets_builder.dart'; import 'package:native_assets_builder/src/build_runner/build_planner.dart'; import 'package:test/test.dart'; @@ -34,8 +35,8 @@ void main() async { final graph = PackageGraph.fromPubDepsJsonString(result.stdout); - final packageLayout = - await PackageLayout.fromRootPackageRoot(nativeAddUri); + final packageLayout = await PackageLayout.fromRootPackageRoot( + const LocalFileSystem(), nativeAddUri); final packagesWithNativeAssets = await packageLayout.packagesWithAssets(Hook.build); @@ -59,8 +60,8 @@ void main() async { // First, run `pub get`, we need pub to resolve our dependencies. await runPubGet(workingDirectory: nativeAddUri, logger: logger); - final packageLayout = - await PackageLayout.fromRootPackageRoot(nativeAddUri); + final packageLayout = await PackageLayout.fromRootPackageRoot( + const LocalFileSystem(), nativeAddUri); final packagesWithNativeAssets = await packageLayout.packagesWithAssets(Hook.build); final nativeAssetsBuildPlanner = @@ -86,8 +87,8 @@ void main() async { // First, run `pub get`, we need pub to resolve our dependencies. await runPubGet(workingDirectory: nativeAddUri, logger: logger); - final packageLayout = - await PackageLayout.fromRootPackageRoot(nativeAddUri); + final packageLayout = await PackageLayout.fromRootPackageRoot( + const LocalFileSystem(), nativeAddUri); final packagesWithNativeAssets = await packageLayout.packagesWithAssets(Hook.build); final nativeAssetsBuildPlanner = diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart index aa7356a6c..706edb90b 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'package:file/local.dart'; import 'package:native_assets_builder/src/build_runner/build_runner.dart'; import 'package:test/test.dart'; @@ -25,6 +26,7 @@ void main() async { final buildRunner = NativeAssetsBuildRunner( logger: logger, dartExecutable: dartExecutable, + fileSystem: const LocalFileSystem(), ); BuildConfigBuilder configCreator() => BuildConfigBuilder() diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_test.dart index 70df079d1..451353811 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_test.dart @@ -4,6 +4,7 @@ import 'dart:io'; +import 'package:file/local.dart'; import 'package:native_assets_builder/native_assets_builder.dart'; import 'package:test/test.dart'; @@ -50,7 +51,8 @@ void main() async { for (final passPackageLayout in [true, false]) { PackageLayout? packageLayout; if (passPackageLayout) { - packageLayout = await PackageLayout.fromRootPackageRoot(packageUri); + packageLayout = await PackageLayout.fromRootPackageRoot( + const LocalFileSystem(), packageUri); } final logMessages = []; final result = (await build( diff --git a/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart b/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart index d31b8c434..251c4e329 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'package:file/local.dart'; import 'package:logging/logging.dart'; import 'package:native_assets_builder/native_assets_builder.dart'; @@ -19,6 +20,7 @@ void main(List args) async { final result = await NativeAssetsBuildRunner( logger: logger, dartExecutable: dartExecutable, + fileSystem: const LocalFileSystem(), ).build( // Set up the code config, so that the builds for different targets are // in different directories. diff --git a/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart b/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart index 75d2cb096..9e04f312c 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'package:file/local.dart'; import 'package:logging/logging.dart'; import 'package:native_assets_builder/native_assets_builder.dart'; @@ -24,6 +25,7 @@ void main(List args) async { logger: logger, dartExecutable: dartExecutable, singleHookTimeout: timeout, + fileSystem: const LocalFileSystem(), ).build( configCreator: () => BuildConfigBuilder() ..setupCodeConfig( diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index 432b5dade..b96baa5ed 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:file/local.dart'; import 'package:logging/logging.dart'; import 'package:native_assets_builder/native_assets_builder.dart'; import 'package:test/test.dart'; @@ -53,6 +54,7 @@ Future build( final result = await NativeAssetsBuildRunner( logger: logger, dartExecutable: dartExecutable, + fileSystem: const LocalFileSystem(), ).build( configCreator: () { final configBuilder = BuildConfigBuilder(); @@ -118,6 +120,7 @@ Future link( final result = await NativeAssetsBuildRunner( logger: logger, dartExecutable: dartExecutable, + fileSystem: const LocalFileSystem(), ).link( configCreator: () { final configBuilder = LinkConfigBuilder(); @@ -180,6 +183,7 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( final buildRunner = NativeAssetsBuildRunner( logger: logger, dartExecutable: dartExecutable, + fileSystem: const LocalFileSystem(), ); final buildResult = await buildRunner.build( configCreator: () => BuildConfigBuilder() diff --git a/pkgs/native_assets_builder/test/build_runner/package_layout_test.dart b/pkgs/native_assets_builder/test/build_runner/package_layout_test.dart index a92992f2d..f63cc61aa 100644 --- a/pkgs/native_assets_builder/test/build_runner/package_layout_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/package_layout_test.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'package:file/local.dart'; import 'package:native_assets_builder/native_assets_builder.dart'; import 'package:test/test.dart'; @@ -17,9 +18,11 @@ void main() async { // First, run `pub get`, we need pub to resolve our dependencies. await runPubGet(workingDirectory: nativeAddUri, logger: logger); + const fileSystem = LocalFileSystem(); final packageLayout = - await PackageLayout.fromRootPackageRoot(nativeAddUri); + await PackageLayout.fromRootPackageRoot(fileSystem, nativeAddUri); final packageLayout2 = PackageLayout.fromPackageConfig( + fileSystem, packageLayout.packageConfig, packageLayout.packageConfigUri, ); diff --git a/pkgs/native_assets_builder/test/dependencies_hash_file/dependencies_hash_file_test.dart b/pkgs/native_assets_builder/test/dependencies_hash_file/dependencies_hash_file_test.dart index c222b31a4..dcd1b7e6b 100644 --- a/pkgs/native_assets_builder/test/dependencies_hash_file/dependencies_hash_file_test.dart +++ b/pkgs/native_assets_builder/test/dependencies_hash_file/dependencies_hash_file_test.dart @@ -3,8 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async'; -import 'dart:io'; +import 'dart:io' show Platform; +import 'package:file/local.dart'; import 'package:native_assets_builder/src/dependencies_hash_file/dependencies_hash_file.dart'; import 'package:test/test.dart'; @@ -12,6 +13,7 @@ import '../helpers.dart'; void main() async { final environment = Platform.environment; + const fileSystem = LocalFileSystem(); test('json format', () async { await inTempDir((tempUri) async { @@ -31,12 +33,12 @@ void main() async { test('dependencies hash file', () async { await inTempDir((tempUri) async { - final tempFile = File.fromUri(tempUri.resolve('foo.txt')); - final tempSubDir = Directory.fromUri(tempUri.resolve('subdir/')); - final subFile = File.fromUri(tempSubDir.uri.resolve('bar.txt')); + final tempFile = fileSystem.file(tempUri.resolve('foo.txt')); + final tempSubDir = fileSystem.directory(tempUri.resolve('subdir/')); + final subFile = fileSystem.file(tempSubDir.uri.resolve('bar.txt')); - final hashesFile = File.fromUri(tempUri.resolve('hashes.json')); - final hashes = DependenciesHashFile(file: hashesFile); + final hashesFile = fileSystem.file(tempUri.resolve('hashes.json')); + final hashes = DependenciesHashFile(fileSystem, file: hashesFile); Future reset() async { await tempFile.create(recursive: true); @@ -77,7 +79,7 @@ void main() async { await reset(); // Add file to tracked directory. - final subFile2 = File.fromUri(tempSubDir.uri.resolve('baz.txt')); + final subFile2 = fileSystem.file(tempSubDir.uri.resolve('baz.txt')); await subFile2.create(recursive: true); await subFile2.writeAsString('hello'); expect( @@ -103,7 +105,7 @@ void main() async { await reset(); // Add directory to tracked directory. - final subDir2 = Directory.fromUri(tempSubDir.uri.resolve('baz/')); + final subDir2 = fileSystem.directory(tempSubDir.uri.resolve('baz/')); await subDir2.create(recursive: true); expect( await hashes.findOutdatedDependency(environment), diff --git a/pkgs/native_assets_builder/test/locking/locking_test_helper.dart b/pkgs/native_assets_builder/test/locking/locking_test_helper.dart index 3fa8248c6..9332b9383 100644 --- a/pkgs/native_assets_builder/test/locking/locking_test_helper.dart +++ b/pkgs/native_assets_builder/test/locking/locking_test_helper.dart @@ -2,12 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:io'; - +import 'package:file/local.dart'; import 'package:native_assets_builder/src/locking/locking.dart'; void main(List args) async { - final directory = Directory.fromUri(Uri.directory(args[0])); + const fileSystem = LocalFileSystem(); + final directory = fileSystem.directory(Uri.directory(args[0])); Duration? timeout; if (args.length >= 2) { timeout = Duration(milliseconds: int.parse(args[1])); @@ -15,6 +15,7 @@ void main(List args) async { print('locking directory'); await runUnderDirectoryLock( + fileSystem, directory, timeout: timeout, () async {