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 14d7e8bee9..ee48105a05 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 @@ -38,19 +38,17 @@ class NativeAssetsBuildPlanner { required FileSystem fileSystem, }) async { final workingDirectory = packageConfigUri.resolve('../'); - final result = await Process.run( - dartExecutable.toFilePath(), - [ - 'pub', - 'deps', - '--json', - ], - workingDirectory: workingDirectory.toFilePath(), + final result = await Process.run(dartExecutable.toFilePath(), [ + 'pub', + 'deps', + '--json', + ], workingDirectory: workingDirectory.toFilePath()); + final packageGraph = PackageGraph.fromPubDepsJsonString( + result.stdout as String, + ); + final packageGraphFromRunPackage = packageGraph.subGraph( + packageLayout.runPackageName, ); - final packageGraph = - PackageGraph.fromPubDepsJsonString(result.stdout as String); - final packageGraphFromRunPackage = - packageGraph.subGraph(packageLayout.runPackageName); return NativeAssetsBuildPlanner._( packageGraph: packageGraphFromRunPackage, dartExecutable: dartExecutable, @@ -70,10 +68,9 @@ class NativeAssetsBuildPlanner { // everyone has migrated. (Probably once we stop backwards compatibility of // the protocol version pre 1.2.0 on some future version.) Future> packagesWithHook(Hook hook) async => switch (hook) { - Hook.build => _packagesWithBuildHook ??= - await _runPackagesWithHook(hook), - Hook.link => _packagesWithLinkHook ??= await _runPackagesWithHook(hook), - }; + Hook.build => _packagesWithBuildHook ??= await _runPackagesWithHook(hook), + Hook.link => _packagesWithLinkHook ??= await _runPackagesWithHook(hook), + }; List? _packagesWithBuildHook; List? _packagesWithLinkHook; @@ -111,7 +108,7 @@ class NativeAssetsBuildPlanner { if (_buildHookPlan != null) return _buildHookPlan; final packagesWithNativeAssets = await packagesWithHook(Hook.build); final packageMap = { - for (final package in packagesWithNativeAssets) package.name: package + for (final package in packagesWithNativeAssets) package.name: package, }; final packagesToBuild = packageMap.keys.toSet(); final stronglyConnectedComponents = packageGraph.computeStrongComponents(); @@ -119,7 +116,7 @@ class NativeAssetsBuildPlanner { for (final stronglyConnectedComponent in stronglyConnectedComponents) { final stronglyConnectedComponentWithNativeAssets = [ for (final packageName in stronglyConnectedComponent) - if (packagesToBuild.contains(packageName)) packageName + if (packagesToBuild.contains(packageName)) packageName, ]; if (stronglyConnectedComponentWithNativeAssets.length > 1) { logger.severe( @@ -129,7 +126,8 @@ class NativeAssetsBuildPlanner { return null; } else if (stronglyConnectedComponentWithNativeAssets.length == 1) { result.add( - packageMap[stronglyConnectedComponentWithNativeAssets.single]!); + packageMap[stronglyConnectedComponentWithNativeAssets.single]!, + ); } } _buildHookPlan = result; @@ -157,9 +155,10 @@ class PackageGraph { for (final package in packages) { final package_ = package as Map; final name = package_['name'] as String; - final dependencies = (package_['dependencies'] as List) - .whereType() - .toList(); + final dependencies = + (package_['dependencies'] as List) + .whereType() + .toList(); result[name] = dependencies; } return PackageGraph(result); @@ -188,7 +187,7 @@ class PackageGraph { vertex: [ for (final neighbor in map[vertex]!) if (subgraphVertices.contains(neighbor)) neighbor, - ] + ], }); } 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 21389312bf..66f5d7b83d 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 @@ -30,31 +30,31 @@ typedef BuildInputCreator = BuildInputBuilder Function(); typedef LinkInputCreator = LinkInputBuilder Function(); -typedef _HookValidator = Future Function( - HookInput input, HookOutput output); +typedef _HookValidator = + Future Function(HookInput input, HookOutput output); // A callback that validates the invariants of the [BuildInput]. -typedef BuildInputValidator = Future Function( - BuildInput input); +typedef BuildInputValidator = + Future Function(BuildInput input); // A callback that validates the invariants of the [LinkInput]. typedef LinkInputValidator = Future Function(LinkInput input); // A callback that validates the output of a `hook/link.dart` invocation is // valid (it may valid asset-type specific information). -typedef BuildValidator = Future Function( - BuildInput input, BuildOutput outup); +typedef BuildValidator = + Future Function(BuildInput input, BuildOutput outup); // A callback that validates the output of a `hook/link.dart` invocation is // valid (it may valid asset-type specific information). -typedef LinkValidator = Future Function( - LinkInput input, LinkOutput output); +typedef LinkValidator = + Future Function(LinkInput input, LinkOutput output); // A callback that validates assets emitted across all packages are valid / can // be used together (it may valid asset-type specific information - e.g. that // there are no classes in shared library filenames). -typedef ApplicationAssetValidator = Future Function( - List assets); +typedef ApplicationAssetValidator = + Future Function(List assets); /// The programmatic API to be used by Dart launchers to invoke native builds. /// @@ -79,10 +79,11 @@ class NativeAssetsBuildRunner { required this.packageLayout, Duration? singleHookTimeout, Map? hookEnvironment, - }) : _fileSystem = fileSystem, - singleHookTimeout = singleHookTimeout ?? const Duration(minutes: 5), - hookEnvironment = hookEnvironment ?? - filteredEnvironment(hookEnvironmentVariablesFilter); + }) : _fileSystem = fileSystem, + singleHookTimeout = singleHookTimeout ?? const Duration(minutes: 5), + hookEnvironment = + hookEnvironment ?? + filteredEnvironment(hookEnvironmentVariablesFilter); /// Checks whether any hooks need to be run. /// @@ -131,15 +132,11 @@ class NativeAssetsBuildRunner { targetMetadata: globalMetadata, )?.forEach((key, value) => metadata[key] = value); - final inputBuilder = inputCreator() - ..config.setupShared(buildAssetTypes: buildAssetTypes) - ..config.setupBuild( - dryRun: false, - linkingEnabled: linkingEnabled, - ) - ..setupBuildInput( - metadata: metadata, - ); + final inputBuilder = + inputCreator() + ..config.setupShared(buildAssetTypes: buildAssetTypes) + ..config.setupBuild(dryRun: false, linkingEnabled: linkingEnabled) + ..setupBuildInput(metadata: metadata); final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories( Hook.build, @@ -162,7 +159,9 @@ class NativeAssetsBuildRunner { ]; if (errors.isNotEmpty) { return _printErrors( - 'Build input for ${package.name} contains errors', errors); + 'Build input for ${package.name} contains errors', + errors, + ); } final result = await _runHookForPackageCached( @@ -213,8 +212,8 @@ class NativeAssetsBuildRunner { var hookResult = HookResult(encodedAssets: buildResult.encodedAssets); for (final package in buildPlan) { - final inputBuilder = inputCreator() - ..config.setupShared(buildAssetTypes: buildAssetTypes); + final inputBuilder = + inputCreator()..config.setupShared(buildAssetTypes: buildAssetTypes); final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories( Hook.link, @@ -249,7 +248,9 @@ class NativeAssetsBuildRunner { if (errors.isNotEmpty) { print(input.assets.encodedAssets); return _printErrors( - 'Link input for ${package.name} contains errors', errors); + 'Link input for ${package.name} contains errors', + errors, + ); } final result = await _runHookForPackageCached( @@ -287,16 +288,18 @@ class NativeAssetsBuildRunner { ) async { final buildDirName = inputBuilder.computeChecksum(); final packageName = package.name; - final buildDirUri = packageLayout.dartToolNativeAssetsBuilder - .resolve('$packageName/$buildDirName/'); + final buildDirUri = packageLayout.dartToolNativeAssetsBuilder.resolve( + '$packageName/$buildDirName/', + ); final outDirUri = buildDirUri.resolve('out/'); 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 outDirSharedUri = packageLayout.dartToolNativeAssetsBuilder.resolve( + 'shared/${package.name}/$hook/', + ); final outDirShared = _fileSystem.directory(outDirSharedUri); if (!await outDirShared.exists()) { // TODO(https://dartbug.com/50565): Purge old or unused folders. @@ -333,13 +336,16 @@ class NativeAssetsBuildRunner { final buildOutputFile = _fileSystem.file(input.outputFile); final buildOutputFileDeprecated = _fileSystem - // ignore: deprecated_member_use - .file(input.outputDirectory.resolve(hook.outputNameDeprecated)); + // ignore: deprecated_member_use + .file(input.outputDirectory.resolve(hook.outputNameDeprecated)); - final dependenciesHashFile = input.outputDirectory - .resolve('../dependencies.dependencies_hash_file.json'); - final dependenciesHashes = - DependenciesHashFile(_fileSystem, fileUri: dependenciesHashFile); + final dependenciesHashFile = input.outputDirectory.resolve( + '../dependencies.dependencies_hash_file.json', + ); + final dependenciesHashes = DependenciesHashFile( + _fileSystem, + fileUri: dependenciesHashFile, + ); final lastModifiedCutoffTime = DateTime.now(); if ((buildOutputFile.existsSync() || buildOutputFileDeprecated.existsSync()) && @@ -347,7 +353,10 @@ class NativeAssetsBuildRunner { late final HookOutput output; try { output = _readHookOutputFromUri( - hook, buildOutputFile, buildOutputFileDeprecated); + hook, + buildOutputFile, + buildOutputFileDeprecated, + ); } on FormatException catch (e) { logger.severe(''' Building assets for package:${input.packageName} failed. @@ -359,8 +368,8 @@ ${e.message} return null; } - final outdatedDependency = - await dependenciesHashes.findOutdatedDependency(hookEnvironment); + final outdatedDependency = await dependenciesHashes + .findOutdatedDependency(hookEnvironment); if (outdatedDependency == null) { logger.info( 'Skipping ${hook.name} for ${input.packageName}' @@ -435,8 +444,9 @@ ${e.message} Map environment, ) async { final inputFile = input.outputDirectory.resolve('../input.json'); - final inputFileContents = - const JsonEncoder.withIndent(' ').convert(input.json); + final inputFileContents = const JsonEncoder.withIndent( + ' ', + ).convert(input.json); logger.info('input.json contents: $inputFileContents'); await _fileSystem.file(inputFile).writeAsString(inputFileContents); final hookOutputUri = input.outputFile; @@ -446,8 +456,8 @@ ${e.message} await hookOutputFile.delete(); } final hookOutputUriDeprecated = - // ignore: deprecated_member_use - input.outputDirectory.resolve(hook.outputNameDeprecated); + // ignore: deprecated_member_use + input.outputDirectory.resolve(hook.outputNameDeprecated); final hookOutputFileDeprecated = _fileSystem.file(hookOutputUriDeprecated); if (await hookOutputFileDeprecated.exists()) { // Ensure we'll never read outdated build results. @@ -483,8 +493,7 @@ ${e.message} ...arguments.map((a) => a.contains(' ') ? "'$a'" : a), if (printWorkingDir) ')', ].join(' '); - logger.severe( - ''' + logger.severe(''' Building assets for package:${input.packageName} failed. ${hook.scriptName} returned with exit code: ${result.exitCode}. To reproduce run: @@ -493,8 +502,7 @@ ${e.message} ${result.stderr} stdout: ${result.stdout} - ''', - ); + '''); deleteOutputIfExists = true; return null; } @@ -507,8 +515,9 @@ ${e.message} final errors = await _validate(input, output, validator); if (errors.isNotEmpty) { _printErrors( - '$hook hook of package:${input.packageName} has invalid output', - errors); + '$hook hook of package:${input.packageName} has invalid output', + errors, + ); deleteOutputIfExists = true; return null; } @@ -532,28 +541,31 @@ ${e.message} } Future _createFileStreamingLogger(HookInput input) async { - final stdoutFile = - _fileSystem.file(input.outputDirectory.resolve('../stdout.txt')); + final stdoutFile = _fileSystem.file( + input.outputDirectory.resolve('../stdout.txt'), + ); await stdoutFile.writeAsString(''); - final stderrFile = - _fileSystem.file(input.outputDirectory.resolve('../stderr.txt')); + final stderrFile = _fileSystem.file( + input.outputDirectory.resolve('../stderr.txt'), + ); await stderrFile.writeAsString(''); - final wrappedLogger = Logger.detached('') - ..level = Level.ALL - ..onRecord.listen((record) async { - logger.log(record.level, record.message); - if (record.level <= Level.INFO) { - await stdoutFile.writeAsString( - '${record.message}\n', - mode: FileMode.append, - ); - } else { - await stderrFile.writeAsString( - '${record.message}\n', - mode: FileMode.append, - ); - } - }); + final wrappedLogger = + Logger.detached('') + ..level = Level.ALL + ..onRecord.listen((record) async { + logger.log(record.level, record.message); + if (record.level <= Level.INFO) { + await stdoutFile.writeAsString( + '${record.message}\n', + mode: FileMode.append, + ); + } else { + await stderrFile.writeAsString( + '${record.message}\n', + mode: FileMode.append, + ); + } + }); return wrappedLogger; } @@ -577,26 +589,28 @@ ${e.message} /// TODO(https://github.com/dart-lang/native/issues/1578): Compile only once /// instead of per input. This requires more locking. Future<(File kernelFile, DependenciesHashFile cacheFile)?> - _compileHookForPackageCached( + _compileHookForPackageCached( String packageName, Uri outputDirectory, Uri scriptUri, ) async { // Don't invalidate cache with environment changes. final environmentForCaching = {}; - final packageConfigHashable = - outputDirectory.resolve('../package_config_hashable.json'); + final packageConfigHashable = outputDirectory.resolve( + '../package_config_hashable.json', + ); await _makeHashablePackageConfig(packageConfigHashable); final kernelFile = _fileSystem.file( outputDirectory.resolve('../hook.dill'), ); - final depFile = _fileSystem.file( - outputDirectory.resolve('../hook.dill.d'), + final depFile = _fileSystem.file(outputDirectory.resolve('../hook.dill.d')); + final dependenciesHashFile = outputDirectory.resolve( + '../hook.dependencies_hash_file.json', + ); + final dependenciesHashes = DependenciesHashFile( + _fileSystem, + fileUri: dependenciesHashFile, ); - final dependenciesHashFile = - outputDirectory.resolve('../hook.dependencies_hash_file.json'); - final dependenciesHashes = - DependenciesHashFile(_fileSystem, fileUri: dependenciesHashFile); final lastModifiedCutoffTime = DateTime.now(); var mustCompile = false; if (!await dependenciesHashes.exists()) { @@ -650,8 +664,9 @@ ${e.message} await _fileSystem.file(packageLayout.packageConfigUri).readAsString(); final jsonData = jsonDecode(contents) as Map; jsonData.remove('generated'); - final contentsSanitized = - const JsonEncoder.withIndent(' ').convert(jsonData); + final contentsSanitized = const JsonEncoder.withIndent( + ' ', + ).convert(jsonData); await _fileSystem.file(uri).writeAsString(contentsSanitized); } @@ -688,8 +703,7 @@ ${e.message} ...compileArguments.map((a) => a.contains(' ') ? "'$a'" : a), if (printWorkingDir) ')', ].join(' '); - logger.severe( - ''' + logger.severe(''' Building native assets for package:$packageName failed. Compilation of hook returned with exit code: ${compileResult.exitCode}. To reproduce run: @@ -698,8 +712,7 @@ stderr: ${compileResult.stderr} stdout: ${compileResult.stdout} - ''', - ); + '''); success = false; if (await depFile.exists()) { await depFile.delete(); @@ -731,15 +744,20 @@ ${compileResult.stdout} HookOutput output, _HookValidator validator, ) async { - final errors = input is BuildInput - ? await validateBuildOutput(input, output as BuildOutput) - : await validateLinkOutput(input as LinkInput, output as LinkOutput); + final errors = + input is BuildInput + ? await validateBuildOutput(input, output as BuildOutput) + : await validateLinkOutput( + input as LinkInput, + output as LinkOutput, + ); errors.addAll(await validator(input, output)); if (input is BuildInput) { final planner = await _planner; - final packagesWithLink = - (await planner.packagesWithHook(Hook.link)).map((p) => p.name); + final packagesWithLink = (await planner.packagesWithHook( + Hook.link, + )).map((p) => p.name); for (final targetPackage in (output as BuildOutput).assets.encodedAssetsForLinking.keys) { if (!packagesWithLink.contains(targetPackage)) { @@ -822,7 +840,8 @@ ${compileResult.stdout} } Future _ensureNativeAssetsCliProtocolVersion() async { - final package = packageLayout.packageConfig['native_assets_cli'] ?? + final package = + packageLayout.packageConfig['native_assets_cli'] ?? packageLayout.packageConfig['hook']; // Anticipate rename. if (package == null) { // No dependencies with a hook or using a different protocol helper @@ -832,8 +851,10 @@ ${compileResult.stdout} final packageRoot = package.root.normalizePath(); final hookVersion = await _nativeAssetsCliProtocolVersion(packageRoot); if (hookVersion == null) { - logger.fine('Could not determine the protocol version of ' - '${packageRoot.toFilePath()}.'); + logger.fine( + 'Could not determine the protocol version of ' + '${packageRoot.toFilePath()}.', + ); // This is most likely due to a newer version of the package. return true; } @@ -850,10 +871,7 @@ ${compileResult.stdout} } Future _nativeAssetsCliProtocolVersion(Uri packageRoot) async { - const files = [ - 'lib/src/config.dart', - 'lib/src/model/hook_config.dart', - ]; + const files = ['lib/src/config.dart', 'lib/src/model/hook_config.dart']; for (final fileName in files) { final file = _fileSystem.file(packageRoot.resolve(fileName)); if (!await file.exists()) { @@ -931,6 +949,6 @@ Future> _readDepFile(File depFile) async { @internal Map filteredEnvironment(Set allowList) => { - for (final entry in Platform.environment.entries) - if (allowList.contains(entry.key.toUpperCase())) entry.key: entry.value, - }; + for (final entry in Platform.environment.entries) + if (allowList.contains(entry.key.toUpperCase())) entry.key: entry.value, +}; 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 2c2f9c806d..35b39bc78a 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 @@ -13,10 +13,7 @@ import '../utils/file.dart'; import '../utils/uri.dart'; class DependenciesHashFile { - DependenciesHashFile( - this._fileSystem, { - required this.fileUri, - }); + DependenciesHashFile(this._fileSystem, {required this.fileUri}); final FileSystem _fileSystem; final Uri fileUri; @@ -72,8 +69,9 @@ class DependenciesHashFile { _hashes.files.add(FilesystemEntityHash(uri, hash)); } for (final entry in environment.entries) { - _hashes.environment.add(EnvironmentVariableHash( - entry.key, _hashEnvironmentValue(entry.value))); + _hashes.environment.add( + EnvironmentVariableHash(entry.key, _hashEnvironmentValue(entry.value)), + ); } await _persist(); return modifiedAfterTimeStamp; @@ -145,8 +143,8 @@ class DependenciesHashFile { return _hashNotExists; } final children = directory.listSync(followLinks: true, recursive: false); - final childrenNames = children.map((e) => _pathBaseName(e.path)).toList() - ..sort(); + final childrenNames = + children.map((e) => _pathBaseName(e.path)).toList()..sort(); return _md5int64(utf8.encode(childrenNames.join(';'))); } @@ -178,8 +176,8 @@ class FileSystemHashes { FileSystemHashes({ List? files, List? environment, - }) : files = files ?? [], - environment = environment ?? []; + }) : files = files ?? [], + environment = environment ?? []; factory FileSystemHashes.fromJson(Map json) { final rawFilesystemEntries = @@ -194,10 +192,7 @@ class FileSystemHashes { for (final rawEntry in rawEnvironmentEntries) EnvironmentVariableHash._fromJson((rawEntry as Map).cast()), ]; - return FileSystemHashes( - files: files, - environment: environment, - ); + return FileSystemHashes(files: files, environment: environment); } final List files; @@ -208,13 +203,13 @@ class FileSystemHashes { static const _environmentKey = 'environment'; Map toJson() => { - _filesystemKey: [ - for (final FilesystemEntityHash file in files) file.toJson(), - ], - _environmentKey: [ - for (final EnvironmentVariableHash env in environment) env.toJson(), - ], - }; + _filesystemKey: [ + for (final FilesystemEntityHash file in files) file.toJson(), + ], + _environmentKey: [ + for (final EnvironmentVariableHash env in environment) env.toJson(), + ], + }; } /// A stored file or directory hash and path. @@ -223,10 +218,7 @@ class FileSystemHashes { /// /// [Directory] hashes are a hash of the names of the direct children. class FilesystemEntityHash { - FilesystemEntityHash( - this.path, - this.hash, - ); + FilesystemEntityHash(this.path, this.hash); factory FilesystemEntityHash._fromJson(Map json) => FilesystemEntityHash( @@ -243,22 +235,16 @@ class FilesystemEntityHash { final int hash; Object toJson() => { - _pathKey: path.toFilePath(), - _hashKey: hash, - }; + _pathKey: path.toFilePath(), + _hashKey: hash, + }; } class EnvironmentVariableHash { - EnvironmentVariableHash( - this.key, - this.hash, - ); + EnvironmentVariableHash(this.key, this.hash); factory EnvironmentVariableHash._fromJson(Map json) => - EnvironmentVariableHash( - json[_keyKey] as String, - json[_hashKey] as int, - ); + EnvironmentVariableHash(json[_keyKey] as String, json[_hashKey] as int); static const _keyKey = 'key'; static const _hashKey = 'hash'; @@ -268,10 +254,7 @@ class EnvironmentVariableHash { /// A 64 bit hash. final int hash; - Object toJson() => { - _keyKey: key, - _hashKey: hash, - }; + Object toJson() => {_keyKey: key, _hashKey: hash}; } bool _isDirectoryPath(String path) => diff --git a/pkgs/native_assets_builder/lib/src/model/hook_result.dart b/pkgs/native_assets_builder/lib/src/model/hook_result.dart index 9a7eeaf0a5..151208cc41 100644 --- a/pkgs/native_assets_builder/lib/src/model/hook_result.dart +++ b/pkgs/native_assets_builder/lib/src/model/hook_result.dart @@ -32,31 +32,30 @@ final class HookResult implements BuildResult, LinkResult { List? encodedAssets, Map>? encodedAssetsForLinking, List? dependencies, - }) => - HookResult._( - encodedAssets: encodedAssets ?? [], - encodedAssetsForLinking: encodedAssetsForLinking ?? {}, - dependencies: dependencies ?? [], - ); + }) => HookResult._( + encodedAssets: encodedAssets ?? [], + encodedAssetsForLinking: encodedAssetsForLinking ?? {}, + dependencies: dependencies ?? [], + ); HookResult copyAdd(HookOutput hookOutput, List hookDependencies) { final mergedMaps = mergeMaps( - encodedAssetsForLinking, - hookOutput is BuildOutput - ? hookOutput.assets.encodedAssetsForLinking - : >{}, - value: (encodedAssets1, encodedAssets2) => [ - ...encodedAssets1, - ...encodedAssets2, - ]); - final hookOutputAssets = (hookOutput is BuildOutput) - ? hookOutput.assets.encodedAssets - : (hookOutput as LinkOutput).assets.encodedAssets; + encodedAssetsForLinking, + hookOutput is BuildOutput + ? hookOutput.assets.encodedAssetsForLinking + : >{}, + value: + (encodedAssets1, encodedAssets2) => [ + ...encodedAssets1, + ...encodedAssets2, + ], + ); + final hookOutputAssets = + (hookOutput is BuildOutput) + ? hookOutput.assets.encodedAssets + : (hookOutput as LinkOutput).assets.encodedAssets; return HookResult( - encodedAssets: [ - ...encodedAssets, - ...hookOutputAssets, - ], + encodedAssets: [...encodedAssets, ...hookOutputAssets], encodedAssetsForLinking: mergedMaps, dependencies: [ ...dependencies, diff --git a/pkgs/native_assets_builder/lib/src/model/kernel_assets.dart b/pkgs/native_assets_builder/lib/src/model/kernel_assets.dart index b430282ed2..924f766adb 100644 --- a/pkgs/native_assets_builder/lib/src/model/kernel_assets.dart +++ b/pkgs/native_assets_builder/lib/src/model/kernel_assets.dart @@ -37,7 +37,7 @@ class KernelAssets { for (final entry in assetsPerTarget.entries) entry.key.toString(): { for (final e in entry.value) e.id: e.path.toJson(), - } + }, }, }; @@ -50,11 +50,7 @@ class KernelAsset { final Target target; final KernelAssetPath path; - KernelAsset({ - required this.id, - required this.target, - required this.path, - }); + KernelAsset({required this.id, required this.target, required this.path}); } abstract class KernelAssetPath { 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 813b7e0c80..18368cd565 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 @@ -48,11 +48,7 @@ class PackageLayout { ) { assert(fileSystem.file(packageConfigUri).existsSync()); packageConfigUri = packageConfigUri.normalizePath(); - return PackageLayout._( - packageConfig, - packageConfigUri, - runPackageName, - ); + return PackageLayout._(packageConfig, packageConfigUri, runPackageName); } static Future fromWorkingDirectory( @@ -61,23 +57,22 @@ class PackageLayout { String runPackgeName, ) async { workingDirectory = workingDirectory.normalizePath(); - final packageConfigUri = - await findPackageConfig(fileSystem, workingDirectory); + final packageConfigUri = await findPackageConfig( + fileSystem, + workingDirectory, + ); assert(await fileSystem.file(packageConfigUri).exists()); final packageConfig = await loadPackageConfigUri(packageConfigUri!); - return PackageLayout._( - packageConfig, - packageConfigUri, - runPackgeName, - ); + return PackageLayout._(packageConfig, packageConfigUri, runPackgeName); } static Future findPackageConfig( FileSystem fileSystem, Uri rootPackageRoot, ) async { - final packageConfigUri = - rootPackageRoot.resolve('.dart_tool/package_config.json'); + final packageConfigUri = rootPackageRoot.resolve( + '.dart_tool/package_config.json', + ); final file = fileSystem.file(packageConfigUri); if (await file.exists()) { return file.uri; @@ -109,8 +104,9 @@ class PackageLayout { /// https://dart.dev/tools/pub/package-layout#project-specific-caching-for-tools /// /// `$rootPackageRoot/.dart_tool/native_assets_builder/`. - late final Uri dartToolNativeAssetsBuilder = - dartTool.resolve('native_assets_builder/'); + late final Uri dartToolNativeAssetsBuilder = dartTool.resolve( + 'native_assets_builder/', + ); /// The root of `package:$packageName`. /// diff --git a/pkgs/native_assets_builder/lib/src/utils/run_process.dart b/pkgs/native_assets_builder/lib/src/utils/run_process.dart index 2da342848c..671e8c27ad 100644 --- a/pkgs/native_assets_builder/lib/src/utils/run_process.dart +++ b/pkgs/native_assets_builder/lib/src/utils/run_process.dart @@ -27,7 +27,8 @@ Future runProcess({ int expectedExitCode = 0, bool throwOnUnexpectedExitCode = false, }) async { - final printWorkingDir = workingDirectory != null && + final printWorkingDir = + workingDirectory != null && workingDirectory != filesystem.currentDirectory.uri; final commandString = [ if (printWorkingDir) '(cd ${workingDirectory.toFilePath()};', @@ -46,34 +47,40 @@ Future runProcess({ workingDirectory: workingDirectory?.toFilePath(), environment: environment, includeParentEnvironment: includeParentEnvironment, - runInShell: Platform.isWindows && + runInShell: + Platform.isWindows && (!includeParentEnvironment || workingDirectory != null), ); final stdoutSub = process.stdout .transform(utf8.decoder) .transform(const LineSplitter()) - .listen(captureOutput - ? (s) { + .listen( + captureOutput + ? (s) { logger?.fine(s); stdoutBuffer.writeln(s); } - : logger?.fine); + : logger?.fine, + ); final stderrSub = process.stderr .transform(utf8.decoder) .transform(const LineSplitter()) - .listen(captureOutput - ? (s) { + .listen( + captureOutput + ? (s) { logger?.severe(s); stderrBuffer.writeln(s); } - : logger?.severe); + : logger?.severe, + ); - final (exitCode, _, _) = await ( - process.exitCode, - stdoutSub.asFuture(), - stderrSub.asFuture() - ).wait; + final (exitCode, _, _) = + await ( + process.exitCode, + stdoutSub.asFuture(), + stderrSub.asFuture(), + ).wait; final result = RunProcessResult( pid: process.pid, command: commandString, diff --git a/pkgs/native_assets_builder/lib/src/utils/yaml.dart b/pkgs/native_assets_builder/lib/src/utils/yaml.dart index d626f3633f..baae74e250 100644 --- a/pkgs/native_assets_builder/lib/src/utils/yaml.dart +++ b/pkgs/native_assets_builder/lib/src/utils/yaml.dart @@ -9,10 +9,7 @@ String yamlEncode(Object yamlEncoding) { final editor = YamlEditor(''); editor.update( [], - wrapAsYamlNode( - yamlEncoding, - collectionStyle: CollectionStyle.BLOCK, - ), + wrapAsYamlNode(yamlEncoding, collectionStyle: CollectionStyle.BLOCK), ); return editor.toString(); } diff --git a/pkgs/native_assets_builder/pubspec.yaml b/pkgs/native_assets_builder/pubspec.yaml index 8e10e33453..42d4b1da43 100644 --- a/pkgs/native_assets_builder/pubspec.yaml +++ b/pkgs/native_assets_builder/pubspec.yaml @@ -7,7 +7,7 @@ repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_bui publish_to: none environment: - sdk: '>=3.5.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: collection: ^1.18.0 diff --git a/pkgs/native_assets_builder/test/build_runner/absolute_path_test.dart b/pkgs/native_assets_builder/test/build_runner/absolute_path_test.dart index bcb9e10d7a..ccda2033b9 100644 --- a/pkgs/native_assets_builder/test/build_runner/absolute_path_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/absolute_path_test.dart @@ -13,10 +13,7 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('relative_path/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final logMessages = []; @@ -26,10 +23,7 @@ void main() async { ); final fullLog = logMessages.join('\n'); expect(result, isNull); - expect( - fullLog, - contains('must be an absolute path'), - ); + expect(fullLog, contains('must be an absolute path')); } }); }); diff --git a/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart b/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart index 9deecda9fd..27dfb4fe0e 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart @@ -18,34 +18,30 @@ void main() async { final packageUri = tempUri.resolve('dart_app/'); // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); // Trigger a build, should invoke build for libraries with native assets. { final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect( logMessages.join('\n'), - stringContainsInOrder( - [ - 'native_add${Platform.pathSeparator}hook' - '${Platform.pathSeparator}build.dart', - 'native_subtract${Platform.pathSeparator}hook' - '${Platform.pathSeparator}build.dart', - ], - ), + stringContainsInOrder([ + 'native_add${Platform.pathSeparator}hook' + '${Platform.pathSeparator}build.dart', + 'native_subtract${Platform.pathSeparator}hook' + '${Platform.pathSeparator}build.dart', + ]), ); expect(result.encodedAssets.length, 2); expect( @@ -64,12 +60,15 @@ void main() async { // https://github.com/dart-lang/sdk/issues/59657 // Deps file on windows sometimes have lowercase drive letters. // File.exists will work, but Uri equality doesn't. - result.dependencies - .map((e) => Uri.file(e.toFilePath().toLowerCase())), - containsAll([ - tempUri.resolve('native_add/hook/build.dart'), - tempUri.resolve('native_subtract/hook/build.dart'), - ].map((e) => Uri.file(e.toFilePath().toLowerCase()))), + result.dependencies.map( + (e) => Uri.file(e.toFilePath().toLowerCase()), + ), + containsAll( + [ + tempUri.resolve('native_add/hook/build.dart'), + tempUri.resolve('native_subtract/hook/build.dart'), + ].map((e) => Uri.file(e.toFilePath().toLowerCase())), + ), ); } } 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 01feb4ccb5..2b3faf8785 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 @@ -22,17 +22,20 @@ void main() async { await runPubGet(workingDirectory: nativeAddUri, logger: logger); final packageLayout = await PackageLayout.fromWorkingDirectory( - const LocalFileSystem(), nativeAddUri, 'native_add'); + const LocalFileSystem(), + nativeAddUri, + 'native_add', + ); final nativeAssetsBuildPlanner = await NativeAssetsBuildPlanner.fromPackageConfigUri( - packageConfigUri: nativeAddUri.resolve( - '.dart_tool/package_config.json', - ), - dartExecutable: Uri.file(Platform.resolvedExecutable), - logger: logger, - packageLayout: packageLayout, - fileSystem: const LocalFileSystem(), - ); + packageConfigUri: nativeAddUri.resolve( + '.dart_tool/package_config.json', + ), + dartExecutable: Uri.file(Platform.resolvedExecutable), + logger: logger, + packageLayout: packageLayout, + fileSystem: const LocalFileSystem(), + ); final buildPlan = await nativeAssetsBuildPlanner.makeBuildHookPlan(); expect(buildPlan!.length, 1); expect(buildPlan.single.name, 'native_add'); @@ -56,14 +59,14 @@ void main() async { ); final nativeAssetsBuildPlanner = await NativeAssetsBuildPlanner.fromPackageConfigUri( - packageConfigUri: nativeAddUri.resolve( - '.dart_tool/package_config.json', - ), - dartExecutable: Uri.file(Platform.resolvedExecutable), - logger: logger, - packageLayout: packageLayout, - fileSystem: const LocalFileSystem(), - ); + packageConfigUri: nativeAddUri.resolve( + '.dart_tool/package_config.json', + ), + dartExecutable: Uri.file(Platform.resolvedExecutable), + logger: logger, + packageLayout: packageLayout, + fileSystem: const LocalFileSystem(), + ); final buildPlan = await nativeAssetsBuildPlanner.makeBuildHookPlan(); expect(buildPlan!.length, 0); }); diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_asset_id_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_asset_id_test.dart index b0ef95df2b..69598a9ba7 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_asset_id_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_asset_id_test.dart @@ -16,10 +16,7 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('wrong_namespace_asset/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final logMessages = []; @@ -45,18 +42,13 @@ void main() async { test('right asset id but other directory', timeout: longTimeout, () async { await inTempDir((tempUri) async { final packageUri = tempUri.resolve('different_root_dir/'); - await copyTestProjects( - targetUri: tempUri, - ); + await copyTestProjects(targetUri: tempUri); await copyTestProjects( sourceUri: testDataUri.resolve('native_add/'), targetUri: packageUri, ); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final result = await build( diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_build_output_format_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_build_output_format_test.dart index 19a4557b2c..55421e2a5d 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_build_output_format_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_build_output_format_test.dart @@ -21,10 +21,7 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('$package/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); // Run twice, failures should not be cached and return the same errors. for (final _ in [1, 2]) { @@ -42,15 +39,9 @@ void main() async { expect(result, isNull); if (package == 'wrong_build_output_3') { // Should re-execute the process on second run. - expect( - fullLog, - contains('build.dart returned with exit code: 1.'), - ); + expect(fullLog, contains('build.dart returned with exit code: 1.')); } else { - expect( - fullLog, - contains('output.json contained a format error.'), - ); + expect(fullLog, contains('output.json contained a format error.')); } } }); diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart index b7131c7bb0..b368b97a50 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart @@ -19,23 +19,21 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('native_add/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect( logMessages.join('\n'), contains( @@ -45,24 +43,23 @@ void main() async { ); expect( result.dependencies, - contains( - packageUri.resolve('src/native_add.c'), - ), + contains(packageUri.resolve('src/native_add.c')), ); } { final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; final hookUri = packageUri.resolve('hook/build.dart'); expect( logMessages.join('\n'), @@ -74,16 +71,16 @@ void main() async { ); expect( logMessages.join('\n'), - isNot(contains( - 'native_add${Platform.pathSeparator}hook' - '${Platform.pathSeparator}build.dart', - )), + isNot( + contains( + 'native_add${Platform.pathSeparator}hook' + '${Platform.pathSeparator}build.dart', + ), + ), ); expect( result.dependencies, - contains( - packageUri.resolve('src/native_add.c'), - ), + contains(packageUri.resolve('src/native_add.c')), ); } }); @@ -97,25 +94,24 @@ void main() async { final logMessages = []; final logger = createCapturingLogger(logMessages); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); logMessages.clear(); { - final result = (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; await expectSymbols( - asset: CodeAsset.fromEncoded(result.encodedAssets.single), - symbols: ['add']); + asset: CodeAsset.fromEncoded(result.encodedAssets.single), + symbols: ['add'], + ); logMessages.clear(); } @@ -125,25 +121,24 @@ void main() async { ); { - final result = (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; final cUri = packageUri.resolve('src/').resolve('native_add.c'); expect( logMessages.join('\n'), - stringContainsInOrder( - [ - 'Rerunning build for native_add in', - 'File contents changed: ${cUri.toFilePath()}.' - ], - ), + stringContainsInOrder([ + 'Rerunning build for native_add in', + 'File contents changed: ${cUri.toFilePath()}.', + ]), ); await expectSymbols( @@ -154,49 +149,19 @@ void main() async { }); }); - test( - 'add C file, modify hook', - timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add/'); - - final logMessages = []; - final logger = createCapturingLogger(logMessages); - - await runPubGet(workingDirectory: packageUri, logger: logger); - logMessages.clear(); + test('add C file, modify hook', timeout: longTimeout, () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('native_add/'); - final result = (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; - { - final compiledHook = logMessages - .where((m) => - m.contains('dart compile kernel') || - m.contains('dart.exe compile kernel')) - .isNotEmpty; - expect(compiledHook, isTrue); - } - logMessages.clear(); - await expectSymbols( - asset: CodeAsset.fromEncoded(result.encodedAssets.single), - symbols: ['add'], - ); + final logMessages = []; + final logger = createCapturingLogger(logMessages); - await copyTestProjects( - sourceUri: testDataUri.resolve('native_add_add_source/'), - targetUri: packageUri); + await runPubGet(workingDirectory: packageUri, logger: logger); + logMessages.clear(); - { - final result = (await build( + final result = + (await build( packageUri, logger, dartExecutable, @@ -205,98 +170,123 @@ void main() async { buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; + { + final compiledHook = + logMessages + .where( + (m) => + m.contains('dart compile kernel') || + m.contains('dart.exe compile kernel'), + ) + .isNotEmpty; + expect(compiledHook, isTrue); + } + logMessages.clear(); + await expectSymbols( + asset: CodeAsset.fromEncoded(result.encodedAssets.single), + symbols: ['add'], + ); - final hookUri = packageUri.resolve('hook/build.dart'); - expect( - logMessages.join('\n'), - contains('Recompiling ${hookUri.toFilePath()}'), - ); + await copyTestProjects( + sourceUri: testDataUri.resolve('native_add_add_source/'), + targetUri: packageUri, + ); - logMessages.clear(); - await expectSymbols( - asset: CodeAsset.fromEncoded(result.encodedAssets.single), - symbols: ['add', 'multiply'], - ); - } - }); - }, - ); + { + final result = + (await build( + packageUri, + logger, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; - for (final modifiedEnvKey in ['PATH', 'CUSTOM_KEY_123']) { - test( - 'change environment $modifiedEnvKey', - timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add/'); + final hookUri = packageUri.resolve('hook/build.dart'); + expect( + logMessages.join('\n'), + contains('Recompiling ${hookUri.toFilePath()}'), + ); - final logMessages = []; - final logger = createCapturingLogger(logMessages); + logMessages.clear(); + await expectSymbols( + asset: CodeAsset.fromEncoded(result.encodedAssets.single), + symbols: ['add', 'multiply'], + ); + } + }); + }); - await runPubGet(workingDirectory: packageUri, logger: logger); - logMessages.clear(); + for (final modifiedEnvKey in ['PATH', 'CUSTOM_KEY_123']) { + test('change environment $modifiedEnvKey', timeout: longTimeout, () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('native_add/'); - final result = (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - hookEnvironment: modifiedEnvKey == 'PATH' - ? null - : filteredEnvironment( - NativeAssetsBuildRunner.hookEnvironmentVariablesFilter, - ), - ))!; - logMessages.clear(); + final logMessages = []; + final logger = createCapturingLogger(logMessages); - // Simulate that the environment variables changed by augmenting the - // persisted environment from the last invocation. - final dependenciesHashFile = File.fromUri( - CodeAsset.fromEncoded(result.encodedAssets.single) - .file! - .parent - .parent - .resolve('dependencies.dependencies_hash_file.json'), - ); - expect(await dependenciesHashFile.exists(), true); - final dependenciesContent = - jsonDecode(await dependenciesHashFile.readAsString()) - as Map; - (dependenciesContent['environment'] as List).add({ - 'key': modifiedEnvKey, - 'hash': 123456789, - }); - await dependenciesHashFile - .writeAsString(jsonEncode(dependenciesContent)); + await runPubGet(workingDirectory: packageUri, logger: logger); + logMessages.clear(); - (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; - expect( - logMessages.join('\n'), - contains('hook.dill'), - ); - expect( - logMessages.join('\n'), - isNot(contains('Skipping build for native_add')), - ); - expect( - logMessages.join('\n'), - contains('Environment variable changed: $modifiedEnvKey.'), - ); - logMessages.clear(); + final result = + (await build( + packageUri, + logger, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + hookEnvironment: + modifiedEnvKey == 'PATH' + ? null + : filteredEnvironment( + NativeAssetsBuildRunner.hookEnvironmentVariablesFilter, + ), + ))!; + logMessages.clear(); + + // Simulate that the environment variables changed by augmenting the + // persisted environment from the last invocation. + final dependenciesHashFile = File.fromUri( + CodeAsset.fromEncoded(result.encodedAssets.single).file!.parent.parent + .resolve('dependencies.dependencies_hash_file.json'), + ); + expect(await dependenciesHashFile.exists(), true); + final dependenciesContent = + jsonDecode(await dependenciesHashFile.readAsString()) + as Map; + (dependenciesContent['environment'] as List).add({ + 'key': modifiedEnvKey, + 'hash': 123456789, }); - }, - ); + await dependenciesHashFile.writeAsString( + jsonEncode(dependenciesContent), + ); + + (await build( + packageUri, + logger, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; + expect(logMessages.join('\n'), contains('hook.dill')); + expect( + logMessages.join('\n'), + isNot(contains('Skipping build for native_add')), + ); + expect( + logMessages.join('\n'), + contains('Environment variable changed: $modifiedEnvKey.'), + ); + logMessages.clear(); + }); + }); } } diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart index c54967b392..4a538f1a41 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart @@ -16,10 +16,7 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('cyclic_package_1/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final logMessages = []; diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart index 3ea4db6634..a155f96819 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart @@ -18,30 +18,27 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('native_add/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { - final result = (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect(result.encodedAssets.length, 1); await expectSymbols( - asset: CodeAsset.fromEncoded(result.encodedAssets.single), - symbols: ['add']); + asset: CodeAsset.fromEncoded(result.encodedAssets.single), + symbols: ['add'], + ); expect( result.dependencies, - contains( - packageUri.resolve('src/native_add.c'), - ), + contains(packageUri.resolve('src/native_add.c')), ); } @@ -64,13 +61,17 @@ void main() async { final fullLog = logMessages.join('\n'); expect(result, isNull); expect(fullLog, contains('To reproduce run:')); - final reproCommand = fullLog - .split('\n') - .skipWhile((l) => !l.contains('To reproduce run:')) - .skip(1) - .first; - final reproResult = - await Process.run(reproCommand, [], runInShell: true); + final reproCommand = + fullLog + .split('\n') + .skipWhile((l) => !l.contains('To reproduce run:')) + .skip(1) + .first; + final reproResult = await Process.run( + reproCommand, + [], + runInShell: true, + ); expect(reproResult.exitCode, isNot(0)); } @@ -80,66 +81,66 @@ void main() async { ); { - final result = (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect(result.encodedAssets.length, 1); await expectSymbols( - asset: CodeAsset.fromEncoded(result.encodedAssets.single), - symbols: ['add']); + asset: CodeAsset.fromEncoded(result.encodedAssets.single), + symbols: ['add'], + ); expect( result.dependencies, - contains( - packageUri.resolve('src/native_add.c'), - ), + contains(packageUri.resolve('src/native_add.c')), ); } }); }); - test('do not build dependees after build failure', timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('depend_on_fail_build_app/'); + test( + 'do not build dependees after build failure', + timeout: longTimeout, + () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('depend_on_fail_build_app/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); - final logMessages = []; - await build( - packageUri, - logger, - capturedLogs: logMessages, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ); - Matcher stringContainsBuildHookCompilation(String packageName) => - stringContainsInOrder([ - 'Running', - 'hook.dill', - '$packageName${Platform.pathSeparator}' - 'hook${Platform.pathSeparator}build.dart', - ]); - expect( - logMessages.join('\n'), - stringContainsBuildHookCompilation('fail_build'), - ); - expect( - logMessages.join('\n'), - isNot(stringContainsBuildHookCompilation('depends_on_fail_build')), - ); - }); - }); + final logMessages = []; + await build( + packageUri, + logger, + capturedLogs: logMessages, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ); + Matcher stringContainsBuildHookCompilation(String packageName) => + stringContainsInOrder([ + 'Running', + 'hook.dill', + '$packageName${Platform.pathSeparator}' + 'hook${Platform.pathSeparator}build.dart', + ]); + expect( + logMessages.join('\n'), + stringContainsBuildHookCompilation('fail_build'), + ); + expect( + logMessages.join('\n'), + isNot(stringContainsBuildHookCompilation('depends_on_fail_build')), + ); + }); + }, + ); } diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart index 00189fc2f8..5fe9d2395d 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart @@ -17,47 +17,44 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('native_add/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - runPackageName: 'some_dev_dep', - buildAssetTypes: [CodeAsset.type], - inputValidator: validateDataAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + runPackageName: 'some_dev_dep', + buildAssetTypes: [CodeAsset.type], + inputValidator: validateDataAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect(result.encodedAssets, isEmpty); expect(result.dependencies, isEmpty); } { final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - runPackageName: 'native_add', - buildAssetTypes: [CodeAsset.type], - inputValidator: validateDataAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + runPackageName: 'native_add', + buildAssetTypes: [CodeAsset.type], + inputValidator: validateDataAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect(result.encodedAssets, isNotEmpty); expect( result.dependencies, - contains( - packageUri.resolve('src/native_add.c'), - ), + contains(packageUri.resolve('src/native_add.c')), ); expect( logMessages.join('\n'), 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 f1e4b3b501..08bfd0b4e6 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 @@ -20,10 +20,7 @@ void main() async { final packageUri = tempUri.resolve('$packageName/'); // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); final packageLayout = await PackageLayout.fromWorkingDirectory( const LocalFileSystem(), @@ -39,15 +36,17 @@ void main() async { final targetOS = OS.current; const defaultMacOSVersion = 13; - BuildInputBuilder inputCreator() => BuildInputBuilder() - ..config.setupCode( - targetArchitecture: Architecture.current, - targetOS: OS.current, - macOS: targetOS == OS.macOS - ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) - : null, - linkModePreference: LinkModePreference.dynamic, - ); + BuildInputBuilder inputCreator() => + BuildInputBuilder() + ..config.setupCode( + targetArchitecture: Architecture.current, + targetOS: OS.current, + macOS: + targetOS == OS.macOS + ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) + : null, + linkModePreference: LinkModePreference.dynamic, + ); await buildRunner.build( inputCreator: inputCreator, 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 7cd5b6e5c6..3e065b3c99 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 @@ -18,41 +18,43 @@ void main() async { final packageUri = tempUri.resolve('native_add/'); // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); // Trigger a build, should invoke build for libraries with native assets. { final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - inputValidator: validateCodeAssetBuildInput, - buildAssetTypes: [CodeAsset.type], - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + inputValidator: validateCodeAssetBuildInput, + buildAssetTypes: [CodeAsset.type], + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect( - logMessages.join('\n'), - stringContainsInOrder([ - 'native_add${Platform.pathSeparator}hook' - '${Platform.pathSeparator}build.dart', - ])); + logMessages.join('\n'), + stringContainsInOrder([ + 'native_add${Platform.pathSeparator}hook' + '${Platform.pathSeparator}build.dart', + ]), + ); expect(result.encodedAssets.length, 1); // Check that invocation logs are written to disk. final packgeBuildDirectory = Directory.fromUri( - packageUri.resolve('.dart_tool/native_assets_builder/native_add/')); + packageUri.resolve('.dart_tool/native_assets_builder/native_add/'), + ); final buildDirectory = packgeBuildDirectory.listSync().single as Directory; - final stdoutFile = - File.fromUri(buildDirectory.uri.resolve('stdout.txt')); - final stderrFile = - File.fromUri(buildDirectory.uri.resolve('stderr.txt')); + final stdoutFile = File.fromUri( + buildDirectory.uri.resolve('stdout.txt'), + ); + final stderrFile = File.fromUri( + buildDirectory.uri.resolve('stderr.txt'), + ); expect(stdoutFile.existsSync(), true); expect(stdoutFile.readAsStringSync(), contains('Some stdout.')); expect(stderrFile.existsSync(), true); @@ -61,19 +63,22 @@ void main() async { // Trigger a build, should not invoke anything. final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect( false, - logMessages.join('\n').contains( + logMessages + .join('\n') + .contains( 'native_add${Platform.pathSeparator}hook' '${Platform.pathSeparator}build.dart', ), diff --git a/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test.dart b/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test.dart index 3dc75b3071..3baa621bf7 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test.dart @@ -24,14 +24,9 @@ void main() async { targetUri: packageUri, ); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); - Future runBuildInProcess( - Target target, - ) async { + Future runBuildInProcess(Target target) async { final result = await runProcess( executable: dartExecutable, arguments: [ 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 339d442cc4..b600d1208f 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 @@ -14,9 +14,10 @@ void main(List args) async { final packageName = packageUri.pathSegments.lastWhere((e) => e.isNotEmpty); final target = Target.fromString(args[1]); - final logger = Logger('') - ..level = Level.ALL - ..onRecord.listen((event) => print(event.message)); + final logger = + Logger('') + ..level = Level.ALL + ..onRecord.listen((event) => print(event.message)); final targetOS = target.os; final packageLayout = await PackageLayout.fromWorkingDirectory( @@ -32,27 +33,34 @@ void main(List args) async { ).build( // Set up the code input, so that the builds for different targets are // in different directories. - inputCreator: () => BuildInputBuilder() - ..config.setupCode( - targetArchitecture: target.architecture, - targetOS: targetOS, - macOS: targetOS == OS.macOS - ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) - : null, - android: - targetOS == OS.android ? AndroidCodeConfig(targetNdkApi: 30) : null, - linkModePreference: LinkModePreference.dynamic, - ), + inputCreator: + () => + BuildInputBuilder() + ..config.setupCode( + targetArchitecture: target.architecture, + targetOS: targetOS, + macOS: + targetOS == OS.macOS + ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) + : null, + android: + targetOS == OS.android + ? AndroidCodeConfig(targetNdkApi: 30) + : null, + linkModePreference: LinkModePreference.dynamic, + ), linkingEnabled: false, buildAssetTypes: [DataAsset.type, CodeAsset.type], - inputValidator: (input) async => [ - ...await validateDataAssetBuildInput(input), - ...await validateCodeAssetBuildInput(input), - ], - buildValidator: (input, output) async => [ - ...await validateDataAssetBuildOutput(input, output), - ...await validateCodeAssetBuildOutput(input, output), - ], + inputValidator: + (input) async => [ + ...await validateDataAssetBuildInput(input), + ...await validateCodeAssetBuildInput(input), + ], + buildValidator: + (input, output) async => [ + ...await validateDataAssetBuildOutput(input, output), + ...await validateCodeAssetBuildOutput(input, output), + ], applicationAssetValidator: validateCodeAssetInApplication, ); if (result == null) { diff --git a/pkgs/native_assets_builder/test/build_runner/concurrency_test.dart b/pkgs/native_assets_builder/test/build_runner/concurrency_test.dart index 80d0243b19..56863b3c32 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_test.dart @@ -22,10 +22,7 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('native_add/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); Future runBuildInProcess() async { final result = await runProcess( @@ -54,7 +51,8 @@ void main() async { File? findLockFile(Uri packageUri, String packageName) { final dir = Directory.fromUri( - packageUri.resolve('.dart_tool/native_assets_builder/$packageName/')); + packageUri.resolve('.dart_tool/native_assets_builder/$packageName/'), + ); if (!dir.existsSync()) { // Too quick, dir doesn't exist yet. return null; @@ -66,10 +64,7 @@ void main() async { if (lockFileContents.isNotEmpty) { // The process might have been killed in between creating the lock // file and writing to it. - expect( - lockFileContents, - stringContainsInOrder(['Last acquired by']), - ); + expect(lockFileContents, stringContainsInOrder(['Last acquired by'])); } return lockFile; } @@ -83,22 +78,15 @@ void main() async { const packageName = 'native_add'; final packageUri = tempUri.resolve('$packageName/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); Future runBuildInProcess({Duration? killAfter}) async { - final process = await Process.start( - dartExecutable.toFilePath(), - [ - pkgNativeAssetsBuilderUri - .resolve('test/build_runner/concurrency_test_helper.dart') - .toFilePath(), - packageUri.toFilePath(), - ], - workingDirectory: packageUri.toFilePath(), - ); + final process = await Process.start(dartExecutable.toFilePath(), [ + pkgNativeAssetsBuilderUri + .resolve('test/build_runner/concurrency_test_helper.dart') + .toFilePath(), + packageUri.toFilePath(), + ], workingDirectory: packageUri.toFilePath()); final stdoutSub = process.stdout .transform(utf8.decoder) .transform(const LineSplitter()) @@ -112,11 +100,12 @@ void main() async { if (killAfter != null) { timer = Timer(killAfter, process.kill); } - final (exitCode, _, _) = await ( - process.exitCode, - stdoutSub.asFuture(), - stderrSub.asFuture() - ).wait; + final (exitCode, _, _) = + await ( + process.exitCode, + stdoutSub.asFuture(), + stderrSub.asFuture(), + ).wait; if (timer != null) { timer.cancel(); } @@ -147,10 +136,7 @@ void main() async { const packageName = 'native_add'; final packageUri = tempUri.resolve('$packageName/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); Future runBuildInProcess({ Duration? timeout, @@ -195,14 +181,16 @@ void main() async { // And give the timer to end this test and release the lock even more // time. In a normal test run, the timer should always be cancelled. final helperTimeout = singleHookTimeout * 10; - printOnFailure([ - 'cachedInvocationDuration', - cachedInvocationDuration, - 'singleHookTimeout', - singleHookTimeout, - 'helperTimeout', - helperTimeout, - ].toString()); + printOnFailure( + [ + 'cachedInvocationDuration', + cachedInvocationDuration, + 'singleHookTimeout', + singleHookTimeout, + 'helperTimeout', + helperTimeout, + ].toString(), + ); final randomAccessFile = await lockFile.open(mode: FileMode.write); final lock = await randomAccessFile.lock(FileLock.exclusive); 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 8690d1c058..4f076dc530 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 @@ -18,9 +18,10 @@ void main(List args) async { timeout = Duration(milliseconds: int.parse(args[1])); } - final logger = Logger('') - ..level = Level.ALL - ..onRecord.listen((event) => print(event.message)); + final logger = + Logger('') + ..level = Level.ALL + ..onRecord.listen((event) => print(event.message)); final targetOS = OS.current; final packageLayout = await PackageLayout.fromWorkingDirectory( @@ -35,26 +36,31 @@ void main(List args) async { fileSystem: const LocalFileSystem(), packageLayout: packageLayout, ).build( - inputCreator: () => BuildInputBuilder() - ..config.setupCode( - targetArchitecture: Architecture.current, - targetOS: targetOS, - linkModePreference: LinkModePreference.dynamic, - cCompiler: dartCICompilerConfig, - macOS: targetOS == OS.macOS - ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) - : null, - ), + inputCreator: + () => + BuildInputBuilder() + ..config.setupCode( + targetArchitecture: Architecture.current, + targetOS: targetOS, + linkModePreference: LinkModePreference.dynamic, + cCompiler: dartCICompilerConfig, + macOS: + targetOS == OS.macOS + ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) + : null, + ), linkingEnabled: false, buildAssetTypes: [CodeAsset.type, DataAsset.type], - inputValidator: (input) async => [ - ...await validateDataAssetBuildInput(input), - ...await validateCodeAssetBuildInput(input), - ], - buildValidator: (input, output) async => [ - ...await validateCodeAssetBuildOutput(input, output), - ...await validateDataAssetBuildOutput(input, output), - ], + inputValidator: + (input) async => [ + ...await validateDataAssetBuildInput(input), + ...await validateCodeAssetBuildInput(input), + ], + buildValidator: + (input, output) async => [ + ...await validateCodeAssetBuildOutput(input, output), + ...await validateDataAssetBuildOutput(input, output), + ], applicationAssetValidator: validateCodeAssetInApplication, ); if (result == null) { diff --git a/pkgs/native_assets_builder/test/build_runner/conflicting_dylib_test.dart b/pkgs/native_assets_builder/test/build_runner/conflicting_dylib_test.dart index 4672080d75..194ef48921 100644 --- a/pkgs/native_assets_builder/test/build_runner/conflicting_dylib_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/conflicting_dylib_test.dart @@ -16,10 +16,7 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('native_add_duplicate/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final logMessages = []; @@ -34,48 +31,46 @@ void main() async { ); final fullLog = logMessages.join('\n'); expect(result, isNull); - expect( - fullLog, - contains('Duplicate dynamic library file name'), - ); + expect(fullLog, contains('Duplicate dynamic library file name')); } }); }); - test('conflicting dylib name between link and build', timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add_duplicate/'); + test( + 'conflicting dylib name between link and build', + timeout: longTimeout, + () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('native_add_duplicate/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); - final buildResult = (await build( - packageUri, - logger, - linkingEnabled: true, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final buildResult = + (await build( + packageUri, + logger, + linkingEnabled: true, + dartExecutable, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; - final linkResult = await link( - packageUri, - logger, - dartExecutable, - buildResult: buildResult, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetLinkInput, - linkValidator: validateCodeAssetLinkOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ); - // Application validation error due to conflicting dylib name. - expect(linkResult, isNull); - }); - }); + final linkResult = await link( + packageUri, + logger, + dartExecutable, + buildResult: buildResult, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetLinkInput, + linkValidator: validateCodeAssetLinkOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ); + // Application validation error due to conflicting dylib name. + expect(linkResult, isNull); + }); + }, + ); } diff --git a/pkgs/native_assets_builder/test/build_runner/fail_on_os_sdk_version_test.dart b/pkgs/native_assets_builder/test/build_runner/fail_on_os_sdk_version_test.dart index 6d810e8af3..e95dca22e1 100644 --- a/pkgs/native_assets_builder/test/build_runner/fail_on_os_sdk_version_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/fail_on_os_sdk_version_test.dart @@ -20,23 +20,23 @@ final List<(Target, List<(int sdkVersion, bool success)>)> osInput = [ Target.androidArm64, [ (minNdkApiVersionForThisPackage, true), - (minNdkApiVersionForThisPackage - 1, false) - ] + (minNdkApiVersionForThisPackage - 1, false), + ], ), if (OS.current == OS.macOS) ...[ ( Target.macOSArm64, [ (minMacOSVersionForThisPackage, true), - (minMacOSVersionForThisPackage - 1, false) - ] + (minMacOSVersionForThisPackage - 1, false), + ], ), ( Target.iOSArm64, [ (minIosVersionForThisPackage, true), - (minIosVersionForThisPackage - 1, false) - ] + (minIosVersionForThisPackage - 1, false), + ], ), ], ]; @@ -51,66 +51,71 @@ void main() async { for (final (version, success) in versions) { final statusString = success ? 'succeed' : 'fail'; for (final (hook, packagePath) in hooks) { - test('$statusString $hook for $target sdk version', - timeout: longTimeout, () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve(packagePath); + test( + '$statusString $hook for $target sdk version', + timeout: longTimeout, + () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve(packagePath); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); - { - final logMessages = []; - final (buildResult, linkResult) = await buildAndLink( - target: target, - targetIOSSdk: (target.os == OS.iOS) ? IOSSdk.iPhoneOS : null, - targetIOSVersion: (target.os == OS.iOS) ? version : null, - targetMacOSVersion: (target.os == OS.macOS) ? version : null, - targetAndroidNdkApi: (target.os == OS.android) ? version : null, - packageUri, - createCapturingLogger(logMessages, level: Level.SEVERE), - dartExecutable, - buildAssetTypes: [CodeAsset.type, DataAsset.type], - buildInputValidator: (input) async => [ - ...await validateDataAssetBuildInput(input), - ...await validateCodeAssetBuildInput(input), - ], - buildValidator: (input, output) async => [ - ...await validateCodeAssetBuildOutput(input, output), - ...await validateDataAssetBuildOutput(input, output), - ], - linkInputValidator: (input) async => [ - ...await validateDataAssetLinkInput(input), - ...await validateCodeAssetLinkInput(input), - ], - linkValidator: (input, output) async => [ - ...await validateCodeAssetLinkOutput(input, output), - ...await validateDataAssetLinkOutput(input, output), - ], - applicationAssetValidator: validateCodeAssetInApplication, - ); - final fullLog = logMessages.join('\n'); - if (hook == 'build') { - expect(buildResult, success ? isNotNull : isNull); - } else { - assert(hook == 'link'); - expect(buildResult, isNotNull); - expect(linkResult, success ? isNotNull : isNull); - } - if (!success) { - expect( - fullLog, - contains( - 'The native assets for this package require at least', - ), + { + final logMessages = []; + final (buildResult, linkResult) = await buildAndLink( + target: target, + targetIOSSdk: (target.os == OS.iOS) ? IOSSdk.iPhoneOS : null, + targetIOSVersion: (target.os == OS.iOS) ? version : null, + targetMacOSVersion: (target.os == OS.macOS) ? version : null, + targetAndroidNdkApi: + (target.os == OS.android) ? version : null, + packageUri, + createCapturingLogger(logMessages, level: Level.SEVERE), + dartExecutable, + buildAssetTypes: [CodeAsset.type, DataAsset.type], + buildInputValidator: + (input) async => [ + ...await validateDataAssetBuildInput(input), + ...await validateCodeAssetBuildInput(input), + ], + buildValidator: + (input, output) async => [ + ...await validateCodeAssetBuildOutput(input, output), + ...await validateDataAssetBuildOutput(input, output), + ], + linkInputValidator: + (input) async => [ + ...await validateDataAssetLinkInput(input), + ...await validateCodeAssetLinkInput(input), + ], + linkValidator: + (input, output) async => [ + ...await validateCodeAssetLinkOutput(input, output), + ...await validateDataAssetLinkOutput(input, output), + ], + applicationAssetValidator: validateCodeAssetInApplication, ); + final fullLog = logMessages.join('\n'); + if (hook == 'build') { + expect(buildResult, success ? isNotNull : isNull); + } else { + assert(hook == 'link'); + expect(buildResult, isNotNull); + expect(linkResult, success ? isNotNull : isNull); + } + if (!success) { + expect( + fullLog, + contains( + 'The native assets for this package require at least', + ), + ); + } } - } - }); - }); + }); + }, + ); } } } diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index 122772f41c..90ab5392dc 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -34,36 +34,34 @@ Future buildDataAssets( String? runPackageName, List? capturedLogs, bool linkingEnabled = false, -}) => - build( - packageUri, - logger, - dartExecutable, - capturedLogs: capturedLogs, - buildAssetTypes: [DataAsset.type], - inputValidator: validateDataAssetBuildInput, - buildValidator: validateDataAssetBuildOutput, - applicationAssetValidator: (_) async => [], - runPackageName: runPackageName, - linkingEnabled: linkingEnabled, - ); +}) => build( + packageUri, + logger, + dartExecutable, + capturedLogs: capturedLogs, + buildAssetTypes: [DataAsset.type], + inputValidator: validateDataAssetBuildInput, + buildValidator: validateDataAssetBuildOutput, + applicationAssetValidator: (_) async => [], + runPackageName: runPackageName, + linkingEnabled: linkingEnabled, +); Future buildCodeAssets( Uri packageUri, { String? runPackageName, List? capturedLogs, -}) => - build( - packageUri, - logger, - dartExecutable, - capturedLogs: capturedLogs, - inputValidator: validateCodeAssetBuildInput, - buildAssetTypes: [CodeAsset.type], - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - runPackageName: runPackageName, - ); +}) => build( + packageUri, + logger, + dartExecutable, + capturedLogs: capturedLogs, + inputValidator: validateCodeAssetBuildInput, + buildAssetTypes: [CodeAsset.type], + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + runPackageName: runPackageName, +); Future build( Uri packageUri, @@ -109,19 +107,23 @@ Future build( targetOS: targetOS, linkModePreference: linkModePreference, cCompiler: cCompiler ?? dartCICompilerConfig, - iOS: targetOS == OS.iOS - ? IOSCodeConfig( - targetSdk: targetIOSSdk!, - targetVersion: targetIOSVersion!, - ) - : null, - macOS: targetOS == OS.macOS - ? MacOSCodeConfig( - targetVersion: targetMacOSVersion ?? defaultMacOSVersion) - : null, - android: targetOS == OS.android - ? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!) - : null, + iOS: + targetOS == OS.iOS + ? IOSCodeConfig( + targetSdk: targetIOSSdk!, + targetVersion: targetIOSVersion!, + ) + : null, + macOS: + targetOS == OS.macOS + ? MacOSCodeConfig( + targetVersion: targetMacOSVersion ?? defaultMacOSVersion, + ) + : null, + android: + targetOS == OS.android + ? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!) + : null, ); } return inputBuilder; @@ -188,19 +190,23 @@ Future link( targetOS: target?.os ?? OS.current, linkModePreference: linkModePreference, cCompiler: cCompiler ?? dartCICompilerConfig, - iOS: targetOS == OS.iOS - ? IOSCodeConfig( - targetSdk: targetIOSSdk!, - targetVersion: targetIOSVersion!, - ) - : null, - macOS: targetOS == OS.macOS - ? MacOSCodeConfig( - targetVersion: targetMacOSVersion ?? defaultMacOSVersion) - : null, - android: targetOS == OS.android - ? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!) - : null, + iOS: + targetOS == OS.iOS + ? IOSCodeConfig( + targetSdk: targetIOSSdk!, + targetVersion: targetIOSVersion!, + ) + : null, + macOS: + targetOS == OS.macOS + ? MacOSCodeConfig( + targetVersion: targetMacOSVersion ?? defaultMacOSVersion, + ) + : null, + android: + targetOS == OS.android + ? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!) + : null, ); } return inputBuilder; @@ -242,105 +248,112 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( Target? target, Uri? resourceIdentifiers, required List buildAssetTypes, -}) async => - await runWithLog(capturedLogs, () async { - final runPackageName_ = runPackageName ?? - packageUri.pathSegments.lastWhere((e) => e.isNotEmpty); - final packageLayout = await PackageLayout.fromWorkingDirectory( - const LocalFileSystem(), - packageUri, - runPackageName_, - ); - final buildRunner = NativeAssetsBuildRunner( - logger: logger, - dartExecutable: dartExecutable, - fileSystem: const LocalFileSystem(), - packageLayout: packageLayout, - ); - final targetOS = target?.os ?? OS.current; - final buildResult = await buildRunner.build( - inputCreator: () { - final inputBuilder = BuildInputBuilder(); - if (buildAssetTypes.contains(CodeAsset.type)) { - inputBuilder.config.setupCode( - targetArchitecture: target?.architecture ?? Architecture.current, - targetOS: target?.os ?? OS.current, - linkModePreference: linkModePreference, - cCompiler: cCompiler ?? dartCICompilerConfig, - iOS: targetOS == OS.iOS +}) async => await runWithLog(capturedLogs, () async { + final runPackageName_ = + runPackageName ?? packageUri.pathSegments.lastWhere((e) => e.isNotEmpty); + final packageLayout = await PackageLayout.fromWorkingDirectory( + const LocalFileSystem(), + packageUri, + runPackageName_, + ); + final buildRunner = NativeAssetsBuildRunner( + logger: logger, + dartExecutable: dartExecutable, + fileSystem: const LocalFileSystem(), + packageLayout: packageLayout, + ); + final targetOS = target?.os ?? OS.current; + final buildResult = await buildRunner.build( + inputCreator: () { + final inputBuilder = BuildInputBuilder(); + if (buildAssetTypes.contains(CodeAsset.type)) { + inputBuilder.config.setupCode( + targetArchitecture: target?.architecture ?? Architecture.current, + targetOS: target?.os ?? OS.current, + linkModePreference: linkModePreference, + cCompiler: cCompiler ?? dartCICompilerConfig, + iOS: + targetOS == OS.iOS ? IOSCodeConfig( - targetSdk: targetIOSSdk!, - targetVersion: targetIOSVersion!, - ) + targetSdk: targetIOSSdk!, + targetVersion: targetIOSVersion!, + ) : null, - macOS: targetOS == OS.macOS + macOS: + targetOS == OS.macOS ? MacOSCodeConfig( - targetVersion: targetMacOSVersion ?? defaultMacOSVersion) + targetVersion: targetMacOSVersion ?? defaultMacOSVersion, + ) : null, - android: targetOS == OS.android + android: + targetOS == OS.android ? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!) : null, - ); - } - return inputBuilder; - }, - inputValidator: buildInputValidator, - linkingEnabled: true, - buildAssetTypes: buildAssetTypes, - buildValidator: buildValidator, - applicationAssetValidator: applicationAssetValidator, - ); - - if (buildResult == null) { - return (null, null); + ); } + return inputBuilder; + }, + inputValidator: buildInputValidator, + linkingEnabled: true, + buildAssetTypes: buildAssetTypes, + buildValidator: buildValidator, + applicationAssetValidator: applicationAssetValidator, + ); - expect(await buildResult.encodedAssets.allExist(), true); - for (final encodedAssetsForLinking - in buildResult.encodedAssetsForLinking.values) { - expect(await encodedAssetsForLinking.allExist(), true); - } + if (buildResult == null) { + return (null, null); + } - final linkResult = await buildRunner.link( - inputCreator: () { - final inputBuilder = LinkInputBuilder(); - if (buildAssetTypes.contains(CodeAsset.type)) { - inputBuilder.config.setupCode( - targetArchitecture: target?.architecture ?? Architecture.current, - targetOS: target?.os ?? OS.current, - linkModePreference: linkModePreference, - cCompiler: cCompiler ?? dartCICompilerConfig, - iOS: targetOS == OS.iOS + expect(await buildResult.encodedAssets.allExist(), true); + for (final encodedAssetsForLinking + in buildResult.encodedAssetsForLinking.values) { + expect(await encodedAssetsForLinking.allExist(), true); + } + + final linkResult = await buildRunner.link( + inputCreator: () { + final inputBuilder = LinkInputBuilder(); + if (buildAssetTypes.contains(CodeAsset.type)) { + inputBuilder.config.setupCode( + targetArchitecture: target?.architecture ?? Architecture.current, + targetOS: target?.os ?? OS.current, + linkModePreference: linkModePreference, + cCompiler: cCompiler ?? dartCICompilerConfig, + iOS: + targetOS == OS.iOS ? IOSCodeConfig( - targetSdk: targetIOSSdk!, - targetVersion: targetIOSVersion!, - ) + targetSdk: targetIOSSdk!, + targetVersion: targetIOSVersion!, + ) : null, - macOS: targetOS == OS.macOS + macOS: + targetOS == OS.macOS ? MacOSCodeConfig( - targetVersion: targetMacOSVersion ?? defaultMacOSVersion) + targetVersion: targetMacOSVersion ?? defaultMacOSVersion, + ) : null, - android: targetOS == OS.android + android: + targetOS == OS.android ? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!) : null, - ); - } - return inputBuilder; - }, - inputValidator: linkInputValidator, - buildResult: buildResult, - resourceIdentifiers: resourceIdentifiers, - buildAssetTypes: buildAssetTypes, - linkValidator: linkValidator, - applicationAssetValidator: applicationAssetValidator, - ); - - if (linkResult != null) { - expect(await linkResult.encodedAssets.allExist(), true); + ); } + return inputBuilder; + }, + inputValidator: linkInputValidator, + buildResult: buildResult, + resourceIdentifiers: resourceIdentifiers, + buildAssetTypes: buildAssetTypes, + linkValidator: linkValidator, + applicationAssetValidator: applicationAssetValidator, + ); - return (buildResult, linkResult); - }); + if (linkResult != null) { + expect(await linkResult.encodedAssets.allExist(), true); + } + + return (buildResult, linkResult); +}); Future runWithLog( List? capturedLogs, @@ -348,8 +361,9 @@ Future runWithLog( ) async { StreamSubscription? subscription; if (capturedLogs != null) { - subscription = - logger.onRecord.listen((event) => capturedLogs.add(event.message)); + subscription = logger.onRecord.listen( + (event) => capturedLogs.add(event.message), + ); } final result = await f(); @@ -369,50 +383,47 @@ Future expectSymbols({ final assetUri = asset.file!; final nmResult = await runProcess( executable: Uri(path: 'nm'), - arguments: [ - '-D', - assetUri.toFilePath(), - ], + arguments: ['-D', assetUri.toFilePath()], logger: logger, ); - expect( - nmResult.stdout, - stringContainsInOrder(symbols), - ); + expect(nmResult.stdout, stringContainsInOrder(symbols)); } } -final CCompilerConfig? dartCICompilerConfig = (() { - // Specifically for running our tests on Dart CI with the test runner, we - // recognize specific variables to setup the C Compiler configuration. - final env = Platform.environment; - final cc = env['DART_HOOK_TESTING_C_COMPILER__CC']; - final ar = env['DART_HOOK_TESTING_C_COMPILER__AR']; - final ld = env['DART_HOOK_TESTING_C_COMPILER__LD']; - final envScript = env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT']; - final envScriptArgs = - env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT_ARGUMENTS'] - ?.split(' ') - .map((arg) => arg.trim()) - .where((arg) => arg.isNotEmpty) - .toList(); +final CCompilerConfig? dartCICompilerConfig = + (() { + // Specifically for running our tests on Dart CI with the test runner, we + // recognize specific variables to setup the C Compiler configuration. + final env = Platform.environment; + final cc = env['DART_HOOK_TESTING_C_COMPILER__CC']; + final ar = env['DART_HOOK_TESTING_C_COMPILER__AR']; + final ld = env['DART_HOOK_TESTING_C_COMPILER__LD']; + final envScript = env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT']; + final envScriptArgs = + env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT_ARGUMENTS'] + ?.split(' ') + .map((arg) => arg.trim()) + .where((arg) => arg.isNotEmpty) + .toList(); - if (cc != null && ar != null && ld != null) { - return CCompilerConfig( - archiver: Uri.file(ar), - compiler: Uri.file(cc), - linker: Uri.file(ld), - windows: WindowsCCompilerConfig( - developerCommandPrompt: envScript == null - ? null - : DeveloperCommandPrompt( - script: Uri.file(envScript), - arguments: envScriptArgs ?? [], - )), - ); - } - return null; -})(); + if (cc != null && ar != null && ld != null) { + return CCompilerConfig( + archiver: Uri.file(ar), + compiler: Uri.file(cc), + linker: Uri.file(ld), + windows: WindowsCCompilerConfig( + developerCommandPrompt: + envScript == null + ? null + : DeveloperCommandPrompt( + script: Uri.file(envScript), + arguments: envScriptArgs ?? [], + ), + ), + ); + } + return null; + })(); int defaultMacOSVersion = 13; diff --git a/pkgs/native_assets_builder/test/build_runner/link_caching_test.dart b/pkgs/native_assets_builder/test/build_runner/link_caching_test.dart index 711d49d583..0d100c6393 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_caching_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_caching_test.dart @@ -19,36 +19,35 @@ void main() async { final packageUri = tempUri.resolve('$packageName/'); // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); final logMessages = []; late BuildResult buildResult; late LinkResult linkResult; Future runBuild() async { logMessages.clear(); - buildResult = (await buildDataAssets( - packageUri, - linkingEnabled: true, - capturedLogs: logMessages, - ))!; + buildResult = + (await buildDataAssets( + packageUri, + linkingEnabled: true, + capturedLogs: logMessages, + ))!; } Future runLink() async { logMessages.clear(); - linkResult = (await link( - packageUri, - logger, - dartExecutable, - buildResult: buildResult, - buildAssetTypes: [DataAsset.type], - capturedLogs: logMessages, - inputValidator: validateDataAssetLinkInput, - linkValidator: validateDataAssetLinkOutput, - applicationAssetValidator: (_) async => [], - ))!; + linkResult = + (await link( + packageUri, + logger, + dartExecutable, + buildResult: buildResult, + buildAssetTypes: [DataAsset.type], + capturedLogs: logMessages, + inputValidator: validateDataAssetLinkInput, + linkValidator: validateDataAssetLinkOutput, + applicationAssetValidator: (_) async => [], + ))!; } await runBuild(); diff --git a/pkgs/native_assets_builder/test/build_runner/link_test.dart b/pkgs/native_assets_builder/test/build_runner/link_test.dart index 9d32f8df4a..8fe8fab81c 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_test.dart @@ -12,138 +12,121 @@ import 'helpers.dart'; const Timeout longTimeout = Timeout(Duration(minutes: 5)); void main() async { - test( - 'simple_link linking', - timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('simple_link/'); - - // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); - - final buildResult = (await buildDataAssets( - packageUri, - linkingEnabled: true, - ))!; - expect(buildResult.encodedAssets.length, 0); - - final linkResult = (await link( - packageUri, - logger, - dartExecutable, - buildResult: buildResult, - buildAssetTypes: [DataAsset.type], - inputValidator: validateDataAssetLinkInput, - linkValidator: validateDataAssetLinkOutput, - applicationAssetValidator: (_) async => [], - ))!; - expect(linkResult.encodedAssets.length, 2); - - final buildNoLinkResult = (await buildDataAssets( - packageUri, - linkingEnabled: false, - ))!; - expect(buildNoLinkResult.encodedAssets.length, 4); - }); - }, - ); - - test( - 'complex_link linking', - timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - // From package:complex_link_helper. - const builtHelperAssets = [ - 'assets/data_helper_0.json', - 'assets/data_helper_1.json', - ]; - const helperAssetsForLinking = [ - 'assets/data_helper_2.json', - 'assets/data_helper_3.json', - ]; - // From package:complex_link. - const mainAssetsForLinking = [ - 'assets/data_0.json', - 'assets/data_1.json', - ]; - final encodedAssetsForLinking = [ - ...helperAssetsForLinking, - ...mainAssetsForLinking, - ]; - final linkedAssets = encodedAssetsForLinking.skip(1); - - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('complex_link/'); - - // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet(workingDirectory: packageUri, logger: logger); - - final buildResult = await buildDataAssets( - packageUri, - linkingEnabled: true, - ); - expect(buildResult, isNotNull); - expect(_getNames(buildResult!.encodedAssets), - unorderedEquals(builtHelperAssets)); - expect( - _getNames(buildResult.encodedAssetsForLinking['complex_link']!), - unorderedEquals(encodedAssetsForLinking), - ); - - final linkResult = await link( - packageUri, - logger, - dartExecutable, - buildResult: buildResult, - buildAssetTypes: [DataAsset.type], - inputValidator: validateDataAssetLinkInput, - linkValidator: validateDataAssetLinkOutput, - applicationAssetValidator: (_) async => [], - ); - expect(linkResult, isNotNull); - - expect(_getNames(linkResult!.encodedAssets), - unorderedEquals([...builtHelperAssets, ...linkedAssets])); - }); - }, - ); + test('simple_link linking', timeout: longTimeout, () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('simple_link/'); - test('no_asset_for_link', timeout: longTimeout, () async { + // First, run `pub get`, we need pub to resolve our dependencies. + await runPubGet(workingDirectory: packageUri, logger: logger); + + final buildResult = + (await buildDataAssets(packageUri, linkingEnabled: true))!; + expect(buildResult.encodedAssets.length, 0); + + final linkResult = + (await link( + packageUri, + logger, + dartExecutable, + buildResult: buildResult, + buildAssetTypes: [DataAsset.type], + inputValidator: validateDataAssetLinkInput, + linkValidator: validateDataAssetLinkOutput, + applicationAssetValidator: (_) async => [], + ))!; + expect(linkResult.encodedAssets.length, 2); + + final buildNoLinkResult = + (await buildDataAssets(packageUri, linkingEnabled: false))!; + expect(buildNoLinkResult.encodedAssets.length, 4); + }); + }); + + test('complex_link linking', timeout: longTimeout, () async { await inTempDir((tempUri) async { + // From package:complex_link_helper. + const builtHelperAssets = [ + 'assets/data_helper_0.json', + 'assets/data_helper_1.json', + ]; + const helperAssetsForLinking = [ + 'assets/data_helper_2.json', + 'assets/data_helper_3.json', + ]; + // From package:complex_link. + const mainAssetsForLinking = ['assets/data_0.json', 'assets/data_1.json']; + final encodedAssetsForLinking = [ + ...helperAssetsForLinking, + ...mainAssetsForLinking, + ]; + final linkedAssets = encodedAssetsForLinking.skip(1); + await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('no_asset_for_link/'); + final packageUri = tempUri.resolve('complex_link/'); // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); - final buildResult = (await buildDataAssets( + final buildResult = await buildDataAssets( packageUri, linkingEnabled: true, - ))!; - expect(buildResult.encodedAssets.length, 0); - expect(buildResult.encodedAssetsForLinking.length, 0); + ); + expect(buildResult, isNotNull); + expect( + _getNames(buildResult!.encodedAssets), + unorderedEquals(builtHelperAssets), + ); + expect( + _getNames(buildResult.encodedAssetsForLinking['complex_link']!), + unorderedEquals(encodedAssetsForLinking), + ); - final logMessages = []; - final linkResult = (await link( + final linkResult = await link( packageUri, logger, dartExecutable, buildResult: buildResult, - capturedLogs: logMessages, buildAssetTypes: [DataAsset.type], inputValidator: validateDataAssetLinkInput, linkValidator: validateDataAssetLinkOutput, applicationAssetValidator: (_) async => [], - ))!; + ); + expect(linkResult, isNotNull); + + expect( + _getNames(linkResult!.encodedAssets), + unorderedEquals([...builtHelperAssets, ...linkedAssets]), + ); + }); + }); + + test('no_asset_for_link', timeout: longTimeout, () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('no_asset_for_link/'); + + // First, run `pub get`, we need pub to resolve our dependencies. + await runPubGet(workingDirectory: packageUri, logger: logger); + + final buildResult = + (await buildDataAssets(packageUri, linkingEnabled: true))!; + expect(buildResult.encodedAssets.length, 0); + expect(buildResult.encodedAssetsForLinking.length, 0); + + final logMessages = []; + final linkResult = + (await link( + packageUri, + logger, + dartExecutable, + buildResult: buildResult, + capturedLogs: logMessages, + buildAssetTypes: [DataAsset.type], + inputValidator: validateDataAssetLinkInput, + linkValidator: validateDataAssetLinkOutput, + applicationAssetValidator: (_) async => [], + ))!; expect(linkResult.encodedAssets.length, 0); expect( logMessages, @@ -160,50 +143,45 @@ void main() async { return; } - test( - 'treeshaking assets using CLinker', - timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('treeshaking_native_libs/'); - - // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); - - final buildResult = (await build( - packageUri, - logger, - dartExecutable, - linkingEnabled: true, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; - expect(buildResult.encodedAssets.length, 0); - expect(buildResult.encodedAssetsForLinking.length, 1); - - final logMessages = []; - final linkResult = (await link( - packageUri, - logger, - dartExecutable, - buildResult: buildResult, - capturedLogs: logMessages, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetLinkInput, - linkValidator: validateCodeAssetLinkOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; - expect(linkResult.encodedAssets.length, 1); - expect(linkResult.encodedAssets.first.type, CodeAsset.type); - }); - }, - ); + test('treeshaking assets using CLinker', timeout: longTimeout, () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('treeshaking_native_libs/'); + + // First, run `pub get`, we need pub to resolve our dependencies. + await runPubGet(workingDirectory: packageUri, logger: logger); + + final buildResult = + (await build( + packageUri, + logger, + dartExecutable, + linkingEnabled: true, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; + expect(buildResult.encodedAssets.length, 0); + expect(buildResult.encodedAssetsForLinking.length, 1); + + final logMessages = []; + final linkResult = + (await link( + packageUri, + logger, + dartExecutable, + buildResult: buildResult, + capturedLogs: logMessages, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetLinkInput, + linkValidator: validateCodeAssetLinkOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; + expect(linkResult.encodedAssets.length, 1); + expect(linkResult.encodedAssets.first.type, CodeAsset.type); + }); + }); } Iterable _getNames(List assets) => assets diff --git a/pkgs/native_assets_builder/test/build_runner/metadata_test.dart b/pkgs/native_assets_builder/test/build_runner/metadata_test.dart index e5a345f6b5..ae6361425b 100644 --- a/pkgs/native_assets_builder/test/build_runner/metadata_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/metadata_test.dart @@ -18,10 +18,7 @@ void main() async { final packageUri = tempUri.resolve('package_reading_metadata/'); // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); // Trigger a build, should invoke build for libraries with native assets. { @@ -37,14 +34,15 @@ void main() async { applicationAssetValidator: (_) async => [], ); expect( - logMessages.join('\n'), - stringContainsInOrder([ - 'package_with_metadata${Platform.pathSeparator}hook' - '${Platform.pathSeparator}build.dart', - 'package_reading_metadata${Platform.pathSeparator}hook' - '${Platform.pathSeparator}build.dart', - '{some_int: 3, some_key: some_value}', - ])); + logMessages.join('\n'), + stringContainsInOrder([ + 'package_with_metadata${Platform.pathSeparator}hook' + '${Platform.pathSeparator}build.dart', + 'package_reading_metadata${Platform.pathSeparator}hook' + '${Platform.pathSeparator}build.dart', + '{some_int: 3, some_key: some_value}', + ]), + ); } }); }); diff --git a/pkgs/native_assets_builder/test/build_runner/packaging_preference_test.dart b/pkgs/native_assets_builder/test/build_runner/packaging_preference_test.dart index cfeb90cf91..134479813b 100644 --- a/pkgs/native_assets_builder/test/build_runner/packaging_preference_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/packaging_preference_test.dart @@ -16,54 +16,55 @@ void main() async { final packageUri = tempUri.resolve('native_add/'); // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); - final resultDynamic = (await build( - packageUri, - logger, - dartExecutable, - linkModePreference: LinkModePreference.dynamic, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final resultDynamic = + (await build( + packageUri, + logger, + dartExecutable, + linkModePreference: LinkModePreference.dynamic, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; - final resultPreferDynamic = (await build( - packageUri, - logger, - dartExecutable, - linkModePreference: LinkModePreference.preferDynamic, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final resultPreferDynamic = + (await build( + packageUri, + logger, + dartExecutable, + linkModePreference: LinkModePreference.preferDynamic, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; - final resultStatic = (await build( - packageUri, - logger, - dartExecutable, - linkModePreference: LinkModePreference.static, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final resultStatic = + (await build( + packageUri, + logger, + dartExecutable, + linkModePreference: LinkModePreference.static, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; - final resultPreferStatic = (await build( - packageUri, - logger, - dartExecutable, - linkModePreference: LinkModePreference.preferStatic, - buildAssetTypes: [CodeAsset.type], - inputValidator: validateCodeAssetBuildInput, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final resultPreferStatic = + (await build( + packageUri, + logger, + dartExecutable, + linkModePreference: LinkModePreference.preferStatic, + buildAssetTypes: [CodeAsset.type], + inputValidator: validateCodeAssetBuildInput, + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; // This package honors preferences. expect( @@ -71,8 +72,9 @@ void main() async { DynamicLoadingBundled(), ); expect( - CodeAsset.fromEncoded(resultPreferDynamic.encodedAssets.single) - .linkMode, + CodeAsset.fromEncoded( + resultPreferDynamic.encodedAssets.single, + ).linkMode, DynamicLoadingBundled(), ); expect( diff --git a/pkgs/native_assets_builder/test/build_runner/parse_dep_file_test.dart b/pkgs/native_assets_builder/test/build_runner/parse_dep_file_test.dart index 02897123e6..f59cd8d76e 100644 --- a/pkgs/native_assets_builder/test/build_runner/parse_dep_file_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/parse_dep_file_test.dart @@ -11,10 +11,7 @@ void main() { parseDepFileInputs( r'C:\\Program\ Files\\foo.dill: C:\\Program\ Files\\foo.dart C:\\Program\ Files\\bar.dart', ), - [ - r'C:\Program Files\foo.dart', - r'C:\Program Files\bar.dart', - ], + [r'C:\Program Files\foo.dart', r'C:\Program Files\bar.dart'], ); }); } diff --git a/pkgs/native_assets_builder/test/build_runner/pub_workspace_test.dart b/pkgs/native_assets_builder/test/build_runner/pub_workspace_test.dart index 94bf0062eb..21fd4ffc75 100644 --- a/pkgs/native_assets_builder/test/build_runner/pub_workspace_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/pub_workspace_test.dart @@ -46,16 +46,14 @@ workspace: } await File.fromUri(workspacePubSpecUri).writeAsString(workspacePubSpec); - await runPubGet( - workingDirectory: tempUri, - logger: logger, - ); + await runPubGet(workingDirectory: tempUri, logger: logger); } test('pub workspaces', () async { final packageUri = tempUri.resolve('named_add_renamed/'); - await Directory.fromUri(tempUri.resolve('native_add/')) - .rename(packageUri.toFilePath()); + await Directory.fromUri( + tempUri.resolve('native_add/'), + ).rename(packageUri.toFilePath()); await makePubWorkspace([ 'dart_app', 'native_subtract', @@ -68,21 +66,19 @@ workspace: (await buildCodeAssets(packageUri, runPackageName: 'native_add'))!; final buildDirectory = tempUri.resolve('.dart_tool/native_assets_builder/'); - final buildDirs = Directory.fromUri(buildDirectory) - .listSync() - .whereType() - .map((e) => e.uri.pathSegments.lastWhere((e) => e.isNotEmpty)) - .toList() - ..sort(); + final buildDirs = + Directory.fromUri(buildDirectory) + .listSync() + .whereType() + .map((e) => e.uri.pathSegments.lastWhere((e) => e.isNotEmpty)) + .toList() + ..sort(); expect(buildDirs, contains('native_add')); // Do not build packages not in dependencies of runPackageName. expect(buildDirs, isNot(contains('native_subtract'))); final logs = []; - (await buildCodeAssets( - tempUri.resolve('dart_app/'), - capturedLogs: logs, - ))!; + (await buildCodeAssets(tempUri.resolve('dart_app/'), capturedLogs: logs))!; // Reuse hook results of other packages in the same workspace expect(logs.join('\n'), contains('Skipping build for native_add')); }); diff --git a/pkgs/native_assets_builder/test/build_runner/resources_test.dart b/pkgs/native_assets_builder/test/build_runner/resources_test.dart index 16b932e21d..2d14c4295a 100644 --- a/pkgs/native_assets_builder/test/build_runner/resources_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/resources_test.dart @@ -12,48 +12,38 @@ import 'helpers.dart'; const Timeout longTimeout = Timeout(Duration(minutes: 5)); void main() async { - test( - 'simple_link linking', - timeout: longTimeout, - () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('simple_link/'); - - final resourcesUri = tempUri.resolve('treeshaking_info.json'); - await File.fromUri(resourcesUri).create(); - - // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); - - final buildResult = (await buildDataAssets( - packageUri, - linkingEnabled: true, - ))!; - - Iterable buildFiles() => Directory.fromUri( - packageUri.resolve('.dart_tool/native_assets_builder/')) - .listSync(recursive: true) - .map((file) => file.path); - - expect(buildFiles(), isNot(anyElement(endsWith('resources.json')))); - - await link( - packageUri, - logger, - dartExecutable, - buildResult: buildResult, - resourceIdentifiers: resourcesUri, - buildAssetTypes: [DataAsset.type], - inputValidator: validateDataAssetLinkInput, - linkValidator: validateDataAssetLinkOutput, - applicationAssetValidator: (_) async => [], - ); - expect(buildFiles(), anyElement(endsWith('resources.json'))); - }); - }, - ); + test('simple_link linking', timeout: longTimeout, () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('simple_link/'); + + final resourcesUri = tempUri.resolve('treeshaking_info.json'); + await File.fromUri(resourcesUri).create(); + + // First, run `pub get`, we need pub to resolve our dependencies. + await runPubGet(workingDirectory: packageUri, logger: logger); + + final buildResult = + (await buildDataAssets(packageUri, linkingEnabled: true))!; + + Iterable buildFiles() => Directory.fromUri( + packageUri.resolve('.dart_tool/native_assets_builder/'), + ).listSync(recursive: true).map((file) => file.path); + + expect(buildFiles(), isNot(anyElement(endsWith('resources.json')))); + + await link( + packageUri, + logger, + dartExecutable, + buildResult: buildResult, + resourceIdentifiers: resourcesUri, + buildAssetTypes: [DataAsset.type], + inputValidator: validateDataAssetLinkInput, + linkValidator: validateDataAssetLinkOutput, + applicationAssetValidator: (_) async => [], + ); + expect(buildFiles(), anyElement(endsWith('resources.json'))); + }); + }); } diff --git a/pkgs/native_assets_builder/test/build_runner/system_library_test.dart b/pkgs/native_assets_builder/test/build_runner/system_library_test.dart index e962b7b94a..0c3acbb3c6 100644 --- a/pkgs/native_assets_builder/test/build_runner/system_library_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/system_library_test.dart @@ -15,22 +15,20 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('system_library/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); final logMessages = []; - final result = (await build( - packageUri, - logger, - dartExecutable, - capturedLogs: logMessages, - inputValidator: validateCodeAssetBuildInput, - buildAssetTypes: [CodeAsset.type], - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; + final result = + (await build( + packageUri, + logger, + dartExecutable, + capturedLogs: logMessages, + inputValidator: validateCodeAssetBuildInput, + buildAssetTypes: [CodeAsset.type], + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ))!; expect(result.encodedAssets.length, 3); }); }); diff --git a/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart b/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart index 1ccb56cc3a..1835390342 100644 --- a/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart @@ -10,59 +10,60 @@ import 'helpers.dart'; const Timeout longTimeout = Timeout(Duration(minutes: 5)); void main() async { - test('Test hook using an older version of native_assets_cli', - timeout: longTimeout, () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add_version_skew/'); + test( + 'Test hook using an older version of native_assets_cli', + timeout: longTimeout, + () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('native_add_version_skew/'); - // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + // First, run `pub get`, we need pub to resolve our dependencies. + await runPubGet(workingDirectory: packageUri, logger: logger); - { - final result = await build( - packageUri, - logger, - dartExecutable, - inputValidator: validateCodeAssetBuildInput, - buildAssetTypes: [CodeAsset.type], - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ); - expect(result?.encodedAssets.length, 1); - } - }); - }); + { + final result = await build( + packageUri, + logger, + dartExecutable, + inputValidator: validateCodeAssetBuildInput, + buildAssetTypes: [CodeAsset.type], + buildValidator: validateCodeAssetBuildOutput, + applicationAssetValidator: validateCodeAssetInApplication, + ); + expect(result?.encodedAssets.length, 1); + } + }); + }, + ); - test('Test hook using a too old version of native_assets_cli', - timeout: longTimeout, () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add_version_skew_2/'); + test( + 'Test hook using a too old version of native_assets_cli', + timeout: longTimeout, + () async { + await inTempDir((tempUri) async { + await copyTestProjects(targetUri: tempUri); + final packageUri = tempUri.resolve('native_add_version_skew_2/'); - // First, run `pub get`, we need pub to resolve our dependencies. - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + // First, run `pub get`, we need pub to resolve our dependencies. + await runPubGet(workingDirectory: packageUri, logger: logger); - final logMessages = []; - final result = await buildCodeAssets( - packageUri, - capturedLogs: logMessages, - ); - expect(result, isNull); - expect( + final logMessages = []; + final result = await buildCodeAssets( + packageUri, + capturedLogs: logMessages, + ); + expect(result, isNull); + expect( logMessages.join('\n'), stringContainsInOrder([ 'The protocol version of ', 'native_assets_cli', ' is 1.3.0, which is no longer supported.', - 'Please update your dependencies.' - ])); - }); - }); + 'Please update your dependencies.', + ]), + ); + }); + }, + ); } diff --git a/pkgs/native_assets_builder/test/build_runner/wrong_linker_test.dart b/pkgs/native_assets_builder/test/build_runner/wrong_linker_test.dart index 3116a59cc8..7d58b68df7 100644 --- a/pkgs/native_assets_builder/test/build_runner/wrong_linker_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/wrong_linker_test.dart @@ -16,10 +16,7 @@ void main() async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('wrong_linker/'); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); { final logMessages = []; @@ -35,10 +32,7 @@ void main() async { ); final fullLog = logMessages.join('\n'); expect(result, isNull); - expect( - fullLog, - contains('but that package does not have a link hook'), - ); + expect(fullLog, contains('but that package does not have a link hook')); } }); }); 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 b97dc1d912..23186f4de3 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 @@ -18,12 +18,7 @@ void main() async { test('json format', () async { await inTempDir((tempUri) async { final hashes = FileSystemHashes( - files: [ - FilesystemEntityHash( - tempUri.resolve('foo.dll'), - 1337, - ), - ], + files: [FilesystemEntityHash(tempUri.resolve('foo.dll'), 1337)], ); final hashes2 = FileSystemHashes.fromJson(hashes.toJson()); expect(hashes.files.single.path, equals(hashes2.files.single.path)); @@ -48,10 +43,7 @@ void main() async { await subFile.writeAsString('world'); await hashes.hashDependencies( - [ - tempFile.uri, - tempSubDir.uri, - ], + [tempFile.uri, tempSubDir.uri], (await tempFile.lastModified()).add(const Duration(minutes: 1)), environment, ); @@ -122,9 +114,7 @@ void main() async { // If a file is modified after the valid timestamp, it should be marked // as changed. await hashes.hashDependencies( - [ - tempFile.uri, - ], + [tempFile.uri], (await tempFile.lastModified()).subtract(const Duration(seconds: 1)), environment, ); diff --git a/pkgs/native_assets_builder/test/helpers.dart b/pkgs/native_assets_builder/test/helpers.dart index 6170f3e6a0..652bbd28ff 100644 --- a/pkgs/native_assets_builder/test/helpers.dart +++ b/pkgs/native_assets_builder/test/helpers.dart @@ -99,18 +99,17 @@ Future runProcess({ bool captureOutput = true, int expectedExitCode = 0, bool throwOnUnexpectedExitCode = false, -}) => - run_process.runProcess( - filesystem: const LocalFileSystem(), - executable: executable, - arguments: arguments, - workingDirectory: workingDirectory, - environment: environment, - logger: logger, - captureOutput: captureOutput, - expectedExitCode: expectedExitCode, - throwOnUnexpectedExitCode: throwOnUnexpectedExitCode, - ); +}) => run_process.runProcess( + filesystem: const LocalFileSystem(), + executable: executable, + arguments: arguments, + workingDirectory: workingDirectory, + environment: environment, + logger: logger, + captureOutput: captureOutput, + expectedExitCode: expectedExitCode, + throwOnUnexpectedExitCode: throwOnUnexpectedExitCode, +); /// Test files are run in a variety of ways, find this package root in all. /// @@ -143,10 +142,12 @@ Uri findPackageRoot(String packageName) { return cwd; } } - throw StateError("Could not find package root for package '$packageName'. " - 'Tried finding the package root via Platform.script ' - "'${Platform.script.toFilePath()}' and Directory.current " - "'${Directory.current.uri.toFilePath()}'."); + throw StateError( + "Could not find package root for package '$packageName'. " + 'Tried finding the package root via Platform.script ' + "'${Platform.script.toFilePath()}' and Directory.current " + "'${Directory.current.uri.toFilePath()}'.", + ); } final pkgNativeAssetsBuilderUri = findPackageRoot('native_assets_builder'); @@ -174,9 +175,9 @@ final Uri? _ld = /// Path to script that sets environment variables for [_cc], [_ld], and [_ar]. /// /// Provided on Dart CI. -final Uri? _envScript = Platform - .environment['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT'] - ?.asFileUri(); +final Uri? _envScript = + Platform.environment['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT'] + ?.asFileUri(); /// Arguments for [_envScript] provided by environment. /// @@ -188,21 +189,23 @@ final List? _envScriptArgs = Platform /// Configuration for the native toolchain. /// /// Provided on Dart CI. -final cCompiler = (_cc == null || _ar == null || _ld == null) - ? null - : CCompilerConfig( - compiler: _cc!, - archiver: _ar!, - linker: _ld!, - windows: _envScript == null - ? null - : WindowsCCompilerConfig( - developerCommandPrompt: DeveloperCommandPrompt( - script: _envScript!, - arguments: _envScriptArgs ?? [], - ), - ), - ); +final cCompiler = + (_cc == null || _ar == null || _ld == null) + ? null + : CCompilerConfig( + compiler: _cc!, + archiver: _ar!, + linker: _ld!, + windows: + _envScript == null + ? null + : WindowsCCompilerConfig( + developerCommandPrompt: DeveloperCommandPrompt( + script: _envScript!, + arguments: _envScriptArgs ?? [], + ), + ), + ); extension on String { Uri asFileUri() => Uri.file(this); @@ -229,10 +232,7 @@ extension AssetIterable on Iterable { } } -Future copyTestProjects({ - Uri? sourceUri, - required Uri targetUri, -}) async { +Future copyTestProjects({Uri? sourceUri, required Uri targetUri}) async { sourceUri ??= testDataUri; final manifestUri = sourceUri.resolve('manifest.yaml'); final manifestFile = File.fromUri(manifestUri); @@ -240,17 +240,24 @@ Future copyTestProjects({ final manifestYaml = loadYamlDocument(manifestString); final manifest = [ for (final path in manifestYaml.contents as List) - Uri(path: path as String) + Uri(path: path as String), ]; - final filesToCopy = manifest - .where((e) => !(e.pathSegments.last.startsWith('pubspec') && - e.pathSegments.last.endsWith('.yaml'))) - .toList(); - final filesToModify = manifest - .where((e) => - e.pathSegments.last.startsWith('pubspec') && - e.pathSegments.last.endsWith('.yaml')) - .toList(); + final filesToCopy = + manifest + .where( + (e) => + !(e.pathSegments.last.startsWith('pubspec') && + e.pathSegments.last.endsWith('.yaml')), + ) + .toList(); + final filesToModify = + manifest + .where( + (e) => + e.pathSegments.last.startsWith('pubspec') && + e.pathSegments.last.endsWith('.yaml'), + ) + .toList(); for (final pathToCopy in filesToCopy) { final sourceFile = File.fromUri(sourceUri.resolveUri(pathToCopy)); @@ -275,8 +282,9 @@ Future copyTestProjects({ 'path: ../../', 'path: ${pkgNativeAssetsBuilderUri.toFilePath().unescape()}', ); - await File.fromUri(targetFileUri) - .writeAsString(modifiedString, flush: true); + await File.fromUri( + targetFileUri, + ).writeAsString(modifiedString, flush: true); } } @@ -287,7 +295,8 @@ extension UnescapePath on String { } /// Logger that outputs the full trace when a test fails. -Logger get logger => _logger ??= () { +Logger get logger => + _logger ??= () { // A new logger is lazily created for each test so that the messages // captured by printOnFailure are scoped to the correct test. addTearDown(() => _logger = null); @@ -299,8 +308,7 @@ Logger? _logger; Logger createCapturingLogger( List capturedMessages, { Level level = Level.ALL, -}) => - _createTestLogger(capturedMessages: capturedMessages, level: level); +}) => _createTestLogger(capturedMessages: capturedMessages, level: level); Logger _createTestLogger({ List? capturedMessages, diff --git a/pkgs/native_assets_builder/test/locking/locking_test.dart b/pkgs/native_assets_builder/test/locking/locking_test.dart index ecf89d5e39..983a3b156d 100644 --- a/pkgs/native_assets_builder/test/locking/locking_test.dart +++ b/pkgs/native_assets_builder/test/locking/locking_test.dart @@ -19,26 +19,19 @@ void main() async { test('Concurrent invocations', timeout: longTimeout, () async { await inTempDir((tempUri) async { Future runInProcess() async { - final result = await Process.run( - dartExecutable.toFilePath(), - [ - packageUri - .resolve('test/locking/locking_test_helper.dart') - .toFilePath(), - tempUri.toFilePath(), - ], - ); + final result = await Process.run(dartExecutable.toFilePath(), [ + packageUri + .resolve('test/locking/locking_test_helper.dart') + .toFilePath(), + tempUri.toFilePath(), + ]); printOnFailure(result.stderr.toString()); printOnFailure(result.stdout.toString()); expect(result.exitCode, 0); return result; } - await Future.wait([ - runInProcess(), - runInProcess(), - runInProcess(), - ]); + await Future.wait([runInProcess(), runInProcess(), runInProcess()]); }); }); @@ -49,10 +42,7 @@ void main() async { if (lockFileContents.isNotEmpty) { // The process might have been killed in between creating the lock // file and writing to it. - expect( - lockFileContents, - stringContainsInOrder(['Last acquired by']), - ); + expect(lockFileContents, stringContainsInOrder(['Last acquired by'])); } return lockFile; } @@ -61,18 +51,13 @@ void main() async { test('Terminations unlock', timeout: longTimeout, () async { await inTempDir((tempUri) async { - Future runProcess({ - Duration? killAfter, - }) async { - final process = await Process.start( - dartExecutable.toFilePath(), - [ - packageUri - .resolve('test/locking/locking_test_helper.dart') - .toFilePath(), - tempUri.toFilePath(), - ], - ); + Future runProcess({Duration? killAfter}) async { + final process = await Process.start(dartExecutable.toFilePath(), [ + packageUri + .resolve('test/locking/locking_test_helper.dart') + .toFilePath(), + tempUri.toFilePath(), + ]); final stdoutSub = process.stdout .transform(utf8.decoder) .transform(const LineSplitter()) @@ -89,11 +74,12 @@ void main() async { process.kill(); }); } - final (exitCode, _, _) = await ( - process.exitCode, - stdoutSub.asFuture(), - stderrSub.asFuture() - ).wait; + final (exitCode, _, _) = + await ( + process.exitCode, + stdoutSub.asFuture(), + stderrSub.asFuture(), + ).wait; if (timer != null) { timer.cancel(); } @@ -123,16 +109,13 @@ void main() async { Duration? timeout, bool expectTimeOut = false, }) async { - final process = await Process.start( - dartExecutable.toFilePath(), - [ - packageUri - .resolve('test/locking/locking_test_helper.dart') - .toFilePath(), - tempUri.toFilePath(), - if (timeout != null) timeout.inMilliseconds.toString(), - ], - ); + final process = await Process.start(dartExecutable.toFilePath(), [ + packageUri + .resolve('test/locking/locking_test_helper.dart') + .toFilePath(), + tempUri.toFilePath(), + if (timeout != null) timeout.inMilliseconds.toString(), + ]); final stdoutSub = process.stdout .transform(utf8.decoder) @@ -143,11 +126,12 @@ void main() async { .transform(const LineSplitter()) .listen(logger.severe); - final (exitCode, _, _) = await ( - process.exitCode, - stdoutSub.asFuture(), - stderrSub.asFuture() - ).wait; + final (exitCode, _, _) = + await ( + process.exitCode, + stdoutSub.asFuture(), + stderrSub.asFuture(), + ).wait; if (expectTimeOut) { expect(exitCode, isNot(0)); @@ -189,17 +173,16 @@ void main() async { } await lock.unlock(); }); - await runProcess( - timeout: helperProcessTimeout, - expectTimeOut: true, - ).then((v) async { - printOnFailure('${DateTime.now()}: Helper exited.'); - if (!timeoutCompletedFirst) { - printOnFailure('${DateTime.now()}: timeoutCompletedFirst'); - helperCompletedFirst = true; - } - timer.cancel(); - }); + await runProcess(timeout: helperProcessTimeout, expectTimeOut: true).then( + (v) async { + printOnFailure('${DateTime.now()}: Helper exited.'); + if (!timeoutCompletedFirst) { + printOnFailure('${DateTime.now()}: timeoutCompletedFirst'); + helperCompletedFirst = true; + } + timer.cancel(); + }, + ); expect(helperCompletedFirst, isTrue); expect(timeoutCompletedFirst, isFalse); }); diff --git a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_helper.dart b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_helper.dart index 54262de66d..f0b65845b2 100644 --- a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_helper.dart +++ b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_helper.dart @@ -9,7 +9,9 @@ void main(List arguments) { final a = int.parse(arguments[1]); final b = int.parse(arguments[2]); final addLibrary = DynamicLibrary.open(addLibraryPath); - final add = addLibrary.lookupFunction('add'); + final add = addLibrary + .lookupFunction( + 'add', + ); print('Result: ${add(a, b)}'); } diff --git a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart index 6af3d1763e..45873a8d3f 100644 --- a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart +++ b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart @@ -2,10 +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. -@OnPlatform({ - 'mac-os': Timeout.factor(2), - 'windows': Timeout.factor(10), -}) +@OnPlatform({'mac-os': Timeout.factor(2), 'windows': Timeout.factor(10)}) library; import 'dart:convert'; @@ -32,38 +29,37 @@ void main() async { final dartUri = Uri.file(Platform.resolvedExecutable); final targetOS = OS.current; - final inputBuilder = BuildInputBuilder() - ..setupShared( - packageName: name, - packageRoot: testPackageUri, - outputFile: buildOutputUri, - outputDirectory: outputDirectory, - outputDirectoryShared: outputDirectoryShared, - ) - ..config.setupBuild(dryRun: false, linkingEnabled: false) - ..config.setupShared(buildAssetTypes: [CodeAsset.type]) - ..config.setupCode( - targetArchitecture: Architecture.current, - targetOS: targetOS, - macOS: targetOS == OS.macOS - ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) - : null, - linkModePreference: LinkModePreference.dynamic, - cCompiler: cCompiler, - ); + final inputBuilder = + BuildInputBuilder() + ..setupShared( + packageName: name, + packageRoot: testPackageUri, + outputFile: buildOutputUri, + outputDirectory: outputDirectory, + outputDirectoryShared: outputDirectoryShared, + ) + ..config.setupBuild(dryRun: false, linkingEnabled: false) + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( + targetArchitecture: Architecture.current, + targetOS: targetOS, + macOS: + targetOS == OS.macOS + ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) + : null, + linkModePreference: LinkModePreference.dynamic, + cCompiler: cCompiler, + ); final buildInputUri = testTempUri.resolve('build_input.json'); - File.fromUri(buildInputUri) - .writeAsStringSync(jsonEncode(inputBuilder.json)); + File.fromUri( + buildInputUri, + ).writeAsStringSync(jsonEncode(inputBuilder.json)); - final processResult = await Process.run( - dartUri.toFilePath(), - [ - 'hook/build.dart', - '--config=${buildInputUri.toFilePath()}', - ], - workingDirectory: testPackageUri.toFilePath(), - ); + final processResult = await Process.run(dartUri.toFilePath(), [ + 'hook/build.dart', + '--config=${buildInputUri.toFilePath()}', + ], workingDirectory: testPackageUri.toFilePath()); if (processResult.exitCode != 0) { print(processResult.stdout); print(processResult.stderr); @@ -72,28 +68,27 @@ void main() async { expect(processResult.exitCode, 0); final buildOutput = BuildOutput( - json.decode(await File.fromUri(buildOutputUri).readAsString()) - as Map); + json.decode(await File.fromUri(buildOutputUri).readAsString()) + as Map, + ); final assets = buildOutput.assets.encodedAssets; final dependencies = buildOutput.dependencies; expect(assets.length, 3); expect(await assets.allExist(), true); - expect( - dependencies, - [ - testPackageUri.resolve('src/debug.c'), - testPackageUri.resolve('src/math.c'), - testPackageUri.resolve('src/add.c'), - ], - ); + expect(dependencies, [ + testPackageUri.resolve('src/debug.c'), + testPackageUri.resolve('src/math.c'), + testPackageUri.resolve('src/add.c'), + ]); - final addLibraryPath = assets - .where((e) => e.type == CodeAsset.type) - .map(CodeAsset.fromEncoded) - .firstWhere((asset) => asset.id.endsWith('add.dart')) - .file! - .toFilePath(); + final addLibraryPath = + assets + .where((e) => e.type == CodeAsset.type) + .map(CodeAsset.fromEncoded) + .firstWhere((asset) => asset.id.endsWith('add.dart')) + .file! + .toFilePath(); final addResult = await runProcess( executable: dartExecutable, arguments: [ @@ -112,7 +107,8 @@ void main() async { // skip this if Dart would implicitly add dylib containing // directories to the PATH. if (Platform.isWindows) - 'PATH': '${outputDirectory.toFilePath()};' + 'PATH': + '${outputDirectory.toFilePath()};' '${Platform.environment['PATH']}', }, throwOnUnexpectedExitCode: true, @@ -120,10 +116,7 @@ void main() async { ); expect( addResult.stdout, - allOf( - contains('Adding 1 and 2.'), - contains('Result: 3'), - ), + allOf(contains('Adding 1 and 2.'), contains('Result: 3')), ); }), ); diff --git a/pkgs/native_assets_builder/test/test_data/transformer_test.dart b/pkgs/native_assets_builder/test/test_data/transformer_test.dart index ebcefee292..63bd7b61f2 100644 --- a/pkgs/native_assets_builder/test/test_data/transformer_test.dart +++ b/pkgs/native_assets_builder/test/test_data/transformer_test.dart @@ -2,10 +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. -@OnPlatform({ - 'mac-os': Timeout.factor(2), - 'windows': Timeout.factor(10), -}) +@OnPlatform({'mac-os': Timeout.factor(2), 'windows': Timeout.factor(10)}) library; import 'dart:convert'; @@ -28,10 +25,7 @@ void main() async { targetUri: packageUri, ); - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); + await runPubGet(workingDirectory: packageUri, logger: logger); final buildOutputUri = tempUri.resolve('build_output.json'); final outputDirectory = tempUri.resolve('out/'); @@ -47,40 +41,38 @@ void main() async { final targetOS = OS.current; Future runBuild(Architecture architecture) async { - final inputBuilder = BuildInputBuilder() - ..setupShared( - packageName: packageName, - packageRoot: packageUri, - outputFile: buildOutputUri, - outputDirectory: outputDirectory, - outputDirectoryShared: outputDirectoryShared, - ) - ..config.setupBuild(dryRun: false, linkingEnabled: false) - ..config.setupShared(buildAssetTypes: [ - CodeAsset.type, - DataAsset.type, - ]) - ..config.setupCode( - targetArchitecture: architecture, - targetOS: targetOS, - macOS: targetOS == OS.macOS - ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) - : null, - linkModePreference: LinkModePreference.dynamic, - ); + final inputBuilder = + BuildInputBuilder() + ..setupShared( + packageName: packageName, + packageRoot: packageUri, + outputFile: buildOutputUri, + outputDirectory: outputDirectory, + outputDirectoryShared: outputDirectoryShared, + ) + ..config.setupBuild(dryRun: false, linkingEnabled: false) + ..config.setupShared( + buildAssetTypes: [CodeAsset.type, DataAsset.type], + ) + ..config.setupCode( + targetArchitecture: architecture, + targetOS: targetOS, + macOS: + targetOS == OS.macOS + ? MacOSCodeConfig(targetVersion: defaultMacOSVersion) + : null, + linkModePreference: LinkModePreference.dynamic, + ); final buildInputUri = testTempUri.resolve('build_input.json'); - File.fromUri(buildInputUri) - .writeAsStringSync(jsonEncode(inputBuilder.json)); - - final processResult = await Process.run( - dartUri.toFilePath(), - [ - 'hook/build.dart', - '--config=${buildInputUri.toFilePath()}', - ], - workingDirectory: packageUri.toFilePath(), - ); + File.fromUri( + buildInputUri, + ).writeAsStringSync(jsonEncode(inputBuilder.json)); + + final processResult = await Process.run(dartUri.toFilePath(), [ + 'hook/build.dart', + '--config=${buildInputUri.toFilePath()}', + ], workingDirectory: packageUri.toFilePath()); if (processResult.exitCode != 0) { print(processResult.stdout); print(processResult.stderr); @@ -90,8 +82,9 @@ void main() async { stdout = processResult.stdout as String; output = BuildOutput( - json.decode(await File.fromUri(buildOutputUri).readAsString()) - as Map); + json.decode(await File.fromUri(buildOutputUri).readAsString()) + as Map, + ); } await runBuild(Architecture.x64); @@ -120,9 +113,9 @@ void main() async { ]), ); - await File.fromUri(packageUri.resolve('data/data0.json')).writeAsString( - jsonEncode({'foo': 'bar'}), - ); + await File.fromUri( + packageUri.resolve('data/data0.json'), + ).writeAsString(jsonEncode({'foo': 'bar'})); // Run the build for a different architecture. // This should use the caching inside the hook. diff --git a/pkgs/native_assets_builder/test_data/complex_link/hook/build.dart b/pkgs/native_assets_builder/test_data/complex_link/hook/build.dart index 9ed8be59ac..6bfff46ac1 100644 --- a/pkgs/native_assets_builder/test_data/complex_link/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/complex_link/hook/build.dart @@ -9,8 +9,9 @@ import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { await build(args, (input, output) async { final packageName = input.packageName; - final assetDirectory = - Directory.fromUri(input.packageRoot.resolve('assets/')); + final assetDirectory = Directory.fromUri( + input.packageRoot.resolve('assets/'), + ); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -25,11 +26,7 @@ void main(List args) async { .substring(input.packageRoot.toFilePath(windows: false).length); output.assets.data.add( - DataAsset( - package: packageName, - name: name, - file: dataAsset.uri, - ), + DataAsset(package: packageName, name: name, file: dataAsset.uri), linkInPackage: input.config.linkingEnabled ? packageName : null, ); // TODO(https://github.com/dart-lang/native/issues/1208): Report diff --git a/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml index 640ce76f08..998ba3edf5 100644 --- a/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: cli_config: ^0.2.0 diff --git a/pkgs/native_assets_builder/test_data/complex_link_helper/hook/build.dart b/pkgs/native_assets_builder/test_data/complex_link_helper/hook/build.dart index 2d4368b94f..033d9329e8 100644 --- a/pkgs/native_assets_builder/test_data/complex_link_helper/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/complex_link_helper/hook/build.dart @@ -9,8 +9,9 @@ import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { await build(args, (input, output) async { final packageName = input.packageName; - final assetDirectory = - Directory.fromUri(input.packageRoot.resolve('assets/')); + final assetDirectory = Directory.fromUri( + input.packageRoot.resolve('assets/'), + ); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -26,11 +27,7 @@ void main(List args) async { final forLinking = name.contains('2') || name.contains('3'); output.assets.data.add( - DataAsset( - package: packageName, - name: name, - file: dataAsset.uri, - ), + DataAsset(package: packageName, name: name, file: dataAsset.uri), linkInPackage: forLinking && input.config.linkingEnabled ? 'complex_link' : null, ); diff --git a/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml b/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml index 3b21271746..eab36c75a9 100644 --- a/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: cli_config: ^0.2.0 diff --git a/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml b/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml index 7424fa2a9c..a7856f6a38 100644 --- a/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.6.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: cyclic_package_2: diff --git a/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml b/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml index 4cf117372d..60bee379ec 100644 --- a/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.6.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: cyclic_package_1: diff --git a/pkgs/native_assets_builder/test_data/dart_app/pubspec.yaml b/pkgs/native_assets_builder/test_data/dart_app/pubspec.yaml index 9177503c51..1953613964 100644 --- a/pkgs/native_assets_builder/test_data/dart_app/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/dart_app/pubspec.yaml @@ -3,7 +3,7 @@ name: dart_app publish_to: none environment: - sdk: '>=3.6.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: native_add: diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml b/pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml index bfa9c72fda..5d4f2dbed6 100644 --- a/pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: fail_build: diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml b/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml index f7b6bb876c..39a94cc5a1 100644 --- a/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build_app/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: depend_on_fail_build: diff --git a/pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml index 3e0256b277..4f5a628615 100644 --- a/pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/fail_build/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml index d5d2d831d3..468ca3d131 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml index 087759e5a8..f4f77bc773 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: fail_on_os_sdk_version_linker: diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml index ab72b71eac..546802240a 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/manifest_generator.dart b/pkgs/native_assets_builder/test_data/manifest_generator.dart index f2cc186332..f628d76aee 100644 --- a/pkgs/native_assets_builder/test_data/manifest_generator.dart +++ b/pkgs/native_assets_builder/test_data/manifest_generator.dart @@ -35,20 +35,21 @@ void updateManifest(Directory directory, bool allowPartialProjects) { } final all = directory.listSync(recursive: true); final dirPath = directory.uri.toFilePath(); - final files = all - .whereType() - .where((f) { - for (final denyString in [ - ...denyList, - if (!allowPartialProjects) ...partialProjects, - ]) { - if (f.path.contains(denyString)) return false; - } - return true; - }) - .map((e) => e.path.replaceFirst(dirPath, '')) - .toList() - ..sort(); + final files = + all + .whereType() + .where((f) { + for (final denyString in [ + ...denyList, + if (!allowPartialProjects) ...partialProjects, + ]) { + if (f.path.contains(denyString)) return false; + } + return true; + }) + .map((e) => e.path.replaceFirst(dirPath, '')) + .toList() + ..sort(); manifestFile.writeAsStringSync(header + files.map((e) => '- $e\n').join()); } diff --git a/pkgs/native_assets_builder/test_data/native_add/hook/build.dart b/pkgs/native_assets_builder/test_data/native_add/hook/build.dart index 179b649f36..ec8bc6fe6d 100644 --- a/pkgs/native_assets_builder/test_data/native_add/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_add/hook/build.dart @@ -14,18 +14,17 @@ void main(List arguments) async { final cbuilder = CBuilder.library( name: packageName, assetName: 'src/${packageName}_bindings_generated.dart', - sources: [ - 'src/$packageName.c', - ], + sources: ['src/$packageName.c'], ); await cbuilder.run( input: input, output: output, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), ); stdout.writeln('Some stdout.'); stderr.writeln('Some stderr.'); diff --git a/pkgs/native_assets_builder/test_data/native_add/lib/src/native_add_bindings_generated.dart b/pkgs/native_assets_builder/test_data/native_add/lib/src/native_add_bindings_generated.dart index 4d1e803aa4..14bbeb6e99 100644 --- a/pkgs/native_assets_builder/test_data/native_add/lib/src/native_add_bindings_generated.dart +++ b/pkgs/native_assets_builder/test_data/native_add/lib/src/native_add_bindings_generated.dart @@ -9,7 +9,4 @@ import 'dart:ffi' as ffi; @ffi.Native(symbol: 'add') -external int add( - int a, - int b, -); +external int add(int a, int b); diff --git a/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml index 7e87ee6189..a4230e7047 100644 --- a/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.6.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart b/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart index d3a10056ca..6a78b874da 100644 --- a/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart @@ -12,19 +12,17 @@ void main(List arguments) async { final cbuilder = CBuilder.library( name: packageName, assetName: '${packageName}_bindings_generated.dart', - sources: [ - 'src/$packageName.c', - 'src/native_multiply.c', - ], + sources: ['src/$packageName.c', 'src/native_multiply.c'], ); await cbuilder.run( input: input, output: output, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), ); }); } diff --git a/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml index 7e87ee6189..a4230e7047 100644 --- a/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.6.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/build.dart b/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/build.dart index a903eb19aa..509fbbaed1 100644 --- a/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/build.dart @@ -14,20 +14,19 @@ void main(List arguments) async { final cbuilder = CBuilder.library( name: duplicatedPackageName, assetName: 'src/${packageName}_bindings_generated.dart', - sources: [ - 'src/$duplicatedPackageName.c', - ], + sources: ['src/$duplicatedPackageName.c'], ); // Temp output to prevent outputting the dylib for bundling. final outputBuilder = BuildOutputBuilder(); await cbuilder.run( input: input, output: outputBuilder, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), ); final tempBuildOutput = BuildOutput(outputBuilder.json); output.assets.code.add( @@ -35,8 +34,6 @@ void main(List arguments) async { // Send dylib to linking if linking is enabled. linkInPackage: input.config.linkingEnabled ? packageName : null, ); - output.addDependencies( - tempBuildOutput.dependencies, - ); + output.addDependencies(tempBuildOutput.dependencies); }); } diff --git a/pkgs/native_assets_builder/test_data/native_add_duplicate/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_add_duplicate/pubspec.yaml index 7714cb99cc..0cff1eedd4 100644 --- a/pkgs/native_assets_builder/test_data/native_add_duplicate/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_add_duplicate/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/native_add_version_skew/hook/build.dart b/pkgs/native_assets_builder/test_data/native_add_version_skew/hook/build.dart index 89f512fdfd..f27417eb1c 100644 --- a/pkgs/native_assets_builder/test_data/native_add_version_skew/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_add_version_skew/hook/build.dart @@ -12,18 +12,17 @@ void main(List arguments) async { final cbuilder = CBuilder.library( name: packageName, assetName: 'src/native_add_bindings_generated.dart', - sources: [ - 'src/native_add.c', - ], + sources: ['src/native_add.c'], ); await cbuilder.run( config: config, output: output, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), ); }); } diff --git a/pkgs/native_assets_builder/test_data/native_add_version_skew/lib/src/native_add_bindings_generated.dart b/pkgs/native_assets_builder/test_data/native_add_version_skew/lib/src/native_add_bindings_generated.dart index 68f7e2c4f8..5b7ead5930 100644 --- a/pkgs/native_assets_builder/test_data/native_add_version_skew/lib/src/native_add_bindings_generated.dart +++ b/pkgs/native_assets_builder/test_data/native_add_version_skew/lib/src/native_add_bindings_generated.dart @@ -9,7 +9,4 @@ import 'dart:ffi' as ffi; @ffi.Native(symbol: 'add') -external int add( - int a, - int b, -); +external int add(int a, int b); diff --git a/pkgs/native_assets_builder/test_data/native_add_version_skew/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_add_version_skew/pubspec.yaml index db4c69a77a..b427ebd7b8 100644 --- a/pkgs/native_assets_builder/test_data/native_add_version_skew/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_add_version_skew/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/native_add_version_skew_2/hook/build.dart b/pkgs/native_assets_builder/test_data/native_add_version_skew_2/hook/build.dart index a521272a97..7b550dcd7d 100644 --- a/pkgs/native_assets_builder/test_data/native_add_version_skew_2/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_add_version_skew_2/hook/build.dart @@ -12,19 +12,18 @@ void main(List arguments) async { final cbuilder = CBuilder.library( name: packageName, assetName: 'src/native_add_bindings_generated.dart', - sources: [ - 'src/native_add.c', - ], + sources: ['src/native_add.c'], dartBuildFiles: [], ); await cbuilder.run( config: config, output: output, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), ); }); } diff --git a/pkgs/native_assets_builder/test_data/native_add_version_skew_2/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_add_version_skew_2/pubspec.yaml index 41dcb16dc1..6388af2b91 100644 --- a/pkgs/native_assets_builder/test_data/native_add_version_skew_2/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_add_version_skew_2/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/native_dynamic_linking/hook/build.dart b/pkgs/native_assets_builder/test_data/native_dynamic_linking/hook/build.dart index 1dc4aa6a02..6749b8480e 100644 --- a/pkgs/native_assets_builder/test_data/native_dynamic_linking/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_dynamic_linking/hook/build.dart @@ -8,47 +8,38 @@ import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List args) async { await build(args, (input, output) async { - final logger = Logger('') - ..level = Level.ALL - ..onRecord.listen((record) => print(record.message)); + final logger = + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) => print(record.message)); final builders = [ CBuilder.library( name: 'debug', assetName: 'debug', - sources: [ - 'src/debug.c', - ], + sources: ['src/debug.c'], buildMode: BuildMode.debug, ), CBuilder.library( name: 'math', assetName: 'math', - sources: [ - 'src/math.c', - ], + sources: ['src/math.c'], libraries: ['debug'], buildMode: BuildMode.debug, ), CBuilder.library( name: 'add', assetName: 'add.dart', - sources: [ - 'src/add.c', - ], + sources: ['src/add.c'], libraries: ['math'], buildMode: BuildMode.debug, - ) + ), ]; // Note: These builders need to be run sequentially because they depend on // each others output. for (final builder in builders) { - await builder.run( - input: input, - output: output, - logger: logger, - ); + await builder.run(input: input, output: output, logger: logger); } }); } diff --git a/pkgs/native_assets_builder/test_data/native_dynamic_linking/lib/add.dart b/pkgs/native_assets_builder/test_data/native_dynamic_linking/lib/add.dart index 68f7e2c4f8..5b7ead5930 100644 --- a/pkgs/native_assets_builder/test_data/native_dynamic_linking/lib/add.dart +++ b/pkgs/native_assets_builder/test_data/native_dynamic_linking/lib/add.dart @@ -9,7 +9,4 @@ import 'dart:ffi' as ffi; @ffi.Native(symbol: 'add') -external int add( - int a, - int b, -); +external int add(int a, int b); diff --git a/pkgs/native_assets_builder/test_data/native_dynamic_linking/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_dynamic_linking/pubspec.yaml index aa9de56871..6457568ab1 100644 --- a/pkgs/native_assets_builder/test_data/native_dynamic_linking/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_dynamic_linking/pubspec.yaml @@ -6,7 +6,7 @@ version: 0.1.0 repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli/example/build/native_dynamic_linking environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart b/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart index bdeb571bf9..907a0fcd82 100644 --- a/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart @@ -12,18 +12,17 @@ void main(List arguments) async { final cbuilder = CBuilder.library( name: packageName, assetName: 'src/${packageName}_bindings_generated.dart', - sources: [ - 'src/$packageName.c', - ], + sources: ['src/$packageName.c'], ); await cbuilder.run( input: input, output: output, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), ); }); } diff --git a/pkgs/native_assets_builder/test_data/native_subtract/lib/src/native_subtract_bindings_generated.dart b/pkgs/native_assets_builder/test_data/native_subtract/lib/src/native_subtract_bindings_generated.dart index 1a952fec52..696fe2a7b1 100644 --- a/pkgs/native_assets_builder/test_data/native_subtract/lib/src/native_subtract_bindings_generated.dart +++ b/pkgs/native_assets_builder/test_data/native_subtract/lib/src/native_subtract_bindings_generated.dart @@ -9,7 +9,4 @@ import 'dart:ffi' as ffi; @ffi.Native(symbol: 'subtract') -external int subtract( - int a, - int b, -); +external int subtract(int a, int b); diff --git a/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml index af5d533027..484b773deb 100644 --- a/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.6.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/no_hook/pubspec.yaml b/pkgs/native_assets_builder/test_data/no_hook/pubspec.yaml index 29a4a91d90..45b6a39a53 100644 --- a/pkgs/native_assets_builder/test_data/no_hook/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/no_hook/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.6.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart b/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart index aa0c5f15d5..9a4c8d7c33 100644 --- a/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart @@ -12,9 +12,6 @@ void main(List args) async { assert(someValue != null); final someInt = input.metadatum('package_with_metadata', 'some_int'); assert(someInt != null); - print({ - 'some_int': someInt, - 'some_key': someValue, - }); + print({'some_int': someInt, 'some_key': someValue}); }); } diff --git a/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml b/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml index 6b430e6daa..a91c79738b 100644 --- a/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/package_with_metadata/hook/build.dart b/pkgs/native_assets_builder/test_data/package_with_metadata/hook/build.dart index 12b1c996ec..f933efab6a 100644 --- a/pkgs/native_assets_builder/test_data/package_with_metadata/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/package_with_metadata/hook/build.dart @@ -7,9 +7,6 @@ import 'package:native_assets_cli/native_assets_cli.dart'; void main(List arguments) async { await build(arguments, (input, output) async { // ignore: deprecated_member_use - output.addMetadata({ - 'some_key': 'some_value', - 'some_int': 3, - }); + output.addMetadata({'some_key': 'some_value', 'some_int': 3}); }); } diff --git a/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml b/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml index 6fa2b5e7ec..de087f4012 100644 --- a/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/relative_path/hook/build.dart b/pkgs/native_assets_builder/test_data/relative_path/hook/build.dart index db71d38084..e8305b421e 100644 --- a/pkgs/native_assets_builder/test_data/relative_path/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/relative_path/hook/build.dart @@ -7,18 +7,15 @@ import 'dart:io'; import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { - await build( - args, - (input, output) async { - if (input.config.buildAssetTypes.contains(DataAsset.type)) { - output.assets.data.add( - DataAsset( - package: input.packageName, - name: 'assets/test_asset.txt', - file: File('assets/test_asset.txt').uri, - ), - ); - } - }, - ); + await build(args, (input, output) async { + if (input.config.buildAssetTypes.contains(DataAsset.type)) { + output.assets.data.add( + DataAsset( + package: input.packageName, + name: 'assets/test_asset.txt', + file: File('assets/test_asset.txt').uri, + ), + ); + } + }); } diff --git a/pkgs/native_assets_builder/test_data/relative_path/pubspec.yaml b/pkgs/native_assets_builder/test_data/relative_path/pubspec.yaml index 38a82b82bb..bbbee0b3aa 100644 --- a/pkgs/native_assets_builder/test_data/relative_path/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/relative_path/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: ^3.0.0 + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/simple_data_asset/hook/build.dart b/pkgs/native_assets_builder/test_data/simple_data_asset/hook/build.dart index 03f47d10f1..99b90d9203 100644 --- a/pkgs/native_assets_builder/test_data/simple_data_asset/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/simple_data_asset/hook/build.dart @@ -6,35 +6,29 @@ import 'dart:io'; import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { - await build( - args, - (input, output) async { - final assetDirectory = - Directory.fromUri(input.packageRoot.resolve('assets/')); - // If assets are added, rerun hook. - output.addDependency(assetDirectory.uri); + await build(args, (input, output) async { + final assetDirectory = Directory.fromUri( + input.packageRoot.resolve('assets/'), + ); + // If assets are added, rerun hook. + output.addDependency(assetDirectory.uri); - await for (final dataAsset in assetDirectory.list()) { - if (dataAsset is! File) { - continue; - } + await for (final dataAsset in assetDirectory.list()) { + if (dataAsset is! File) { + continue; + } - // The file path relative to the package root, with forward slashes. - final name = dataAsset.uri - .toFilePath(windows: false) - .substring(input.packageRoot.toFilePath(windows: false).length); + // The file path relative to the package root, with forward slashes. + final name = dataAsset.uri + .toFilePath(windows: false) + .substring(input.packageRoot.toFilePath(windows: false).length); - output.assets.data.add( - DataAsset( - package: input.packageName, - name: name, - file: dataAsset.uri, - ), - ); - // TODO(https://github.com/dart-lang/native/issues/1208): Report - // dependency on asset. - output.addDependency(dataAsset.uri); - } - }, - ); + output.assets.data.add( + DataAsset(package: input.packageName, name: name, file: dataAsset.uri), + ); + // TODO(https://github.com/dart-lang/native/issues/1208): Report + // dependency on asset. + output.addDependency(dataAsset.uri); + } + }); } diff --git a/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml b/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml index 6fa76399b7..3e3eed3130 100644 --- a/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml @@ -5,7 +5,7 @@ version: 1.0.0 publish_to: none environment: - sdk: ^3.0.0 + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/simple_link/hook/build.dart b/pkgs/native_assets_builder/test_data/simple_link/hook/build.dart index 9ed8be59ac..6bfff46ac1 100644 --- a/pkgs/native_assets_builder/test_data/simple_link/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/simple_link/hook/build.dart @@ -9,8 +9,9 @@ import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { await build(args, (input, output) async { final packageName = input.packageName; - final assetDirectory = - Directory.fromUri(input.packageRoot.resolve('assets/')); + final assetDirectory = Directory.fromUri( + input.packageRoot.resolve('assets/'), + ); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -25,11 +26,7 @@ void main(List args) async { .substring(input.packageRoot.toFilePath(windows: false).length); output.assets.data.add( - DataAsset( - package: packageName, - name: name, - file: dataAsset.uri, - ), + DataAsset(package: packageName, name: name, file: dataAsset.uri), linkInPackage: input.config.linkingEnabled ? packageName : null, ); // TODO(https://github.com/dart-lang/native/issues/1208): Report diff --git a/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml index 7b21340b17..3bd95d7181 100644 --- a/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: cli_config: ^0.2.0 diff --git a/pkgs/native_assets_builder/test_data/some_dev_dep/pubspec.yaml b/pkgs/native_assets_builder/test_data/some_dev_dep/pubspec.yaml index f3fe7dc849..8cc6efed59 100644 --- a/pkgs/native_assets_builder/test_data/some_dev_dep/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/some_dev_dep/pubspec.yaml @@ -5,4 +5,4 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' diff --git a/pkgs/native_assets_builder/test_data/system_library/hook/build.dart b/pkgs/native_assets_builder/test_data/system_library/hook/build.dart index eeeb406fb7..56d727e7f9 100644 --- a/pkgs/native_assets_builder/test_data/system_library/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/system_library/hook/build.dart @@ -13,17 +13,14 @@ void main(List arguments) async { package: input.packageName, name: 'memory_system.dart', linkMode: DynamicLoadingSystem( - Uri.file( - switch (targetOS) { - OS.android => 'libc.so.6', - OS.iOS => 'libc.dylib', - OS.linux => 'libc.so.6', - OS.macOS => 'libc.dylib', - OS.windows => 'ole32.dll', - _ => - throw UnsupportedError('Unknown operating system: $targetOS'), - }, - ), + Uri.file(switch (targetOS) { + OS.android => 'libc.so.6', + OS.iOS => 'libc.dylib', + OS.linux => 'libc.so.6', + OS.macOS => 'libc.dylib', + OS.windows => 'ole32.dll', + _ => throw UnsupportedError('Unknown operating system: $targetOS'), + }), ), os: targetOS, architecture: targetArchitecture, diff --git a/pkgs/native_assets_builder/test_data/system_library/pubspec.yaml b/pkgs/native_assets_builder/test_data/system_library/pubspec.yaml index 0bd4cf1d29..71f90b2d6f 100644 --- a/pkgs/native_assets_builder/test_data/system_library/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/system_library/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/transformer/hook/build.dart b/pkgs/native_assets_builder/test_data/transformer/hook/build.dart index 8932270ca2..03fb7cee42 100644 --- a/pkgs/native_assets_builder/test_data/transformer/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/transformer/hook/build.dart @@ -18,12 +18,14 @@ void main(List arguments) async { var transformedFiles = 0; var cachedFiles = 0; - final hashesFile = - File.fromUri(input.outputDirectoryShared.resolve('hashes.json')); - final hashes = await hashesFile.exists() - ? (json.decoder.convert(await hashesFile.readAsString()) as Map) - .cast() - : {}; + final hashesFile = File.fromUri( + input.outputDirectoryShared.resolve('hashes.json'), + ); + final hashes = + await hashesFile.exists() + ? (json.decoder.convert(await hashesFile.readAsString()) as Map) + .cast() + : {}; final newHashes = {}; await for (final sourceFile in dataDirectory.list()) { @@ -31,16 +33,20 @@ void main(List arguments) async { continue; } - final sourceName = - sourceFile.uri.pathSegments.lastWhere((e) => e.isNotEmpty); + final sourceName = sourceFile.uri.pathSegments.lastWhere( + (e) => e.isNotEmpty, + ); final sourceContents = await sourceFile.readAsString(); final sourceHash = md5.convert(sourceContents.codeUnits).toString(); newHashes[sourceName] = sourceHash; final prevHash = hashes[sourceName]; final name = sourceName.replaceFirst('data', 'data_transformed'); - final targetFile = File.fromUri(input.outputDirectoryShared - .resolve(sourceName.replaceFirst('data', 'data_transformed'))); + final targetFile = File.fromUri( + input.outputDirectoryShared.resolve( + sourceName.replaceFirst('data', 'data_transformed'), + ), + ); if (!await targetFile.exists() || sourceHash != prevHash) { await transformFile(sourceFile, targetFile); @@ -50,15 +56,9 @@ void main(List arguments) async { } output.assets.data.add( - DataAsset( - package: input.packageName, - name: name, - file: targetFile.uri, - ), - ); - output.addDependency( - sourceFile.uri, + DataAsset(package: input.packageName, name: name, file: targetFile.uri), ); + output.addDependency(sourceFile.uri); } await hashesFile.writeAsString(json.encoder.convert(newHashes)); diff --git a/pkgs/native_assets_builder/test_data/transformer/pubspec.yaml b/pkgs/native_assets_builder/test_data/transformer/pubspec.yaml index 552c4ababc..2c68b83ef3 100644 --- a/pkgs/native_assets_builder/test_data/transformer/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/transformer/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: crypto: ^3.0.6 diff --git a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/build.dart b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/build.dart index e049a1399e..b28738411d 100644 --- a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/build.dart @@ -11,23 +11,22 @@ void main(List arguments) async { final cbuilder = CBuilder.library( name: input.packageName + (input.config.linkingEnabled ? '_static' : ''), assetName: 'src/${input.packageName}_bindings_generated.dart', - sources: [ - 'src/native_add.c', - 'src/native_multiply.c', - ], - linkModePreference: input.config.linkingEnabled - ? LinkModePreference.static - : LinkModePreference.dynamic, + sources: ['src/native_add.c', 'src/native_multiply.c'], + linkModePreference: + input.config.linkingEnabled + ? LinkModePreference.static + : LinkModePreference.dynamic, ); await cbuilder.run( input: input, output: output, linkInPackage: input.config.linkingEnabled ? input.packageName : null, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), ); }); } diff --git a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/link.dart b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/link.dart index 18384eda21..8d5fbec9ae 100644 --- a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/hook/link.dart @@ -7,24 +7,22 @@ import 'package:native_assets_cli/code_assets.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await link( - arguments, - (input, output) async { - final linker = CLinker.library( - name: input.packageName, - assetName: input.assets.code.single.id.split('/').skip(1).join('/'), - linkerOptions: LinkerOptions.treeshake(symbols: ['add']), - sources: [input.assets.code.single.file!.toFilePath()], - ); - await linker.run( - input: input, - output: output, - logger: Logger('') - ..level = Level.ALL - ..onRecord.listen((record) { - print('${record.level.name}: ${record.time}: ${record.message}'); - }), - ); - }, - ); + await link(arguments, (input, output) async { + final linker = CLinker.library( + name: input.packageName, + assetName: input.assets.code.single.id.split('/').skip(1).join('/'), + linkerOptions: LinkerOptions.treeshake(symbols: ['add']), + sources: [input.assets.code.single.file!.toFilePath()], + ); + await linker.run( + input: input, + output: output, + logger: + Logger('') + ..level = Level.ALL + ..onRecord.listen((record) { + print('${record.level.name}: ${record.time}: ${record.message}'); + }), + ); + }); } diff --git a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/lib/src/treeshaking_native_libs_bindings_generated.dart b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/lib/src/treeshaking_native_libs_bindings_generated.dart index a1e22c95c9..0d30e3c152 100644 --- a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/lib/src/treeshaking_native_libs_bindings_generated.dart +++ b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/lib/src/treeshaking_native_libs_bindings_generated.dart @@ -9,13 +9,7 @@ import 'dart:ffi' as ffi; @ffi.Native(symbol: 'add') -external int add( - int a, - int b, -); +external int add(int a, int b); @ffi.Native(symbol: 'multiply') -external int multiply( - int a, - int b, -); +external int multiply(int a, int b); diff --git a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/pubspec.yaml b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/pubspec.yaml index c6d619b49a..e4e7c422fa 100644 --- a/pkgs/native_assets_builder/test_data/treeshaking_native_libs/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/treeshaking_native_libs/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: logging: ^1.1.1 diff --git a/pkgs/native_assets_builder/test_data/use_all_api/hook/build.dart b/pkgs/native_assets_builder/test_data/use_all_api/hook/build.dart index 880b7a18db..8bc1d3dcc9 100644 --- a/pkgs/native_assets_builder/test_data/use_all_api/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/use_all_api/hook/build.dart @@ -33,14 +33,16 @@ void main(List args) async { input.config.code.cCompiler?.compiler; input.config.code.cCompiler?.linker; - output.assets.code.add(CodeAsset( - package: 'package', - name: 'name', - linkMode: DynamicLoadingBundled(), - os: input.config.code.targetOS, - architecture: input.config.code.targetArchitecture, - file: input.outputDirectory.resolve('foo'), - )); + output.assets.code.add( + CodeAsset( + package: 'package', + name: 'name', + linkMode: DynamicLoadingBundled(), + os: input.config.code.targetOS, + architecture: input.config.code.targetArchitecture, + file: input.outputDirectory.resolve('foo'), + ), + ); output.assets.data.add( DataAsset( file: input.outputDirectory.resolve('foo'), diff --git a/pkgs/native_assets_builder/test_data/use_all_api/pubspec.yaml b/pkgs/native_assets_builder/test_data/use_all_api/pubspec.yaml index f4be40edbc..97dcbc028e 100644 --- a/pkgs/native_assets_builder/test_data/use_all_api/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/use_all_api/pubspec.yaml @@ -6,7 +6,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: cli_config: ^0.2.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output/hook/build.dart b/pkgs/native_assets_builder/test_data/wrong_build_output/hook/build.dart index 07b16aa5c8..199f761b8f 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/wrong_build_output/hook/build.dart @@ -11,7 +11,8 @@ import 'package:native_assets_cli/src/args_parser.dart'; void main(List args) async { final inputPath = getInputArgument(args); final buildInput = BuildInput( - json.decode(File(inputPath).readAsStringSync()) as Map); + json.decode(File(inputPath).readAsStringSync()) as Map, + ); await File.fromUri(buildInput.outputFile).writeAsString(_wrongContents); } diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml index 6380806f5e..b08596f3cf 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output_2/hook/build.dart b/pkgs/native_assets_builder/test_data/wrong_build_output_2/hook/build.dart index d6796c5622..12d829e38e 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output_2/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/wrong_build_output_2/hook/build.dart @@ -11,7 +11,8 @@ import 'package:native_assets_cli/src/args_parser.dart'; void main(List args) async { final inputPath = getInputArgument(args); final buildInput = BuildInput( - json.decode(File(inputPath).readAsStringSync()) as Map); + json.decode(File(inputPath).readAsStringSync()) as Map, + ); await File.fromUri(buildInput.outputFile).writeAsString(_wrongContents); } diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml index d96e22882a..598fab8b8d 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output_3/hook/build.dart b/pkgs/native_assets_builder/test_data/wrong_build_output_3/hook/build.dart index 08fa134800..c31882fdc3 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output_3/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/wrong_build_output_3/hook/build.dart @@ -11,7 +11,8 @@ import 'package:native_assets_cli/src/args_parser.dart'; void main(List args) async { final inputPath = getInputArgument(args); final buildInput = BuildInput( - json.decode(File(inputPath).readAsStringSync()) as Map); + json.decode(File(inputPath).readAsStringSync()) as Map, + ); await File.fromUri(buildInput.outputFile).writeAsString(_rightContents); exit(1); } diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml index 9d4a747dd9..e3f88be588 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_linker/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_linker/pubspec.yaml index 40f601f901..cfdb46d2e1 100644 --- a/pkgs/native_assets_builder/test_data/wrong_linker/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_linker/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml index 4617b8d452..e69a383cbd 100644 --- a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 publish_to: none environment: - sdk: '>=3.3.0 <4.0.0' + sdk: '>=3.7.0 <4.0.0' dependencies: # native_assets_cli: ^0.11.0