diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index 786424849..a0c5ece28 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -1,6 +1,6 @@ -## 0.10.3-wip +## 0.11.0-wip -- Nothing yet. +- Bump `package:native_assets_cli` to 0.11.0. ## 0.10.2 diff --git a/pkgs/native_assets_builder/lib/native_assets_builder.dart b/pkgs/native_assets_builder/lib/native_assets_builder.dart index 651ab73a9..f56216ddc 100644 --- a/pkgs/native_assets_builder/lib/native_assets_builder.dart +++ b/pkgs/native_assets_builder/lib/native_assets_builder.dart @@ -5,11 +5,11 @@ export 'package:native_assets_builder/src/build_runner/build_runner.dart' show ApplicationAssetValidator, - BuildConfigCreator, - BuildConfigValidator, + BuildInputCreator, + BuildInputValidator, BuildValidator, - LinkConfigCreator, - LinkConfigValidator, + LinkInputCreator, + LinkInputValidator, LinkValidator, NativeAssetsBuildRunner; export 'package:native_assets_builder/src/model/build_result.dart'; diff --git a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart index b0d708c52..0287cc3da 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 @@ -22,32 +22,31 @@ import 'build_planner.dart'; typedef DependencyMetadata = Map; -typedef ConfigCreator = HookConfigBuilder Function(); +typedef InputCreator = HookInputBuilder Function(); -typedef BuildConfigCreator = BuildConfigBuilder Function(); +typedef BuildInputCreator = BuildInputBuilder Function(); -typedef LinkConfigCreator = LinkConfigBuilder Function(); +typedef LinkInputCreator = LinkInputBuilder Function(); typedef _HookValidator = Future Function( - HookConfig config, HookOutput output); + HookInput input, HookOutput output); -// A callback that validates the invariants of the [BuildConfig]. -typedef BuildConfigValidator = Future Function( - BuildConfig config); +// A callback that validates the invariants of the [BuildInput]. +typedef BuildInputValidator = Future Function( + BuildInput input); -// A callback that validates the invariants of the [LinkConfig]. -typedef LinkConfigValidator = Future Function( - LinkConfig config); +// 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( - BuildConfig config, BuildOutput outup); + 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( - LinkConfig config, LinkOutput output); + 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 @@ -61,7 +60,7 @@ typedef ApplicationAssetValidator = Future Function( /// and flutter_tools (for `flutter run` and `flutter build`). /// /// The native assets build runner does not support reentrancy for identical -/// [BuildConfig] and [LinkConfig]! For more info see: +/// [BuildInput] and [LinkInput]! For more info see: /// https://github.com/dart-lang/native/issues/1319 class NativeAssetsBuildRunner { final FileSystem _fileSystem; @@ -93,11 +92,11 @@ class NativeAssetsBuildRunner { /// performed without linking (i.e. [linkingEnabled] is `false`). /// /// The native assets build runner does not support reentrancy for identical - /// [BuildConfig] and [LinkConfig]! For more info see: + /// [BuildInput] and [LinkInput]! For more info see: /// https://github.com/dart-lang/native/issues/1319 Future build({ - required BuildConfigCreator configCreator, - required BuildConfigValidator configValidator, + required BuildInputCreator inputCreator, + required BuildInputValidator inputValidator, required BuildValidator buildValidator, required ApplicationAssetValidator applicationAssetValidator, required Uri workingDirectory, @@ -127,34 +126,34 @@ class NativeAssetsBuildRunner { targetMetadata: globalMetadata, )?.forEach((key, value) => metadata[key] = value); - final configBuilder = configCreator() - ..setupHookConfig( - buildAssetTypes: buildAssetTypes, - packageName: package.name, - packageRoot: packageLayout.packageRoot(package.name), - ) - ..setupBuildConfig( + final inputBuilder = inputCreator() + ..config.setupShared(buildAssetTypes: buildAssetTypes) + ..config.setupBuild( dryRun: false, linkingEnabled: linkingEnabled, + ) + ..setupBuildInput( metadata: metadata, ); final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories( Hook.build, packageLayout, - configBuilder, + inputBuilder, package, ); - configBuilder.setupBuildRunConfig( + inputBuilder.setupShared( + packageName: package.name, + packageRoot: packageLayout.packageRoot(package.name), outputDirectory: outDirUri, outputDirectoryShared: outDirSharedUri, ); - final config = BuildConfig(configBuilder.json); + final input = BuildInput(inputBuilder.json); final errors = [ - ...await validateBuildConfig(config), - ...await configValidator(config), + ...await validateBuildInput(input), + ...await inputValidator(input), ]; if (errors.isNotEmpty) { return _printErrors( @@ -163,9 +162,9 @@ class NativeAssetsBuildRunner { final result = await _runHookForPackageCached( Hook.build, - config, - (config, output) => - buildValidator(config as BuildConfig, output as BuildOutput), + input, + (input, output) => + buildValidator(input as BuildInput, output as BuildOutput), packageLayout.packageConfigUri, workingDirectory, null, @@ -198,11 +197,11 @@ class NativeAssetsBuildRunner { /// [runPackageName] are linked. /// /// The native assets build runner does not support reentrancy for identical - /// [BuildConfig] and [LinkConfig]! For more info see: + /// [BuildInput] and [LinkInput]! For more info see: /// https://github.com/dart-lang/native/issues/1319 Future link({ - required LinkConfigCreator configCreator, - required LinkConfigValidator configValidator, + required LinkInputCreator inputCreator, + required LinkInputValidator inputValidator, required LinkValidator linkValidator, required Uri workingDirectory, required ApplicationAssetValidator applicationAssetValidator, @@ -225,18 +224,14 @@ class NativeAssetsBuildRunner { var hookResult = HookResult(encodedAssets: buildResult.encodedAssets); for (final package in buildPlan) { - final configBuilder = configCreator() - ..setupHookConfig( - buildAssetTypes: buildAssetTypes, - packageName: package.name, - packageRoot: packageLayout.packageRoot(package.name), - ); + final inputBuilder = inputCreator() + ..config.setupShared(buildAssetTypes: buildAssetTypes); final (buildDirUri, outDirUri, outDirSharedUri) = await _setupDirectories( - Hook.link, packageLayout, configBuilder, package); - - configBuilder.setupLinkConfig( - assets: buildResult.encodedAssetsForLinking[package.name] ?? [], + Hook.link, + packageLayout, + inputBuilder, + package, ); File? resourcesFile; @@ -245,16 +240,22 @@ class NativeAssetsBuildRunner { await resourcesFile.create(); await _fileSystem.file(resourceIdentifiers).copy(resourcesFile.path); } - configBuilder.setupLinkRunConfig( + + inputBuilder.setupShared( + packageName: package.name, + packageRoot: packageLayout.packageRoot(package.name), outputDirectory: outDirUri, outputDirectoryShared: outDirSharedUri, + ); + inputBuilder.setupLink( + assets: buildResult.encodedAssetsForLinking[package.name] ?? [], recordedUsesFile: resourcesFile?.uri, ); - final config = LinkConfig(configBuilder.json); + final input = LinkInput(inputBuilder.json); final errors = [ - ...await validateLinkConfig(config), - ...await configValidator(config), + ...await validateLinkInput(input), + ...await inputValidator(input), ]; if (errors.isNotEmpty) { return _printErrors( @@ -263,9 +264,9 @@ class NativeAssetsBuildRunner { final result = await _runHookForPackageCached( Hook.link, - config, - (config, output) => - linkValidator(config as LinkConfig, output as LinkOutput), + input, + (input, output) => + linkValidator(input as LinkInput, output as LinkOutput), packageLayout.packageConfigUri, workingDirectory, resourceIdentifiers, @@ -293,13 +294,15 @@ class NativeAssetsBuildRunner { } Future<(Uri, Uri, Uri)> _setupDirectories( - Hook hook, - PackageLayout packageLayout, - HookConfigBuilder configBuilder, - Package package) async { - final buildDirName = configBuilder.computeChecksum(); - final buildDirUri = - packageLayout.dartToolNativeAssetsBuilder.resolve('$buildDirName/'); + Hook hook, + PackageLayout packageLayout, + HookInputBuilder inputBuilder, + Package package, + ) async { + final buildDirName = inputBuilder.computeChecksum(); + final packageName = package.name; + final buildDirUri = packageLayout.dartToolNativeAssetsBuilder + .resolve('$packageName/$buildDirName/'); final outDirUri = buildDirUri.resolve('out/'); final outDir = _fileSystem.directory(outDirUri); if (!await outDir.exists()) { @@ -318,27 +321,27 @@ class NativeAssetsBuildRunner { Future<(HookOutput, List)?> _runHookForPackageCached( Hook hook, - HookConfig config, + HookInput input, _HookValidator validator, Uri packageConfigUri, Uri workingDirectory, Uri? resources, PackageLayout packageLayout, ) async { - final outDir = config.outputDirectory; + final outDir = input.outputDirectory; return await runUnderDirectoriesLock( _fileSystem, [ - _fileSystem.directory(config.outputDirectoryShared).parent.uri, - _fileSystem.directory(config.outputDirectory).parent.uri, + _fileSystem.directory(input.outputDirectoryShared).parent.uri, + _fileSystem.directory(input.outputDirectory).parent.uri, ], timeout: singleHookTimeout, logger: logger, () async { final hookCompileResult = await _compileHookForPackageCached( - config.packageName, - config.outputDirectory, - config.packageRoot.resolve('hook/${hook.scriptName}'), + input.packageName, + input.outputDirectory, + input.packageRoot.resolve('hook/${hook.scriptName}'), packageConfigUri, workingDirectory, ); @@ -348,8 +351,8 @@ class NativeAssetsBuildRunner { final (hookKernelFile, hookHashes) = hookCompileResult; final buildOutputFile = - _fileSystem.file(config.outputDirectory.resolve(hook.outputName)); - final dependenciesHashFile = config.outputDirectory + _fileSystem.file(input.outputDirectory.resolve(hook.outputName)); + final dependenciesHashFile = input.outputDirectory .resolve('../dependencies.dependencies_hash_file.json'); final dependenciesHashes = DependenciesHashFile(_fileSystem, fileUri: dependenciesHashFile); @@ -360,7 +363,7 @@ class NativeAssetsBuildRunner { output = _readHookOutputFromUri(hook, buildOutputFile); } on FormatException catch (e) { logger.severe(''' -Building assets for package:${config.packageName} failed. +Building assets for package:${input.packageName} failed. ${hook.outputName} contained a format error. Contents: ${buildOutputFile.readAsStringSync()}. @@ -373,23 +376,23 @@ ${e.message} await dependenciesHashes.findOutdatedDependency(hookEnvironment); if (outdatedDependency == null) { logger.info( - 'Skipping ${hook.name} for ${config.packageName}' + 'Skipping ${hook.name} for ${input.packageName}' ' in ${outDir.toFilePath()}.' ' Last build on ${output.timestamp}.', ); // All build flags go into [outDir]. Therefore we do not have to - // check here whether the config is equal. + // check here whether the input is equal. return (output, hookHashes.fileSystemEntities); } logger.info( - 'Rerunning ${hook.name} for ${config.packageName}' + 'Rerunning ${hook.name} for ${input.packageName}' ' in ${outDir.toFilePath()}. $outdatedDependency', ); } final result = await _runHookForPackage( hook, - config, + input, validator, packageConfigUri, workingDirectory, @@ -441,7 +444,7 @@ ${e.message} Future _runHookForPackage( Hook hook, - HookConfig config, + HookInput input, _HookValidator validator, Uri packageConfigUri, Uri workingDirectory, @@ -450,12 +453,12 @@ ${e.message} PackageLayout packageLayout, Map environment, ) async { - final configFile = config.outputDirectory.resolve('../config.json'); - final configFileContents = - const JsonEncoder.withIndent(' ').convert(config.json); - logger.info('config.json contents: $configFileContents'); - await _fileSystem.file(configFile).writeAsString(configFileContents); - final hookOutputUri = config.outputDirectory.resolve(hook.outputName); + final inputFile = input.outputDirectory.resolve('../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.outputDirectory.resolve(hook.outputName); final hookOutputFile = _fileSystem.file(hookOutputUri); if (await hookOutputFile.exists()) { // Ensure we'll never read outdated build results. @@ -465,7 +468,7 @@ ${e.message} final arguments = [ '--packages=${packageConfigUri.toFilePath()}', hookKernelFile.path, - '--config=${configFile.toFilePath()}', + '--config=${inputFile.toFilePath()}', if (resources != null) resources.toFilePath(), ]; final result = await runProcess( @@ -491,7 +494,7 @@ ${e.message} ].join(' '); logger.severe( ''' - Building assets for package:${config.packageName} failed. + Building assets for package:${input.packageName} failed. ${hook.scriptName} returned with exit code: ${result.exitCode}. To reproduce run: $commandString @@ -506,10 +509,10 @@ ${e.message} } final output = _readHookOutputFromUri(hook, hookOutputFile); - final errors = await _validate(config, output, packageLayout, validator); + final errors = await _validate(input, output, packageLayout, validator); if (errors.isNotEmpty) { _printErrors( - '$hook hook of package:${config.packageName} has invalid output', + '$hook hook of package:${input.packageName} has invalid output', errors); deleteOutputIfExists = true; return null; @@ -517,7 +520,7 @@ ${e.message} return output; } on FormatException catch (e) { logger.severe(''' -Building assets for package:${config.packageName} failed. +Building assets for package:${input.packageName} failed. ${hook.outputName} contained a format error. Contents: ${hookOutputFile.readAsStringSync()}. @@ -546,12 +549,12 @@ ${e.message} /// one time too many, then not recompiling when recompilation should have /// happened. /// - /// It does not reuse the cached kernel for different configs due to + /// It does not reuse the cached kernel for different inputs due to /// reentrancy requirements. For more info see: /// https://github.com/dart-lang/native/issues/1319 /// /// TODO(https://github.com/dart-lang/native/issues/1578): Compile only once - /// instead of per config. This requires more locking. + /// instead of per input. This requires more locking. Future<(File kernelFile, DependenciesHashFile cacheFile)?> _compileHookForPackageCached( String packageName, @@ -693,24 +696,25 @@ ${compileResult.stdout} } Future _validate( - HookConfig config, + HookInput input, HookOutput output, PackageLayout packageLayout, _HookValidator validator, ) async { - final errors = config is BuildConfig - ? await validateBuildOutput(config, output as BuildOutput) - : await validateLinkOutput(config as LinkConfig, output as LinkOutput); - errors.addAll(await validator(config, output)); + 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 (config is BuildConfig) { + if (input is BuildInput) { final packagesWithLink = (await packageLayout.packagesWithAssets(Hook.link)) .map((p) => p.name); for (final targetPackage - in (output as BuildOutput).encodedAssetsForLinking.keys) { + in (output as BuildOutput).assets.encodedAssetsForLinking.keys) { if (!packagesWithLink.contains(targetPackage)) { - for (final asset in output.encodedAssetsForLinking[targetPackage]!) { + for (final asset + in output.assets.encodedAssetsForLinking[targetPackage]!) { errors.add( 'Asset "$asset" is sent to package "$targetPackage" for' ' linking, but that package does not have a link hook.', 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 5a157f1a4..9a7eeaf0a 100644 --- a/pkgs/native_assets_builder/lib/src/model/hook_result.dart +++ b/pkgs/native_assets_builder/lib/src/model/hook_result.dart @@ -43,15 +43,15 @@ final class HookResult implements BuildResult, LinkResult { final mergedMaps = mergeMaps( encodedAssetsForLinking, hookOutput is BuildOutput - ? hookOutput.encodedAssetsForLinking + ? hookOutput.assets.encodedAssetsForLinking : >{}, value: (encodedAssets1, encodedAssets2) => [ ...encodedAssets1, ...encodedAssets2, ]); final hookOutputAssets = (hookOutput is BuildOutput) - ? hookOutput.encodedAssets - : (hookOutput as LinkOutput).encodedAssets; + ? hookOutput.assets.encodedAssets + : (hookOutput as LinkOutput).assets.encodedAssets; return HookResult( encodedAssets: [ ...encodedAssets, diff --git a/pkgs/native_assets_builder/pubspec.yaml b/pkgs/native_assets_builder/pubspec.yaml index e496e8443..cce634a1b 100644 --- a/pkgs/native_assets_builder/pubspec.yaml +++ b/pkgs/native_assets_builder/pubspec.yaml @@ -1,7 +1,7 @@ name: native_assets_builder description: >- This package is the backend that invokes build hooks. -version: 0.10.3-wip +version: 0.11.0-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder publish_to: none 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 a9cce0ba3..9deecda9f 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 @@ -32,7 +32,7 @@ void main() async { dartExecutable, capturedLogs: logMessages, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; 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 1563350df..b0ef95df2 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 @@ -28,7 +28,7 @@ void main() async { createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ); @@ -64,7 +64,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ); 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 65f766341..2b4e4fb92 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 @@ -34,8 +34,8 @@ void main() async { createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, buildAssetTypes: [], - configValidator: (config) async => [], - buildValidator: (config, output) async => [], + inputValidator: (input) async => [], + buildValidator: (input, output) async => [], applicationAssetValidator: validateCodeAssetInApplication, ); final fullLog = logMessages.join('\n'); 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 de8241f6d..b7131c7bb 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 @@ -32,7 +32,7 @@ void main() async { dartExecutable, capturedLogs: logMessages, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -59,7 +59,7 @@ void main() async { dartExecutable, capturedLogs: logMessages, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -109,7 +109,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -130,7 +130,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -173,7 +173,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -201,7 +201,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -242,7 +242,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, hookEnvironment: modifiedEnvKey == 'PATH' @@ -278,7 +278,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; 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 7e3f3a75c..c54967b39 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 @@ -28,8 +28,8 @@ void main() async { createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, buildAssetTypes: [], - configValidator: (config) async => [], - buildValidator: (config, output) async => [], + inputValidator: (input) async => [], + buildValidator: (input, output) async => [], applicationAssetValidator: (_) async => [], ); final fullLog = logMessages.join('\n'); 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 26059a5a1..3ea4db663 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 @@ -29,7 +29,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -57,7 +57,7 @@ void main() async { createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ); @@ -85,7 +85,7 @@ void main() async { logger, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -121,7 +121,7 @@ void main() async { capturedLogs: logMessages, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ); 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 29381b67c..00189fc2f 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 @@ -31,7 +31,7 @@ void main() async { capturedLogs: logMessages, runPackageName: 'some_dev_dep', buildAssetTypes: [CodeAsset.type], - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -48,7 +48,7 @@ void main() async { capturedLogs: logMessages, runPackageName: 'native_add', buildAssetTypes: [CodeAsset.type], - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; 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 0920edf04..810a27f26 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 @@ -31,32 +31,32 @@ void main() async { final targetOS = OS.current; const defaultMacOSVersion = 13; - BuildConfigBuilder configCreator() => BuildConfigBuilder() - ..setupCodeConfig( + BuildInputBuilder inputCreator() => BuildInputBuilder() + ..config.setupCode( targetArchitecture: Architecture.current, targetOS: OS.current, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, linkModePreference: LinkModePreference.dynamic, ); await buildRunner.build( - configCreator: configCreator, + inputCreator: inputCreator, workingDirectory: packageUri, linkingEnabled: false, buildAssetTypes: [], - configValidator: (config) async => [], - buildValidator: (config, output) async => [], + inputValidator: (input) async => [], + buildValidator: (input, output) async => [], applicationAssetValidator: (_) async => [], ); await buildRunner.build( - configCreator: configCreator, + inputCreator: inputCreator, workingDirectory: packageUri, linkingEnabled: false, buildAssetTypes: [], - configValidator: (config) async => [], - buildValidator: (config, output) async => [], + inputValidator: (input) async => [], + buildValidator: (input, output) async => [], applicationAssetValidator: (_) async => [], ); }); 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 451353811..a9df15982 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 @@ -33,7 +33,7 @@ void main() async { logger, dartExecutable, capturedLogs: logMessages, - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildAssetTypes: [CodeAsset.type], buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, @@ -62,7 +62,7 @@ void main() async { capturedLogs: logMessages, packageLayout: packageLayout, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; 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 5b872ca26..9b1707d64 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 @@ -23,24 +23,32 @@ void main(List args) async { dartExecutable: dartExecutable, fileSystem: const LocalFileSystem(), ).build( - // Set up the code config, so that the builds for different targets are + // Set up the code input, so that the builds for different targets are // in different directories. - configCreator: () => BuildConfigBuilder() - ..setupCodeConfig( + inputCreator: () => BuildInputBuilder() + ..config.setupCode( targetArchitecture: target.architecture, targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, + android: + targetOS == OS.android ? AndroidConfig(targetNdkApi: 30) : null, linkModePreference: LinkModePreference.dynamic, ), + workingDirectory: packageUri, linkingEnabled: false, - buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetBuildConfig, - buildValidator: (config, output) async => - await validateDataAssetBuildOutput(config, output), - applicationAssetValidator: (_) async => [], + 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), + ], + applicationAssetValidator: validateCodeAssetInApplication, ); if (result == null) { throw Error(); 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 78ac04ffd..80d0243b1 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_test.dart @@ -52,9 +52,9 @@ void main() async { }); }); - File? findLockFile(Uri packageUri) { + File? findLockFile(Uri packageUri, String packageName) { final dir = Directory.fromUri( - packageUri.resolve('.dart_tool/native_assets_builder/')); + packageUri.resolve('.dart_tool/native_assets_builder/$packageName/')); if (!dir.existsSync()) { // Too quick, dir doesn't exist yet. return null; @@ -80,7 +80,8 @@ void main() async { test('Terminations unlock', timeout: longTimeout, () async { await inTempDir((tempUri) async { await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add/'); + const packageName = 'native_add'; + final packageUri = tempUri.resolve('$packageName/'); await runPubGet( workingDirectory: packageUri, @@ -126,14 +127,14 @@ void main() async { // Simulate hitting ctrl+c on `dart` and `flutter` commands at different // time intervals. var milliseconds = 200; - while (findLockFile(packageUri) == null) { + while (findLockFile(packageUri, packageName) == null) { final result = await runBuildInProcess( killAfter: Duration(milliseconds: milliseconds), ); expect(result, isNot(0)); milliseconds = max((milliseconds * 1.2).round(), milliseconds + 200); } - expect(findLockFile(packageUri), isNotNull); + expect(findLockFile(packageUri, packageName), isNotNull); final result2 = await runBuildInProcess(); expect(result2, 0); @@ -143,7 +144,8 @@ void main() async { test('Timeout exits process', timeout: longTimeout, () async { await inTempDir((tempUri) async { await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add/'); + const packageName = 'native_add'; + final packageUri = tempUri.resolve('$packageName/'); await runPubGet( workingDirectory: packageUri, @@ -177,7 +179,7 @@ void main() async { await runBuildInProcess(); - final lockFile = findLockFile(packageUri); + final lockFile = findLockFile(packageUri, packageName); expect(lockFile, isNotNull); lockFile!; 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 25ec31463..a04455907 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 @@ -28,26 +28,26 @@ void main(List args) async { singleHookTimeout: timeout, fileSystem: const LocalFileSystem(), ).build( - configCreator: () => BuildConfigBuilder() - ..setupCodeConfig( + inputCreator: () => BuildInputBuilder() + ..config.setupCode( targetArchitecture: Architecture.current, targetOS: targetOS, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dartCICompilerConfig, - macOSConfig: targetOS == OS.macOS + cCompiler: dartCICompilerConfig, + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, ), workingDirectory: packageUri, linkingEnabled: false, buildAssetTypes: [CodeAsset.type, DataAsset.type], - configValidator: (config) async => [ - ...await validateDataAssetBuildConfig(config), - ...await validateCodeAssetBuildConfig(config), + inputValidator: (input) async => [ + ...await validateDataAssetBuildInput(input), + ...await validateCodeAssetBuildInput(input), ], - buildValidator: (config, output) async => [ - ...await validateCodeAssetBuildOutput(config, output), - ...await validateDataAssetBuildOutput(config, output), + buildValidator: (input, output) async => [ + ...await validateCodeAssetBuildOutput(input, output), + ...await validateDataAssetBuildOutput(input, output), ], applicationAssetValidator: validateCodeAssetInApplication, ); 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 2aee76303..4672080d7 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 @@ -28,7 +28,7 @@ void main() async { createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ); @@ -59,7 +59,7 @@ void main() async { linkingEnabled: true, dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -70,7 +70,7 @@ void main() async { dartExecutable, buildResult: buildResult, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetLinkConfig, + inputValidator: validateCodeAssetLinkInput, linkValidator: validateCodeAssetLinkOutput, applicationAssetValidator: validateCodeAssetInApplication, ); 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 072ae2f4d..6d810e8af 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 @@ -15,7 +15,7 @@ const minNdkApiVersionForThisPackage = 28; const minIosVersionForThisPackage = 16; const minMacOSVersionForThisPackage = 13; -final List<(Target, List<(int sdkVersion, bool success)>)> osConfig = [ +final List<(Target, List<(int sdkVersion, bool success)>)> osInput = [ ( Target.androidArm64, [ @@ -47,7 +47,7 @@ final List<(String hook, String testPath)> hooks = [ ]; void main() async { - for (final (target, versions) in osConfig) { + for (final (target, versions) in osInput) { for (final (version, success) in versions) { final statusString = success ? 'succeed' : 'fail'; for (final (hook, packagePath) in hooks) { @@ -74,21 +74,21 @@ void main() async { createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, buildAssetTypes: [CodeAsset.type, DataAsset.type], - buildConfigValidator: (config) async => [ - ...await validateDataAssetBuildConfig(config), - ...await validateCodeAssetBuildConfig(config), + buildInputValidator: (input) async => [ + ...await validateDataAssetBuildInput(input), + ...await validateCodeAssetBuildInput(input), ], - buildValidator: (config, output) async => [ - ...await validateCodeAssetBuildOutput(config, output), - ...await validateDataAssetBuildOutput(config, output), + buildValidator: (input, output) async => [ + ...await validateCodeAssetBuildOutput(input, output), + ...await validateDataAssetBuildOutput(input, output), ], - linkConfigValidator: (config) async => [ - ...await validateDataAssetLinkConfig(config), - ...await validateCodeAssetLinkConfig(config), + linkInputValidator: (input) async => [ + ...await validateDataAssetLinkInput(input), + ...await validateCodeAssetLinkInput(input), ], - linkValidator: (config, output) async => [ - ...await validateCodeAssetLinkOutput(config, output), - ...await validateDataAssetLinkOutput(config, output), + linkValidator: (input, output) async => [ + ...await validateCodeAssetLinkOutput(input, output), + ...await validateDataAssetLinkOutput(input, output), ], applicationAssetValidator: validateCodeAssetInApplication, ); diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index 4790d1b0e..d772d1a55 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -33,11 +33,11 @@ Future build( Uri packageUri, Logger logger, Uri dartExecutable, { - required BuildConfigValidator configValidator, + required BuildInputValidator inputValidator, required BuildValidator buildValidator, required ApplicationAssetValidator applicationAssetValidator, LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfig? cCompilerConfig, + CCompilerConfig? cCompiler, List? capturedLogs, PackageLayout? packageLayout, String? runPackageName, @@ -58,32 +58,32 @@ Future build( fileSystem: const LocalFileSystem(), hookEnvironment: hookEnvironment, ).build( - configCreator: () { - final configBuilder = BuildConfigBuilder(); + inputCreator: () { + final inputBuilder = BuildInputBuilder(); if (buildAssetTypes.contains(CodeAsset.type)) { - configBuilder.setupCodeConfig( + inputBuilder.config.setupCode( targetArchitecture: target?.architecture ?? Architecture.current, targetOS: targetOS, linkModePreference: linkModePreference, - cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, - iOSConfig: targetOS == OS.iOS + cCompiler: cCompiler ?? dartCICompilerConfig, + iOS: targetOS == OS.iOS ? IOSConfig( targetSdk: targetIOSSdk!, targetVersion: targetIOSVersion!, ) : null, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig( targetVersion: targetMacOSVersion ?? defaultMacOSVersion) : null, - androidConfig: targetOS == OS.android + android: targetOS == OS.android ? AndroidConfig(targetNdkApi: targetAndroidNdkApi!) : null, ); } - return configBuilder; + return inputBuilder; }, - configValidator: configValidator, + inputValidator: inputValidator, workingDirectory: packageUri, packageLayout: packageLayout, runPackageName: runPackageName, @@ -109,11 +109,11 @@ Future link( Uri packageUri, Logger logger, Uri dartExecutable, { - required LinkConfigValidator configValidator, + required LinkInputValidator inputValidator, required LinkValidator linkValidator, required ApplicationAssetValidator applicationAssetValidator, LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfig? cCompilerConfig, + CCompilerConfig? cCompiler, List? capturedLogs, PackageLayout? packageLayout, required BuildResult buildResult, @@ -132,32 +132,32 @@ Future link( dartExecutable: dartExecutable, fileSystem: const LocalFileSystem(), ).link( - configCreator: () { - final configBuilder = LinkConfigBuilder(); + inputCreator: () { + final inputBuilder = LinkInputBuilder(); if (buildAssetTypes.contains(CodeAsset.type)) { - configBuilder.setupCodeConfig( + inputBuilder.config.setupCode( targetArchitecture: target?.architecture ?? Architecture.current, targetOS: target?.os ?? OS.current, linkModePreference: linkModePreference, - cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, - iOSConfig: targetOS == OS.iOS + cCompiler: cCompiler ?? dartCICompilerConfig, + iOS: targetOS == OS.iOS ? IOSConfig( targetSdk: targetIOSSdk!, targetVersion: targetIOSVersion!, ) : null, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig( targetVersion: targetMacOSVersion ?? defaultMacOSVersion) : null, - androidConfig: targetOS == OS.android + android: targetOS == OS.android ? AndroidConfig(targetNdkApi: targetAndroidNdkApi!) : null, ); } - return configBuilder; + return inputBuilder; }, - configValidator: configValidator, + inputValidator: inputValidator, workingDirectory: packageUri, packageLayout: packageLayout, buildResult: buildResult, @@ -180,9 +180,9 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( Logger logger, Uri dartExecutable, { LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfig? cCompilerConfig, - required BuildConfigValidator buildConfigValidator, - required LinkConfigValidator linkConfigValidator, + CCompilerConfig? cCompiler, + required BuildInputValidator buildInputValidator, + required LinkInputValidator linkInputValidator, required BuildValidator buildValidator, required LinkValidator linkValidator, required ApplicationAssetValidator applicationAssetValidator, @@ -205,27 +205,32 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( ); final targetOS = target?.os ?? OS.current; final buildResult = await buildRunner.build( - configCreator: () => BuildConfigBuilder() - ..setupCodeConfig( - targetArchitecture: target?.architecture ?? Architecture.current, - targetOS: targetOS, - linkModePreference: linkModePreference, - cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, - iOSConfig: targetOS == OS.iOS - ? IOSConfig( - targetSdk: targetIOSSdk!, - targetVersion: targetIOSVersion!, - ) - : null, - macOSConfig: targetOS == OS.macOS - ? MacOSConfig( - targetVersion: targetMacOSVersion ?? defaultMacOSVersion) - : null, - androidConfig: targetOS == OS.android - ? AndroidConfig(targetNdkApi: targetAndroidNdkApi!) - : null, - ), - configValidator: buildConfigValidator, + 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 + ? IOSConfig( + targetSdk: targetIOSSdk!, + targetVersion: targetIOSVersion!, + ) + : null, + macOS: targetOS == OS.macOS + ? MacOSConfig( + targetVersion: targetMacOSVersion ?? defaultMacOSVersion) + : null, + android: targetOS == OS.android + ? AndroidConfig(targetNdkApi: targetAndroidNdkApi!) + : null, + ); + } + return inputBuilder; + }, + inputValidator: buildInputValidator, workingDirectory: packageUri, packageLayout: packageLayout, runPackageName: runPackageName, @@ -246,27 +251,32 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( } final linkResult = await buildRunner.link( - configCreator: () => LinkConfigBuilder() - ..setupCodeConfig( - targetArchitecture: target?.architecture ?? Architecture.current, - targetOS: targetOS, - linkModePreference: linkModePreference, - cCompilerConfig: cCompilerConfig, - iOSConfig: targetOS == OS.iOS - ? IOSConfig( - targetSdk: targetIOSSdk!, - targetVersion: targetIOSVersion!, - ) - : null, - macOSConfig: targetOS == OS.macOS - ? MacOSConfig( - targetVersion: targetMacOSVersion ?? defaultMacOSVersion) - : null, - androidConfig: targetOS == OS.android - ? AndroidConfig(targetNdkApi: targetAndroidNdkApi!) - : null, - ), - configValidator: linkConfigValidator, + 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 + ? IOSConfig( + targetSdk: targetIOSSdk!, + targetVersion: targetIOSVersion!, + ) + : null, + macOS: targetOS == OS.macOS + ? MacOSConfig( + targetVersion: targetMacOSVersion ?? defaultMacOSVersion) + : null, + android: targetOS == OS.android + ? AndroidConfig(targetNdkApi: targetAndroidNdkApi!) + : null, + ); + } + return inputBuilder; + }, + inputValidator: linkInputValidator, workingDirectory: packageUri, packageLayout: packageLayout, buildResult: buildResult, 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 e83275b9b..fca7f62fe 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 @@ -36,7 +36,7 @@ void main() async { linkingEnabled: true, buildAssetTypes: [DataAsset.type], capturedLogs: logMessages, - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateDataAssetBuildOutput, applicationAssetValidator: (_) async => [], ))!; @@ -51,7 +51,7 @@ void main() async { buildResult: buildResult, buildAssetTypes: [DataAsset.type], capturedLogs: logMessages, - configValidator: validateDataAssetLinkConfig, + inputValidator: validateDataAssetLinkInput, linkValidator: validateDataAssetLinkOutput, applicationAssetValidator: (_) async => [], ))!; 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 1ec0046b5..159788b19 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_test.dart @@ -32,7 +32,7 @@ void main() async { dartExecutable, linkingEnabled: true, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateDataAssetBuildOutput, applicationAssetValidator: (_) async => [], ))!; @@ -44,7 +44,7 @@ void main() async { dartExecutable, buildResult: buildResult, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetLinkConfig, + inputValidator: validateDataAssetLinkInput, linkValidator: validateDataAssetLinkOutput, applicationAssetValidator: (_) async => [], ))!; @@ -56,7 +56,7 @@ void main() async { dartExecutable, linkingEnabled: false, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateDataAssetBuildOutput, applicationAssetValidator: (_) async => [], ))!; @@ -102,7 +102,7 @@ void main() async { dartExecutable, linkingEnabled: true, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateDataAssetBuildOutput, applicationAssetValidator: (_) async => [], ); @@ -120,7 +120,7 @@ void main() async { dartExecutable, buildResult: buildResult, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetLinkConfig, + inputValidator: validateDataAssetLinkInput, linkValidator: validateDataAssetLinkOutput, applicationAssetValidator: (_) async => [], ); @@ -149,7 +149,7 @@ void main() async { dartExecutable, linkingEnabled: true, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateDataAssetBuildOutput, applicationAssetValidator: (_) async => [], ))!; @@ -164,7 +164,7 @@ void main() async { buildResult: buildResult, capturedLogs: logMessages, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetLinkConfig, + inputValidator: validateDataAssetLinkInput, linkValidator: validateDataAssetLinkOutput, applicationAssetValidator: (_) async => [], ))!; @@ -204,7 +204,7 @@ void main() async { dartExecutable, linkingEnabled: true, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -219,7 +219,7 @@ void main() async { buildResult: buildResult, capturedLogs: logMessages, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetLinkConfig, + inputValidator: validateCodeAssetLinkInput, linkValidator: validateCodeAssetLinkOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; 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 274b88c9c..e5a345f6b 100644 --- a/pkgs/native_assets_builder/test/build_runner/metadata_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/metadata_test.dart @@ -32,8 +32,8 @@ void main() async { dartExecutable, capturedLogs: logMessages, buildAssetTypes: ['foo'], - configValidator: (config) async => [], - buildValidator: (config, output) async => [], + inputValidator: (input) async => [], + buildValidator: (input, output) async => [], applicationAssetValidator: (_) async => [], ); expect( 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 92e60dc01..cfeb90cf9 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 @@ -27,7 +27,7 @@ void main() async { dartExecutable, linkModePreference: LinkModePreference.dynamic, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -38,7 +38,7 @@ void main() async { dartExecutable, linkModePreference: LinkModePreference.preferDynamic, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -49,7 +49,7 @@ void main() async { dartExecutable, linkModePreference: LinkModePreference.static, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; @@ -60,7 +60,7 @@ void main() async { dartExecutable, linkModePreference: LinkModePreference.preferStatic, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, ))!; 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 4d5a87207..c036df36e 100644 --- a/pkgs/native_assets_builder/test/build_runner/resources_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/resources_test.dart @@ -35,7 +35,7 @@ void main() async { dartExecutable, linkingEnabled: true, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetBuildConfig, + inputValidator: validateDataAssetBuildInput, buildValidator: validateDataAssetBuildOutput, applicationAssetValidator: (_) async => [], ))!; @@ -54,7 +54,7 @@ void main() async { buildResult: buildResult, resourceIdentifiers: resourcesUri, buildAssetTypes: [DataAsset.type], - configValidator: validateDataAssetLinkConfig, + inputValidator: validateDataAssetLinkInput, linkValidator: validateDataAssetLinkOutput, applicationAssetValidator: (_) async => [], ); 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 8170c215f..4c17ffa9d 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 @@ -27,7 +27,7 @@ void main() async { packageUri, logger, dartExecutable, - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildAssetTypes: [CodeAsset.type], buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, 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 4a1c58d25..3116a59cc 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 @@ -28,7 +28,7 @@ void main() async { createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, + inputValidator: validateCodeAssetBuildInput, buildValidator: validateCodeAssetBuildOutput, applicationAssetValidator: validateCodeAssetInApplication, linkingEnabled: true, 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 e0f042c29..f6c975916 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 @@ -31,36 +31,34 @@ void main() async { final dartUri = Uri.file(Platform.resolvedExecutable); final targetOS = OS.current; - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: testPackageUri, - buildAssetTypes: [CodeAsset.type], - ) - ..setupBuildConfig(dryRun: false, linkingEnabled: false) - ..setupBuildRunConfig( outputDirectory: outputDirectory, outputDirectoryShared: outputDirectoryShared, ) - ..setupCodeConfig( + ..config.setupBuild(dryRun: false, linkingEnabled: false) + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetArchitecture: Architecture.current, targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - final buildConfigUri = testTempUri.resolve('build_config.json'); - File.fromUri(buildConfigUri) - .writeAsStringSync(jsonEncode(configBuilder.json)); + 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=${buildConfigUri.toFilePath()}', + '--config=${buildInputUri.toFilePath()}', ], workingDirectory: testPackageUri.toFilePath(), ); @@ -75,7 +73,7 @@ void main() async { final buildOutput = BuildOutput( json.decode(await File.fromUri(buildOutputUri).readAsString()) as Map); - final assets = buildOutput.encodedAssets; + final assets = buildOutput.assets.encodedAssets; final dependencies = buildOutput.dependencies; expect(assets.length, 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 42b8eb404..faa97046b 100644 --- a/pkgs/native_assets_builder/test/test_data/transformer_test.dart +++ b/pkgs/native_assets_builder/test/test_data/transformer_test.dart @@ -46,35 +46,36 @@ void main() async { final targetOS = OS.current; Future runBuild(Architecture architecture) async { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: packageName, packageRoot: packageUri, - buildAssetTypes: [DataAsset.type], - ) - ..setupBuildConfig(dryRun: false, linkingEnabled: false) - ..setupBuildRunConfig( outputDirectory: outputDirectory, outputDirectoryShared: outputDirectoryShared, ) - ..setupCodeConfig( + ..config.setupBuild(dryRun: false, linkingEnabled: false) + ..config.setupShared(buildAssetTypes: [ + CodeAsset.type, + DataAsset.type, + ]) + ..config.setupCode( targetArchitecture: architecture, targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, linkModePreference: LinkModePreference.dynamic, ); - final buildConfigUri = testTempUri.resolve('build_config.json'); - File.fromUri(buildConfigUri) - .writeAsStringSync(jsonEncode(configBuilder.json)); + 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=${buildConfigUri.toFilePath()}', + '--config=${buildInputUri.toFilePath()}', ], workingDirectory: packageUri.toFilePath(), ); @@ -101,7 +102,7 @@ void main() async { ]), ); expect( - output.dataAssets, + output.assets.data, contains( DataAsset( file: outputDirectoryShared.resolve('data_transformed0.json'), diff --git a/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart b/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart index 10a1d4575..c35df83c8 100644 --- a/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart @@ -7,8 +7,8 @@ import 'package:native_assets_cli/code_assets.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - if (!config.linkingEnabled) { + await build(arguments, (input, output) async { + if (!input.config.linkingEnabled) { throw Exception('Link hook must be run!'); } final logger = Logger('') @@ -24,7 +24,7 @@ void main(List arguments) async { ], linkModePreference: LinkModePreference.dynamic, ).run( - config: config, + input: input, output: output, logger: logger, linkInPackage: 'add_asset_link', diff --git a/pkgs/native_assets_builder/test_data/add_asset_link/hook/link.dart b/pkgs/native_assets_builder/test_data/add_asset_link/hook/link.dart index 67ff71cfb..f49e5a67e 100644 --- a/pkgs/native_assets_builder/test_data/add_asset_link/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/add_asset_link/hook/link.dart @@ -5,19 +5,19 @@ import 'package:native_assets_cli/code_assets.dart'; void main(List arguments) async { - await link(arguments, (config, output) async { - final builtDylib = config.codeAssets.first; + await link(arguments, (input, output) async { + final builtDylib = input.assets.code.first; output - ..codeAssets.add( - CodeAsset( - package: 'add_asset_link', - name: 'dylib_add_link', - linkMode: builtDylib.linkMode, - os: builtDylib.os, - architecture: builtDylib.architecture, - file: builtDylib.file, - ), - ) - ..addDependency(config.packageRoot.resolve('hook/link.dart')); + ..assets.code.add( + CodeAsset( + package: 'add_asset_link', + name: 'dylib_add_link', + linkMode: builtDylib.linkMode, + os: builtDylib.os, + architecture: builtDylib.architecture, + file: builtDylib.file, + ), + ) + ..addDependency(input.packageRoot.resolve('hook/link.dart')); }); } 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 5a508c4c0..9ed8be59a 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 @@ -7,10 +7,10 @@ import 'dart:io'; import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { - await build(args, (config, output) async { - final packageName = config.packageName; + await build(args, (input, output) async { + final packageName = input.packageName; final assetDirectory = - Directory.fromUri(config.packageRoot.resolve('assets/')); + Directory.fromUri(input.packageRoot.resolve('assets/')); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -22,15 +22,15 @@ void main(List args) async { // The file path relative to the package root, with forward slashes. final name = dataAsset.uri .toFilePath(windows: false) - .substring(config.packageRoot.toFilePath(windows: false).length); + .substring(input.packageRoot.toFilePath(windows: false).length); - output.dataAssets.add( + output.assets.data.add( DataAsset( package: packageName, name: name, file: dataAsset.uri, ), - linkInPackage: config.linkingEnabled ? packageName : null, + linkInPackage: input.config.linkingEnabled ? packageName : null, ); // TODO(https://github.com/dart-lang/native/issues/1208): Report // dependency on asset. diff --git a/pkgs/native_assets_builder/test_data/complex_link/hook/link.dart b/pkgs/native_assets_builder/test_data/complex_link/hook/link.dart index 735c78502..a7926e43c 100644 --- a/pkgs/native_assets_builder/test_data/complex_link/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/complex_link/hook/link.dart @@ -7,8 +7,8 @@ import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { await link( args, - (config, output) async => - output.dataAssets.addAll(treeshake(config.dataAssets)), + (input, output) async => + output.assets.data.addAll(treeshake(input.assets.data)), ); } 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 fe2829fd5..2d4368b94 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 @@ -7,10 +7,10 @@ import 'dart:io'; import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { - await build(args, (config, output) async { - final packageName = config.packageName; + await build(args, (input, output) async { + final packageName = input.packageName; final assetDirectory = - Directory.fromUri(config.packageRoot.resolve('assets/')); + Directory.fromUri(input.packageRoot.resolve('assets/')); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -22,17 +22,17 @@ void main(List args) async { // The file path relative to the package root, with forward slashes. final name = dataAsset.uri .toFilePath(windows: false) - .substring(config.packageRoot.toFilePath(windows: false).length); + .substring(input.packageRoot.toFilePath(windows: false).length); final forLinking = name.contains('2') || name.contains('3'); - output.dataAssets.add( + output.assets.data.add( DataAsset( package: packageName, name: name, file: dataAsset.uri, ), linkInPackage: - forLinking && config.linkingEnabled ? 'complex_link' : null, + forLinking && input.config.linkingEnabled ? 'complex_link' : null, ); // TODO(https://github.com/dart-lang/native/issues/1208): Report // dependency on asset. diff --git a/pkgs/native_assets_builder/test_data/cyclic_package_1/hook/build.dart b/pkgs/native_assets_builder/test_data/cyclic_package_1/hook/build.dart index 291cc50bd..67df9f89e 100644 --- a/pkgs/native_assets_builder/test_data/cyclic_package_1/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/cyclic_package_1/hook/build.dart @@ -5,5 +5,5 @@ import 'package:native_assets_cli/native_assets_cli.dart'; void main(List arguments) async { - await build(arguments, (config, output) async {}); + await build(arguments, (input, output) async {}); } diff --git a/pkgs/native_assets_builder/test_data/cyclic_package_2/hook/build.dart b/pkgs/native_assets_builder/test_data/cyclic_package_2/hook/build.dart index 291cc50bd..67df9f89e 100644 --- a/pkgs/native_assets_builder/test_data/cyclic_package_2/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/cyclic_package_2/hook/build.dart @@ -5,5 +5,5 @@ import 'package:native_assets_cli/native_assets_cli.dart'; void main(List arguments) async { - await build(arguments, (config, output) async {}); + await build(arguments, (input, output) async {}); } diff --git a/pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart b/pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart index bee5aadf4..437c9790f 100644 --- a/pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/depend_on_fail_build/hook/build.dart @@ -6,7 +6,7 @@ import 'package:fail_build/fail_build.dart'; import 'package:native_assets_cli/data_assets.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { + await build(arguments, (input, output) async { // Does nothing, just depends on `package:fail_build`. invokeFailBuildCode(); }); diff --git a/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart b/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart index a924a9ee8..10fa73f45 100644 --- a/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart @@ -7,13 +7,14 @@ import 'package:native_assets_cli/code_assets.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { + await build(arguments, (input, output) async { final logger = Logger('') ..level = Level.ALL ..onRecord.listen((record) { print('${record.level.name}: ${record.time}: ${record.message}'); }); - final linkInPackage = config.linkingEnabled ? config.packageName : null; + final linkInPackage = + input.config.linkingEnabled ? input.packageName : null; await CBuilder.library( name: 'add', assetName: 'dylib_add', @@ -22,7 +23,7 @@ void main(List arguments) async { ], linkModePreference: LinkModePreference.dynamic, ).run( - config: config, + input: input, output: output, logger: logger, linkInPackage: linkInPackage, @@ -36,7 +37,7 @@ void main(List arguments) async { ], linkModePreference: LinkModePreference.dynamic, ).run( - config: config, + input: input, output: output, logger: logger, linkInPackage: linkInPackage, diff --git a/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/link.dart b/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/link.dart index 9e5f01743..73bb61111 100644 --- a/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/link.dart @@ -5,11 +5,11 @@ import 'package:native_assets_cli/code_assets.dart'; void main(List arguments) async { - await link(arguments, (config, output) async { - for (final codeAsset in config.codeAssets) { + await link(arguments, (input, output) async { + for (final codeAsset in input.assets.code) { print('Got code asset: ${codeAsset.id}'); if (codeAsset.id.endsWith('add')) { - output.codeAssets.add(codeAsset); + output.assets.code.add(codeAsset); print('-> Keeping ${codeAsset.id}'); } else { print('-> Dropping ${codeAsset.id}'); diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart index ac2f821f2..cc815afd3 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart @@ -13,17 +13,17 @@ const minIosVersionForThisPackage = 16; const minMacOSVersionForThisPackage = 13; void main(List arguments) async { - await build(arguments, (config, output) async { - if (config.codeConfig.targetOS == OS.android) { - if (config.codeConfig.androidConfig.targetNdkApi < + await build(arguments, (input, output) async { + if (input.config.code.targetOS == OS.android) { + if (input.config.code.android.targetNdkApi < minNdkApiVersionForThisPackage) { throw UnsupportedError( 'The native assets for this package require at ' 'least Android NDK API level $minNdkApiVersionForThisPackage.', ); } - } else if (config.codeConfig.targetOS == OS.iOS) { - final iosVersion = config.codeConfig.iOSConfig.targetVersion; + } else if (input.config.code.targetOS == OS.iOS) { + final iosVersion = input.config.code.iOS.targetVersion; // iosVersion is nullable to deal with version skew. if (iosVersion < minIosVersionForThisPackage) { throw UnsupportedError( @@ -31,8 +31,8 @@ void main(List arguments) async { 'least iOS version $minIosVersionForThisPackage.', ); } - } else if (config.codeConfig.targetOS == OS.macOS) { - final macosVersion = config.codeConfig.macOSConfig.targetVersion; + } else if (input.config.code.targetOS == OS.macOS) { + final macosVersion = input.config.code.macOS.targetVersion; // macosVersion is nullable to deal with version skew. if (macosVersion < minMacOSVersionForThisPackage) { throw UnsupportedError( diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/hook/build.dart b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/hook/build.dart index 3d96b622e..8cfdb1ef4 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/hook/build.dart @@ -5,15 +5,15 @@ import 'package:native_assets_cli/data_assets.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - output.dataAssets.add( + await build(arguments, (input, output) async { + output.assets.data.add( DataAsset( name: 'data', - file: config.packageRoot.resolve('assets/data.json'), - package: config.packageName, + file: input.packageRoot.resolve('assets/data.json'), + package: input.packageName, ), linkInPackage: - config.linkingEnabled ? 'fail_on_os_sdk_version_linker' : null, + input.config.linkingEnabled ? 'fail_on_os_sdk_version_linker' : null, ); }); } diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart index 852c89f47..97ae98697 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart @@ -13,17 +13,17 @@ const minIosVersionForThisPackage = 16; const minMacOSVersionForThisPackage = 13; void main(List arguments) async { - await link(arguments, (config, output) async { - if (config.codeConfig.targetOS == OS.android) { - if (config.codeConfig.androidConfig.targetNdkApi < + await link(arguments, (input, output) async { + if (input.config.code.targetOS == OS.android) { + if (input.config.code.android.targetNdkApi < minNdkApiVersionForThisPackage) { throw UnsupportedError( 'The native assets for this package require at ' 'least Android NDK API level $minNdkApiVersionForThisPackage.', ); } - } else if (config.codeConfig.targetOS == OS.iOS) { - final iosVersion = config.codeConfig.iOSConfig.targetVersion; + } else if (input.config.code.targetOS == OS.iOS) { + final iosVersion = input.config.code.iOS.targetVersion; // iosVersion is nullable to deal with version skew. if (iosVersion < minIosVersionForThisPackage) { throw UnsupportedError( @@ -31,8 +31,8 @@ void main(List arguments) async { 'least iOS version $minIosVersionForThisPackage.', ); } - } else if (config.codeConfig.targetOS == OS.macOS) { - final macosVersion = config.codeConfig.macOSConfig.targetVersion; + } else if (input.config.code.targetOS == OS.macOS) { + final macosVersion = input.config.code.macOS.targetVersion; // macosVersion is nullable to deal with version skew. if (macosVersion < minMacOSVersionForThisPackage) { throw UnsupportedError( 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 320f1d3a8..bdeb571bf 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 @@ -7,8 +7,8 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final packageName = config.packageName; + await build(arguments, (input, output) async { + final packageName = input.packageName; final cbuilder = CBuilder.library( name: packageName, assetName: 'src/${packageName}_bindings_generated.dart', @@ -17,7 +17,7 @@ void main(List arguments) async { ], ); await cbuilder.run( - config: config, + input: input, output: output, logger: Logger('') ..level = Level.ALL 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 efe55428b..d3a10056c 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 @@ -7,8 +7,8 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final packageName = config.packageName; + await build(arguments, (input, output) async { + final packageName = input.packageName; final cbuilder = CBuilder.library( name: packageName, assetName: '${packageName}_bindings_generated.dart', @@ -18,7 +18,7 @@ void main(List arguments) async { ], ); await cbuilder.run( - config: config, + input: input, output: output, logger: Logger('') ..level = Level.ALL 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 faeeab1c6..a903eb19a 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 @@ -8,8 +8,8 @@ import 'package:native_assets_cli/code_assets_builder.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final packageName = config.packageName; + await build(arguments, (input, output) async { + final packageName = input.packageName; const duplicatedPackageName = 'native_add'; final cbuilder = CBuilder.library( name: duplicatedPackageName, @@ -21,7 +21,7 @@ void main(List arguments) async { // Temp output to prevent outputting the dylib for bundling. final outputBuilder = BuildOutputBuilder(); await cbuilder.run( - config: config, + input: input, output: outputBuilder, logger: Logger('') ..level = Level.ALL @@ -30,10 +30,10 @@ void main(List arguments) async { }), ); final tempBuildOutput = BuildOutput(outputBuilder.json); - output.codeAssets.add( - tempBuildOutput.codeAssets.single, + output.assets.code.add( + tempBuildOutput.assets.code.single, // Send dylib to linking if linking is enabled. - linkInPackage: config.linkingEnabled ? packageName : null, + linkInPackage: input.config.linkingEnabled ? packageName : null, ); output.addDependencies( tempBuildOutput.dependencies, diff --git a/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/link.dart b/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/link.dart index c2ca7d027..15861eb84 100644 --- a/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/native_add_duplicate/hook/link.dart @@ -5,8 +5,8 @@ import 'package:native_assets_cli/code_assets.dart'; void main(List args) async { - await link(args, (config, output) async { + await link(args, (input, output) async { // Simply output the dylib in the link hook. - output.codeAssets.addAll(config.codeAssets); + output.assets.code.addAll(input.assets.code); }); } 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 ee718dfcb..1dc4aa6a0 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 @@ -7,7 +7,7 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List args) async { - await build(args, (config, output) async { + await build(args, (input, output) async { final logger = Logger('') ..level = Level.ALL ..onRecord.listen((record) => print(record.message)); @@ -45,7 +45,7 @@ void main(List args) async { // each others output. for (final builder in builders) { await builder.run( - config: config, + input: input, output: output, logger: logger, ); 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 320f1d3a8..bdeb571bf 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 @@ -7,8 +7,8 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final packageName = config.packageName; + await build(arguments, (input, output) async { + final packageName = input.packageName; final cbuilder = CBuilder.library( name: packageName, assetName: 'src/${packageName}_bindings_generated.dart', @@ -17,7 +17,7 @@ void main(List arguments) async { ], ); await cbuilder.run( - config: config, + input: input, output: output, logger: Logger('') ..level = Level.ALL diff --git a/pkgs/native_assets_builder/test_data/no_asset_for_link/hook/link.dart b/pkgs/native_assets_builder/test_data/no_asset_for_link/hook/link.dart index 150300fea..38445a20f 100644 --- a/pkgs/native_assets_builder/test_data/no_asset_for_link/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/no_asset_for_link/hook/link.dart @@ -6,8 +6,8 @@ import 'package:native_assets_cli/code_assets.dart'; import 'package:native_assets_cli/data_assets.dart'; void main(List arguments) async { - await link(arguments, (config, output) async { - output.codeAssets.addAll(config.codeAssets); - output.dataAssets.addAll(config.dataAssets); + await link(arguments, (input, output) async { + output.assets.code.addAll(input.assets.code); + output.assets.data.addAll(input.assets.data); }); } 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 148fb9b6b..aa0c5f15d 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 @@ -7,11 +7,10 @@ import 'package:native_assets_cli/native_assets_cli.dart'; void main(List args) async { - await build(args, (buildConfig, _) async { - final someValue = - buildConfig.metadatum('package_with_metadata', 'some_key'); + await build(args, (input, _) async { + final someValue = input.metadatum('package_with_metadata', 'some_key'); assert(someValue != null); - final someInt = buildConfig.metadatum('package_with_metadata', 'some_int'); + final someInt = input.metadatum('package_with_metadata', 'some_int'); assert(someInt != null); print({ 'some_int': someInt, 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 214bac4b8..12b1c996e 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 @@ -5,7 +5,7 @@ import 'package:native_assets_cli/native_assets_cli.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { + await build(arguments, (input, output) async { // ignore: deprecated_member_use output.addMetadata({ 'some_key': 'some_value', 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 db164a614..03f47d10f 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 @@ -8,9 +8,9 @@ import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { await build( args, - (config, output) async { + (input, output) async { final assetDirectory = - Directory.fromUri(config.packageRoot.resolve('assets/')); + Directory.fromUri(input.packageRoot.resolve('assets/')); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -22,11 +22,11 @@ void main(List args) async { // The file path relative to the package root, with forward slashes. final name = dataAsset.uri .toFilePath(windows: false) - .substring(config.packageRoot.toFilePath(windows: false).length); + .substring(input.packageRoot.toFilePath(windows: false).length); - output.dataAssets.add( + output.assets.data.add( DataAsset( - package: config.packageName, + package: input.packageName, name: name, file: dataAsset.uri, ), 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 5a508c4c0..9ed8be59a 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 @@ -7,10 +7,10 @@ import 'dart:io'; import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { - await build(args, (config, output) async { - final packageName = config.packageName; + await build(args, (input, output) async { + final packageName = input.packageName; final assetDirectory = - Directory.fromUri(config.packageRoot.resolve('assets/')); + Directory.fromUri(input.packageRoot.resolve('assets/')); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -22,15 +22,15 @@ void main(List args) async { // The file path relative to the package root, with forward slashes. final name = dataAsset.uri .toFilePath(windows: false) - .substring(config.packageRoot.toFilePath(windows: false).length); + .substring(input.packageRoot.toFilePath(windows: false).length); - output.dataAssets.add( + output.assets.data.add( DataAsset( package: packageName, name: name, file: dataAsset.uri, ), - linkInPackage: config.linkingEnabled ? packageName : null, + linkInPackage: input.config.linkingEnabled ? packageName : null, ); // TODO(https://github.com/dart-lang/native/issues/1208): Report // dependency on asset. diff --git a/pkgs/native_assets_builder/test_data/simple_link/hook/link.dart b/pkgs/native_assets_builder/test_data/simple_link/hook/link.dart index 413dbd6f6..c4f4fd458 100644 --- a/pkgs/native_assets_builder/test_data/simple_link/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/simple_link/hook/link.dart @@ -5,14 +5,14 @@ import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { - await link(args, (config, output) async { - shake(output, config.dataAssets); + await link(args, (input, output) async { + shake(output, input.assets.data); }); } void shake(LinkOutputBuilder output, Iterable assets) { for (final asset in assets.skip(2)) { - output.dataAssets.add(asset); + output.assets.data.add(asset); // If the file changes we'd like to re-run the linker. output.addDependency(asset.file); 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 856d61fc9..8932270ca 100644 --- a/pkgs/native_assets_builder/test_data/transformer/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/transformer/hook/build.dart @@ -10,9 +10,8 @@ import 'package:native_assets_cli/data_assets.dart'; import 'package:transformer/src/transform.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final dataDirectory = - Directory.fromUri(config.packageRoot.resolve('data/')); + await build(arguments, (input, output) async { + final dataDirectory = Directory.fromUri(input.packageRoot.resolve('data/')); // If data are added, rerun hook. output.addDependency(dataDirectory.uri); @@ -20,7 +19,7 @@ void main(List arguments) async { var cachedFiles = 0; final hashesFile = - File.fromUri(config.outputDirectoryShared.resolve('hashes.json')); + File.fromUri(input.outputDirectoryShared.resolve('hashes.json')); final hashes = await hashesFile.exists() ? (json.decoder.convert(await hashesFile.readAsString()) as Map) .cast() @@ -40,7 +39,7 @@ void main(List arguments) async { final prevHash = hashes[sourceName]; final name = sourceName.replaceFirst('data', 'data_transformed'); - final targetFile = File.fromUri(config.outputDirectoryShared + final targetFile = File.fromUri(input.outputDirectoryShared .resolve(sourceName.replaceFirst('data', 'data_transformed'))); if (!await targetFile.exists() || sourceHash != prevHash) { @@ -50,9 +49,9 @@ void main(List arguments) async { cachedFiles++; } - output.dataAssets.add( + output.assets.data.add( DataAsset( - package: config.packageName, + package: input.packageName, name: name, file: targetFile.uri, ), 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 e24b38a3a..e049a1399 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 @@ -7,22 +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 build(arguments, (config, output) async { + await build(arguments, (input, output) async { final cbuilder = CBuilder.library( - name: config.packageName + (config.linkingEnabled ? '_static' : ''), - assetName: 'src/${config.packageName}_bindings_generated.dart', + name: input.packageName + (input.config.linkingEnabled ? '_static' : ''), + assetName: 'src/${input.packageName}_bindings_generated.dart', sources: [ 'src/native_add.c', 'src/native_multiply.c', ], - linkModePreference: config.linkingEnabled + linkModePreference: input.config.linkingEnabled ? LinkModePreference.static : LinkModePreference.dynamic, ); await cbuilder.run( - config: config, + input: input, output: output, - linkInPackage: config.linkingEnabled ? config.packageName : null, + linkInPackage: input.config.linkingEnabled ? input.packageName : null, logger: Logger('') ..level = Level.ALL ..onRecord.listen((record) { 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 a3c4c9095..18384eda2 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 @@ -9,15 +9,15 @@ import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { await link( arguments, - (config, output) async { + (input, output) async { final linker = CLinker.library( - name: config.packageName, - assetName: config.codeAssets.single.id.split('/').skip(1).join('/'), + name: input.packageName, + assetName: input.assets.code.single.id.split('/').skip(1).join('/'), linkerOptions: LinkerOptions.treeshake(symbols: ['add']), - sources: [config.codeAssets.single.file!.toFilePath()], + sources: [input.assets.code.single.file!.toFilePath()], ); await linker.run( - config: config, + input: input, output: output, logger: Logger('') ..level = Level.ALL diff --git a/pkgs/native_assets_builder/test_data/use_all_api/README.md b/pkgs/native_assets_builder/test_data/use_all_api/README.md new file mode 100644 index 000000000..fcffe7231 --- /dev/null +++ b/pkgs/native_assets_builder/test_data/use_all_api/README.md @@ -0,0 +1 @@ +Not inteded to be executable, rather, intended to be used to see API changes. 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 new file mode 100644 index 000000000..880b7a18d --- /dev/null +++ b/pkgs/native_assets_builder/test_data/use_all_api/hook/build.dart @@ -0,0 +1,54 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// 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. + +// ignore_for_file: unnecessary_statements, deprecated_member_use + +import 'package:native_assets_cli/code_assets.dart'; +import 'package:native_assets_cli/data_assets.dart'; + +void main(List args) async { + await build(args, (input, output) async { + // a. shared + input.packageName; + input.packageRoot; + input.outputDirectory; + input.outputDirectoryShared; + // b. hook-specific + input.metadata; // build only + // c. target config + // c.1. per hook + input.config.linkingEnabled; // build only + input.config.dryRun; // build only, deleted soon + // c.2. per asset + input.config.buildAssetTypes; + input.config.code.linkModePreference; + input.config.code.targetArchitecture; + input.config.code.targetOS; + input.config.code.android.targetNdkApi; + input.config.code.iOS.targetSdk; + input.config.code.iOS.targetVersion; + input.config.code.macOS.targetVersion; + input.config.code.cCompiler?.archiver; + 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.data.add( + DataAsset( + file: input.outputDirectory.resolve('foo'), + name: 'name', + package: 'package', + ), + linkInPackage: 'foo', + ); + output.addDependency(input.packageRoot.resolve('x.txt')); + }); +} diff --git a/pkgs/native_assets_builder/test_data/use_all_api/hook/link.dart b/pkgs/native_assets_builder/test_data/use_all_api/hook/link.dart new file mode 100644 index 000000000..d877d5df8 --- /dev/null +++ b/pkgs/native_assets_builder/test_data/use_all_api/hook/link.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +// ignore_for_file: unnecessary_statements + +import 'package:native_assets_cli/code_assets.dart'; +import 'package:native_assets_cli/data_assets.dart'; + +void main(List args) async { + await link(args, (input, output) async { + // a. shared + input.packageName; + input.packageRoot; + input.outputDirectory; + input.outputDirectoryShared; + // b. hook-specific + input.assets.code; // link only + input.assets.data; // link only + input.recordedUsagesFile; // link only + // c. target config + // c.2. per asset + input.config.buildAssetTypes; + input.config.code.linkModePreference; + input.config.code.targetArchitecture; + input.config.code.targetOS; + input.config.code.android.targetNdkApi; + input.config.code.iOS.targetSdk; + input.config.code.iOS.targetVersion; + input.config.code.macOS.targetVersion; + input.config.code.cCompiler?.archiver; + input.config.code.cCompiler?.compiler; + input.config.code.cCompiler?.linker; + + output.assets.code.addAll(input.assets.code); + output.assets.data.addAll(input.assets.data); + + output.addDependency(input.packageRoot.resolve('x.txt')); + }); +} 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 new file mode 100644 index 000000000..309548f41 --- /dev/null +++ b/pkgs/native_assets_builder/test_data/use_all_api/pubspec.yaml @@ -0,0 +1,21 @@ +name: use_all_api +description: Example to use all API. + +version: 0.1.0 + +publish_to: none + +environment: + sdk: '>=3.0.0 <4.0.0' + +dependencies: + cli_config: ^0.2.0 + logging: ^1.1.1 + # native_assets_cli: ^0.10.0 + native_assets_cli: + path: ../../../native_assets_cli/ + +dev_dependencies: + lints: ^3.0.0 + path: ^1.9.0 + test: ^1.23.1 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 d1d26aeb1..6151a3917 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 @@ -9,10 +9,10 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_assets_cli/src/args_parser.dart'; void main(List args) async { - final configPath = getConfigArgument(args); - final buildConfig = BuildConfig( - json.decode(File(configPath).readAsStringSync()) as Map); - await File.fromUri(buildConfig.outputDirectory.resolve('build_output.json')) + final inputPath = getInputArgument(args); + final buildInput = BuildInput( + json.decode(File(inputPath).readAsStringSync()) as Map); + await File.fromUri(buildInput.outputDirectory.resolve('build_output.json')) .writeAsString(_wrongContents); } 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 9f8ff4ed8..af7921b5a 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 @@ -9,10 +9,10 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_assets_cli/src/args_parser.dart'; void main(List args) async { - final configPath = getConfigArgument(args); - final buildConfig = BuildConfig( - json.decode(File(configPath).readAsStringSync()) as Map); - await File.fromUri(buildConfig.outputDirectory.resolve('build_output.json')) + final inputPath = getInputArgument(args); + final buildInput = BuildInput( + json.decode(File(inputPath).readAsStringSync()) as Map); + await File.fromUri(buildInput.outputDirectory.resolve('build_output.json')) .writeAsString(_wrongContents); } 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 b53f9c872..454d60801 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 @@ -9,10 +9,10 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_assets_cli/src/args_parser.dart'; void main(List args) async { - final configPath = getConfigArgument(args); - final buildConfig = BuildConfig( - json.decode(File(configPath).readAsStringSync()) as Map); - await File.fromUri(buildConfig.outputDirectory.resolve('build_output.json')) + final inputPath = getInputArgument(args); + final buildInput = BuildInput( + json.decode(File(inputPath).readAsStringSync()) as Map); + await File.fromUri(buildInput.outputDirectory.resolve('build_output.json')) .writeAsString(_rightContents); exit(1); } diff --git a/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart b/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart index e0d486071..6eeab7445 100644 --- a/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart @@ -7,16 +7,16 @@ import 'dart:io'; import 'package:native_assets_cli/code_assets.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final assetUri = config.outputDirectory.resolve( + await build(arguments, (input, output) async { + final assetUri = input.outputDirectory.resolve( OS.current.dylibFileName('foo'), ); await File.fromUri(assetUri).writeAsBytes([1, 2, 3]); - output.codeAssets.add( + output.assets.code.add( CodeAsset( - package: config.packageName, + package: input.packageName, name: 'foo', file: assetUri, linkMode: DynamicLoadingBundled(), diff --git a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart index f776f1aa1..2e27f2fbc 100644 --- a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart @@ -7,14 +7,14 @@ import 'dart:io'; import 'package:native_assets_cli/code_assets.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final assetUri = config.outputDirectory.resolve( + await build(arguments, (input, output) async { + final assetUri = input.outputDirectory.resolve( OS.current.dylibFileName('foo'), ); await File.fromUri(assetUri).writeAsBytes([1, 2, 3]); - output.codeAssets.add( + output.assets.code.add( CodeAsset( package: 'other_package', name: 'foo', diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index 384a63aac..c9d716c76 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -1,6 +1,11 @@ -## 0.10.1 - -- Nothing yet. +## 0.11.0-wip + +- **Breaking change** Complete overhaul of the API used in build and link hooks. + The `BuildConfig` is now split in `BuildInput` and `BuildConfig`. The input is + everything passed in to the hook. The config (a part of the input) is what + shouldn't change on subsequent invocations of the same flutter or dart command + for the same target. The `outputDirectory` is the same if the config is the + same. ## 0.10.0 diff --git a/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart b/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart index 9547ac51b..b2898fd63 100644 --- a/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart @@ -10,19 +10,19 @@ const assetName = 'asset.txt'; final packageAssetPath = Uri.file('assets/$assetName'); Future main(List args) async { - await build(args, (config, output) async { - if (config.codeConfig.linkModePreference == LinkModePreference.static) { + await build(args, (input, output) async { + if (input.config.code.linkModePreference == LinkModePreference.static) { // Simulate that this build hook only supports dynamic libraries. throw UnsupportedError( 'LinkModePreference.static is not supported.', ); } - final packageName = config.packageName; - final assetPath = config.outputDirectory.resolve(assetName); - final assetSourcePath = config.packageRoot.resolveUri(packageAssetPath); + final packageName = input.packageName; + final assetPath = input.outputDirectory.resolve(assetName); + final assetSourcePath = input.packageRoot.resolveUri(packageAssetPath); // ignore: deprecated_member_use - if (!config.dryRun) { + if (!input.config.dryRun) { // Insert code that downloads or builds the asset to `assetPath`. await File.fromUri(assetSourcePath).copy(assetPath.toFilePath()); @@ -31,17 +31,17 @@ Future main(List args) async { ]); } - output.codeAssets.add( + output.assets.code.add( // TODO: Change to DataAsset once the Dart/Flutter SDK can consume it. CodeAsset( package: packageName, name: 'asset.txt', file: assetPath, linkMode: DynamicLoadingBundled(), - os: config.codeConfig.targetOS, + os: input.config.code.targetOS, architecture: // ignore: deprecated_member_use - config.dryRun ? null : config.codeConfig.targetArchitecture, + input.config.dryRun ? null : input.config.code.targetArchitecture, ), ); }); diff --git a/pkgs/native_assets_cli/example/build/local_asset/test/build_test.dart b/pkgs/native_assets_cli/example/build/local_asset/test/build_test.dart index 7b8ad34d6..e68483873 100644 --- a/pkgs/native_assets_cli/example/build/local_asset/test/build_test.dart +++ b/pkgs/native_assets_cli/example/build/local_asset/test/build_test.dart @@ -12,13 +12,12 @@ void main() async { await testCodeBuildHook( mainMethod: build.main, check: (_, output) { - expect(output.codeAssets, isNotEmpty); + expect(output.assets.code, isNotEmpty); expect( - output.codeAssets.first.id, + output.assets.code.first.id, 'package:local_asset/asset.txt', ); }, - buildAssetTypes: [CodeAsset.type], ); }); } diff --git a/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart b/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart index 1aef62bb1..49156bcb0 100644 --- a/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart @@ -7,8 +7,8 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List args) async { - await build(args, (config, output) async { - final packageName = config.packageName; + await build(args, (input, output) async { + final packageName = input.packageName; final cbuilder = CBuilder.library( name: packageName, assetName: '$packageName.dart', @@ -17,7 +17,7 @@ void main(List args) async { ], ); await cbuilder.run( - config: config, + input: input, output: output, logger: Logger('') ..level = Level.ALL diff --git a/pkgs/native_assets_cli/example/build/native_dynamic_linking/hook/build.dart b/pkgs/native_assets_cli/example/build/native_dynamic_linking/hook/build.dart index 0713eab62..fcaa2cfdb 100644 --- a/pkgs/native_assets_cli/example/build/native_dynamic_linking/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/native_dynamic_linking/hook/build.dart @@ -7,7 +7,7 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List args) async { - await build(args, (config, output) async { + await build(args, (input, output) async { final logger = Logger('') ..level = Level.ALL ..onRecord.listen((record) => print(record.message)); @@ -42,7 +42,7 @@ void main(List args) async { // each others output. for (final builder in builders) { await builder.run( - config: config, + input: input, output: output, logger: logger, ); diff --git a/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart b/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart index 16e8249c8..3f94e19e3 100644 --- a/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart @@ -7,8 +7,8 @@ import 'package:native_assets_cli/native_assets_cli.dart'; import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { - await build(arguments, (config, output) async { - final packageName = config.packageName; + await build(arguments, (input, output) async { + final packageName = input.packageName; final cbuilder = CBuilder.library( name: packageName, assetName: 'src/${packageName}_bindings_generated.dart', @@ -18,7 +18,7 @@ void main(List arguments) async { ], ); await cbuilder.run( - config: config, + input: input, output: output, logger: Logger('') ..level = Level.ALL diff --git a/pkgs/native_assets_cli/example/link/package_with_assets/hook/build.dart b/pkgs/native_assets_cli/example/link/package_with_assets/hook/build.dart index 5a508c4c0..9ed8be59a 100644 --- a/pkgs/native_assets_cli/example/link/package_with_assets/hook/build.dart +++ b/pkgs/native_assets_cli/example/link/package_with_assets/hook/build.dart @@ -7,10 +7,10 @@ import 'dart:io'; import 'package:native_assets_cli/data_assets.dart'; void main(List args) async { - await build(args, (config, output) async { - final packageName = config.packageName; + await build(args, (input, output) async { + final packageName = input.packageName; final assetDirectory = - Directory.fromUri(config.packageRoot.resolve('assets/')); + Directory.fromUri(input.packageRoot.resolve('assets/')); // If assets are added, rerun hook. output.addDependency(assetDirectory.uri); @@ -22,15 +22,15 @@ void main(List args) async { // The file path relative to the package root, with forward slashes. final name = dataAsset.uri .toFilePath(windows: false) - .substring(config.packageRoot.toFilePath(windows: false).length); + .substring(input.packageRoot.toFilePath(windows: false).length); - output.dataAssets.add( + output.assets.data.add( DataAsset( package: packageName, name: name, file: dataAsset.uri, ), - linkInPackage: config.linkingEnabled ? packageName : null, + linkInPackage: input.config.linkingEnabled ? packageName : null, ); // TODO(https://github.com/dart-lang/native/issues/1208): Report // dependency on asset. diff --git a/pkgs/native_assets_cli/example/link/package_with_assets/hook/link.dart b/pkgs/native_assets_cli/example/link/package_with_assets/hook/link.dart index 403d0f15b..e44738b46 100644 --- a/pkgs/native_assets_cli/example/link/package_with_assets/hook/link.dart +++ b/pkgs/native_assets_cli/example/link/package_with_assets/hook/link.dart @@ -14,18 +14,18 @@ const multiplyIdentifier = Identifier( ); void main(List args) async { - await link(args, (config, output) async { - final usages = config.usages; + await link(args, (input, output) async { + final usages = input.usages; final usedAssets = (usages.instancesOf(multiplyIdentifier) ?? []).map((e) => (e.instanceConstant.fields.values.first as StringConstant).value); - output.dataAssets.addAll(config.dataAssets + output.assets.data.addAll(input.assets.data .where((dataAsset) => usedAssets.contains(dataAsset.name))); }); } -extension on LinkConfig { +extension on LinkInput { RecordedUsages get usages { final usagesFile = recordedUsagesFile; final usagesContent = File.fromUri(usagesFile!).readAsStringSync(); diff --git a/pkgs/native_assets_cli/lib/code_assets.dart b/pkgs/native_assets_cli/lib/code_assets.dart index f173dad88..c2558a2ad 100644 --- a/pkgs/native_assets_cli/lib/code_assets.dart +++ b/pkgs/native_assets_cli/lib/code_assets.dart @@ -16,10 +16,10 @@ export 'src/code_assets/code_asset.dart' show CodeAsset, OSLibraryNaming; export 'src/code_assets/config.dart' show AndroidConfig, - CodeAssetBuildConfig, CodeAssetBuildOutputBuilder, CodeAssetBuildOutputBuilderAdd, - CodeAssetLinkConfig, + CodeAssetHookConfig, + CodeAssetLinkInput, CodeAssetLinkOutputBuilder, CodeAssetLinkOutputBuilderAdd, CodeConfig, diff --git a/pkgs/native_assets_cli/lib/code_assets_builder.dart b/pkgs/native_assets_cli/lib/code_assets_builder.dart index 38c5fe668..7ea57f334 100644 --- a/pkgs/native_assets_cli/lib/code_assets_builder.dart +++ b/pkgs/native_assets_cli/lib/code_assets_builder.dart @@ -9,11 +9,11 @@ export 'code_assets.dart' hide build, link; export 'native_assets_cli_builder.dart' hide EncodedAssetBuildOutputBuilder, EncodedAssetLinkOutputBuilder; export 'src/code_assets/config.dart' - show CodeAssetBuildConfigBuilder, CodeAssetBuildOutput, CodeAssetLinkOutput; + show CodeAssetBuildInputBuilder, CodeAssetBuildOutput, CodeAssetLinkOutput; export 'src/code_assets/validation.dart' show - validateCodeAssetBuildConfig, + validateCodeAssetBuildInput, validateCodeAssetBuildOutput, validateCodeAssetInApplication, - validateCodeAssetLinkConfig, + validateCodeAssetLinkInput, validateCodeAssetLinkOutput; diff --git a/pkgs/native_assets_cli/lib/data_assets.dart b/pkgs/native_assets_cli/lib/data_assets.dart index a2abce48b..8c9b3f7f9 100644 --- a/pkgs/native_assets_cli/lib/data_assets.dart +++ b/pkgs/native_assets_cli/lib/data_assets.dart @@ -14,7 +14,7 @@ export 'src/data_assets/config.dart' show DataAssetBuildOutputBuilder, DataAssetBuildOutputBuilderAdd, - DataAssetLinkConfig, + DataAssetLinkInput, DataAssetLinkOutputBuilder, DataAssetLinkOutputBuilderAdd; export 'src/data_assets/data_asset.dart' show DataAsset; diff --git a/pkgs/native_assets_cli/lib/data_assets_builder.dart b/pkgs/native_assets_cli/lib/data_assets_builder.dart index fe9d43a79..dd4651dcf 100644 --- a/pkgs/native_assets_cli/lib/data_assets_builder.dart +++ b/pkgs/native_assets_cli/lib/data_assets_builder.dart @@ -9,10 +9,10 @@ export 'data_assets.dart' hide build, link; export 'native_assets_cli_builder.dart' hide EncodedAssetBuildOutputBuilder, EncodedAssetLinkOutputBuilder; export 'src/data_assets/config.dart' - show DataAssetBuildOutput, DataAssetLinkOutput; + show DataAssetBuildInputBuilder, DataAssetBuildOutput, DataAssetLinkOutput; export 'src/data_assets/validation.dart' show - validateDataAssetBuildConfig, + validateDataAssetBuildInput, validateDataAssetBuildOutput, - validateDataAssetLinkConfig, + validateDataAssetLinkInput, validateDataAssetLinkOutput; diff --git a/pkgs/native_assets_cli/lib/native_assets_cli.dart b/pkgs/native_assets_cli/lib/native_assets_cli.dart index be4d880a3..4c4a0cb83 100644 --- a/pkgs/native_assets_cli/lib/native_assets_cli.dart +++ b/pkgs/native_assets_cli/lib/native_assets_cli.dart @@ -12,12 +12,12 @@ export 'src/api/link.dart' show link; export 'src/api/linker.dart' show Linker; export 'src/config.dart' show - BuildConfig, + BuildInput, BuildOutputBuilder, EncodedAssetBuildOutputBuilder, EncodedAssetLinkOutputBuilder, - HookConfig, - LinkConfig, + HookInput, + LinkInput, LinkOutputBuilder; export 'src/encoded_asset.dart' show EncodedAsset; export 'src/metadata.dart'; diff --git a/pkgs/native_assets_cli/lib/native_assets_cli_builder.dart b/pkgs/native_assets_cli/lib/native_assets_cli_builder.dart index 2d164ecd8..d556e9f3f 100644 --- a/pkgs/native_assets_cli/lib/native_assets_cli_builder.dart +++ b/pkgs/native_assets_cli/lib/native_assets_cli_builder.dart @@ -8,11 +8,12 @@ library; export 'native_assets_cli.dart' hide build, link; export 'src/config.dart' show - BuildConfigBuilder, + BuildConfigBuilderSetup, + BuildInputBuilder, BuildOutput, - HookConfigBuilder, + HookInputBuilder, HookOutput, - LinkConfigBuilder, + LinkInputBuilder, LinkOutput; export 'src/model/dependencies.dart'; export 'src/model/resource_identifiers.dart'; @@ -20,7 +21,7 @@ export 'src/target.dart' show Target; export 'src/validation.dart' show ValidationErrors, - validateBuildConfig, + validateBuildInput, validateBuildOutput, - validateLinkConfig, + validateLinkInput, validateLinkOutput; diff --git a/pkgs/native_assets_cli/lib/src/api/build.dart b/pkgs/native_assets_cli/lib/src/api/build.dart index cd7cc063f..7bab01fc8 100644 --- a/pkgs/native_assets_cli/lib/src/api/build.dart +++ b/pkgs/native_assets_cli/lib/src/api/build.dart @@ -24,8 +24,8 @@ import '../validation.dart'; /// import 'package:native_toolchain_c/native_toolchain_c.dart'; /// /// void main(List args) async { -/// await build(args, (config, output) async { -/// final packageName = config.packageName; +/// await build(args, (input, output) async { +/// final packageName = input.packageName; /// final cbuilder = CBuilder.library( /// name: packageName, /// assetName: '$packageName.dart', @@ -34,7 +34,7 @@ import '../validation.dart'; /// ], /// ); /// await cbuilder.run( -/// config: config, +/// input: input, /// output: output, /// logger: Logger('') /// ..level = Level.ALL @@ -55,18 +55,19 @@ import '../validation.dart'; /// final packageAssetPath = Uri.file('data/$assetName'); /// /// void main(List args) async { -/// await build(args, (config, output) async { -/// if (config.codeConfig.linkModePreference == LinkModePreference.static) { +/// await build(args, (input, output) async { +/// if (input.config.code.linkModePreference == +/// LinkModePreference.static) { /// // Simulate that this hook only supports dynamic libraries. /// throw UnsupportedError( /// 'LinkModePreference.static is not supported.', /// ); /// } /// -/// final packageName = config.packageName; -/// final assetPath = config.outputDirectory.resolve(assetName); -/// final assetSourcePath = config.packageRoot.resolveUri(packageAssetPath); -/// if (!config.dryRun) { +/// final packageName = input.packageName; +/// final assetPath = input.outputDirectory.resolve(assetName); +/// final assetSourcePath = input.packageRoot.resolveUri(packageAssetPath); +/// if (!input.dryRun) { /// // Insert code that downloads or builds the asset to `assetPath`. /// await File.fromUri(assetSourcePath).copy(assetPath.toFilePath()); /// @@ -75,15 +76,15 @@ import '../validation.dart'; /// ]); /// } /// -/// output.codeAssets.add( +/// output.assets.code.add( /// // TODO: Change to DataAsset once the Dart/Flutter SDK can consume it. /// CodeAsset( /// package: packageName, /// name: 'asset.txt', /// file: assetPath, /// linkMode: DynamicLoadingBundled(), -/// os: config.codeConfig.targetOS, -/// architecture: config.codeConfig.targetArchitecture, +/// os: input.config.code.targetOS, +/// architecture: input.config.code.targetArchitecture, /// ), /// ); /// }); @@ -96,21 +97,20 @@ import '../validation.dart'; /// exit code. Future build( List arguments, - Future Function(BuildConfig config, BuildOutputBuilder output) builder, + Future Function(BuildInput input, BuildOutputBuilder output) builder, ) async { - final configPath = getConfigArgument(arguments); - final bytes = File(configPath).readAsBytesSync(); - final jsonConfig = const Utf8Decoder() - .fuse(const JsonDecoder()) - .convert(bytes) as Map; - final config = BuildConfig(jsonConfig); + final inputPath = getInputArgument(arguments); + final bytes = File(inputPath).readAsBytesSync(); + final jsonInput = const Utf8Decoder().fuse(const JsonDecoder()).convert(bytes) + as Map; + final input = BuildInput(jsonInput); final output = BuildOutputBuilder(); - await builder(config, output); - final errors = await validateBuildOutput(config, BuildOutput(output.json)); + await builder(input, output); + final errors = await validateBuildOutput(input, BuildOutput(output.json)); if (errors.isEmpty) { final jsonOutput = const JsonEncoder().fuse(const Utf8Encoder()).convert(output.json); - await File.fromUri(config.outputDirectory.resolve('build_output.json')) + await File.fromUri(input.outputDirectory.resolve('build_output.json')) .writeAsBytes(jsonOutput); } else { final message = [ diff --git a/pkgs/native_assets_cli/lib/src/api/builder.dart b/pkgs/native_assets_cli/lib/src/api/builder.dart index 40c543c4d..e71b69845 100644 --- a/pkgs/native_assets_cli/lib/src/api/builder.dart +++ b/pkgs/native_assets_cli/lib/src/api/builder.dart @@ -28,8 +28,8 @@ import 'linker.dart'; /// import 'package:native_toolchain_c/native_toolchain_c.dart'; /// /// void main(List args) async { -/// await build(args, (config, output) async { -/// final packageName = config.packageName; +/// await build(args, (input, output) async { +/// final packageName = input.packageName; /// final cbuilder = CBuilder.library( /// name: packageName, /// assetName: '$packageName.dart', @@ -38,7 +38,7 @@ import 'linker.dart'; /// ], /// ); /// await cbuilder.run( -/// buildConfig: config, +/// buildInput: input, /// buildOutput: output, /// logger: Logger('') /// ..level = Level.ALL @@ -50,10 +50,10 @@ import 'linker.dart'; abstract interface class Builder { /// Runs this build. /// - /// Reads the config from [config], streams output to [output], and streams + /// Reads the input from [input], streams output to [output], and streams /// logs to [logger]. Future run({ - required BuildConfig config, + required BuildInput input, required BuildOutputBuilder output, required Logger? logger, }); diff --git a/pkgs/native_assets_cli/lib/src/api/link.dart b/pkgs/native_assets_cli/lib/src/api/link.dart index fe3d445bf..6e7e45852 100644 --- a/pkgs/native_assets_cli/lib/src/api/link.dart +++ b/pkgs/native_assets_cli/lib/src/api/link.dart @@ -17,16 +17,16 @@ import '../validation.dart'; /// files. Each individual asset is assigned a unique asset ID. /// /// The linking script may receive assets from build scripts, which are accessed -/// through [LinkConfig.encodedAssets]. They will only be bundled with the final -/// application if included in the [LinkOutput]. +/// through [LinkInputAssets.encodedAssets]. They will only be bundled with the +/// final application if included in the [LinkOutput]. /// /// /// ```dart /// import 'package:native_assets_cli/native_assets_cli.dart'; /// /// void main(List args) async { -/// await link(args, (config, output) async { -/// final dataEncodedAssets = config.assets +/// await link(args, (input, output) async { +/// final dataEncodedAssets = input.assets /// .whereType(); /// output.addEncodedAssets(dataEncodedAssets); /// }); @@ -38,21 +38,20 @@ import '../validation.dart'; /// exit code. Future link( List arguments, - Future Function(LinkConfig config, LinkOutputBuilder output) linker, + Future Function(LinkInput input, LinkOutputBuilder output) linker, ) async { - final configPath = getConfigArgument(arguments); - final bytes = File(configPath).readAsBytesSync(); - final jsonConfig = const Utf8Decoder() - .fuse(const JsonDecoder()) - .convert(bytes) as Map; - final config = LinkConfig(jsonConfig); + final inputPath = getInputArgument(arguments); + final bytes = File(inputPath).readAsBytesSync(); + final jsonInput = const Utf8Decoder().fuse(const JsonDecoder()).convert(bytes) + as Map; + final input = LinkInput(jsonInput); final output = LinkOutputBuilder(); - await linker(config, output); - final errors = await validateLinkOutput(config, LinkOutput(output.json)); + await linker(input, output); + final errors = await validateLinkOutput(input, LinkOutput(output.json)); if (errors.isEmpty) { final jsonOutput = const JsonEncoder().fuse(const Utf8Encoder()).convert(output.json); - await File.fromUri(config.outputDirectory.resolve('link_output.json')) + await File.fromUri(input.outputDirectory.resolve('link_output.json')) .writeAsBytes(jsonOutput); } else { final message = [ diff --git a/pkgs/native_assets_cli/lib/src/api/linker.dart b/pkgs/native_assets_cli/lib/src/api/linker.dart index a6e034cd0..8b46339ee 100644 --- a/pkgs/native_assets_cli/lib/src/api/linker.dart +++ b/pkgs/native_assets_cli/lib/src/api/linker.dart @@ -13,15 +13,15 @@ import 'builder.dart'; /// information. [Linker]s have access to tree-shaking information in some build /// modes. However, due to the tree-shaking information being an input to link /// hooks, link hooks are re-run more often than [Builder]s. A link hook is -/// rerun when its declared [BuildOutput.dependencies] or its [LinkConfig] tree +/// rerun when its declared [BuildOutput.dependencies] or its [LinkInput] tree /// shaking information changes. /// /// A package to be used in link hooks should implement this interface. The /// typical pattern of link hooks should be a declarative specification of one /// or more linkers (constructor calls), followed by [run]ning these linkers. /// -/// The linker is designed to immediately operate on [LinkConfig]. If a linker -/// should deviate behavior from the build config, this should be configurable +/// The linker is designed to immediately operate on [LinkInput]. If a linker +/// should deviate behavior from the build input, this should be configurable /// through a constructor parameter. /// /// The linker is designed to immediately operate on [LinkOutput]. If a linker @@ -32,10 +32,10 @@ import 'builder.dart'; abstract interface class Linker { /// Runs this linker. /// - /// Reads the config from [config], streams output to [output], and streams + /// Reads the input from [input], streams output to [output], and streams /// logs to [logger]. Future run({ - required LinkConfig config, + required LinkInput input, required LinkOutputBuilder output, required Logger? logger, }); diff --git a/pkgs/native_assets_cli/lib/src/args_parser.dart b/pkgs/native_assets_cli/lib/src/args_parser.dart index 942b3a6d4..320fce73b 100644 --- a/pkgs/native_assets_cli/lib/src/args_parser.dart +++ b/pkgs/native_assets_cli/lib/src/args_parser.dart @@ -2,7 +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. -String getConfigArgument(List arguments) { +String getInputArgument(List arguments) { for (var i = 0; i < arguments.length; ++i) { final argument = arguments[i]; if (argument.startsWith('--config=')) { diff --git a/pkgs/native_assets_cli/lib/src/code_assets/config.dart b/pkgs/native_assets_cli/lib/src/code_assets/config.dart index 6d0e5194f..f7a790439 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/config.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/config.dart @@ -11,20 +11,19 @@ import 'ios_sdk.dart'; import 'link_mode_preference.dart'; import 'os.dart'; -/// Extension to the [BuildConfig] providing access to configuration specific to -/// code assets (only available if code assets are supported). -extension CodeAssetBuildConfig on BuildConfig { +/// Extension to the [HookConfig] providing access to configuration specific +/// to code assets (only available if code assets are supported). +extension CodeAssetHookConfig on HookConfig { /// Code asset specific configuration. - CodeConfig get codeConfig => CodeConfig.fromJson(json); + CodeConfig get code => CodeConfig.fromJson(json); + + bool get buildCodeAssets => buildAssetTypes.contains(CodeAsset.type); } -/// Extension to the [LinkConfig] providing access to configuration specific to +/// Extension to the [LinkInput] providing access to configuration specific to /// code assets as well as code asset inputs to the linker (only available if /// code assets are supported). -extension CodeAssetLinkConfig on LinkConfig { - /// Code asset specific configuration. - CodeConfig get codeConfig => CodeConfig.fromJson(json); - +extension CodeAssetLinkInput on LinkInputAssets { // Returns the code assets that were sent to this linker. // // NOTE: If the linker implementation depends on the contents of the files the @@ -32,7 +31,7 @@ extension CodeAssetLinkConfig on LinkConfig { // linker script has to add those files as dependencies via // [LinkOutput.addDependency] to ensure the linker script will be re-run if // the content of the files changes. - Iterable get codeAssets => encodedAssets + Iterable get code => encodedAssets .where((e) => e.type == CodeAsset.type) .map(CodeAsset.fromEncoded); } @@ -109,7 +108,7 @@ class CodeConfig { } /// Configuration provided when [CodeConfig.targetOS] is [OS.macOS]. - IOSConfig get iOSConfig => switch (_iOSConfig) { + IOSConfig get iOS => switch (_iOSConfig) { null => throw StateError('Cannot access iOSConfig if targetOS is not iOS' ' or in dry runs.'), @@ -117,7 +116,7 @@ class CodeConfig { }; /// Configuration provided when [CodeConfig.targetOS] is [OS.android]. - AndroidConfig get androidConfig => switch (_androidConfig) { + AndroidConfig get android => switch (_androidConfig) { null => throw StateError( 'Cannot access androidConfig if targetOS is not android' ' or in dry runs.'), @@ -125,7 +124,7 @@ class CodeConfig { }; /// Configuration provided when [CodeConfig.targetOS] is [OS.macOS]. - MacOSConfig get macOSConfig => switch (_macOSConfig) { + MacOSConfig get macOS => switch (_macOSConfig) { null => throw StateError('Cannot access macOSConfig if targetOS is not MacOS' ' or in dry runs.'), @@ -205,14 +204,15 @@ extension MacOSConfigSyntactic on MacOSConfig { /// Extension to the [BuildOutputBuilder] providing access to emitting code /// assets (only available if code assets are supported). -extension CodeAssetBuildOutputBuilder on BuildOutputBuilder { +extension CodeAssetBuildOutputBuilder on EncodedAssetBuildOutputBuilder { /// Provides access to emitting code assets. - CodeAssetBuildOutputBuilderAdd get codeAssets => + CodeAssetBuildOutputBuilderAdd get code => CodeAssetBuildOutputBuilderAdd._(this); } /// Supports emitting code assets for build hooks. -extension type CodeAssetBuildOutputBuilderAdd._(BuildOutputBuilder _output) { +extension type CodeAssetBuildOutputBuilderAdd._( + EncodedAssetBuildOutputBuilder _output) { /// Adds the given [asset] to the hook output (or send to [linkInPackage] /// for linking if provided). void add(CodeAsset asset, {String? linkInPackage}) => @@ -229,14 +229,15 @@ extension type CodeAssetBuildOutputBuilderAdd._(BuildOutputBuilder _output) { /// Extension to the [LinkOutputBuilder] providing access to emitting code /// assets (only available if code assets are supported). -extension CodeAssetLinkOutputBuilder on LinkOutputBuilder { +extension CodeAssetLinkOutputBuilder on EncodedAssetLinkOutputBuilder { /// Provides access to emitting code assets. - CodeAssetLinkOutputBuilderAdd get codeAssets => + CodeAssetLinkOutputBuilderAdd get code => CodeAssetLinkOutputBuilderAdd._(this); } /// Extension on [LinkOutputBuilder] to emit code assets. -extension type CodeAssetLinkOutputBuilderAdd._(LinkOutputBuilder _output) { +extension type CodeAssetLinkOutputBuilderAdd._( + EncodedAssetLinkOutputBuilder _output) { /// Adds the given [asset] to the link hook output. void add(CodeAsset asset) => _output.addEncodedAsset(asset.encode()); @@ -244,52 +245,52 @@ extension type CodeAssetLinkOutputBuilderAdd._(LinkOutputBuilder _output) { void addAll(Iterable assets) => assets.forEach(add); } -/// Extension to initialize code specific configuration on link/build configs. -extension CodeAssetBuildConfigBuilder on HookConfigBuilder { - void setupCodeConfig({ +/// Extension to initialize code specific configuration on link/build inputs. +extension CodeAssetBuildInputBuilder on HookConfigBuilder { + void setupCode({ required Architecture? targetArchitecture, required OS targetOS, required LinkModePreference linkModePreference, - CCompilerConfig? cCompilerConfig, - AndroidConfig? androidConfig, - IOSConfig? iOSConfig, - MacOSConfig? macOSConfig, + CCompilerConfig? cCompiler, + AndroidConfig? android, + IOSConfig? iOS, + MacOSConfig? macOS, }) { if (targetArchitecture != null) { json[_targetArchitectureKey] = targetArchitecture.toString(); } json[_targetOSConfigKey] = targetOS.toString(); json[_linkModePreferenceKey] = linkModePreference.toString(); - if (cCompilerConfig != null) { - json[_compilerKey] = cCompilerConfig.toJson(); + if (cCompiler != null) { + json[_compilerKey] = cCompiler.toJson(); } // Note, using ?. instead of !. makes missing data be a semantic error // rather than a syntactic error to be caught in the validation. if (targetOS == OS.android) { - json[_targetAndroidNdkApiKey] = androidConfig?.targetNdkApi; + json[_targetAndroidNdkApiKey] = android?.targetNdkApi; } else if (targetOS == OS.iOS) { - json[_targetIOSSdkKey] = iOSConfig?.targetSdk.toString(); - json[_targetIOSVersionKey] = iOSConfig?.targetVersion; + json[_targetIOSSdkKey] = iOS?.targetSdk.toString(); + json[_targetIOSVersionKey] = iOS?.targetVersion; } else if (targetOS == OS.macOS) { - json[_targetMacOSVersionKey] = macOSConfig?.targetVersion; + json[_targetMacOSVersionKey] = macOS?.targetVersion; } } } /// Provides access to [CodeAsset]s from a build hook output. -extension CodeAssetBuildOutput on BuildOutput { +extension CodeAssetBuildOutput on BuildOutputAssets { /// The code assets emitted by the build hook. - List get codeAssets => encodedAssets + List get code => encodedAssets .where((asset) => asset.type == CodeAsset.type) .map(CodeAsset.fromEncoded) .toList(); } /// Provides access to [CodeAsset]s from a link hook output. -extension CodeAssetLinkOutput on LinkOutput { +extension CodeAssetLinkOutput on LinkOutputAssets { /// The code assets emitted by the link hook. - List get codeAssets => encodedAssets + List get code => encodedAssets .where((asset) => asset.type == CodeAsset.type) .map(CodeAsset.fromEncoded) .toList(); diff --git a/pkgs/native_assets_cli/lib/src/code_assets/testing.dart b/pkgs/native_assets_cli/lib/src/code_assets/testing.dart index 0ad67ba96..af357e585 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/testing.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/testing.dart @@ -23,7 +23,7 @@ import '../validation.dart'; Future testCodeBuildHook({ // ignore: inference_failure_on_function_return_type required Function(List arguments) mainMethod, - required FutureOr Function(BuildConfig, BuildOutput) check, + required FutureOr Function(BuildInput, BuildOutput) check, Architecture? targetArchitecture, OS? targetOS, IOSSdk? targetIOSSdk, @@ -32,42 +32,41 @@ Future testCodeBuildHook({ int? targetAndroidNdkApi, CCompilerConfig? cCompiler, LinkModePreference? linkModePreference, - required List buildAssetTypes, bool? linkingEnabled, }) async { await testBuildHook( mainMethod: mainMethod, - extraConfigSetup: (config) { - config.setupCodeConfig( + extraInputSetup: (input) { + input.config.setupShared(buildAssetTypes: [CodeAsset.type]); + input.config.setupCode( linkModePreference: linkModePreference ?? LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, targetArchitecture: targetArchitecture ?? Architecture.current, targetOS: targetOS ?? OS.current, - iOSConfig: targetOS == OS.iOS + iOS: targetOS == OS.iOS ? IOSConfig( targetSdk: targetIOSSdk!, targetVersion: targetIOSVersion!, ) : null, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: targetMacOSVersion!) : null, - androidConfig: targetOS == OS.android + android: targetOS == OS.android ? AndroidConfig(targetNdkApi: targetAndroidNdkApi!) : null, ); }, - check: (config, output) async { + check: (input, output) async { final validationErrors = - await validateCodeAssetBuildOutput(config, output); + await validateCodeAssetBuildOutput(input, output); if (validationErrors.isNotEmpty) { throw ValidationFailure( 'encountered build output validation issues: $validationErrors'); } - await check(config, output); + await check(input, output); }, - buildAssetTypes: buildAssetTypes, linkingEnabled: linkingEnabled, ); } diff --git a/pkgs/native_assets_cli/lib/src/code_assets/validation.dart b/pkgs/native_assets_cli/lib/src/code_assets/validation.dart index fb9c1ad1d..03825d0c9 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/validation.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/validation.dart @@ -8,24 +8,23 @@ import '../../code_assets_builder.dart'; import 'config.dart'; import 'link_mode.dart'; -Future validateCodeAssetBuildConfig( - BuildConfig config) async => +Future validateCodeAssetBuildInput(BuildInput input) async => _validateCodeConfig( - 'BuildConfig', + 'BuildInput', // ignore: deprecated_member_use_from_same_package - config.dryRun, - config.codeConfig, + input.config.dryRun, + input.config.code, ); -Future validateCodeAssetLinkConfig(LinkConfig config) async => +Future validateCodeAssetLinkInput(LinkInput input) async => _validateCodeConfig( - 'LinkConfig', + 'LinkInput', false, - config.codeConfig, + input.config.code, ); ValidationErrors _validateCodeConfig( - String configName, + String inputName, bool dryRun, CodeConfig codeConfig, ) { @@ -36,25 +35,25 @@ ValidationErrors _validateCodeConfig( final targetOS = codeConfig.targetOS; switch (targetOS) { case OS.macOS: - if (codeConfig.macOSConfig.targetVersionSyntactic == null) { - errors.add('$configName.targetOS is OS.macOS but ' - '$configName.codeConfig.macOSConfig.targetVersion was missing'); + if (codeConfig.macOS.targetVersionSyntactic == null) { + errors.add('$inputName.config.code.targetOS is OS.macOS but ' + '$inputName.config.code.macOS.targetVersion was missing'); } break; case OS.iOS: - if (codeConfig.iOSConfig.targetSdkSyntactic == null) { - errors.add('$configName.targetOS is OS.iOS but ' - '$configName.codeConfig.targetIOSSdk was missing'); + if (codeConfig.iOS.targetSdkSyntactic == null) { + errors.add('$inputName.config.code.targetOS is OS.iOS but ' + '$inputName.config.code.iOS.targetSdk was missing'); } - if (codeConfig.iOSConfig.targetVersionSyntactic == null) { - errors.add('$configName.targetOS is OS.iOS but ' - '$configName.codeConfig.iOSConfig.targetVersion was missing'); + if (codeConfig.iOS.targetVersionSyntactic == null) { + errors.add('$inputName.config.code.targetOS is OS.iOS but ' + '$inputName.config.code.iOS.targetVersion was missing'); } break; case OS.android: - if (codeConfig.androidConfig.targetNdkApiSyntactic == null) { - errors.add('$configName.targetOS is OS.android but ' - '$configName.codeConfig.androidConfig.targetNdkApi was missing'); + if (codeConfig.android.targetNdkApiSyntactic == null) { + errors.add('$inputName.config.code.targetOS is OS.android but ' + '$inputName.config.code.android.targetNdkApi was missing'); } break; } @@ -62,45 +61,49 @@ ValidationErrors _validateCodeConfig( if (compilerConfig != null) { final compiler = compilerConfig.compiler.toFilePath(); if (!File(compiler).existsSync()) { - errors.add('$configName.codeConfig.compiler ($compiler) does not exist.'); + errors.add('$inputName.config.code.compiler ($compiler) does' + ' not exist.'); } final linker = compilerConfig.linker.toFilePath(); if (!File(linker).existsSync()) { - errors.add('$configName.codeConfig.linker ($linker) does not exist.'); + errors.add( + '$inputName.config.code.linker ($linker) does not exist.', + ); } final archiver = compilerConfig.archiver.toFilePath(); if (!File(archiver).existsSync()) { - errors.add('$configName.codeConfig.archiver ($archiver) does not exist.'); + errors.add('$inputName.config.code.archiver ($archiver) does' + ' not exist.'); } final envScript = compilerConfig.envScript?.toFilePath(); if (envScript != null && !File(envScript).existsSync()) { - errors - .add('$configName.codeConfig.envScript ($envScript) does not exist.'); + errors.add('$inputName.config.code.envScript ($envScript) does' + ' not exist.'); } } return errors; } Future validateCodeAssetBuildOutput( - BuildConfig config, + BuildInput input, BuildOutput output, ) => _validateCodeAssetBuildOrLinkOutput( - config, - config.codeConfig, - output.encodedAssets, + input, + input.config.code, + output.assets.encodedAssets, // ignore: deprecated_member_use_from_same_package - config.dryRun, + input.config.dryRun, output, true, ); Future validateCodeAssetLinkOutput( - LinkConfig config, + LinkInput input, LinkOutput output, ) => - _validateCodeAssetBuildOrLinkOutput( - config, config.codeConfig, output.encodedAssets, false, output, false); + _validateCodeAssetBuildOrLinkOutput(input, input.config.code, + output.assets.encodedAssets, false, output, false); /// Validates that the given code assets can be used together in an application. /// @@ -121,7 +124,7 @@ Future validateCodeAssetInApplication( } Future _validateCodeAssetBuildOrLinkOutput( - HookConfig config, + HookInput input, CodeConfig codeConfig, List encodedAssets, bool dryRun, @@ -135,7 +138,7 @@ Future _validateCodeAssetBuildOrLinkOutput( for (final asset in encodedAssets) { if (asset.type != CodeAsset.type) continue; _validateCodeAssets( - config, + input, codeConfig, dryRun, CodeAsset.fromEncoded(asset), @@ -151,7 +154,7 @@ Future _validateCodeAssetBuildOrLinkOutput( } void _validateCodeAssets( - HookConfig config, + HookInput input, CodeConfig codeConfig, bool dryRun, CodeAsset codeAsset, @@ -160,7 +163,7 @@ void _validateCodeAssets( bool isBuild, ) { final id = codeAsset.id; - final prefix = 'package:${config.packageName}/'; + final prefix = 'package:${input.packageName}/'; if (isBuild && !id.startsWith(prefix)) { errors.add('Code asset "$id" does not start with "$prefix".'); } @@ -173,7 +176,7 @@ void _validateCodeAssets( if ((linkMode is DynamicLoading && preference == LinkModePreference.static) || (linkMode is StaticLinking && preference == LinkModePreference.dynamic)) { errors.add('CodeAsset "$id" has a link mode "$linkMode", which ' - 'is not allowed by by the config link mode preference ' + 'is not allowed by by the input link mode preference ' '"$preference".'); } diff --git a/pkgs/native_assets_cli/lib/src/config.dart b/pkgs/native_assets_cli/lib/src/config.dart index 41a7b6416..a9ec3324d 100644 --- a/pkgs/native_assets_cli/lib/src/config.dart +++ b/pkgs/native_assets_cli/lib/src/config.dart @@ -17,21 +17,21 @@ import 'metadata.dart'; import 'utils/datetime.dart'; import 'utils/json.dart'; -/// The shared properties of a [LinkConfig] and a [BuildConfig]. +/// The shared properties of a [LinkInput] and a [BuildInput]. /// /// This abstraction makes it easier to design APIs intended for both kinds of /// build hooks, building and linking. -sealed class HookConfig { - /// The underlying json configuration of this [HookConfig]. +sealed class HookInput { + /// The underlying json configuration of this [HookInput]. final Map json; - /// The version of the [HookConfig]. + /// The version of the [HookInput]. final Version version; /// The directory in which output and intermediate artifacts that are unique - /// to this configuration can be placed. + /// to the [config] can be placed. /// - /// This directory is unique per hook and per configuration. + /// This directory is unique per hook and per [config]. /// /// The contents of this directory will not be modified by anything else than /// the hook itself. @@ -61,10 +61,7 @@ sealed class HookConfig { /// another. For this it is convenient to know the packageRoot. final Uri packageRoot; - /// The asset types that the invoker of this hook supports. - final List buildAssetTypes; - - HookConfig(this.json) + HookInput(this.json) : version = switch (Version.parse(json.string(_versionKey))) { final Version version => (version.major != latestVersion.major || version < latestParsableVersion) @@ -73,50 +70,49 @@ sealed class HookConfig { '(was: $version).') : version, }, - outputDirectory = json.path(_outDirConfigKey), - outputDirectoryShared = json.path(_outDirSharedConfigKey), - packageRoot = json.path(_packageRootConfigKey), - packageName = json.string(_packageNameConfigKey), - buildAssetTypes = json.optionalStringList(_buildAssetTypesKey) ?? - json.optionalStringList(_supportedAssetTypesKey) ?? - const []; + outputDirectory = json.path(_outDirInputKey), + outputDirectoryShared = json.path(_outDirSharedInputKey), + packageRoot = json.path(_packageRootInputKey), + packageName = json.string(_packageNameInputKey); @override String toString() => const JsonEncoder.withIndent(' ').convert(json); + + HookConfig get config => HookConfig(json); } -sealed class HookConfigBuilder { +sealed class HookInputBuilder { final Map json = { 'version': latestVersion.toString(), }; - void setupHookConfig({ + void setupShared({ required Uri packageRoot, required String packageName, - required List buildAssetTypes, + required Uri outputDirectory, + required Uri outputDirectoryShared, }) { - json[_packageNameConfigKey] = packageName; - json[_packageRootConfigKey] = packageRoot.toFilePath(); - json[_buildAssetTypesKey] = buildAssetTypes; - json[_supportedAssetTypesKey] = buildAssetTypes; + json[_packageNameInputKey] = packageName; + json[_packageRootInputKey] = packageRoot.toFilePath(); + json[_outDirInputKey] = outputDirectory.toFilePath(); + json[_outDirSharedInputKey] = outputDirectoryShared.toFilePath(); } - /// Constructs a checksum for a [BuildConfig]. + /// Constructs a checksum for a [BuildInput]. /// /// This can be used to construct an output directory name specific to the - /// [BuildConfig] being built with this [BuildConfigBuilder]. It is therefore + /// [BuildInput] being built with this [BuildInputBuilder]. It is therefore /// assumed the output directory has not been set yet. String computeChecksum() { - if (json.containsKey(_outDirConfigKey) || - json.containsKey(_outDirSharedConfigKey) || + if (json.containsKey(_outDirInputKey) || + json.containsKey(_outDirSharedInputKey) || json.containsKey(_assetsKey)) { // The bundling tools would first calculate the checksum, create an output - // directory and then call [BuildConfigBuilder.setupBuildRunConfig] & - // [LinkConfigBuilder.setupLinkRunConfig]. + // directory and then call [setupHookInput]. // The output directory should not depend on the assets passed in for // linking. throw StateError('The checksum should be generated before setting ' - 'up the run configuration'); + 'up the hook configuration'); } final hash = sha256 .convert(const JsonEncoder().fuse(const Utf8Encoder()).convert(json)) @@ -127,37 +123,25 @@ sealed class HookConfigBuilder { .substring(0, 32); return hash; } + + HookConfigBuilder get config => HookConfigBuilder._(this); } // TODO: Bump min-SDK constraint to 3.7 and remove once stable. -const _buildModeConfigKeyDeprecated = 'build_mode'; +const _buildModeInputKeyDeprecated = 'build_mode'; const _metadataConfigKey = 'metadata'; -const _outDirConfigKey = 'out_dir'; -const _outDirSharedConfigKey = 'out_dir_shared'; -const _packageNameConfigKey = 'package_name'; -const _packageRootConfigKey = 'package_root'; +const _outDirInputKey = 'out_dir'; +const _outDirSharedInputKey = 'out_dir_shared'; +const _packageNameInputKey = 'package_name'; +const _packageRootInputKey = 'package_root'; const _supportedAssetTypesKey = 'supported_asset_types'; const _buildAssetTypesKey = 'build_asset_types'; -final class BuildConfig extends HookConfig { - // TODO(dcharkes): Remove after 3.7.0 stable is released and bump the SDK - // constraint in the pubspec. Ditto for all uses in related packages. - /// Whether this run is a dry-run, which doesn't build anything. - /// - /// A dry-run only reports information about which assets a build would - /// create, but doesn't actually create files. - @Deprecated('Flutter will no longer invoke dry run as of 3.27.') - final bool dryRun; - - final bool linkingEnabled; - +final class BuildInput extends HookInput { final Map metadata; - BuildConfig(super.json) - // ignore: deprecated_member_use_from_same_package - : dryRun = json.getOptional(_dryRunConfigKey) ?? false, - linkingEnabled = json.get(_linkingEnabledKey), - metadata = { + BuildInput(super.json) + : metadata = { for (final entry in (json.optionalMap(_dependencyMetadataKey) ?? {}).entries) entry.key: Metadata.fromJson(as>(entry.value)), @@ -165,66 +149,88 @@ final class BuildConfig extends HookConfig { Object? metadatum(String packageName, String key) => metadata[packageName]?.metadata[key]; + + @override + BuildConfig get config => BuildConfig(json); +} + +final class BuildInputBuilder extends HookInputBuilder { + void setupBuildInput({ + Map metadata = const {}, + }) { + json[_dependencyMetadataKey] = { + for (final key in metadata.keys) key: metadata[key]!.toJson(), + }; + } + + @override + BuildConfigBuilder get config => BuildConfigBuilder._(this); +} + +final class HookConfigBuilder { + final HookInputBuilder builder; + + Map get json => builder.json; + + HookConfigBuilder._(this.builder); + + void setupShared({ + required List buildAssetTypes, + }) { + json[_buildAssetTypesKey] = buildAssetTypes; + json[_supportedAssetTypesKey] = buildAssetTypes; + } } final class BuildConfigBuilder extends HookConfigBuilder { - void setupBuildConfig({ + BuildConfigBuilder._(super.builder) : super._(); +} + +extension BuildConfigBuilderSetup on BuildConfigBuilder { + void setupBuild({ required bool dryRun, required bool linkingEnabled, - Map metadata = const {}, }) { json[_dryRunConfigKey] = dryRun; json[_linkingEnabledKey] = linkingEnabled; - json[_dependencyMetadataKey] = { - for (final key in metadata.keys) key: metadata[key]!.toJson(), - }; + // TODO: Bump min-SDK constraint to 3.7 and remove once stable. if (!dryRun) { - json[_buildModeConfigKeyDeprecated] = 'release'; + json[_buildModeInputKeyDeprecated] = 'release'; } } - - void setupBuildRunConfig({ - required Uri outputDirectory, - required Uri outputDirectoryShared, - }) { - json[_outDirConfigKey] = outputDirectory.toFilePath(); - json[_outDirSharedConfigKey] = outputDirectoryShared.toFilePath(); - } } const _dryRunConfigKey = 'dry_run'; const _linkingEnabledKey = 'linking_enabled'; -final class LinkConfig extends HookConfig { - final List encodedAssets; +final class LinkInput extends HookInput { + final List _encodedAssets; final Uri? recordedUsagesFile; - LinkConfig(super.json) - : encodedAssets = + LinkInput(super.json) + : _encodedAssets = _parseAssets(json.getOptional>(_assetsKey)), - recordedUsagesFile = json.optionalPath(_recordedUsagesFileConfigKey); + recordedUsagesFile = json.optionalPath(_recordedUsagesFileInputKey); + + LinkInputAssets get assets => LinkInputAssets._(this); +} + +extension type LinkInputAssets._(LinkInput _input) { + List get encodedAssets => _input._encodedAssets; } -final class LinkConfigBuilder extends HookConfigBuilder { - void setupLinkConfig({ +final class LinkInputBuilder extends HookInputBuilder { + void setupLink({ required List assets, + required Uri? recordedUsesFile, }) { json[_assetsKey] = [for (final asset in assets) asset.toJson()]; // TODO: Bump min-SDK constraint to 3.7 and remove once stable. - json[_buildModeConfigKeyDeprecated] = 'release'; - } - - void setupLinkRunConfig({ - required Uri outputDirectory, - required Uri outputDirectoryShared, - required Uri? recordedUsesFile, - }) { - json[_outDirConfigKey] = outputDirectory.toFilePath(); - json[_outDirSharedConfigKey] = outputDirectoryShared.toFilePath(); + json[_buildModeInputKeyDeprecated] = 'release'; if (recordedUsesFile != null) { - json[_recordedUsagesFileConfigKey] = recordedUsesFile.toFilePath(); + json[_recordedUsagesFileInputKey] = recordedUsesFile.toFilePath(); } } } @@ -236,7 +242,7 @@ List _parseAssets(List? object) => object == null EncodedAsset.fromJson(object.mapAt(i)), ]; -const _recordedUsagesFileConfigKey = 'resource_identifiers'; +const _recordedUsagesFileInputKey = 'resource_identifiers'; const _assetsKey = 'assets'; const _versionKey = 'version'; @@ -244,7 +250,7 @@ sealed class HookOutput { /// The underlying json configuration of this [HookOutput]. final Map json; - /// The version of the [HookConfig]. + /// The version of the [HookInput]. final Version version; /// Start time for the build of this output. @@ -324,7 +330,7 @@ class BuildOutput extends HookOutput { /// /// In dry runs, the assets for all [Architecture]s for the [OS] specified in /// the dry run must be provided. - final List encodedAssets; + final List _encodedAssets; /// The assets produced by this build which should be linked. /// @@ -334,21 +340,42 @@ class BuildOutput extends HookOutput { /// /// In dry runs, the assets for all [Architecture]s for the [OS] specified in /// the dry run must be provided. - final Map> encodedAssetsForLinking; + final Map> _encodedAssetsForLinking; /// Metadata passed to dependent build hook invocations. final Metadata metadata; /// Creates a [BuildOutput] from the given [json]. BuildOutput(super.json) - : encodedAssets = _parseEncodedAssets(json.optionalList(_assetsKey)), - encodedAssetsForLinking = { + : _encodedAssets = _parseEncodedAssets(json.optionalList(_assetsKey)), + _encodedAssetsForLinking = { for (final MapEntry(:key, :value) in (json.optionalMap(_assetsForLinkingKey) ?? {}).entries) key: _parseEncodedAssets(value as List), }, metadata = Metadata.fromJson(json.optionalMap(_metadataConfigKey) ?? {}); + + BuildOutputAssets get assets => BuildOutputAssets._(this); +} + +extension type BuildOutputAssets._(BuildOutput _output) { + /// The assets produced by this build. + /// + /// In dry runs, the assets for all [Architecture]s for the [OS] specified in + /// the dry run must be provided. + List get encodedAssets => _output._encodedAssets; + + /// The assets produced by this build which should be linked. + /// + /// Every key in the map is a package name. These assets in the values are not + /// bundled with the application, but are sent to the link hook of the package + /// specified in the key, which can decide if they are bundled or not. + /// + /// In dry runs, the assets for all [Architecture]s for the [OS] specified in + /// the dry run must be provided. + Map> get encodedAssetsForLinking => + _output._encodedAssetsForLinking; } List _parseEncodedAssets(List? json) => json == null @@ -369,9 +396,9 @@ const _dependencyMetadataKey = 'dependency_metadata'; /// /// ```dart /// main(List arguments) async { -/// await build((config, output) { -/// output.codeAssets.add(CodeAsset(...)); -/// output.dataAssets.add(DataAsset(...)); +/// await build((input, output) { +/// output.assets.code.add(CodeAsset(...)); +/// output.assets.data.add(DataAsset(...)); /// }); /// } /// ``` @@ -393,11 +420,12 @@ class BuildOutputBuilder extends HookOutputBuilder { map ??= json[_metadataConfigKey] = {}; map.addAll(metadata); } + + EncodedAssetBuildOutputBuilder get assets => + EncodedAssetBuildOutputBuilder._(this); } -/// Extension for the lower-level API to add [EncodedAsset]s to -/// [BuildOutputBuilder]. -extension EncodedAssetBuildOutputBuilder on BuildOutputBuilder { +extension type EncodedAssetBuildOutputBuilder._(BuildOutputBuilder _output) { /// Adds [EncodedAsset]s produced by this build or dry run. /// /// If the [linkInPackage] argument is specified, the asset will not be @@ -409,14 +437,14 @@ extension EncodedAssetBuildOutputBuilder on BuildOutputBuilder { /// /// ```dart /// main(List arguments) async { - /// await build((config, output) { - /// output.codeAssets.add(CodeAsset(...)); - /// output.dataAssets.add(DataAsset(...)); + /// await build((input, output) { + /// output.assets.code.add(CodeAsset(...)); + /// output.assets.data.add(DataAsset(...)); /// }); /// } /// ``` void addEncodedAsset(EncodedAsset asset, {String? linkInPackage}) { - final list = _getEncodedAssetsList(json, linkInPackage); + final list = _getEncodedAssetsList(_output.json, linkInPackage); list.add(asset.toJson()); } @@ -432,15 +460,17 @@ extension EncodedAssetBuildOutputBuilder on BuildOutputBuilder { /// /// ```dart /// main(List arguments) async { - /// await build((config, output) { - /// output.codeAssets.addAll([CodeAsset(...), ...]); - /// output.dataAssets.addAll([DataAsset(...), ...]); + /// await build((input, output) { + /// output.assets.code.addAll([CodeAsset(...), ...]); + /// output.assets.data.addAll([DataAsset(...), ...]); /// }); /// } /// ``` - void addEncodedAssets(Iterable assets, - {String? linkInPackage}) { - final list = _getEncodedAssetsList(json, linkInPackage); + void addEncodedAssets( + Iterable assets, { + String? linkInPackage, + }) { + final list = _getEncodedAssetsList(_output.json, linkInPackage); for (final asset in assets) { list.add(asset.toJson()); } @@ -448,7 +478,9 @@ extension EncodedAssetBuildOutputBuilder on BuildOutputBuilder { } List _getEncodedAssetsList( - Map json, String? linkInPackage) { + Map json, + String? linkInPackage, +) { if (linkInPackage == null) { var list = json[_assetsKey] as List?; list ??= json[_assetsKey] = >[]; @@ -467,11 +499,21 @@ class LinkOutput extends HookOutput { /// /// In dry runs, the assets for all [Architecture]s for the [OS] specified in /// the dry run must be provided. - final List encodedAssets; + final List _encodedAssets; /// Creates a [BuildOutput] from the given [json]. LinkOutput(super.json) - : encodedAssets = _parseEncodedAssets(json.optionalList(_assetsKey)); + : _encodedAssets = _parseEncodedAssets(json.optionalList(_assetsKey)); + + LinkOutputAssets get assets => LinkOutputAssets._(this); +} + +extension type LinkOutputAssets._(LinkOutput _output) { + /// The assets produced by this build. + /// + /// In dry runs, the assets for all [Architecture]s for the [OS] specified in + /// the dry run must be provided. + List get encodedAssets => _output._encodedAssets; } /// Builder to produce the output of a link hook. @@ -482,17 +524,20 @@ class LinkOutput extends HookOutput { /// /// ```dart /// main(List arguments) async { -/// await build((config, output) { -/// output.codeAssets.add(CodeAsset(...)); -/// output.dataAssets.add(DataAsset(...)); +/// await build((input, output) { +/// output.assets.code.add(CodeAsset(...)); +/// output.assets.data.add(DataAsset(...)); /// }); /// } /// ``` -class LinkOutputBuilder extends HookOutputBuilder {} +class LinkOutputBuilder extends HookOutputBuilder { + EncodedAssetLinkOutputBuilder get assets => + EncodedAssetLinkOutputBuilder._(this); +} /// Extension for the lower-level API to add [EncodedAsset]s to /// [BuildOutputBuilder]. -extension EncodedAssetLinkOutputBuilder on LinkOutputBuilder { +extension type EncodedAssetLinkOutputBuilder._(LinkOutputBuilder _builder) { /// Adds [EncodedAsset]s produced by this build. /// /// Note to hook writers. Prefer using the `.add` method on the extension for @@ -500,15 +545,15 @@ extension EncodedAssetLinkOutputBuilder on LinkOutputBuilder { /// /// ```dart /// main(List arguments) async { - /// await build((config, output) { - /// output.codeAssets.add(CodeAsset(...)); - /// output.dataAssets.add(DataAsset(...)); + /// await build((input, output) { + /// output.assets.code.add(CodeAsset(...)); + /// output.assets.data.add(DataAsset(...)); /// }); /// } /// ``` void addEncodedAsset(EncodedAsset asset) { - var list = json[_assetsKey] as List?; - list ??= json[_assetsKey] = >[]; + var list = _builder.json[_assetsKey] as List?; + list ??= _builder.json[_assetsKey] = >[]; list.add(asset.toJson()); } @@ -519,34 +564,34 @@ extension EncodedAssetLinkOutputBuilder on LinkOutputBuilder { /// /// ```dart /// main(List arguments) async { - /// await build((config, output) { - /// output.codeAssets.addAll([CodeAsset(...), ...]); - /// output.dataAssets.addAll([DataAsset(...), ...]); + /// await build((input, output) { + /// output.assets.code.addAll([CodeAsset(...), ...]); + /// output.assets.data.addAll([DataAsset(...), ...]); /// }); /// } /// ``` void addEncodedAssets(Iterable assets) { - var list = json[_assetsKey] as List?; - list ??= json[_assetsKey] = >[]; + var list = _builder.json[_assetsKey] as List?; + list ??= _builder.json[_assetsKey] = >[]; for (final asset in assets) { list.add(asset.toJson()); } } } -/// The latest supported config version. +/// The latest supported input version. /// /// We'll never bump the major version. Removing old keys from the input and /// output is done via modifying [latestParsableVersion]. final latestVersion = Version(1, 6, 0); -/// The parser can deal with configs and outputs down to this version. +/// The parser can deal with inputs and outputs down to this version. /// /// This version can be bumped when: /// /// 1. The stable version of Dart / Flutter uses a newer version _and_ the SDK /// constraint is bumped in the pubspec of this package to that stable -/// version. (This prevents config parsing from failing.) +/// version. (This prevents input parsing from failing.) /// 2. A stable version of this package is published uses a newer version, _and_ /// most users have migrated to it. (This prevents the output parsing from /// failing.) @@ -554,3 +599,33 @@ final latestVersion = Version(1, 6, 0); /// When updating this number, update the version_skew_test.dart. (This test /// catches issues with 2.) final latestParsableVersion = Version(1, 5, 0); + +final class HookConfig { + final Map json; + + /// The asset types that the invoker of this hook supports. + final List buildAssetTypes; + + HookConfig(this.json) + : buildAssetTypes = json.optionalStringList(_buildAssetTypesKey) ?? + json.optionalStringList(_supportedAssetTypesKey) ?? + const []; +} + +final class BuildConfig extends HookConfig { + // TODO(dcharkes): Remove after 3.7.0 stable is released and bump the SDK + // constraint in the pubspec. Ditto for all uses in related packages. + /// Whether this run is a dry-run, which doesn't build anything. + /// + /// A dry-run only reports information about which assets a build would + /// create, but doesn't actually create files. + @Deprecated('Flutter will no longer invoke dry run as of 3.28.') + final bool dryRun; + + final bool linkingEnabled; + + BuildConfig(super.json) + // ignore: deprecated_member_use_from_same_package + : dryRun = json.getOptional(_dryRunConfigKey) ?? false, + linkingEnabled = json.get(_linkingEnabledKey); +} diff --git a/pkgs/native_assets_cli/lib/src/data_assets/config.dart b/pkgs/native_assets_cli/lib/src/data_assets/config.dart index 5c5433810..0d3b419ad 100644 --- a/pkgs/native_assets_cli/lib/src/data_assets/config.dart +++ b/pkgs/native_assets_cli/lib/src/data_assets/config.dart @@ -6,8 +6,17 @@ import '../config.dart'; import 'data_asset.dart'; +/// Extension to the [HookConfig] providing access to configuration specific +/// to data assets. +extension CodeAssetHookConfig on HookConfig { + bool get buildDataAssets => buildAssetTypes.contains(DataAsset.type); +} + +/// Extension to initialize data specific configuration on link/build inputs. +extension DataAssetBuildInputBuilder on HookConfigBuilder {} + /// Link output extension for data assets. -extension DataAssetLinkConfig on LinkConfig { +extension DataAssetLinkInput on LinkInputAssets { // Returns the data assets that were sent to this linker. // // NOTE: If the linker implementation depends on the contents of the files of @@ -15,20 +24,21 @@ extension DataAssetLinkConfig on LinkConfig { // then the linker script has to add those files as dependencies via // [LinkOutput.addDependency] to ensure the linker script will be re-run if // the content of the files changes. - Iterable get dataAssets => encodedAssets + Iterable get data => encodedAssets .where((e) => e.type == DataAsset.type) .map(DataAsset.fromEncoded); } /// Build output extension for data assets. -extension DataAssetBuildOutputBuilder on BuildOutputBuilder { +extension DataAssetBuildOutputBuilder on EncodedAssetBuildOutputBuilder { /// Provides access to emitting data assets. - DataAssetBuildOutputBuilderAdd get dataAssets => + DataAssetBuildOutputBuilderAdd get data => DataAssetBuildOutputBuilderAdd._(this); } /// Supports emitting code assets for build hooks. -extension type DataAssetBuildOutputBuilderAdd._(BuildOutputBuilder _output) { +extension type DataAssetBuildOutputBuilderAdd._( + EncodedAssetBuildOutputBuilder _output) { /// Adds the given [asset] to the hook output (or send to [linkInPackage] /// for linking if provided). void add(DataAsset asset, {String? linkInPackage}) => @@ -45,14 +55,14 @@ extension type DataAssetBuildOutputBuilderAdd._(BuildOutputBuilder _output) { /// Extension to the [LinkOutputBuilder] providing access to emitting data /// assets (only available if data assets are supported). -extension DataAssetLinkOutputBuilder on LinkOutputBuilder { +extension DataAssetLinkOutputBuilder on EncodedAssetLinkOutputBuilder { /// Provides access to emitting data assets. - DataAssetLinkOutputBuilderAdd get dataAssets => - DataAssetLinkOutputBuilderAdd(this); + DataAssetLinkOutputBuilderAdd get data => DataAssetLinkOutputBuilderAdd(this); } /// Extension on [LinkOutputBuilder] to emit data assets. -extension type DataAssetLinkOutputBuilderAdd(LinkOutputBuilder _output) { +extension type DataAssetLinkOutputBuilderAdd( + EncodedAssetLinkOutputBuilder _output) { /// Adds the given [asset] to the link hook output. void add(DataAsset asset) => _output.addEncodedAsset(asset.encode()); @@ -61,16 +71,16 @@ extension type DataAssetLinkOutputBuilderAdd(LinkOutputBuilder _output) { } /// Provides access to [DataAsset]s from a build hook output. -extension DataAssetBuildOutput on BuildOutput { - List get dataAssets => encodedAssets +extension DataAssetBuildOutput on BuildOutputAssets { + List get data => encodedAssets .where((asset) => asset.type == DataAsset.type) .map(DataAsset.fromEncoded) .toList(); } /// Provides access to [DataAsset]s from a link hook output. -extension DataAssetLinkOutput on LinkOutput { - List get dataAssets => encodedAssets +extension DataAssetLinkOutput on LinkOutputAssets { + List get data => encodedAssets .where((asset) => asset.type == DataAsset.type) .map(DataAsset.fromEncoded) .toList(); diff --git a/pkgs/native_assets_cli/lib/src/data_assets/validation.dart b/pkgs/native_assets_cli/lib/src/data_assets/validation.dart index 8b575a8ef..07670aaf5 100644 --- a/pkgs/native_assets_cli/lib/src/data_assets/validation.dart +++ b/pkgs/native_assets_cli/lib/src/data_assets/validation.dart @@ -6,15 +6,14 @@ import 'dart:io'; import '../../data_assets_builder.dart'; -Future validateDataAssetBuildConfig( - BuildConfig config) async => +Future validateDataAssetBuildInput(BuildInput input) async => const []; -Future validateDataAssetLinkConfig(LinkConfig config) async { +Future validateDataAssetLinkInput(LinkInput input) async { final errors = []; - for (final asset in config.dataAssets) { + for (final asset in input.assets.data) { if (!File.fromUri(asset.file).existsSync()) { - errors.add('LinkConfig.dataAssets contained asset ${asset.id} with file ' + errors.add('LinkInput.assets.data contained asset ${asset.id} with file ' '(${asset.file}) which does not exist.'); } } @@ -22,26 +21,26 @@ Future validateDataAssetLinkConfig(LinkConfig config) async { } Future validateDataAssetBuildOutput( - BuildConfig config, + BuildInput input, BuildOutput output, ) => _validateDataAssetBuildOrLinkOutput( - config, - output.encodedAssets, + input, + output.assets.encodedAssets, // ignore: deprecated_member_use_from_same_package - config.dryRun, + input.config.dryRun, true, ); Future validateDataAssetLinkOutput( - LinkConfig config, + LinkInput input, LinkOutput output, ) => _validateDataAssetBuildOrLinkOutput( - config, output.encodedAssets, false, false); + input, output.assets.encodedAssets, false, false); Future _validateDataAssetBuildOrLinkOutput( - HookConfig config, + HookInput input, List encodedAssets, bool dryRun, bool isBuild, @@ -52,21 +51,21 @@ Future _validateDataAssetBuildOrLinkOutput( for (final asset in encodedAssets) { if (asset.type != DataAsset.type) continue; _validateDataAssets( - config, dryRun, DataAsset.fromEncoded(asset), errors, ids, isBuild); + input, dryRun, DataAsset.fromEncoded(asset), errors, ids, isBuild); } return errors; } void _validateDataAssets( - HookConfig config, + HookInput input, bool dryRun, DataAsset dataAsset, List errors, Set ids, bool isBuild, ) { - if (isBuild && dataAsset.package != config.packageName) { - errors.add('Data asset must have package name ${config.packageName}'); + if (isBuild && dataAsset.package != input.packageName) { + errors.add('Data asset must have package name ${input.packageName}'); } if (!ids.add(dataAsset.name)) { errors.add('More than one code asset with same "${dataAsset.name}" name.'); diff --git a/pkgs/native_assets_cli/lib/src/json_utils.dart b/pkgs/native_assets_cli/lib/src/json_utils.dart index 8c79c527d..c267b86c7 100644 --- a/pkgs/native_assets_cli/lib/src/json_utils.dart +++ b/pkgs/native_assets_cli/lib/src/json_utils.dart @@ -51,7 +51,7 @@ extension MapJsonUtils on Map { } if (value is T) return value; throw FormatException( - 'Unexpected value \'$value\' for key \'.$key\' in config file. ' + 'Unexpected value \'$value\' for key \'.$key\' in input file. ' 'Expected a $T.'); } @@ -59,7 +59,7 @@ extension MapJsonUtils on Map { final value = this[key]; if (value is T?) return value; throw FormatException( - 'Unexpected value \'$value\' for key \'.$key\' in config file. ' + 'Unexpected value \'$value\' for key \'.$key\' in input file. ' 'Expected a $T?.'); } } @@ -72,7 +72,7 @@ extension ListJsonUtils on List { } if (value is T) return value; throw FormatException( - 'Unexpected value \'$value\' for index \'.$index\' in config file. ' + 'Unexpected value \'$value\' for index \'.$index\' in input file. ' 'Expected a $T.'); } diff --git a/pkgs/native_assets_cli/lib/src/validation.dart b/pkgs/native_assets_cli/lib/src/validation.dart index 72c01c7a3..23f94026f 100644 --- a/pkgs/native_assets_cli/lib/src/validation.dart +++ b/pkgs/native_assets_cli/lib/src/validation.dart @@ -8,32 +8,33 @@ import '../native_assets_cli_builder.dart'; typedef ValidationErrors = List; -Future validateBuildConfig(BuildConfig config) async => - _validateHookConfig(config); +Future validateBuildInput(BuildInput input) async => + _validateHookInput('BuildInput', input); -Future validateLinkConfig(LinkConfig config) async { +Future validateLinkInput(LinkInput input) async { final errors = [ - ..._validateHookConfig(config), + ..._validateHookInput('LinkInput', input), ]; - final recordUses = config.recordedUsagesFile; + final recordUses = input.recordedUsagesFile; if (recordUses != null && !File.fromUri(recordUses).existsSync()) { - errors.add('Config.recordUses ($recordUses) does not exist.'); + errors.add('LinkInput.recordUses ($recordUses) does not exist.'); } return errors; } -ValidationErrors _validateHookConfig(HookConfig config) { +ValidationErrors _validateHookInput(String inputName, HookInput input) { final errors = []; - if (!Directory.fromUri(config.packageRoot).existsSync()) { - errors.add('Config.packageRoot (${config.packageRoot}) ' + if (!Directory.fromUri(input.packageRoot).existsSync()) { + errors.add('$inputName.packageRoot (${input.packageRoot}) ' 'has to be an existing directory.'); } - if (!Directory.fromUri(config.outputDirectory).existsSync()) { - errors.add('Config.outputDirectory (${config.outputDirectory}) ' + if (!Directory.fromUri(input.outputDirectory).existsSync()) { + errors.add('$inputName.outputDirectory (${input.outputDirectory}) ' 'has to be an existing directory.'); } - if (!Directory.fromUri(config.outputDirectoryShared).existsSync()) { - errors.add('Config.outputDirectoryShared (${config.outputDirectoryShared}) ' + if (!Directory.fromUri(input.outputDirectoryShared).existsSync()) { + errors.add( + '$inputName.outputDirectoryShared (${input.outputDirectoryShared}) ' 'has to be an existing directory'); } return errors; @@ -41,16 +42,16 @@ ValidationErrors _validateHookConfig(HookConfig config) { /// Invoked by package:native_assets_builder Future validateBuildOutput( - BuildConfig config, + BuildInput input, BuildOutput output, ) async { final errors = [ - ..._validateAssetsForLinking(config, output), - ..._validateOutputAssetTypes(config, output.encodedAssets), + ..._validateAssetsForLinking(input, output), + ..._validateOutputAssetTypes(input, output.assets.encodedAssets), ]; - if (config.linkingEnabled) { - for (final assets in output.encodedAssetsForLinking.values) { - errors.addAll(_validateOutputAssetTypes(config, assets)); + if (input.config.linkingEnabled) { + for (final assets in output.assets.encodedAssetsForLinking.values) { + errors.addAll(_validateOutputAssetTypes(input, assets)); } } return errors; @@ -58,22 +59,27 @@ Future validateBuildOutput( /// Invoked by package:native_assets_builder Future validateLinkOutput( - LinkConfig config, + LinkInput input, LinkOutput output, ) async { final errors = [ - ..._validateOutputAssetTypes(config, output.encodedAssets), + ..._validateOutputAssetTypes(input, output.assets.encodedAssets), ]; return errors; } /// Only output asset types that are supported by the embedder. List _validateOutputAssetTypes( - HookConfig config, + HookInput input, Iterable assets, ) { final errors = []; - final buildAssetTypes = config.buildAssetTypes; + final List buildAssetTypes; + if (input is BuildInput) { + buildAssetTypes = input.config.buildAssetTypes; + } else { + buildAssetTypes = (input as LinkInput).config.buildAssetTypes; + } for (final asset in assets) { if (!buildAssetTypes.contains(asset.type)) { final error = @@ -87,14 +93,14 @@ List _validateOutputAssetTypes( /// EncodedAssetsForLinking should be empty if linking is not supported. List _validateAssetsForLinking( - BuildConfig config, + BuildInput input, BuildOutput output, ) { final errors = []; - if (!config.linkingEnabled) { - if (output.encodedAssetsForLinking.isNotEmpty) { + if (!input.config.linkingEnabled) { + if (output.assets.encodedAssetsForLinking.isNotEmpty) { const error = 'BuildOutput.assetsForLinking is not empty while ' - 'BuildConfig.linkingEnabled is false'; + 'BuildInput.config.linkingEnabled is false'; errors.add(error); } } diff --git a/pkgs/native_assets_cli/lib/test.dart b/pkgs/native_assets_cli/lib/test.dart index e18210a4b..39e9e2021 100644 --- a/pkgs/native_assets_cli/lib/test.dart +++ b/pkgs/native_assets_cli/lib/test.dart @@ -26,11 +26,9 @@ export 'native_assets_cli_builder.dart'; /// }); /// ``` Future testBuildHook({ - required void Function(BuildConfigBuilder) extraConfigSetup, + required void Function(BuildInputBuilder) extraInputSetup, required FutureOr Function(List arguments) mainMethod, - required FutureOr Function(BuildConfig config, BuildOutput output) - check, - List? buildAssetTypes, + required FutureOr Function(BuildInput input, BuildOutput output) check, bool? linkingEnabled, }) async { const keepTempKey = 'KEEP_TEMPORARY_DIRECTORIES'; @@ -47,40 +45,37 @@ Future testBuildHook({ await Directory.fromUri(outputDirectory).create(); await Directory.fromUri(outputDirectoryShared).create(); - final configBuilder = BuildConfigBuilder(); - configBuilder - ..setupHookConfig( + final inputBuilder = BuildInputBuilder(); + inputBuilder + ..setupShared( packageRoot: Directory.current.uri, packageName: _readPackageNameFromPubspec(), - buildAssetTypes: buildAssetTypes ?? [], + outputDirectory: outputDirectory, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildConfig( + ..config.setupBuild( dryRun: false, linkingEnabled: true, - ) - ..setupBuildRunConfig( - outputDirectory: outputDirectory, - outputDirectoryShared: outputDirectoryShared, ); - extraConfigSetup(configBuilder); + extraInputSetup(inputBuilder); - final config = BuildConfig(configBuilder.json); + final input = BuildInput(inputBuilder.json); - final configUri = tempUri.resolve(Hook.build.outputName); - _writeJsonTo(configUri, config.json); - await mainMethod(['--config=${configUri.toFilePath()}']); + final inputUri = tempUri.resolve(Hook.build.outputName); + _writeJsonTo(inputUri, input.json); + await mainMethod(['--config=${inputUri.toFilePath()}']); final output = BuildOutput( - _readJsonFrom(config.outputDirectory.resolve(Hook.build.outputName))); + _readJsonFrom(input.outputDirectory.resolve(Hook.build.outputName))); // Test conformance of protocol invariants. - final validationErrors = await validateBuildOutput(config, output); + final validationErrors = await validateBuildOutput(input, output); if (validationErrors.isNotEmpty) { throw ValidationFailure( 'encountered build output validation issues: $validationErrors'); } // Run user-defined tests. - await check(config, output); + await check(input, output); } finally { final keepTempDir = (Platform.environment[keepTempKey] ?? '').isNotEmpty; if (!keepTempDir) { diff --git a/pkgs/native_assets_cli/pubspec.yaml b/pkgs/native_assets_cli/pubspec.yaml index 96567a4d1..73f9f171c 100644 --- a/pkgs/native_assets_cli/pubspec.yaml +++ b/pkgs/native_assets_cli/pubspec.yaml @@ -4,7 +4,7 @@ description: >- native assets CLI. # Note: Bump BuildConfig.version and BuildOutput.version on breaking changes! -version: 0.10.1-wip +version: 0.11.0-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli publish_to: none diff --git a/pkgs/native_assets_cli/test/api/build_test.dart b/pkgs/native_assets_cli/test/api/build_test.dart index aa2801b37..ace5c17a6 100644 --- a/pkgs/native_assets_cli/test/api/build_test.dart +++ b/pkgs/native_assets_cli/test/api/build_test.dart @@ -17,8 +17,8 @@ void main() async { late Uri outputDirectoryShared; late String packageName; late Uri packageRootUri; - late Uri buildConfigUri; - late BuildConfig config; + late Uri buildInputUri; + late BuildInput input; setUp(() async { tempUri = (await Directory.systemTemp.createTemp()).uri; @@ -29,35 +29,32 @@ void main() async { packageRootUri = tempUri.resolve('$packageName/'); await Directory.fromUri(packageRootUri).create(); - final configBuilder = BuildConfigBuilder(); - configBuilder - ..setupHookConfig( + final inputBuilder = BuildInputBuilder(); + inputBuilder + ..setupShared( packageRoot: tempUri, packageName: packageName, - buildAssetTypes: ['foo'], + outputDirectory: outDirUri, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildConfig( + ..config.setupShared(buildAssetTypes: ['foo']) + ..config.setupBuild( dryRun: false, linkingEnabled: false, - ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outputDirectoryShared, ); - config = BuildConfig(configBuilder.json); + input = BuildInput(inputBuilder.json); - final configJson = json.encode(config.json); - buildConfigUri = tempUri.resolve('build_config.json'); - await File.fromUri(buildConfigUri).writeAsString(configJson); + final inputJson = json.encode(input.json); + buildInputUri = tempUri.resolve('build_input.json'); + await File.fromUri(buildInputUri).writeAsString(inputJson); }); test('build method', () async { - await build(['--config', buildConfigUri.toFilePath()], - (config, output) async { + await build(['--config', buildInputUri.toFilePath()], + (input, output) async { output.addDependency(packageRootUri.resolve('foo')); }); - final buildOutputUri = - config.outputDirectory.resolve(Hook.build.outputName); + final buildOutputUri = input.outputDirectory.resolve(Hook.build.outputName); expect(File.fromUri(buildOutputUri), exists); }); } diff --git a/pkgs/native_assets_cli/test/build_config_test.dart b/pkgs/native_assets_cli/test/build_config_test.dart index 10e844ab0..497d8e466 100644 --- a/pkgs/native_assets_cli/test/build_config_test.dart +++ b/pkgs/native_assets_cli/test/build_config_test.dart @@ -35,25 +35,25 @@ void main() async { }; }); - test('BuildConfigBuilder->JSON->BuildConfig', () { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + test('BuildInputBuilder->JSON->BuildInput', () { + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: packageName, packageRoot: packageRootUri, - buildAssetTypes: ['my-asset-type'], + outputDirectory: outDirUri, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildConfig( + ..config.setupShared(buildAssetTypes: ['my-asset-type']) + ..config.setupBuild( linkingEnabled: false, dryRun: false, - metadata: metadata, ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outputDirectoryShared, + ..setupBuildInput( + metadata: metadata, ); - final config = BuildConfig(configBuilder.json); + final input = BuildInput(inputBuilder.json); - final expectedConfigJson = { + final expectedInputJson = { 'build_asset_types': ['my-asset-type'], 'build_mode': 'release', 'dependency_metadata': { @@ -75,39 +75,38 @@ void main() async { 'version': latestVersion.toString(), }; - expect(config.json, expectedConfigJson); - expect(json.decode(config.toString()), expectedConfigJson); + expect(input.json, expectedInputJson); + expect(json.decode(input.toString()), expectedInputJson); - expect(config.outputDirectory, outDirUri); - expect(config.outputDirectoryShared, outputDirectoryShared); + expect(input.outputDirectory, outDirUri); + expect(input.outputDirectoryShared, outputDirectoryShared); - expect(config.packageName, packageName); - expect(config.packageRoot, packageRootUri); - expect(config.buildAssetTypes, ['my-asset-type']); + expect(input.packageName, packageName); + expect(input.packageRoot, packageRootUri); + expect(input.config.buildAssetTypes, ['my-asset-type']); - expect(config.linkingEnabled, false); - expect(config.dryRun, false); - expect(config.metadata, metadata); + expect(input.config.linkingEnabled, false); + expect(input.config.dryRun, false); + expect(input.metadata, metadata); }); - test('BuildConfig.dryRun', () { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + test('BuildInput.config.dryRun', () { + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: packageName, packageRoot: packageRootUri, - buildAssetTypes: ['my-asset-type'], + outputDirectory: outDirUri, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildConfig( + ..config.setupShared(buildAssetTypes: ['my-asset-type']) + ..config.setupBuild( linkingEnabled: true, dryRun: true, ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outputDirectoryShared, - ); - final config = BuildConfig(configBuilder.json); + ..setupBuildInput(); + final input = BuildInput(inputBuilder.json); - final expectedConfigJson = { + final expectedInputJson = { 'build_asset_types': ['my-asset-type'], 'dependency_metadata': {}, 'dry_run': true, @@ -120,26 +119,26 @@ void main() async { 'version': latestVersion.toString(), }; - expect(config.json, expectedConfigJson); - expect(json.decode(config.toString()), expectedConfigJson); + expect(input.json, expectedInputJson); + expect(json.decode(input.toString()), expectedInputJson); - expect(config.outputDirectory, outDirUri); - expect(config.outputDirectoryShared, outputDirectoryShared); + expect(input.outputDirectory, outDirUri); + expect(input.outputDirectoryShared, outputDirectoryShared); - expect(config.packageName, packageName); - expect(config.packageRoot, packageRootUri); - expect(config.buildAssetTypes, ['my-asset-type']); + expect(input.packageName, packageName); + expect(input.packageRoot, packageRootUri); + expect(input.config.buildAssetTypes, ['my-asset-type']); - expect(config.linkingEnabled, true); - expect(config.dryRun, true); - expect(config.metadata, {}); + expect(input.config.linkingEnabled, true); + expect(input.config.dryRun, true); + expect(input.metadata, {}); }); - group('BuildConfig format issues', () { + group('BuildInput format issues', () { for (final version in ['9001.0.0', '0.0.1']) { - test('BuildConfig version $version', () { + test('BuildInput version $version', () { final outDir = outDirUri; - final config = { + final input = { 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'out_dir_shared': outputDirectoryShared.toFilePath(), @@ -152,7 +151,7 @@ void main() async { 'linking_enabled': false, }; expect( - () => BuildConfig(config), + () => BuildInput(input), throwsA(predicate( (e) => e is FormatException && @@ -163,9 +162,9 @@ void main() async { }); } - test('BuildConfig FormatExceptions', () { + test('BuildInput FormatExceptions', () { expect( - () => BuildConfig({}), + () => BuildInput({}), throwsA(predicate( (e) => e is FormatException && @@ -175,7 +174,7 @@ void main() async { )), ); expect( - () => BuildConfig({ + () => BuildInput({ 'version': latestVersion.toString(), 'package_name': packageName, 'package_root': packageRootUri.toFilePath(), @@ -192,7 +191,7 @@ void main() async { )), ); expect( - () => BuildConfig({ + () => BuildInput({ 'version': latestVersion.toString(), 'out_dir': outDirUri.toFilePath(), 'out_dir_shared': outputDirectoryShared.toFilePath(), diff --git a/pkgs/native_assets_cli/test/build_output_test.dart b/pkgs/native_assets_cli/test/build_output_test.dart index 2b53dc485..58b73b2f5 100644 --- a/pkgs/native_assets_cli/test/build_output_test.dart +++ b/pkgs/native_assets_cli/test/build_output_test.dart @@ -33,19 +33,18 @@ void main() { builder.addMetadatum(metadata0.keys.single, metadata0.values.single); builder.addMetadata(metadata1); - builder.addEncodedAsset(assets.take(1).single); - builder.addEncodedAsset(assets.skip(1).first, + builder.assets.addEncodedAsset(assets.take(1).single); + builder.assets.addEncodedAsset(assets.skip(1).first, linkInPackage: 'package:linker1'); - builder.addEncodedAssets(assets.skip(2).take(2).toList()); - builder.addEncodedAssets(assets.skip(4).toList(), + builder.assets.addEncodedAssets(assets.skip(2).take(2).toList()); + builder.assets.addEncodedAssets(assets.skip(4).toList(), linkInPackage: 'package:linker2'); - final config = BuildOutput(builder.json); - expect(config.timestamp.compareTo(before), greaterThanOrEqualTo(0)); - expect(config.timestamp.compareTo(after), lessThanOrEqualTo(0)); + final input = BuildOutput(builder.json); + expect(input.timestamp.compareTo(before), greaterThanOrEqualTo(0)); + expect(input.timestamp.compareTo(after), lessThanOrEqualTo(0)); expect( - config.timestamp - .isAtSameMomentAs(config.timestamp.roundDownToSeconds()), + input.timestamp.isAtSameMomentAs(input.timestamp.roundDownToSeconds()), true); // The JSON format of the build output. @@ -68,7 +67,7 @@ void main() { 'package:linker2': [], } }.forEach((k, v) { - expect(config.json[k], equals(v)); + expect(input.json[k], equals(v)); }); }); diff --git a/pkgs/native_assets_cli/test/checksum_test.dart b/pkgs/native_assets_cli/test/checksum_test.dart index c4691e4aa..534254b8a 100644 --- a/pkgs/native_assets_cli/test/checksum_test.dart +++ b/pkgs/native_assets_cli/test/checksum_test.dart @@ -13,42 +13,46 @@ import 'helpers.dart'; void main() { test('checksum', () async { // metadata, cc, link vs build, metadata, haslink - final configs = []; + final inputs = []; final checksums = []; - for (final os in [OS.linux, OS.macOS]) { - for (final architecture in [Architecture.arm64, Architecture.x64]) { - for (final packageName in ['foo', 'bar']) { - for (final assetType in [CodeAsset.type, DataAsset.type]) { - for (final dryRun in [true, false]) { - for (final linking in [true, false]) { - final builder = BuildConfigBuilder() - ..setupHookConfig( - packageRoot: Uri.file('foo'), - packageName: packageName, - buildAssetTypes: [assetType], - ) - ..setupBuildConfig( - dryRun: dryRun, - linkingEnabled: linking, - ) - ..setupCodeConfig( - targetArchitecture: architecture, - targetOS: os, - macOSConfig: os == OS.macOS - ? MacOSConfig(targetVersion: defaultMacOSVersion) - : null, - linkModePreference: LinkModePreference.dynamic, - ); - configs.add( - const JsonEncoder.withIndent(' ').convert(builder.json), + + for (final dryRun in [true, false]) { + for (final linking in [true, false]) { + for (final assetType in [CodeAsset.type, DataAsset.type]) { + for (final os in [ + OS.linux, + if (assetType == CodeAsset.type) OS.macOS, + ]) { + for (final architecture in [ + Architecture.arm64, + if (assetType == CodeAsset.type) Architecture.x64, + ]) { + final builder = BuildInputBuilder() + ..config.setupBuild( + dryRun: dryRun, + linkingEnabled: linking, + ); + builder.config.setupShared(buildAssetTypes: [assetType]); + if (assetType == CodeAsset.type) { + builder.config.setupCode( + targetArchitecture: architecture, + targetOS: os, + macOS: os == OS.macOS + ? MacOSConfig(targetVersion: defaultMacOSVersion) + : null, + linkModePreference: LinkModePreference.dynamic, ); - checksums.add(builder.computeChecksum()); } + inputs.add( + const JsonEncoder.withIndent(' ').convert(builder.json), + ); + checksums.add(builder.computeChecksum()); } } } } } + // As all variants have something different, we expect the checksums to be // unique. expect(checksums.toSet().length, checksums.length); @@ -57,70 +61,26 @@ void main() { // needing to update this list). final expectedChecksums = [ - 'd666127fab5478b736d505c0cbd2e08e', - '5d5cf5cf7916bd7adc26f5d5611f23ec', - '29cb9cf638acac26c1e7eb20bf4e359a', - '2214edee21375319f5612344dfe6acbc', - '40b61c96feff406659bc35e24875744b', - 'a0492f5322cea695e3bc1522d66a20ce', - '9f5269a2c0c663023af449e77ac39980', - 'c9add26b586b1fb897f9ff0d2edb235d', - '95ec14e605b3519f00ea8816b328e0ad', - 'fc5792f6beb3c0e0f7894537a3fa4850', - 'bbf84c44fb1ce09636a70d3e9a8590be', - '9c83dfb94b98c6f4ec79cbabc95e6198', - 'af8712f4857423f455d2912c55fe6766', - '99d1eba44f3e914b58768c210d139cc1', - '12cc255c3fc076d3550ac32b43166631', - '2188cca31e8306cbacb9c3d799b5513c', - '65ad5d4fb66745aad4e5a2969a1e45b1', - '29da0a967b9cfd5e4d21d61c97d2a99e', - 'efef4a8ab871ed05a9358a2e4d6d4e03', - '672a07ce5b6f82204ba92b45c287781c', - '4bcdd217687c15fb108dc9a9b8f8537c', - 'c0593c4282d42a659d66d8b72e44b2a6', - 'dd428de57da1d45149f4ff8a27fa3ea0', - 'c04f80b8be73bcfe435c586ef8a979bc', - '1056f2bf80b3c1979952af1e62e34576', - 'b7d943b4bab492e10c582bdd58aced0e', - 'ed56d7afbd306393c3206685e6d1ba81', - '1463940666f69e3b132f3766570ef83b', - '5451c1a2a24bc5e1206b245b028e0078', - '5f2c169a71039d3d6b2ae74e3c2723d7', - '67759625e5a0908dabcaeeb2b1264f84', - '921b2b7012548949e9b465addccc2e71', - 'b1bddc0ed6904d52d8455779ea22ca7e', - 'ddc148493501a29584b859bbad703dc8', - 'f61b611c5cdf32c1251547c63773be4b', - '754258bb3497d76670f306c3bdcfb72e', - '9d7f0c3ea090c5c9a50bc68970b691de', - '2fb6a652e863e63b877bcf4d0f9c18ee', - 'e6c27bf9b26cd1b9e093d8df3eb701f1', - '21b14473b8f4513afc07b10fc49b3a42', - '755e4a51021d2f06f81800d06005d3e8', - '18739efa01630bfb69b359f3471813e3', - '6532e84b2020034445983b4aaca63cf6', - '400486e5b7fd7bcee2cca005d9e365ef', - 'ca9415247d3caf7469f7ef256dbfec7d', - '5f7e1b8477f41b8676d076375edc4160', - '79440103b796d05d7f2e3fe6a7eaaa3c', - '291e0f37d19c0b59abeeb96577f98295', - '266de1a05af22f800e9018dcacf5f9d5', - '899d2db19759e703b5093f4919db72b4', - 'ba8fa2cfec652f80588ce5080cb8e0d7', - 'aa946213d19406fa2db5ba89be7037ba', - '7e29bcee52269e094cf7645dba7b2257', - 'c423ef2466bd1370d04ef82a7676e82c', - '7b258ea5c87c103e12968ea979339e13', - '344189c289fceff30a21681b28be98fb', - '1bfafa1611cef338271a338500a49d13', - 'e59b31a6d8a958f1b894b6e536043b18', - '39c6bf2b59d2e335b444638352967969', - '672fe8c89974fbc794bf992da475b264', - '0690975592703ed47f236c8815d115f0', - '51d7e1b0c5b4a855d070f409150d2bcf', - '3299a12d5041c50fbe81167bf0aca0ff', - '46007e911efe370c1774c3a1d6c35ddd', + '079353bf7f09a5a78aad5dfb74d160ce', + '3f77f197abd56950f6878720f40f1d78', + '95afb0b082567b75143a5a3fe23ded7f', + '20a82fc01786d82ec2e70c81e384ca53', + '9b4a6923ab07618074631e9ee8ea5451', + '1ba05dccc6b7d760f2c085dfb3b3e9be', + '86ca6c0d669baa2f0d29b81aa9db65d9', + 'ad261f0ea9c06e69eaf9870161da902f', + '4973835d48a96917eb2b4fe3266c60f4', + '1c4bddfe0111033df5fd1903123a759b', + '07d32fc26a66558589bd2ef3d243a1bf', + '6237121ffae0bb44b6489913f859e595', + '5ab1d45dc1b8365df17dc13bfe725e3e', + 'efff82f6321e8f2ad2d83f7b87890d12', + '9939ebdbc70de2750b26857ccdf7a308', + '2ac3ed117b93db3686b51c8d3da6947d', + '47d6a16f82e7dc71156af0578e1cde4c', + '07eaf868dd64ef1ffd717111d7a73263', + '5df468122615987a0daa4da40c3f4e07', + '0e551c890758631dfc1dd549d8278fc8', ]; printOnFailure('final expectedChecksums = ['); printOnFailure(checksums.map((e) => " '$e',").join('\n')); diff --git a/pkgs/native_assets_cli/test/code_assets/config_test.dart b/pkgs/native_assets_cli/test/code_assets/config_test.dart index aa40204ab..5f0859a64 100644 --- a/pkgs/native_assets_cli/test/code_assets/config_test.dart +++ b/pkgs/native_assets_cli/test/code_assets/config_test.dart @@ -53,7 +53,7 @@ void main() async { }); expect(() => codeConfig.targetArchitecture, throwsStateError); - expect(() => codeConfig.androidConfig.targetNdkApi, throwsStateError); + expect(() => codeConfig.android.targetNdkApi, throwsStateError); expect(codeConfig.linkModePreference, LinkModePreference.preferStatic); expect(codeConfig.cCompiler, null); } @@ -77,60 +77,56 @@ void main() async { }); expect(codeConfig.targetArchitecture, Architecture.arm64); - expect(codeConfig.androidConfig.targetNdkApi, 30); + expect(codeConfig.android.targetNdkApi, 30); expect(codeConfig.linkModePreference, LinkModePreference.preferStatic); expect(codeConfig.cCompiler?.compiler, fakeClang); expect(codeConfig.cCompiler?.linker, fakeLd); expect(codeConfig.cCompiler?.archiver, fakeAr); } - test('BuildConfig.codeConfig (dry-run)', () { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + test('BuildInput.config.code (dry-run)', () { + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: packageName, packageRoot: packageRootUri, - buildAssetTypes: [CodeAsset.type], + outputDirectory: outDirUri, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: true, dryRun: true, ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outputDirectoryShared, - ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.android, - androidConfig: null, // not available in dry run + android: null, // not available in dry run targetArchitecture: null, // not available in dry run - cCompilerConfig: null, // not available in dry run + cCompiler: null, // not available in dry run linkModePreference: LinkModePreference.preferStatic, ); - final config = BuildConfig(configBuilder.json); - expectCorrectCodeConfigDryRun(config.json, config.codeConfig); + final input = BuildInput(inputBuilder.json); + expectCorrectCodeConfigDryRun(input.json, input.config.code); }); - test('BuildConfig.codeConfig', () { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + test('BuildInput.config.code', () { + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: packageName, packageRoot: packageRootUri, - buildAssetTypes: [CodeAsset.type], + outputDirectory: outDirUri, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outputDirectoryShared, - ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.android, targetArchitecture: Architecture.arm64, - androidConfig: AndroidConfig(targetNdkApi: 30), + android: AndroidConfig(targetNdkApi: 30), linkModePreference: LinkModePreference.preferStatic, - cCompilerConfig: CCompilerConfig( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, archiver: fakeAr, @@ -138,29 +134,29 @@ void main() async { envScriptArgs: ['arg0', 'arg1'], ), ); - final config = BuildConfig(configBuilder.json); - expectCorrectCodeConfig(config.json, config.codeConfig); + final input = BuildInput(inputBuilder.json); + expectCorrectCodeConfig(input.json, input.config.code); }); - test('LinkConfig.{codeConfig,codeAssets}', () { - final configBuilder = LinkConfigBuilder() - ..setupHookConfig( + test('LinkInput.{code,codeAssets}', () { + final inputBuilder = LinkInputBuilder() + ..setupShared( packageName: packageName, packageRoot: packageRootUri, - buildAssetTypes: [CodeAsset.type], - ) - ..setupLinkConfig(assets: assets) - ..setupLinkRunConfig( outputDirectory: outDirUri, outputDirectoryShared: outputDirectoryShared, + ) + ..setupLink( + assets: assets, recordedUsesFile: null, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.android, targetArchitecture: Architecture.arm64, - androidConfig: AndroidConfig(targetNdkApi: 30), + android: AndroidConfig(targetNdkApi: 30), linkModePreference: LinkModePreference.preferStatic, - cCompilerConfig: CCompilerConfig( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, archiver: fakeAr, @@ -168,13 +164,13 @@ void main() async { envScriptArgs: ['arg0', 'arg1'], ), ); - final config = LinkConfig(configBuilder.json); - expectCorrectCodeConfig(config.json, config.codeConfig); - expect(config.encodedAssets, assets); + final input = LinkInput(inputBuilder.json); + expectCorrectCodeConfig(input.json, input.config.code); + expect(input.assets.encodedAssets, assets); }); - test('BuildConfig.codeConfig: invalid architecture', () { - final config = { + test('BuildInput.config.code: invalid architecture', () { + final input = { 'dry_run': false, 'linking_enabled': false, 'link_mode_preference': 'prefer-static', @@ -189,13 +185,13 @@ void main() async { 'version': latestVersion.toString(), }; expect( - () => BuildConfig(config).codeConfig, + () => BuildInput(input).config.code, throwsFormatException, ); }); - test('LinkConfig.codeConfig: invalid architecture', () { - final config = { + test('LinkInput.config.code: invalid architecture', () { + final input = { 'build_asset_types': [CodeAsset.type], 'dry_run': false, 'link_mode_preference': 'prefer-static', @@ -209,7 +205,7 @@ void main() async { 'version': latestVersion.toString(), }; expect( - () => LinkConfig(config).codeConfig, + () => LinkInput(input).config.code, throwsFormatException, ); }); diff --git a/pkgs/native_assets_cli/test/code_assets/validation_test.dart b/pkgs/native_assets_cli/test/code_assets/validation_test.dart index 7b5e6731b..1092188e4 100644 --- a/pkgs/native_assets_cli/test/code_assets/validation_test.dart +++ b/pkgs/native_assets_cli/test/code_assets/validation_test.dart @@ -29,48 +29,46 @@ void main() { await Directory.fromUri(tempUri).delete(recursive: true); }); - BuildConfigBuilder makeBuildConfigBuilder() { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + BuildInputBuilder makeBuildInputBuilder() { + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: packageName, packageRoot: tempUri, - buildAssetTypes: [CodeAsset.type], + outputDirectory: outDirUri, + outputDirectoryShared: outDirSharedUri, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, - ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outDirSharedUri, ); - return configBuilder; + return inputBuilder; } - BuildConfig makeCodeBuildConfig({ + BuildInput makeCodeBuildInput({ LinkModePreference linkModePreference = LinkModePreference.dynamic, }) { - final builder = makeBuildConfigBuilder() - ..setupCodeConfig( + final builder = makeBuildInputBuilder() + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.linux, targetArchitecture: Architecture.arm64, linkModePreference: linkModePreference, ); - return BuildConfig(builder.json); + return BuildInput(builder.json); } test('file not set', () async { - final config = makeCodeBuildConfig(); + final input = makeCodeBuildInput(); final outputBuilder = BuildOutputBuilder(); - outputBuilder.codeAssets.add(CodeAsset( - package: config.packageName, + outputBuilder.assets.code.add(CodeAsset( + package: input.packageName, name: 'foo.dylib', - architecture: config.codeConfig.targetArchitecture, - os: config.codeConfig.targetOS, + architecture: input.config.code.targetArchitecture, + os: input.config.code.targetOS, linkMode: DynamicLoadingBundled(), )); final errors = await validateCodeAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains('has no file')), @@ -82,49 +80,48 @@ void main() { (LinkModePreference.dynamic, StaticLinking()), ]) { test('native code asset wrong linking $linkModePreference', () async { - final config = - makeCodeBuildConfig(linkModePreference: linkModePreference); + final input = makeCodeBuildInput(linkModePreference: linkModePreference); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.codeAssets.add( + outputBuilder.assets.code.add( CodeAsset( - package: config.packageName, + package: input.packageName, name: 'foo.dart', file: assetFile.uri, linkMode: linkMode, - os: config.codeConfig.targetOS, - architecture: config.codeConfig.targetArchitecture, + os: input.config.code.targetOS, + architecture: input.config.code.targetArchitecture, ), ); final errors = await validateCodeAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains( - 'which is not allowed by by the config link mode preference', + 'which is not allowed by by the input link mode preference', )), ); }); } test('native code wrong architecture', () async { - final config = makeCodeBuildConfig(); + final input = makeCodeBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.codeAssets.add( + outputBuilder.assets.code.add( CodeAsset( - package: config.packageName, + package: input.packageName, name: 'foo.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.codeConfig.targetOS, + os: input.config.code.targetOS, architecture: Architecture.x64, ), ); final errors = await validateCodeAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains( @@ -134,21 +131,21 @@ void main() { }); test('native code no architecture', () async { - final config = makeCodeBuildConfig(); + final input = makeCodeBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.codeAssets.add( + outputBuilder.assets.code.add( CodeAsset( - package: config.packageName, + package: input.packageName, name: 'foo.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.codeConfig.targetOS, + os: input.config.code.targetOS, ), ); final errors = await validateCodeAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains( @@ -158,22 +155,22 @@ void main() { }); test('native code asset wrong os', () async { - final config = makeCodeBuildConfig(); + final input = makeCodeBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.codeAssets.add( + outputBuilder.assets.code.add( CodeAsset( - package: config.packageName, + package: input.packageName, name: 'foo.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), os: OS.windows, - architecture: config.codeConfig.targetArchitecture, + architecture: input.config.code.targetArchitecture, ), ); final errors = await validateCodeAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains( @@ -183,99 +180,106 @@ void main() { }); test('duplicate dylib name', () async { - final config = makeCodeBuildConfig(); + final input = makeCodeBuildInput(); final outputBuilder = BuildOutputBuilder(); - final fileName = config.codeConfig.targetOS.dylibFileName('foo'); + final fileName = input.config.code.targetOS.dylibFileName('foo'); final assetFile = File.fromUri(outDirUri.resolve(fileName)); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.codeAssets.addAll([ + outputBuilder.assets.code.addAll([ CodeAsset( - package: config.packageName, + package: input.packageName, name: 'src/foo.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.codeConfig.targetOS, - architecture: config.codeConfig.targetArchitecture, + os: input.config.code.targetOS, + architecture: input.config.code.targetArchitecture, ), CodeAsset( - package: config.packageName, + package: input.packageName, name: 'src/bar.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.codeConfig.targetOS, - architecture: config.codeConfig.targetArchitecture, + os: input.config.code.targetOS, + architecture: input.config.code.targetArchitecture, ), ]); final errors = await validateCodeAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains('Duplicate dynamic library file name')), ); }); - group('BuildConfig.codeConfig validation', () { + group('BuildInput.config.code validation', () { test('Missing targetIOSVersion', () async { - final builder = makeBuildConfigBuilder() - ..setupCodeConfig( + final builder = makeBuildInputBuilder() + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.iOS, targetArchitecture: Architecture.arm64, linkModePreference: LinkModePreference.dynamic, ); final errors = - await validateCodeAssetBuildConfig(BuildConfig(builder.json)); + await validateCodeAssetBuildInput(BuildInput(builder.json)); expect( errors, contains(contains( - 'BuildConfig.codeConfig.iOSConfig.targetVersion was missing'))); + 'BuildInput.config.code.iOS.targetVersion was missing', + ))); expect( errors, contains( - contains('BuildConfig.codeConfig.targetIOSSdk was missing'))); + contains('BuildInput.config.code.iOS.targetSdk was missing'))); }); test('Missing targetAndroidNdkApi', () async { - final builder = makeBuildConfigBuilder() - ..setupCodeConfig( + final builder = makeBuildInputBuilder() + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.android, targetArchitecture: Architecture.arm64, linkModePreference: LinkModePreference.dynamic, ); expect( - await validateCodeAssetBuildConfig(BuildConfig(builder.json)), + await validateCodeAssetBuildInput(BuildInput(builder.json)), contains(contains( - 'BuildConfig.codeConfig.androidConfig.targetNdkApi was missing')), + 'BuildInput.config.code.android.targetNdkApi was missing', + )), ); }); test('Missing targetMacOSVersion', () async { - final builder = makeBuildConfigBuilder() - ..setupCodeConfig( + final builder = makeBuildInputBuilder() + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.macOS, targetArchitecture: Architecture.arm64, linkModePreference: LinkModePreference.dynamic, ); expect( - await validateCodeAssetBuildConfig(BuildConfig(builder.json)), - contains(contains( - 'BuildConfig.codeConfig.macOSConfig.targetVersion was missing'))); + await validateCodeAssetBuildInput(BuildInput(builder.json)), + contains(contains('BuildInput.config.code.macOS.targetVersion' + ' was missing'))); }); test('Nonexisting compiler/archiver/linker/envScript', () async { final nonExistent = outDirUri.resolve('foo baz'); - final builder = makeBuildConfigBuilder() - ..setupCodeConfig( + final builder = makeBuildInputBuilder() + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.linux, targetArchitecture: Architecture.arm64, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: CCompilerConfig( + cCompiler: CCompilerConfig( compiler: nonExistent, linker: nonExistent, archiver: nonExistent, envScript: nonExistent, )); final errors = - await validateCodeAssetBuildConfig(BuildConfig(builder.json)); + await validateCodeAssetBuildInput(BuildInput(builder.json)); bool matches(String error, String field) => - RegExp('BuildConfig.codeConfig.$field (.*foo baz).* does not exist.') + RegExp('BuildInput.config.code.$field (.*foo baz).* does not' + ' exist.') .hasMatch(error); expect(errors.any((e) => matches(e, 'compiler')), true); diff --git a/pkgs/native_assets_cli/test/data_assets/validation_test.dart b/pkgs/native_assets_cli/test/data_assets/validation_test.dart index f38180203..a9d946aed 100644 --- a/pkgs/native_assets_cli/test/data_assets/validation_test.dart +++ b/pkgs/native_assets_cli/test/data_assets/validation_test.dart @@ -29,34 +29,33 @@ void main() { await Directory.fromUri(tempUri).delete(recursive: true); }); - BuildConfig makeDataBuildConfig() { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( - packageName: packageName, - packageRoot: tempUri, - buildAssetTypes: [DataAsset.type]) - ..setupBuildConfig( + BuildInput makeDataBuildInput() { + final inputBuilder = BuildInputBuilder() + ..setupShared( + packageName: packageName, + packageRoot: tempUri, + outputDirectory: outDirUri, + outputDirectoryShared: outDirSharedUri, + ) + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outDirSharedUri, - ); - return BuildConfig(configBuilder.json); + ..config.setupShared(buildAssetTypes: [DataAsset.type]); + return BuildInput(inputBuilder.json); } test('file exists', () async { - final config = makeDataBuildConfig(); + final input = makeDataBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.txt')); - outputBuilder.dataAssets.add(DataAsset( - package: config.packageName, + outputBuilder.assets.data.add(DataAsset( + package: input.packageName, name: 'foo.txt', file: assetFile.uri, )); final errors = await validateDataAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains('which does not exist')), @@ -64,17 +63,17 @@ void main() { }); test('asset id in wrong package', () async { - final config = makeDataBuildConfig(); + final input = makeDataBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.dataAssets.add(DataAsset( + outputBuilder.assets.data.add(DataAsset( package: 'different_package', name: 'foo.txt', file: assetFile.uri, )); final errors = await validateDataAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains('Data asset must have package name my_package')), @@ -82,24 +81,24 @@ void main() { }); test('duplicate asset id', () async { - final config = makeDataBuildConfig(); + final input = makeDataBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.dataAssets.addAll([ + outputBuilder.assets.data.addAll([ DataAsset( - package: config.packageName, + package: input.packageName, name: 'foo.txt', file: assetFile.uri, ), DataAsset( - package: config.packageName, + package: input.packageName, name: 'foo.txt', file: assetFile.uri, ), ]); final errors = await validateDataAssetBuildOutput( - config, BuildOutput(outputBuilder.json)); + input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains('More than one')), diff --git a/pkgs/native_assets_cli/test/example/local_asset_test.dart b/pkgs/native_assets_cli/test/example/local_asset_test.dart index cf830d47a..7d4a42cd8 100644 --- a/pkgs/native_assets_cli/test/example/local_asset_test.dart +++ b/pkgs/native_assets_cli/test/example/local_asset_test.dart @@ -41,35 +41,34 @@ void main() async { final dartUri = Uri.file(Platform.resolvedExecutable); final targetOS = OS.current; - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + final inputBuilder = BuildInputBuilder() + ..setupShared( packageRoot: testPackageUri, packageName: name, - buildAssetTypes: [CodeAsset.type], + outputDirectory: outputDirectory, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildRunConfig( - outputDirectory: outputDirectory, - outputDirectoryShared: outputDirectoryShared) - ..setupBuildConfig(linkingEnabled: false, dryRun: dryRun) - ..setupCodeConfig( + ..config.setupBuild(linkingEnabled: false, dryRun: dryRun) + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, targetArchitecture: dryRun ? null : Architecture.current, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dryRun ? null : cCompiler, + cCompiler: dryRun ? null : cCompiler, ); - final buildConfigUri = testTempUri.resolve('build_config.json'); - await File.fromUri(buildConfigUri) - .writeAsString(jsonEncode(configBuilder.json)); + final buildInputUri = testTempUri.resolve('build_input.json'); + await File.fromUri(buildInputUri) + .writeAsString(jsonEncode(inputBuilder.json)); final processResult = await Process.run( dartUri.toFilePath(), [ 'hook/build.dart', - '--config=${buildConfigUri.toFilePath()}', + '--config=${buildInputUri.toFilePath()}', ], workingDirectory: testPackageUri.toFilePath(), ); @@ -84,10 +83,10 @@ void main() async { final buildOutput = BuildOutput( json.decode(await File.fromUri(buildOutputUri).readAsString()) as Map); - final assets = buildOutput.encodedAssets; + final assets = buildOutput.assets.encodedAssets; final dependencies = buildOutput.dependencies; if (dryRun) { - final codeAsset = buildOutput.codeAssets.first; + final codeAsset = buildOutput.assets.code.first; expect(assets.length, greaterThanOrEqualTo(1)); expect(await File.fromUri(codeAsset.file!).exists(), false); expect(dependencies, []); diff --git a/pkgs/native_assets_cli/test/example/native_add_library_test.dart b/pkgs/native_assets_cli/test/example/native_add_library_test.dart index 32ab57a1d..2cb9ff019 100644 --- a/pkgs/native_assets_cli/test/example/native_add_library_test.dart +++ b/pkgs/native_assets_cli/test/example/native_add_library_test.dart @@ -41,35 +41,34 @@ void main() async { final dartUri = Uri.file(Platform.resolvedExecutable); final targetOS = OS.current; - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + final inputBuilder = BuildInputBuilder() + ..setupShared( packageRoot: testPackageUri, packageName: name, - buildAssetTypes: [CodeAsset.type], + outputDirectory: outputDirectory, + outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildRunConfig( - outputDirectory: outputDirectory, - outputDirectoryShared: outputDirectoryShared) - ..setupBuildConfig(linkingEnabled: false, dryRun: dryRun) - ..setupCodeConfig( + ..config.setupBuild(linkingEnabled: false, dryRun: dryRun) + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.current, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, targetArchitecture: dryRun ? null : Architecture.current, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dryRun ? null : cCompiler, + cCompiler: dryRun ? null : cCompiler, ); - final buildConfigUri = testTempUri.resolve('build_config.json'); - await File.fromUri(buildConfigUri) - .writeAsString(jsonEncode(configBuilder.json)); + final buildInputUri = testTempUri.resolve('build_input.json'); + await File.fromUri(buildInputUri) + .writeAsString(jsonEncode(inputBuilder.json)); final processResult = await Process.run( dartUri.toFilePath(), [ 'hook/build.dart', - '--config=${buildConfigUri.toFilePath()}', + '--config=${buildInputUri.toFilePath()}', ], workingDirectory: testPackageUri.toFilePath(), ); @@ -84,7 +83,7 @@ void main() async { final buildOutput = BuildOutput( json.decode(await File.fromUri(buildOutputUri).readAsString()) as Map); - final assets = buildOutput.encodedAssets; + final assets = buildOutput.assets.encodedAssets; final dependencies = buildOutput.dependencies; if (dryRun) { expect(assets.length, greaterThanOrEqualTo(1)); diff --git a/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart b/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart index 9e97551d4..571b4df3b 100644 --- a/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart +++ b/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart @@ -45,36 +45,34 @@ void main() async { final dartUri = Uri.file(Platform.resolvedExecutable); final targetOS = OS.current; - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + final inputBuilder = BuildInputBuilder() + ..setupShared( packageRoot: testPackageUri, packageName: name, - buildAssetTypes: [CodeAsset.type], - ) - ..setupBuildRunConfig( outputDirectory: outputDirectory, outputDirectoryShared: outputDirectoryShared, ) - ..setupBuildConfig(linkingEnabled: false, dryRun: dryRun) - ..setupCodeConfig( + ..config.setupBuild(linkingEnabled: false, dryRun: dryRun) + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, targetArchitecture: dryRun ? null : Architecture.current, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dryRun ? null : cCompiler, + cCompiler: dryRun ? null : cCompiler, ); - final buildConfigUri = testTempUri.resolve('build_config.json'); - await File.fromUri(buildConfigUri) - .writeAsString(jsonEncode(configBuilder.json)); + final buildInputUri = testTempUri.resolve('build_input.json'); + await File.fromUri(buildInputUri) + .writeAsString(jsonEncode(inputBuilder.json)); final processResult = await Process.run( dartUri.toFilePath(), [ 'hook/build.dart', - '--config=${buildConfigUri.toFilePath()}', + '--config=${buildInputUri.toFilePath()}', ], workingDirectory: testPackageUri.toFilePath(), ); @@ -89,7 +87,7 @@ void main() async { final buildOutput = BuildOutput( json.decode(await File.fromUri(buildOutputUri).readAsString()) as Map); - final assets = buildOutput.encodedAssets; + final assets = buildOutput.assets.encodedAssets; final dependencies = buildOutput.dependencies; if (dryRun) { expect(assets.length, greaterThanOrEqualTo(3)); diff --git a/pkgs/native_assets_cli/test/link_config_test.dart b/pkgs/native_assets_cli/test/link_config_test.dart index 2cf9616ea..2d951f82c 100644 --- a/pkgs/native_assets_cli/test/link_config_test.dart +++ b/pkgs/native_assets_cli/test/link_config_test.dart @@ -28,22 +28,22 @@ void main() async { ]; }); - test('LinkConfigBuilder->JSON->LinkConfig', () { - final configBuilder = LinkConfigBuilder() - ..setupHookConfig( + test('LinkInputBuilder->JSON->LinkInput', () { + final inputBuilder = LinkInputBuilder() + ..setupShared( packageName: packageName, packageRoot: packageRootUri, - buildAssetTypes: ['asset-type-1', 'asset-type-2'], - ) - ..setupLinkConfig(assets: assets) - ..setupLinkRunConfig( outputDirectory: outDirUri, outputDirectoryShared: outputDirectoryShared, + ) + ..config.setupShared(buildAssetTypes: ['asset-type-1', 'asset-type-2']) + ..setupLink( + assets: assets, recordedUsesFile: null, ); - final config = LinkConfig(configBuilder.json); + final input = LinkInput(inputBuilder.json); - final expectedConfigJson = { + final expectedInputJson = { 'assets': [for (final asset in assets) asset.toJson()], 'build_asset_types': ['asset-type-1', 'asset-type-2'], 'build_mode': 'release', @@ -54,23 +54,23 @@ void main() async { 'supported_asset_types': ['asset-type-1', 'asset-type-2'], 'version': latestVersion.toString(), }; - expect(config.json, expectedConfigJson); - expect(json.decode(config.toString()), expectedConfigJson); + expect(input.json, expectedInputJson); + expect(json.decode(input.toString()), expectedInputJson); - expect(config.outputDirectory, outDirUri); - expect(config.outputDirectoryShared, outputDirectoryShared); + expect(input.outputDirectory, outDirUri); + expect(input.outputDirectoryShared, outputDirectoryShared); - expect(config.packageName, packageName); - expect(config.packageRoot, packageRootUri); - expect(config.buildAssetTypes, ['asset-type-1', 'asset-type-2']); - expect(config.encodedAssets, assets); + expect(input.packageName, packageName); + expect(input.packageRoot, packageRootUri); + expect(input.config.buildAssetTypes, ['asset-type-1', 'asset-type-2']); + expect(input.assets.encodedAssets, assets); }); - group('LinkConfig FormatExceptions', () { + group('LinkInput FormatExceptions', () { for (final version in ['9001.0.0', '0.0.1']) { - test('LinkConfig version $version', () { + test('LinkInput version $version', () { final outDir = outDirUri; - final config = { + final input = { 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'out_dir_shared': outputDirectoryShared.toFilePath(), @@ -82,7 +82,7 @@ void main() async { 'dry_run': true, }; expect( - () => LinkConfig(config), + () => LinkInput(input), throwsA(predicate( (e) => e is FormatException && @@ -92,9 +92,9 @@ void main() async { ); }); } - test('LinkConfig FormatExceptions', () { + test('LinkInput FormatExceptions', () { expect( - () => LinkConfig({}), + () => LinkInput({}), throwsA(predicate( (e) => e is FormatException && @@ -102,7 +102,7 @@ void main() async { )), ); expect( - () => LinkConfig({ + () => LinkInput({ 'version': latestVersion.toString(), 'build_asset_types': ['my-asset-type'], 'package_name': packageName, @@ -119,7 +119,7 @@ void main() async { )), ); expect( - () => LinkConfig({ + () => LinkInput({ 'version': latestVersion.toString(), 'build_asset_types': ['my-asset-type'], 'out_dir': outDirUri.toFilePath(), @@ -133,7 +133,7 @@ void main() async { (e) => e is FormatException && e.message.contains( - "Unexpected value 'astring' for key '.assets' in config file. " + "Unexpected value 'astring' for key '.assets' in input file. " 'Expected a List?.', ), )), diff --git a/pkgs/native_assets_cli/test/link_output_test.dart b/pkgs/native_assets_cli/test/link_output_test.dart index 8d87b4aa7..34de1c2b9 100644 --- a/pkgs/native_assets_cli/test/link_output_test.dart +++ b/pkgs/native_assets_cli/test/link_output_test.dart @@ -23,15 +23,14 @@ void main() { builder.addDependency(uris.take(1).single); builder.addDependencies(uris.skip(1).toList()); - builder.addEncodedAsset(assets.take(1).single); - builder.addEncodedAssets(assets.skip(1).take(2).toList()); + builder.assets.addEncodedAsset(assets.take(1).single); + builder.assets.addEncodedAssets(assets.skip(1).take(2).toList()); - final config = BuildOutput(builder.json); - expect(config.timestamp.compareTo(before), greaterThanOrEqualTo(0)); - expect(config.timestamp.compareTo(after), lessThanOrEqualTo(0)); + final input = BuildOutput(builder.json); + expect(input.timestamp.compareTo(before), greaterThanOrEqualTo(0)); + expect(input.timestamp.compareTo(after), lessThanOrEqualTo(0)); expect( - config.timestamp - .isAtSameMomentAs(config.timestamp.roundDownToSeconds()), + input.timestamp.isAtSameMomentAs(input.timestamp.roundDownToSeconds()), true); // The JSON format of the link output. @@ -44,7 +43,7 @@ void main() { {'a-2': 'v-2', 'type': 'my-asset-type'} ] }.forEach((k, v) { - expect(config.json[k], equals(v)); + expect(input.json[k], equals(v)); }); }); diff --git a/pkgs/native_assets_cli/test/validation_test.dart b/pkgs/native_assets_cli/test/validation_test.dart index fae2834d1..d2ddea7e2 100644 --- a/pkgs/native_assets_cli/test/validation_test.dart +++ b/pkgs/native_assets_cli/test/validation_test.dart @@ -29,35 +29,33 @@ void main() { await Directory.fromUri(tempUri).delete(recursive: true); }); - BuildConfig makeBuildConfig() { - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( + BuildInput makeBuildInput() { + final inputBuilder = BuildInputBuilder() + ..setupShared( packageName: packageName, packageRoot: tempUri, - buildAssetTypes: ['my-asset-type'], + outputDirectory: outDirUri, + outputDirectoryShared: outDirSharedUri, ) - ..setupBuildConfig( + ..config.setupShared(buildAssetTypes: ['my-asset-type']) + ..config.setupBuild( linkingEnabled: false, dryRun: false, - ) - ..setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outDirSharedUri, ); - return BuildConfig(configBuilder.json); + return BuildInput(inputBuilder.json); } test('linking not enabled', () async { - final config = makeBuildConfig(); + final input = makeBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.addEncodedAsset( + outputBuilder.assets.addEncodedAsset( EncodedAsset('my-asset-type', {}), linkInPackage: 'bar', ); final errors = - await validateBuildOutput(config, BuildOutput(outputBuilder.json)); + await validateBuildOutput(input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains('linkingEnabled is false')), @@ -65,13 +63,13 @@ void main() { }); test('supported asset type', () async { - final config = makeBuildConfig(); + final input = makeBuildInput(); final outputBuilder = BuildOutputBuilder(); final assetFile = File.fromUri(outDirUri.resolve('foo.dylib')); await assetFile.writeAsBytes([1, 2, 3]); - outputBuilder.addEncodedAsset(EncodedAsset('baz', {})); + outputBuilder.assets.addEncodedAsset(EncodedAsset('baz', {})); final errors = - await validateBuildOutput(config, BuildOutput(outputBuilder.json)); + await validateBuildOutput(input, BuildOutput(outputBuilder.json)); expect( errors, contains(contains('"baz" is not a supported asset type')), diff --git a/pkgs/native_toolchain_c/CHANGELOG.md b/pkgs/native_toolchain_c/CHANGELOG.md index 7b494d069..aa9bd3d35 100644 --- a/pkgs/native_toolchain_c/CHANGELOG.md +++ b/pkgs/native_toolchain_c/CHANGELOG.md @@ -1,6 +1,6 @@ -## 0.7.1-wip +## 0.8.0-wip -- Nothing yet. +- Bump `package:native_assets_cli` to 0.11.0. ## 0.7.0 diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index 5f0038277..27b04cab8 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -20,7 +20,7 @@ import 'run_cbuilder.dart'; class CBuilder extends CTool implements Builder { /// The dart files involved in building this artifact. /// - /// Resolved against [BuildConfig.packageRoot]. + /// Resolved against [BuildInput.packageRoot]. /// /// Used to output the [BuildOutput.dependencies]. @Deprecated( @@ -112,29 +112,30 @@ class CBuilder extends CTool implements Builder { /// Completes with an error if the build fails. @override Future run({ - required BuildConfig config, + required BuildInput input, required BuildOutputBuilder output, required Logger? logger, String? linkInPackage, }) async { - if (!config.buildAssetTypes.contains(CodeAsset.type)) { + if (!input.config.buildCodeAssets) { logger?.info('buildAssetTypes did not contain "${CodeAsset.type}", ' 'skipping CodeAsset $assetName build.'); return; } assert( - config.linkingEnabled || linkInPackage == null, - 'linkInPackage can only be provided if config.linkingEnabled is true.', + input.config.linkingEnabled || linkInPackage == null, + 'linkInPackage can only be provided if input.config.linkingEnabled' + ' is true.', ); - final outDir = config.outputDirectory; - final packageRoot = config.packageRoot; + final outDir = input.outputDirectory; + final packageRoot = input.packageRoot; await Directory.fromUri(outDir).create(recursive: true); final linkMode = - getLinkMode(linkModePreference ?? config.codeConfig.linkModePreference); + getLinkMode(linkModePreference ?? input.config.code.linkModePreference); final libUri = outDir - .resolve(config.codeConfig.targetOS.libraryFileName(name, linkMode)); + .resolve(input.config.code.targetOS.libraryFileName(name, linkMode)); final exeUri = - outDir.resolve(config.codeConfig.targetOS.executableFileName(name)); + outDir.resolve(input.config.code.targetOS.executableFileName(name)); final sources = [ for (final source in this.sources) packageRoot.resolveUri(Uri.file(source)), @@ -152,10 +153,10 @@ class CBuilder extends CTool implements Builder { outDir.resolveUri(Uri.file(directory)), ]; // ignore: deprecated_member_use - if (!config.dryRun) { + if (!input.config.dryRun) { final task = RunCBuilder( - config: config, - codeConfig: config.codeConfig, + input: input, + codeConfig: input.config.code, logger: logger, sources: sources, includes: includes, @@ -188,22 +189,22 @@ class CBuilder extends CTool implements Builder { } if (assetName != null) { - output.codeAssets.add( + output.assets.code.add( CodeAsset( - package: config.packageName, + package: input.packageName, name: assetName!, file: libUri, linkMode: linkMode, - os: config.codeConfig.targetOS, + os: input.config.code.targetOS, architecture: // ignore: deprecated_member_use - config.dryRun ? null : config.codeConfig.targetArchitecture, + input.config.dryRun ? null : input.config.code.targetArchitecture, ), linkInPackage: linkInPackage, ); } // ignore: deprecated_member_use - if (!config.dryRun) { + if (!input.config.dryRun) { final includeFiles = await Stream.fromIterable(includes) .asyncExpand( (include) => Directory(include.toFilePath()) diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart index 425944630..1f72b050f 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart @@ -47,21 +47,21 @@ class CLinker extends CTool implements Linker { /// Completes with an error if the linking fails. @override Future run({ - required LinkConfig config, + required LinkInput input, required LinkOutputBuilder output, required Logger? logger, }) async { - if (OS.current != OS.linux || config.codeConfig.targetOS != OS.linux) { + if (OS.current != OS.linux || input.config.code.targetOS != OS.linux) { throw UnsupportedError('Currently, only linux is supported for this ' 'feature. See also https://github.com/dart-lang/native/issues/1376'); } - final outDir = config.outputDirectory; - final packageRoot = config.packageRoot; + final outDir = input.outputDirectory; + final packageRoot = input.packageRoot; await Directory.fromUri(outDir).create(recursive: true); final linkMode = - getLinkMode(linkModePreference ?? config.codeConfig.linkModePreference); + getLinkMode(linkModePreference ?? input.config.code.linkModePreference); final libUri = outDir - .resolve(config.codeConfig.targetOS.libraryFileName(name, linkMode)); + .resolve(input.config.code.targetOS.libraryFileName(name, linkMode)); final sources = [ for (final source in this.sources) packageRoot.resolveUri(Uri.file(source)), @@ -75,8 +75,8 @@ class CLinker extends CTool implements Linker { outDir.resolveUri(Uri.file(directory)), ]; final task = RunCBuilder( - config: config, - codeConfig: config.codeConfig, + input: input, + codeConfig: input.config.code, linkerOptions: linkerOptions, logger: logger, sources: sources, @@ -99,13 +99,13 @@ class CLinker extends CTool implements Linker { await task.run(); if (assetName != null) { - output.codeAssets.add(CodeAsset( - package: config.packageName, + output.assets.code.add(CodeAsset( + package: input.packageName, name: assetName!, file: libUri, linkMode: linkMode, - os: config.codeConfig.targetOS, - architecture: config.codeConfig.targetArchitecture, + os: input.config.code.targetOS, + architecture: input.config.code.targetArchitecture, )); } final includeFiles = await Stream.fromIterable(includes) diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart index e329435eb..29b4795cc 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart @@ -35,7 +35,7 @@ class CompilerResolver { Future resolveCompiler() async { // First, check if the launcher provided a direct path to the compiler. - var result = await _tryLoadCompilerFromConfig(); + var result = await _tryLoadCompilerFromInput(); // Then, try to detect on the host machine. final tool = _selectCompiler(); @@ -98,16 +98,16 @@ class CompilerResolver { return null; } - Future _tryLoadCompilerFromConfig() async { - final configCcUri = codeConfig.cCompiler?.compiler; - if (configCcUri != null) { - assert(await File.fromUri(configCcUri).exists()); - logger?.finer('Using compiler ${configCcUri.toFilePath()} ' - 'from BuildConfig.cCompiler.cc.'); - return (await CompilerRecognizer(configCcUri).resolve(logger: logger)) + Future _tryLoadCompilerFromInput() async { + final inputCcUri = codeConfig.cCompiler?.compiler; + if (inputCcUri != null) { + assert(await File.fromUri(inputCcUri).exists()); + logger?.finer('Using compiler ${inputCcUri.toFilePath()} ' + 'from BuildInput.cCompiler.cc.'); + return (await CompilerRecognizer(inputCcUri).resolve(logger: logger)) .first; } - logger?.finer('No compiler set in BuildConfig.cCompiler.cc.'); + logger?.finer('No compiler set in BuildInput.cCompiler.cc.'); return null; } @@ -121,7 +121,7 @@ class CompilerResolver { Future resolveArchiver() async { // First, check if the launcher provided a direct path to the compiler. - var result = await _tryLoadArchiverFromConfig(); + var result = await _tryLoadArchiverFromInput(); // Then, try to detect on the host machine. final tool = _selectArchiver(); @@ -183,24 +183,24 @@ class CompilerResolver { return null; } - Future _tryLoadArchiverFromConfig() async { - final configArUri = codeConfig.cCompiler?.archiver; - if (configArUri != null) { - assert(await File.fromUri(configArUri).exists()); - logger?.finer('Using archiver ${configArUri.toFilePath()} ' - 'from BuildConfig.cCompiler.ar.'); - return (await ArchiverRecognizer(configArUri).resolve(logger: logger)) + Future _tryLoadArchiverFromInput() async { + final inputArUri = codeConfig.cCompiler?.archiver; + if (inputArUri != null) { + assert(await File.fromUri(inputArUri).exists()); + logger?.finer('Using archiver ${inputArUri.toFilePath()} ' + 'from BuildInput.cCompiler.ar.'); + return (await ArchiverRecognizer(inputArUri).resolve(logger: logger)) .first; } - logger?.finer('No archiver set in BuildConfig.cCompiler.ar.'); + logger?.finer('No archiver set in BuildInput.cCompiler.ar.'); return null; } Future toolchainEnvironmentScript(ToolInstance compiler) async { - final fromConfig = codeConfig.cCompiler?.envScript; - if (fromConfig != null) { - logger?.fine('Using envScript from config: $fromConfig'); - return fromConfig; + final fromInput = codeConfig.cCompiler?.envScript; + if (fromInput != null) { + logger?.fine('Using envScript from input: $fromInput'); + return fromInput; } final compilerTool = compiler.tool; @@ -211,10 +211,10 @@ class CompilerResolver { } List? toolchainEnvironmentScriptArguments() { - final fromConfig = codeConfig.cCompiler?.envScriptArgs; - if (fromConfig != null) { - logger?.fine('Using envScriptArgs from config: $fromConfig'); - return fromConfig; + final fromInput = codeConfig.cCompiler?.envScriptArgs; + if (fromInput != null) { + logger?.fine('Using envScriptArgs from input: $fromInput'); + return fromInput; } // vcvars above already has x64 or x86 in the script name. @@ -225,7 +225,7 @@ class CompilerResolver { final targetOS = codeConfig.targetOS; final targetArchitecture = codeConfig.targetArchitecture; // First, check if the launcher provided a direct path to the compiler. - var result = await _tryLoadLinkerFromConfig(); + var result = await _tryLoadLinkerFromInput(); // Then, try to detect on the host machine. final tool = _selectLinker(); @@ -244,13 +244,13 @@ class CompilerResolver { throw ToolError(errorMessage); } - Future _tryLoadLinkerFromConfig() async { - final configLdUri = codeConfig.cCompiler?.linker; - if (configLdUri != null) { - assert(await File.fromUri(configLdUri).exists()); - logger?.finer('Using linker ${configLdUri.toFilePath()} ' + Future _tryLoadLinkerFromInput() async { + final inputLdUri = codeConfig.cCompiler?.linker; + if (inputLdUri != null) { + assert(await File.fromUri(inputLdUri).exists()); + logger?.finer('Using linker ${inputLdUri.toFilePath()} ' 'from cCompiler.ld.'); - final tools = await LinkerRecognizer(configLdUri).resolve(logger: logger); + final tools = await LinkerRecognizer(inputLdUri).resolve(logger: logger); return tools.first; } logger?.finer('No linker set in cCompiler.ld.'); diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart index 4234337e2..5d85127b3 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart @@ -22,7 +22,7 @@ abstract class CTool { /// [OSLibraryNaming.libraryFileName] or /// [OSLibraryNaming.executableFileName]. /// - /// File will be placed in [LinkConfig.outputDirectory]. + /// File will be placed in [LinkInput.outputDirectory]. final String name; /// Asset identifier. @@ -34,14 +34,14 @@ abstract class CTool { /// Sources to build the library or executable. /// - /// Resolved against [LinkConfig.packageRoot]. + /// Resolved against [LinkInput.packageRoot]. /// /// The sources will be reported as dependencies of the hook. final List sources; /// Include directories to pass to the linker. /// - /// Resolved against [LinkConfig.packageRoot]. + /// Resolved against [LinkInput.packageRoot]. /// /// The sources will be reported as dependencies of the hook. final List includes; @@ -76,16 +76,16 @@ abstract class CTool { /// Directories to search for [libraries], in addition to the system default /// directories. /// - /// Resolved against [LinkConfig.outputDirectory]. + /// Resolved against [LinkInput.outputDirectory]. /// - /// Defaults to `['.']`, which means the [LinkConfig.outputDirectory] will be + /// Defaults to `['.']`, which means the [LinkInput.outputDirectory] will be /// searched for libraries. final List libraryDirectories; /// The default [libraryDirectories]. static const List defaultLibraryDirectories = ['.']; - /// TODO(https://github.com/dart-lang/native/issues/54): Move to [LinkConfig] + /// TODO(https://github.com/dart-lang/native/issues/54): Move to [LinkInput] /// or hide in public API. @visibleForTesting final Uri? installName; @@ -143,7 +143,7 @@ abstract class CTool { /// If the code asset should be a dynamic or static library. /// /// This determines whether to produce a dynamic or static library. If null, - /// the value is instead retrieved from the [LinkConfig]. + /// the value is instead retrieved from the [LinkInput]. final LinkModePreference? linkModePreference; /// What optimization level should be used for compiling. diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart index d593033e7..184bc679c 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart @@ -22,7 +22,7 @@ class RunCBuilder { /// The options are for linking only, so this will be non-null iff a linker /// should be run. final LinkerOptions? linkerOptions; - final HookConfig config; + final HookInput input; final CodeConfig codeConfig; final Logger? logger; final List sources; @@ -51,7 +51,7 @@ class RunCBuilder { final OptimizationLevel optimizationLevel; RunCBuilder({ - required this.config, + required this.input, required this.codeConfig, this.linkerOptions, this.logger, @@ -71,7 +71,7 @@ class RunCBuilder { this.language = Language.c, this.cppLinkStdLib, required this.optimizationLevel, - }) : outDir = config.outputDirectory, + }) : outDir = input.outputDirectory, assert([executable, dynamicLibrary, staticLibrary] .whereType() .length == @@ -140,7 +140,7 @@ class RunCBuilder { final IOSSdk? targetIosSdk; if (codeConfig.targetOS == OS.iOS) { - targetIosSdk = codeConfig.iOSConfig.targetSdk; + targetIosSdk = codeConfig.iOS.targetSdk; } else { targetIosSdk = null; } @@ -152,18 +152,15 @@ class RunCBuilder { if (codeConfig.targetOS == OS.android) { final minimumApi = codeConfig.targetArchitecture == Architecture.riscv64 ? 35 : 21; - targetAndroidNdkApi = - max(codeConfig.androidConfig.targetNdkApi, minimumApi); + targetAndroidNdkApi = max(codeConfig.android.targetNdkApi, minimumApi); } else { targetAndroidNdkApi = null; } - final targetIOSVersion = codeConfig.targetOS == OS.iOS - ? codeConfig.iOSConfig.targetVersion - : null; - final targetMacOSVersion = codeConfig.targetOS == OS.macOS - ? codeConfig.macOSConfig.targetVersion - : null; + final targetIOSVersion = + codeConfig.targetOS == OS.iOS ? codeConfig.iOS.targetVersion : null; + final targetMacOSVersion = + codeConfig.targetOS == OS.macOS ? codeConfig.macOS.targetVersion : null; final architecture = codeConfig.targetArchitecture; final sourceFiles = sources.map((e) => e.toFilePath()).toList(); diff --git a/pkgs/native_toolchain_c/pubspec.yaml b/pkgs/native_toolchain_c/pubspec.yaml index f90eae972..47bed04e9 100644 --- a/pkgs/native_toolchain_c/pubspec.yaml +++ b/pkgs/native_toolchain_c/pubspec.yaml @@ -1,7 +1,7 @@ name: native_toolchain_c description: >- A library to invoke the native C compiler installed on the host machine. -version: 0.7.1-wip +version: 0.8.0-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c publish_to: none diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart index c8f1961c9..9bea9ee7f 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart @@ -30,31 +30,29 @@ void main() { const name = 'add'; final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -65,7 +63,7 @@ void main() { ); expect( () => cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ), diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart index bafad7c78..35f61b829 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart @@ -144,31 +144,29 @@ Future buildLib( final tempUriShared = tempUri.resolve('shared/'); await Directory.fromUri(tempUriShared).create(); - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUriShared, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.android, targetArchitecture: targetArchitecture, - cCompilerConfig: cCompiler, - androidConfig: AndroidConfig(targetNdkApi: androidNdkApi), + cCompiler: cCompiler, + android: AndroidConfig(targetNdkApi: androidNdkApi), linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUriShared, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -179,7 +177,7 @@ Future buildLib( buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart index d8cba0401..5e31bf7b5 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart @@ -73,34 +73,32 @@ void main() { Language() => throw UnimplementedError(), }; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.iOS, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - iOSConfig: IOSConfig( + iOS: IOSConfig( targetSdk: targetIOSSdk, targetVersion: flutteriOSHighestBestEffort, ), - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -113,7 +111,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -230,34 +228,32 @@ Future buildLib( final addCUri = packageUri.resolve('test/cbuilder/testfiles/add/src/add.c'); const name = 'add'; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.iOS, targetArchitecture: targetArchitecture, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - iOSConfig: IOSConfig( + iOS: IOSConfig( targetSdk: IOSSdk.iPhoneOS, targetVersion: targetIOSVersion, ), - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -267,7 +263,7 @@ Future buildLib( buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart index d0be152b7..27f1db3a5 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart @@ -42,30 +42,28 @@ void main() { packageUri.resolve('test/cbuilder/testfiles/add/src/add.c'); const name = 'add'; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.linux, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -76,7 +74,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart index 09c781cee..412f20afd 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart @@ -57,30 +57,28 @@ void main() { }; const name = 'add'; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.macOS, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - cCompilerConfig: cCompiler, - macOSConfig: MacOSConfig(targetVersion: defaultMacOSVersion), + cCompiler: cCompiler, + macOS: MacOSConfig(targetVersion: defaultMacOSVersion), ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -92,7 +90,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -159,31 +157,29 @@ Future buildLib( final addCUri = packageUri.resolve('test/cbuilder/testfiles/add/src/add.c'); const name = 'add'; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.macOS, targetArchitecture: targetArchitecture, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - macOSConfig: MacOSConfig(targetVersion: targetMacOSVersion), - cCompilerConfig: cCompiler, + macOS: MacOSConfig(targetVersion: targetMacOSVersion), + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -193,7 +189,7 @@ Future buildLib( buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart index 92109a604..11bb9152c 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart @@ -61,30 +61,28 @@ void main() { packageUri.resolve('test/cbuilder/testfiles/add/src/add.c'); const name = 'add'; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.windows, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -95,7 +93,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index e33c18afa..e67cfc85e 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -47,30 +47,28 @@ void main() { final logMessages = []; final logger = createCapturingLogger(logMessages); - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.executable( @@ -80,7 +78,7 @@ void main() { buildMode: buildMode, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -102,7 +100,7 @@ void main() { (message) => message.contains(helloWorldCUri.toFilePath()), ); - switch ((buildConfig.codeConfig.targetOS, pic)) { + switch ((buildInput.config.code.targetOS, pic)) { case (OS.windows, _) || (_, null): expect(compilerInvocation, isNot(contains('-fPIC'))); expect(compilerInvocation, isNot(contains('-fPIE'))); @@ -131,30 +129,31 @@ void main() { final logMessages = []; final logger = createCapturingLogger(logMessages); - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [if (buildCodeAssets) CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: dryRun, ); if (buildCodeAssets) { - buildConfigBuilder.setupCodeConfig( + buildInputBuilder.config.setupShared( + buildAssetTypes: [CodeAsset.type], + ); + buildInputBuilder.config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dryRun ? null : cCompiler, + cCompiler: dryRun ? null : cCompiler, ); } - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -165,7 +164,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -184,7 +183,7 @@ void main() { final compilerInvocation = logMessages.singleWhere( (message) => message.contains(addCUri.toFilePath()), ); - switch ((buildConfig.codeConfig.targetOS, pic)) { + switch ((buildInput.config.code.targetOS, pic)) { case (OS.windows, _) || (_, null): expect(compilerInvocation, isNot(contains('-fPIC'))); expect(compilerInvocation, isNot(contains('-fPIE'))); @@ -239,32 +238,30 @@ void main() { final logMessages = []; final logger = createCapturingLogger(logMessages); - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); - final flag = switch (buildConfig.codeConfig.targetOS) { + final flag = switch (buildInput.config.code.targetOS) { OS.windows => '/DFOO=USER_FLAG', _ => '-DFOO=USER_FLAG', }; @@ -276,7 +273,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -307,29 +304,28 @@ void main() { packageUri.resolve('test/cbuilder/testfiles/includes/src/includes.c'); const name = 'includes'; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + + final buildInput = BuildInput(buildInputBuilder.json); final buildOutputBuilder = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -340,7 +336,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutputBuilder, logger: logger, ); @@ -365,32 +361,31 @@ void main() { final logger = createCapturingLogger(logMessages); final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); - final stdFlag = switch (buildConfig.codeConfig.targetOS) { + final stdFlag = switch (buildInput.config.code.targetOS) { OS.windows => '/std:$std', _ => '-std=$std', }; @@ -403,7 +398,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -435,32 +430,30 @@ void main() { final logger = createCapturingLogger(logMessages); final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); - final defaultStdLibLinkFlag = switch (buildConfig.codeConfig.targetOS) { + final defaultStdLibLinkFlag = switch (buildInput.config.code.targetOS) { OS.windows => null, OS.linux => '-l stdc++', OS.macOS => '-l c++', @@ -474,7 +467,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -510,29 +503,27 @@ void main() { final logger = createCapturingLogger(logMessages); final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.executable( @@ -543,10 +534,10 @@ void main() { buildMode: BuildMode.release, ); - if (buildConfig.codeConfig.targetOS == OS.windows) { + if (buildInput.config.code.targetOS == OS.windows) { await expectLater( () => cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ), @@ -554,7 +545,7 @@ void main() { ); } else { await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -596,29 +587,27 @@ void main() { final logger = createCapturingLogger(logMessages); final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: macOSConfig, + macOS: macOSConfig, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final debugBuilder = CBuilder.library( @@ -630,7 +619,7 @@ void main() { ); await debugBuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -653,7 +642,7 @@ void main() { ); await mathBuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -668,7 +657,7 @@ void main() { ); await executableBuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); @@ -699,31 +688,30 @@ Future testDefines({ const name = 'defines'; final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.executable( @@ -738,7 +726,7 @@ Future testDefines({ buildMode: buildMode, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); diff --git a/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart b/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart index ad4512357..f269bb057 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart @@ -19,7 +19,7 @@ import 'package:test/test.dart'; import '../helpers.dart'; void main() { - test('Config provided compiler', () async { + test('Input provided compiler', () async { final tempUri = await tempDirForTest(); final tempUri2 = await tempDirForTest(); final ar = [ @@ -42,71 +42,67 @@ void main() { ].firstOrNull?.uri; final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: 'dummy', packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: CCompilerConfig( + cCompiler: CCompilerConfig( archiver: ar, compiler: cc, linker: ld, envScript: envScript, ), ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final resolver = - CompilerResolver(codeConfig: buildConfig.codeConfig, logger: logger); + CompilerResolver(codeConfig: buildInput.config.code, logger: logger); final compiler = await resolver.resolveCompiler(); final archiver = await resolver.resolveArchiver(); - expect(compiler.uri, buildConfig.codeConfig.cCompiler?.compiler); - expect(archiver.uri, buildConfig.codeConfig.cCompiler?.archiver); + expect(compiler.uri, buildInput.config.code.cCompiler?.compiler); + expect(archiver.uri, buildInput.config.code.cCompiler?.archiver); }); test('No compiler found', () async { final tempUri = await tempDirForTest(); final tempUri2 = await tempDirForTest(); - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: 'dummy', packageRoot: tempUri, + outputDirectoryShared: tempUri2, + outputDirectory: tempUri, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: OS.windows, targetArchitecture: Architecture.arm64, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectoryShared: tempUri2, - outputDirectory: tempUri, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final resolver = CompilerResolver( - codeConfig: buildConfig.codeConfig, + codeConfig: buildInput.config.code, logger: logger, hostOS: OS.android, // This is never a host. hostArchitecture: Architecture.arm64, // This is never a host. diff --git a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart index 7a78e01eb..8a4a1e433 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart @@ -36,31 +36,29 @@ void main() { final logger = createCapturingLogger(logMessages); final targetOS = OS.current; - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: targetOS, - macOSConfig: targetOS == OS.macOS + macOS: targetOS == OS.macOS ? MacOSConfig(targetVersion: defaultMacOSVersion) : null, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutput = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -71,7 +69,7 @@ void main() { buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutput, logger: logger, ); diff --git a/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart b/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart index 4c76bfef5..06b0c4731 100644 --- a/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart +++ b/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart @@ -25,29 +25,27 @@ Future buildTestArchive( final logMessages = []; final logger = createCapturingLogger(logMessages); - assert(os == OS.linux); // Setup code config for other OSes. - final buildConfigBuilder = BuildConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + assert(os == OS.linux); // Setup code input for other OSes. + final buildInputBuilder = BuildInputBuilder() + ..setupShared( packageName: name, packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupBuildConfig( + ..config.setupBuild( linkingEnabled: false, dryRun: false, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: os, targetArchitecture: architecture, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - buildConfigBuilder.setupBuildRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - ); - final buildConfig = BuildConfig(buildConfigBuilder.json); + final buildInput = BuildInput(buildInputBuilder.json); final buildOutputBuilder = BuildOutputBuilder(); final cbuilder = CBuilder.library( @@ -58,11 +56,11 @@ Future buildTestArchive( buildMode: BuildMode.release, ); await cbuilder.run( - config: buildConfig, + input: buildInput, output: buildOutputBuilder, logger: logger, ); final buildOutput = BuildOutput(buildOutputBuilder.json); - return buildOutput.codeAssets.first.file!; + return buildOutput.assets.code.first.file!; } diff --git a/pkgs/native_toolchain_c/test/clinker/objects_test.dart b/pkgs/native_toolchain_c/test/clinker/objects_test.dart index 0797b194c..020e82381 100644 --- a/pkgs/native_toolchain_c/test/clinker/objects_test.dart +++ b/pkgs/native_toolchain_c/test/clinker/objects_test.dart @@ -31,30 +31,29 @@ Future main() async { final uri = await buildTestArchive(tempUri, tempUri2, os, architecture); - final linkConfigBuilder = LinkConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final linkInputBuilder = LinkInputBuilder() + ..setupShared( packageName: 'testpackage', packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupLinkConfig( + ..setupLink( assets: [], + recordedUsesFile: null, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: os, targetArchitecture: architecture, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - linkConfigBuilder.setupLinkRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - recordedUsesFile: null, - ); - final linkConfig = LinkConfig(linkConfigBuilder.json); + + final linkInput = LinkInput(linkInputBuilder.json); final linkOutput = LinkOutputBuilder(); - printOnFailure(linkConfig.codeConfig.cCompiler.toString()); + printOnFailure(linkInput.config.code.cCompiler.toString()); printOnFailure(Platform.environment.keys.toList().toString()); await CLinker.library( name: name, @@ -62,12 +61,12 @@ Future main() async { linkerOptions: LinkerOptions.manual(gcSections: false), sources: [uri.toFilePath()], ).run( - config: linkConfig, + input: linkInput, output: linkOutput, logger: logger, ); - final codeAssets = LinkOutput(linkOutput.json).codeAssets; + final codeAssets = LinkOutput(linkOutput.json).assets.code; expect(codeAssets, hasLength(1)); final asset = codeAssets.first; expect(asset, isA()); diff --git a/pkgs/native_toolchain_c/test/clinker/throws_test.dart b/pkgs/native_toolchain_c/test/clinker/throws_test.dart index 9a1c2a633..741d26afd 100644 --- a/pkgs/native_toolchain_c/test/clinker/throws_test.dart +++ b/pkgs/native_toolchain_c/test/clinker/throws_test.dart @@ -22,27 +22,26 @@ Future main() async { final tempUri = await tempDirForTest(); final tempUri2 = await tempDirForTest(); - final linkConfigBuilder = LinkConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final linkInputBuilder = LinkInputBuilder() + ..setupShared( packageName: 'testpackage', packageRoot: tempUri, + outputDirectoryShared: tempUri2, + outputDirectory: tempUri, ) - ..setupLinkConfig( + ..setupLink( assets: [], + recordedUsesFile: null, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: os, targetArchitecture: Architecture.x64, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - linkConfigBuilder.setupLinkRunConfig( - outputDirectoryShared: tempUri2, - outputDirectory: tempUri, - recordedUsesFile: null, - ); - final linkHookConfig = LinkConfig(linkConfigBuilder.json); + + final linkHookInput = LinkInput(linkInputBuilder.json); final cLinker = CLinker.library( name: 'mylibname', @@ -50,7 +49,7 @@ Future main() async { ); await expectLater( () => cLinker.run( - config: linkHookConfig, + input: linkHookInput, output: LinkOutputBuilder(), logger: logger, ), diff --git a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart index d8d55c88b..d359b88af 100644 --- a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart +++ b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart @@ -61,39 +61,38 @@ Future runTests(List architectures) async { architecture, ); - final linkConfigBuilder = LinkConfigBuilder() - ..setupHookConfig( - buildAssetTypes: [CodeAsset.type], + final linkInputBuilder = LinkInputBuilder() + ..setupShared( packageName: 'testpackage', packageRoot: tempUri, + outputDirectory: tempUri, + outputDirectoryShared: tempUri2, ) - ..setupLinkConfig( + ..setupLink( assets: [], + recordedUsesFile: null, ) - ..setupCodeConfig( + ..config.setupShared(buildAssetTypes: [CodeAsset.type]) + ..config.setupCode( targetOS: os, targetArchitecture: architecture, linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: cCompiler, + cCompiler: cCompiler, ); - linkConfigBuilder.setupLinkRunConfig( - outputDirectory: tempUri, - outputDirectoryShared: tempUri2, - recordedUsesFile: null, - ); - final linkConfig = LinkConfig(linkConfigBuilder.json); + + final linkInput = LinkInput(linkInputBuilder.json); final linkOutputBuilder = LinkOutputBuilder(); - printOnFailure(linkConfig.codeConfig.cCompiler.toString()); + printOnFailure(linkInput.config.code.cCompiler.toString()); printOnFailure(Platform.environment.keys.toList().toString()); await clinker.linker([testArchive.toFilePath()]).run( - config: linkConfig, + input: linkInput, output: linkOutputBuilder, logger: logger, ); final linkOutput = LinkOutput(linkOutputBuilder.json); - final asset = linkOutput.codeAssets.first; + final asset = linkOutput.assets.code.first; final filePath = asset.file!.toFilePath(); final machine = await readelfMachine(filePath);