From cf9d94463e4c1f143b8048f68f4d8ca62c5a2e54 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 9 Jul 2024 15:11:59 +0200 Subject: [PATCH 1/8] [native_assets_cli] `BuildConfig.hasLinkPhase` --- pkgs/native_assets_builder/CHANGELOG.md | 5 ++- .../lib/src/build_runner/build_runner.dart | 15 +++++++ pkgs/native_assets_builder/pubspec.yaml | 2 +- .../build_runner_build_dry_run_test.dart | 1 + .../build_runner/build_runner_cycle_test.dart | 1 + .../build_runner_reusability_test.dart | 4 ++ .../test/build_runner/helpers.dart | 5 +++ .../test/build_runner/link_dry_run_test.dart | 2 + pkgs/native_assets_cli/CHANGELOG.md | 4 +- .../lib/src/api/build_config.dart | 13 ++++++ .../lib/src/model/build_config.dart | 42 ++++++++++++++++--- .../lib/src/model/build_config_CHANGELOG.md | 7 ++++ .../lib/src/model/build_output_CHANGELOG.md | 6 ++- .../lib/src/model/hook_config.dart | 4 +- pkgs/native_assets_cli/pubspec.yaml | 2 +- .../test/api/build_config_test.dart | 38 +++++++++++++++++ .../test/api/build_test.dart | 1 + .../test/model/build_config_test.dart | 25 ++++++++++- .../test/model/build_output_test.dart | 2 + .../test/model/checksum_test.dart | 22 +++++++++- pkgs/native_toolchain_c/CHANGELOG.md | 2 +- .../cbuilder/cbuilder_build_failure_test.dart | 1 + .../cbuilder/cbuilder_cross_android_test.dart | 1 + .../cbuilder/cbuilder_cross_ios_test.dart | 2 + .../cbuilder_cross_linux_host_test.dart | 1 + .../cbuilder_cross_macos_host_test.dart | 2 + .../cbuilder_cross_windows_host_test.dart | 1 + .../test/cbuilder/cbuilder_test.dart | 9 ++++ .../test/cbuilder/compiler_resolver_test.dart | 2 + .../test/cbuilder/objective_c_test.dart | 1 + 30 files changed, 205 insertions(+), 18 deletions(-) diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index 817ebfd88..9ba2fbeba 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -1,6 +1,7 @@ -## 0.7.2-wip +## 0.8.0-wip -- Nothing yet. +- `BuildRunner.build` and `BuildRunner.buildDryRun` now have a required + `hasLinkPhase` parameter. ## 0.7.1 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 76b07212b..36f34f662 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 @@ -54,6 +54,7 @@ class NativeAssetsBuildRunner { PackageLayout? packageLayout, String? runPackageName, Iterable? supportedAssetTypes, + required bool hasLinkPhase, }) async => _run( hook: Hook.build, @@ -70,6 +71,7 @@ class NativeAssetsBuildRunner { packageLayout: packageLayout, runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, + hasLinkPhase: hasLinkPhase, ); /// [workingDirectory] is expected to contain `.dart_tool`. @@ -133,8 +135,10 @@ class NativeAssetsBuildRunner { String? runPackageName, Iterable? supportedAssetTypes, BuildResult? buildResult, + bool? hasLinkPhase, }) async { assert(hook == Hook.link || buildResult == null); + assert(hook == Hook.build || hasLinkPhase == null); packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final (buildPlan, packageGraph, planSuccess) = await _makePlan( @@ -168,6 +172,7 @@ class NativeAssetsBuildRunner { buildMode, linkModePreference, dependencyMetadata, + hasLinkPhase, cCompilerConfig, targetIOSSdk, targetAndroidNdkApi, @@ -201,6 +206,7 @@ class NativeAssetsBuildRunner { BuildModeImpl buildMode, LinkModePreferenceImpl linkModePreference, DependencyMetadata? dependencyMetadata, + bool? hasLinkPhase, CCompilerConfigImpl? cCompilerConfig, IOSSdkImpl? targetIOSSdk, int? targetAndroidNdkApi, @@ -224,6 +230,7 @@ class NativeAssetsBuildRunner { targetAndroidNdkApi: targetAndroidNdkApi, supportedAssetTypes: supportedAssetTypes, hook: hook, + hasLinkPhase: hasLinkPhase, ); final buildDirUri = packageLayout.dartToolNativeAssetsBuilder.resolve('$buildDirName/'); @@ -273,6 +280,7 @@ class NativeAssetsBuildRunner { targetMacOSVersion: targetMacOSVersion, cCompiler: cCompilerConfig, dependencyMetadata: dependencyMetadata, + hasLinkPhase: hasLinkPhase, targetAndroidNdkApi: targetAndroidNdkApi, ); } @@ -290,6 +298,7 @@ class NativeAssetsBuildRunner { required OSImpl targetOS, required Uri workingDirectory, required bool includeParentEnvironment, + required bool hasLinkPhase, PackageLayout? packageLayout, String? runPackageName, Iterable? supportedAssetTypes, @@ -303,6 +312,7 @@ class NativeAssetsBuildRunner { packageLayout: packageLayout, runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, + hasLinkPhase: hasLinkPhase, ); /// [workingDirectory] is expected to contain `.dart_tool`. @@ -332,6 +342,7 @@ class NativeAssetsBuildRunner { runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, buildDryRunResult: buildDryRunResult, + hasLinkPhase: null, ); Future _runDryRun({ @@ -344,6 +355,7 @@ class NativeAssetsBuildRunner { Iterable? supportedAssetTypes, required Hook hook, BuildDryRunResult? buildDryRunResult, + required bool? hasLinkPhase, }) async { packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final (buildPlan, _, planSuccess) = await _makePlan( @@ -367,6 +379,7 @@ class NativeAssetsBuildRunner { supportedAssetTypes: supportedAssetTypes, hook: hook, buildDryRunResult: buildDryRunResult, + hasLinkPhase: hasLinkPhase, ); var (buildOutput, packageSuccess) = await _runHookForPackage( hook, @@ -538,6 +551,7 @@ ${e.message} required Hook hook, BuildDryRunResult? buildDryRunResult, Iterable? supportedAssetTypes, + required bool? hasLinkPhase, }) async { final hookDirName = 'dry_run_${hook.name}_${targetOS}_$linkMode'; final outDirUri = buildParentDir.resolve('$hookDirName/out/'); @@ -554,6 +568,7 @@ ${e.message} targetOS: targetOS, linkModePreference: linkMode, supportedAssetTypes: supportedAssetTypes, + hasLinkPhase: hasLinkPhase, ); case Hook.link: return LinkConfigImpl.dryRun( diff --git a/pkgs/native_assets_builder/pubspec.yaml b/pkgs/native_assets_builder/pubspec.yaml index b80e25626..c4d124f64 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.7.2-wip +version: 0.8.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_runner_build_dry_run_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart index d40f6e12b..9a30e1e3a 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart @@ -28,6 +28,7 @@ void main() async { packageUri, logger, dartExecutable, + hasLinkPhase: false, ); final dryRunAssets = dryRunResult.assets.toList(); final result = await build( 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 2c1a21266..3e06df284 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 @@ -26,6 +26,7 @@ void main() async { packageUri, createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, + hasLinkPhase: false, ); final fullLog = logMessages.join('\n'); expect(result.success, false); 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 23ab01153..f10f66cf3 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 @@ -33,12 +33,14 @@ void main() async { linkModePreference: LinkModePreferenceImpl.dynamic, workingDirectory: packageUri, includeParentEnvironment: true, + hasLinkPhase: false, ); await buildRunner.buildDryRun( targetOS: Target.current.os, linkModePreference: LinkModePreferenceImpl.dynamic, workingDirectory: packageUri, includeParentEnvironment: true, + hasLinkPhase: false, ); await buildRunner.build( buildMode: BuildModeImpl.release, @@ -46,6 +48,7 @@ void main() async { target: Target.current, workingDirectory: packageUri, includeParentEnvironment: true, + hasLinkPhase: false, ); await buildRunner.build( buildMode: BuildModeImpl.release, @@ -53,6 +56,7 @@ void main() async { target: Target.current, workingDirectory: packageUri, includeParentEnvironment: true, + hasLinkPhase: false, ); }); }); diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index df35451b0..d2900f8d2 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -46,6 +46,7 @@ Future build( int? targetMacOSVersion, int? targetAndroidNdkApi, Target? target, + bool hasLinkPhase = false, }) async => await runWithLog(capturedLogs, () async { final result = await NativeAssetsBuildRunner( @@ -64,6 +65,7 @@ Future build( targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, targetAndroidNdkApi: targetAndroidNdkApi, + hasLinkPhase: hasLinkPhase, ); if (result.success) { @@ -155,6 +157,7 @@ Future<(BuildResult, LinkResult)> buildAndLink( targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, targetAndroidNdkApi: targetAndroidNdkApi, + hasLinkPhase: true, ); if (!buildResult.success) { @@ -217,6 +220,7 @@ Future buildDryRun( bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, + required bool hasLinkPhase, }) async => runWithLog(capturedLogs, () async { final result = await NativeAssetsBuildRunner( @@ -228,6 +232,7 @@ Future buildDryRun( workingDirectory: packageUri, includeParentEnvironment: includeParentEnvironment, packageLayout: packageLayout, + hasLinkPhase: hasLinkPhase, ); return result; }); diff --git a/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart b/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart index abb1eb1ff..ff7e24407 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart @@ -30,6 +30,7 @@ void main() async { packageUri, logger, dartExecutable, + hasLinkPhase: true, ); expect(buildResult.assets.length, 0); @@ -70,6 +71,7 @@ void main() async { packageUri, logger, dartExecutable, + hasLinkPhase: true, ); expect(buildResult.success, true); expect(_getNames(buildResult.assets), orderedEquals(builtHelperAssets)); diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index 8759f5297..454f49629 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -1,6 +1,6 @@ -## 0.6.2-wip +## 0.7.0-wip -- Nothing yet. +- `BuildConfig` constructors now have a required `hasLinkPhase` parameter. ## 0.6.1 diff --git a/pkgs/native_assets_cli/lib/src/api/build_config.dart b/pkgs/native_assets_cli/lib/src/api/build_config.dart index a290a19a6..d7d71d498 100644 --- a/pkgs/native_assets_cli/lib/src/api/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/build_config.dart @@ -16,6 +16,7 @@ import 'architecture.dart'; import 'asset.dart'; import 'build.dart'; import 'build_mode.dart'; +import 'build_output.dart'; import 'hook_config.dart'; import 'ios_sdk.dart'; import 'link_mode_preference.dart'; @@ -42,6 +43,14 @@ abstract final class BuildConfig implements HookConfig { /// during a [dryRun]. Object? metadatum(String packageName, String key); + /// Whether link hooks will be run after the build hooks. + /// + /// If [hasLinkPhase] is true, [BuildOutput.addAsset] can be called with + /// the `linkInPackage` parameter. + /// If [hasLinkPhase] is false, no assets should be added with the + /// `linkInPackage` parameter set. + bool get hasLinkPhase; + /// The version of [BuildConfig]. /// /// The build config is used in the protocol between the Dart and Flutter SDKs @@ -103,6 +112,7 @@ abstract final class BuildConfig implements HookConfig { required LinkModePreference linkModePreference, Map>? dependencyMetadata, Iterable? supportedAssetTypes, + required bool hasLinkPhase, }) => BuildConfigImpl( outputDirectory: outputDirectory, @@ -123,6 +133,7 @@ abstract final class BuildConfig implements HookConfig { entry.key: Metadata(entry.value.cast()) } : null, + hasLinkPhase: hasLinkPhase, supportedAssetTypes: supportedAssetTypes, ); @@ -139,6 +150,7 @@ abstract final class BuildConfig implements HookConfig { required Uri packageRoot, required OS targetOS, required LinkModePreference linkModePreference, + required bool hasLinkPhase, Iterable? supportedAssetTypes, }) => BuildConfigImpl.dryRun( @@ -148,5 +160,6 @@ abstract final class BuildConfig implements HookConfig { targetOS: targetOS as OSImpl, linkModePreference: linkModePreference as LinkModePreferenceImpl, supportedAssetTypes: supportedAssetTypes, + hasLinkPhase: hasLinkPhase, ); } diff --git a/pkgs/native_assets_cli/lib/src/model/build_config.dart b/pkgs/native_assets_cli/lib/src/model/build_config.dart index 61710d10a..8ef1128ba 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/build_config.dart @@ -34,6 +34,19 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { final Map? _dependencyMetadata; + @override + bool get hasLinkPhase { + if (version <= Version(1, 2, 0)) { + return false; + } + if (version == Version(1, 3, 0)) { + return true; + } + return _hasLinkPhase as bool; + } + + final bool? _hasLinkPhase; + static List _supportedAssetTypesBackwardsCompatibility( Iterable? supportedAssetTypes, ) => @@ -55,14 +68,22 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { required super.targetOS, required super.linkModePreference, Map? dependencyMetadata, + required bool? hasLinkPhase, super.dryRun, }) : _dependencyMetadata = dependencyMetadata, + _hasLinkPhase = hasLinkPhase, super( hook: Hook.build, version: version ?? HookConfigImpl.latestVersion, supportedAssetTypes: _supportedAssetTypesBackwardsCompatibility(supportedAssetTypes), - ); + ) { + if (this.version < Version(1, 4, 0)) { + assert(hasLinkPhase == null); + } else { + assert(hasLinkPhase != null); + } + } BuildConfigImpl.dryRun({ required super.outputDirectory, @@ -70,8 +91,10 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { required super.packageRoot, required super.targetOS, required super.linkModePreference, + required bool? hasLinkPhase, Iterable? supportedAssetTypes, }) : _dependencyMetadata = null, + _hasLinkPhase = hasLinkPhase, super.dryRun( hook: Hook.build, version: HookConfigImpl.latestVersion, @@ -100,6 +123,8 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { static const dependencyMetadataConfigKey = 'dependency_metadata'; + static const hasLinkPhaseKey = 'has_link_phase'; + static BuildConfigImpl _readFieldsFromConfig(Config config) { final dryRun = HookConfigImpl.parseDryRun(config) ?? false; final targetOS = HookConfigImpl.parseTargetOS(config); @@ -113,6 +138,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { HookConfigImpl.parseTargetArchitecture(config, dryRun, targetOS), linkModePreference: HookConfigImpl.parseLinkModePreference(config), dependencyMetadata: parseDependencyMetadata(config), + hasLinkPhase: parseHasLinkPhase(config), version: HookConfigImpl.parseVersion(config), cCompiler: HookConfigImpl.parseCCompiler(config, dryRun), supportedAssetTypes: HookConfigImpl.parseSupportedAssetTypes(config), @@ -127,11 +153,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { ); } - static Map? parseDependencyMetadata(Config config) => - _readDependencyMetadataFromConfig(config); - - static Map? _readDependencyMetadataFromConfig( - Config config) { + static Map? parseDependencyMetadata(Config config) { final fileValue = config.valueOf?>(dependencyMetadataConfigKey); if (fileValue == null) { @@ -156,6 +178,9 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { ).sortOnKey(); } + static bool? parseHasLinkPhase(Config config) => + config.optionalBool(hasLinkPhaseKey); + static BuildConfigImpl fromJson(Map buildConfigJson) => BuildConfigImpl._fromConfig(Config(fileParsed: buildConfigJson)); @@ -169,6 +194,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { MapEntry(packageName, metadata.toJson()), ), }, + if (version >= Version(1, 4, 0)) hasLinkPhaseKey: hasLinkPhase, }.sortOnKey(); @override @@ -184,6 +210,9 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { .equals(other._dependencyMetadata, _dependencyMetadata)) { return false; } + if (_hasLinkPhase != other._hasLinkPhase) { + return false; + } return true; } @@ -191,6 +220,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { int get hashCode => Object.hashAll([ super.hashCode, linkModePreference, + hasLinkPhase, if (!dryRun) ...[ const DeepCollectionEquality().hash(_dependencyMetadata), ], diff --git a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md index 6d4c5b415..9c8bac9d7 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md +++ b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 + +- Link hooks are not always run. `BuildConfig.hasLinkPhase` communicates + whether link hooks are run. + Compatibility with older SDKs: the `hasLinkPhase` is false with v1.2.0 and + older, and true with v1.3.0. + ## 1.3.0 - Rev version to know whether the Dart/Flutter SDK can consume diff --git a/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md index 3a7fa0bda..0cfe00c0c 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md +++ b/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md @@ -1,4 +1,8 @@ -## 1.3.0 +## 1.4.0 + +- No changes yet, but rev version due to BuildConfig change. + +## 1.3.0 - Add key for assets to be linked. Backwards compatibility older build hooks: The key can be omitted. diff --git a/pkgs/native_assets_cli/lib/src/model/hook_config.dart b/pkgs/native_assets_cli/lib/src/model/hook_config.dart index 90233519f..8535778eb 100644 --- a/pkgs/native_assets_cli/lib/src/model/hook_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/hook_config.dart @@ -514,6 +514,7 @@ can _only_ depend on OS.'''); Iterable? supportedAssetTypes, Version? version, required Hook hook, + required bool? hasLinkPhase, }) { final input = [ version ?? latestVersion, @@ -536,6 +537,7 @@ can _only_ depend on OS.'''); ], ...supportedAssetTypes ?? [NativeCodeAsset.type], hook.name, + hasLinkPhase, ].join('###'); final sha256String = sha256.convert(utf8.encode(input)).toString(); // 256 bit hashes lead to 64 hex character strings. @@ -553,5 +555,5 @@ can _only_ depend on OS.'''); /// If we ever were to make breaking changes, it would be useful to give /// proper error messages rather than just fail to parse the JSON /// representation in the protocol. - static Version latestVersion = Version(1, 3, 0); + static Version latestVersion = Version(1, 4, 0); } diff --git a/pkgs/native_assets_cli/pubspec.yaml b/pkgs/native_assets_cli/pubspec.yaml index a2ad6dba4..04f212437 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.6.2-wip +version: 0.7.0-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli topics: diff --git a/pkgs/native_assets_cli/test/api/build_config_test.dart b/pkgs/native_assets_cli/test/api/build_config_test.dart index 88f5724fe..6300f469e 100644 --- a/pkgs/native_assets_cli/test/api/build_config_test.dart +++ b/pkgs/native_assets_cli/test/api/build_config_test.dart @@ -61,6 +61,7 @@ void main() async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], + hasLinkPhase: false, ); final config2 = BuildConfig.build( @@ -73,6 +74,7 @@ void main() async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], + hasLinkPhase: false, ); expect(config1, equals(config1)); @@ -92,6 +94,7 @@ void main() async { expect(config1.cCompiler != config2.cCompiler, true); expect(config1.linkModePreference, config2.linkModePreference); expect(config1.supportedAssetTypes, config2.supportedAssetTypes); + expect(config1.hasLinkPhase, config2.hasLinkPhase); }); test('BuildConfig fromConfig', () { @@ -104,11 +107,13 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, + hasLinkPhase: false, ); final config = { 'build_mode': 'release', 'dry_run': false, + 'has_link_phase': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -131,10 +136,12 @@ void main() async { targetOS: OS.android, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], + hasLinkPhase: true, ); final config = { 'dry_run': true, + 'has_link_phase': true, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -166,6 +173,7 @@ void main() async { 'key': 321, }, }, + hasLinkPhase: false, ); final buildConfig2 = BuildConfig.build( @@ -185,6 +193,7 @@ void main() async { 'key': 123, }, }, + hasLinkPhase: false, ); expect(buildConfig1, equals(buildConfig1)); @@ -194,6 +203,34 @@ void main() async { expect(buildConfig1.metadatum('bar', 'key'), 'value'); }); + test('BuildConfig == hasLinkConfig', () { + final buildConfig1 = BuildConfig.build( + outputDirectory: outDirUri, + packageName: packageName, + packageRoot: tempUri, + targetArchitecture: Architecture.x64, + targetOS: OS.windows, + buildMode: BuildMode.release, + linkModePreference: LinkModePreference.preferStatic, + hasLinkPhase: true, + ); + + final buildConfig2 = BuildConfig.build( + outputDirectory: outDirUri, + packageName: packageName, + packageRoot: tempUri, + targetArchitecture: Architecture.x64, + targetOS: OS.windows, + buildMode: BuildMode.release, + linkModePreference: LinkModePreference.preferStatic, + hasLinkPhase: false, + ); + + expect(buildConfig1, equals(buildConfig1)); + expect(buildConfig1.hashCode == buildConfig2.hashCode, false); + expect(buildConfig1, isNot(equals(buildConfig2))); + }); + test('BuildConfig fromArgs', () async { final buildConfig = BuildConfig.build( outputDirectory: outDirUri, @@ -204,6 +241,7 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, + hasLinkPhase: false, ); final configFileContents = (buildConfig as BuildConfigImpl).toJsonString(); final configUri = tempUri.resolve('config.json'); diff --git a/pkgs/native_assets_cli/test/api/build_test.dart b/pkgs/native_assets_cli/test/api/build_test.dart index 23c662d24..6edca0772 100644 --- a/pkgs/native_assets_cli/test/api/build_test.dart +++ b/pkgs/native_assets_cli/test/api/build_test.dart @@ -54,6 +54,7 @@ void main() async { ), buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferDynamic, + hasLinkPhase: false, ); final configJson = (config1 as BuildConfigImpl).toJsonString(); buildConfigUri = tempUri.resolve('build_config.json'); diff --git a/pkgs/native_assets_cli/test/model/build_config_test.dart b/pkgs/native_assets_cli/test/model/build_config_test.dart index 4d82529e0..92f26928e 100644 --- a/pkgs/native_assets_cli/test/model/build_config_test.dart +++ b/pkgs/native_assets_cli/test/model/build_config_test.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'package:native_assets_cli/native_assets_cli_internal.dart'; import 'package:native_assets_cli/src/api/asset.dart'; +import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import '../helpers.dart'; @@ -61,6 +62,7 @@ void main() async { ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, + hasLinkPhase: false, ); final config2 = BuildConfigImpl( @@ -72,6 +74,7 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, + hasLinkPhase: false, ); expect(config1, equals(config1)); @@ -90,6 +93,7 @@ void main() async { true); expect(config1.cCompiler != config2.cCompiler, true); expect(config1.linkModePreference, config2.linkModePreference); + expect(config1.hasLinkPhase, config2.hasLinkPhase); }); test('BuildConfig fromConfig', () { @@ -102,11 +106,13 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, + hasLinkPhase: false, ); final config = { 'build_mode': 'release', 'dry_run': false, + 'has_link_phase': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -128,10 +134,12 @@ void main() async { packageRoot: packageRootUri, targetOS: OSImpl.android, linkModePreference: LinkModePreferenceImpl.preferStatic, + hasLinkPhase: false, ); final config = { 'dry_run': true, + 'has_link_phase': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -158,6 +166,7 @@ void main() async { ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, + hasLinkPhase: false, ); final configFile = buildConfig1.toJson(); @@ -184,6 +193,7 @@ void main() async { 'key': 321, }), }, + hasLinkPhase: false, ); final buildConfig2 = BuildConfigImpl( @@ -203,6 +213,7 @@ void main() async { 'key': 123, }), }, + hasLinkPhase: false, ); expect(buildConfig1, equals(buildConfig1)); @@ -235,6 +246,7 @@ void main() async { 'key': 'value', }), }, + hasLinkPhase: false, ); final jsonObject = buildConfig1.toJson(); @@ -248,6 +260,7 @@ void main() async { 'z': ['z', 'a'] } }, + 'has_link_phase': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, @@ -312,6 +325,8 @@ version: 1.0.0'''; 'key': 'value', }), }, + version: Version(1, 0, 0), + hasLinkPhase: null, ); final buildConfig2 = BuildConfigImpl.fromJson( @@ -408,6 +423,7 @@ version: 1.0.0'''; ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, + hasLinkPhase: false, ); config.toString(); }); @@ -422,6 +438,7 @@ version: 1.0.0'''; targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, + hasLinkPhase: false, ); final configFileContents = buildConfig.toJsonString(); final configUri = tempUri.resolve('config.yaml'); @@ -448,6 +465,7 @@ version: 1.0.0'''; ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.dynamic, + hasLinkPhase: false, ); final configFile = buildConfig1.toJson(); @@ -524,12 +542,13 @@ version: 1.0.0'''; test('BuildConfig dry_run access invalid args', () { final outDir = outDirUri; final config = { + 'dry_run': true, + 'has_link_phase': true, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, 'package_root': tempUri.toFilePath(), 'target_os': 'android', - 'dry_run': true, 'version': HookConfigImpl.latestVersion.toString(), }; final buildConfig = BuildConfigImpl.fromJson(config); @@ -544,12 +563,13 @@ version: 1.0.0'''; test('BuildConfig dry_run target arch', () { final outDir = outDirUri; final config = { + 'dry_run': true, + 'has_link_phase': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, 'package_root': tempUri.toFilePath(), 'target_os': 'windows', - 'dry_run': true, 'version': HookConfigImpl.latestVersion.toString(), }; final buildConfig = BuildConfigImpl.fromJson(config); @@ -563,6 +583,7 @@ version: 1.0.0'''; packageRoot: tempUri, targetOS: OSImpl.windows, linkModePreference: LinkModePreferenceImpl.dynamic, + hasLinkPhase: false, ); buildConfig.toJsonString(); // No crash. diff --git a/pkgs/native_assets_cli/test/model/build_output_test.dart b/pkgs/native_assets_cli/test/model/build_output_test.dart index 0a2aa3089..073709f22 100644 --- a/pkgs/native_assets_cli/test/model/build_output_test.dart +++ b/pkgs/native_assets_cli/test/model/build_output_test.dart @@ -213,6 +213,7 @@ version: 1.0.0'''; targetArchitecture: ArchitectureImpl.arm64, targetOS: OSImpl.macOS, linkModePreference: LinkModePreferenceImpl.dynamic, + hasLinkPhase: false, ); final buildOutput = getBuildOutput(); await buildOutput.writeToFile(config: config); @@ -234,6 +235,7 @@ version: 1.0.0'''; targetOS: OSImpl.macOS, linkModePreference: LinkModePreferenceImpl.dynamic, version: Version(1, 1, 0), + hasLinkPhase: null, // version < 1.4.0 ); final buildOutput = getBuildOutput(withLinkedAssets: false); await buildOutput.writeToFile(config: config); diff --git a/pkgs/native_assets_cli/test/model/checksum_test.dart b/pkgs/native_assets_cli/test/model/checksum_test.dart index 0aa92f235..6c4095790 100644 --- a/pkgs/native_assets_cli/test/model/checksum_test.dart +++ b/pkgs/native_assets_cli/test/model/checksum_test.dart @@ -24,10 +24,11 @@ void main() { supportedAssetTypes: [NativeCodeAsset.type], hook: Hook.build, version: HookConfigImpl.latestVersion, + hasLinkPhase: true, ); // Using the checksum for a build folder should be stable. - expect(name1, 'b6170f6f00000d3766b01cea7637b607'); + expect(name1, '32727df17e2a456516a3301d9fa0a9e4'); // Build folder different due to metadata. final name2 = HookConfigImpl.checksum( @@ -42,6 +43,7 @@ void main() { }, hook: Hook.build, version: HookConfigImpl.latestVersion, + hasLinkPhase: true, ); printOnFailure([name1, name2].toString()); expect(name1 != name2, true); @@ -59,6 +61,7 @@ void main() { ), hook: Hook.build, version: HookConfigImpl.latestVersion, + hasLinkPhase: true, ); printOnFailure([name1, name3].toString()); expect(name1 != name3, true); @@ -76,9 +79,26 @@ void main() { ), hook: Hook.link, version: HookConfigImpl.latestVersion, + hasLinkPhase: true, ); printOnFailure([name1, name4].toString()); expect(name1 != name4, true); + + // Build folder different due to haslinkPhase. + final name5 = HookConfigImpl.checksum( + packageName: packageName, + packageRoot: nativeAddUri, + targetArchitecture: ArchitectureImpl.x64, + targetOS: OSImpl.linux, + buildMode: BuildModeImpl.release, + linkModePreference: LinkModePreferenceImpl.dynamic, + supportedAssetTypes: [NativeCodeAsset.type], + hook: Hook.build, + version: HookConfigImpl.latestVersion, + hasLinkPhase: false, + ); + printOnFailure([name1, name5].toString()); + expect(name1 != name5, true); }); }); } diff --git a/pkgs/native_toolchain_c/CHANGELOG.md b/pkgs/native_toolchain_c/CHANGELOG.md index be66cc723..f286a19db 100644 --- a/pkgs/native_toolchain_c/CHANGELOG.md +++ b/pkgs/native_toolchain_c/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.5.1-wip -- Nothing yet. +- Bump `package:native_assets_cli` to 0.7.0. ## 0.5.0 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 1371080fe..b826a9016 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 @@ -42,6 +42,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); 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 e31e5cb93..5421a24b2 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 @@ -135,6 +135,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, + hasLinkPhase: false, ); final buildOutput = BuildOutput(); 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 efd6b4067..6540e36d4 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,6 +73,7 @@ void main() { ? LinkModePreference.dynamic : LinkModePreference.static, targetIOSSdk: targetIOSSdk, + hasLinkPhase: false, ); final buildOutput = BuildOutput(); @@ -209,6 +210,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, + hasLinkPhase: false, ); final buildOutput = BuildOutput(); 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 df4c7b955..497cbecfd 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 @@ -54,6 +54,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, + hasLinkPhase: false, ); final buildOutput = BuildOutput(); 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 6ab645c0f..e3cf7a955 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 @@ -58,6 +58,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, + hasLinkPhase: false, ); final buildOutput = BuildOutput(); @@ -138,6 +139,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, + hasLinkPhase: false, ); final buildOutput = BuildOutput(); 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 7fa72e5af..15c4230c4 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 @@ -64,6 +64,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, + hasLinkPhase: false, ); final buildOutput = BuildOutput(); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index 5aa00a0d1..9ae91df28 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -57,6 +57,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( @@ -122,6 +123,7 @@ void main() { packageRoot: tempUri, targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, + hasLinkPhase: false, ) : BuildConfig.build( outputDirectory: tempUri, @@ -136,6 +138,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); @@ -230,6 +233,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); @@ -288,6 +292,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); @@ -334,6 +339,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); @@ -394,6 +400,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); @@ -459,6 +466,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( @@ -531,6 +539,7 @@ Future testDefines({ envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( 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 1a2d40860..7fe71b5f8 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart @@ -54,6 +54,7 @@ void main() { linker: ld, envScript: envScript, ), + hasLinkPhase: false, ); final resolver = CompilerResolver(buildConfig: buildConfig, logger: logger); final compiler = await resolver.resolveCompiler(); @@ -72,6 +73,7 @@ void main() { targetOS: OS.windows, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, + hasLinkPhase: false, ); final resolver = CompilerResolver( buildConfig: buildConfig, 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 d95e7d3d6..683df4559 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart @@ -48,6 +48,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), + hasLinkPhase: false, ); final buildOutput = BuildOutput(); From 5514671d5e3d461deec2e6f8ae329d7d6f4f8fb9 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 9 Jul 2024 15:19:56 +0200 Subject: [PATCH 2/8] missing copyright header --- pkgs/native_assets_cli/test/model/checksum_test.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/native_assets_cli/test/model/checksum_test.dart b/pkgs/native_assets_cli/test/model/checksum_test.dart index 6c4095790..7c6a20bd5 100644 --- a/pkgs/native_assets_cli/test/model/checksum_test.dart +++ b/pkgs/native_assets_cli/test/model/checksum_test.dart @@ -1,3 +1,7 @@ +// 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. + import 'dart:io'; import 'package:native_assets_cli/native_assets_cli_internal.dart'; From 5286730be3c84ac5bc130cccd6f05a720f3c91cd Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 9 Jul 2024 15:29:55 +0200 Subject: [PATCH 3/8] only use `linkInPackage` if `hasLinkPhase` --- pkgs/native_assets_builder/test/build_runner/link_test.dart | 3 +++ .../test/build_runner/resources_test.dart | 1 + .../test_data/add_asset_link/hook/build.dart | 3 +++ .../test_data/complex_link/hook/build.dart | 2 +- .../test_data/complex_link_helper/hook/build.dart | 2 +- .../test_data/drop_dylib_link/hook/build.dart | 5 +++-- .../test_data/fail_on_os_sdk_version_link/hook/build.dart | 3 ++- .../test_data/simple_link/hook/build.dart | 2 +- .../example/link/package_with_assets/hook/build.dart | 5 ++++- pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart | 1 + 10 files changed, 20 insertions(+), 7 deletions(-) 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 47388a860..1f99d280d 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_test.dart @@ -30,6 +30,7 @@ void main() async { packageUri, logger, dartExecutable, + hasLinkPhase: true, ); expect(buildResult.assets.length, 0); @@ -70,6 +71,7 @@ void main() async { packageUri, logger, dartExecutable, + hasLinkPhase: true, ); expect(buildResult.success, true); expect(_getNames(buildResult.assets), orderedEquals(builtHelperAssets)); @@ -106,6 +108,7 @@ void main() async { packageUri, logger, dartExecutable, + hasLinkPhase: true, ); expect(buildResult.assets.length, 0); expect(buildResult.assetsForLinking.length, 0); 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 eabc0a6c2..834c37f86 100644 --- a/pkgs/native_assets_builder/test/build_runner/resources_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/resources_test.dart @@ -33,6 +33,7 @@ void main() async { packageUri, logger, dartExecutable, + hasLinkPhase: true, ); Iterable buildFiles() => Directory.fromUri( 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 f37edf7e4..0b7dfeb38 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 @@ -8,6 +8,9 @@ import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { await build(arguments, (config, output) async { + if (!config.hasLinkPhase) { + throw Exception('Link hook must be run!'); + } final logger = Logger('') ..level = Level.ALL ..onRecord.listen((record) { 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 6c693ec5f..3fd2c65cb 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 @@ -17,6 +17,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: 'complex_link', + linkInPackage: config.hasLinkPhase ? 'complex_link' : null, ); }); 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 95ba7e0fa..5a688b594 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 @@ -29,6 +29,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: 'complex_link', + linkInPackage: config.hasLinkPhase ? 'complex_link' : null, ); }); 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 e946f81ce..dc3ff5d4f 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 @@ -15,6 +15,7 @@ void main(List arguments) async { ..onRecord.listen((record) { print('${record.level.name}: ${record.time}: ${record.message}'); }); + final linkInPackage = config.hasLinkPhase ? packageName : null; await CBuilder.library( name: 'add', assetName: 'dylib_add', @@ -27,7 +28,7 @@ void main(List arguments) async { config: config, output: output, logger: logger, - linkInPackage: packageName, + linkInPackage: linkInPackage, ); await CBuilder.library( @@ -42,7 +43,7 @@ void main(List arguments) async { config: config, output: output, logger: logger, - linkInPackage: packageName, + linkInPackage: linkInPackage, ); }); } 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 628a717ad..86b93beed 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 @@ -12,7 +12,8 @@ void main(List arguments) async { file: config.packageRoot.resolve('assets/data.json'), package: config.packageName, ), - linkInPackage: 'fail_on_os_sdk_version_linker', + linkInPackage: + config.hasLinkPhase ? 'fail_on_os_sdk_version_linker' : null, ); }); } 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 aa25818d3..9dbf4fe63 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 @@ -17,6 +17,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: 'simple_link', + linkInPackage: config.hasLinkPhase ? 'simple_link' : null, ); }); 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 ed19aa01a..437644099 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 @@ -19,6 +19,9 @@ void main(List args) async { file: config.packageRoot.resolve('assets/used_asset.json'), ) ]; - output.addAssets(allAssets, linkInPackage: packageName); + output.addAssets( + allAssets, + linkInPackage: config.hasLinkPhase ? packageName : null, + ); }); } diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index 95df3a57a..d2308efab 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -220,6 +220,7 @@ class CBuilder implements Builder { required Logger? logger, String? linkInPackage, }) async { + assert(config.hasLinkPhase == true || linkInPackage == null); final outDir = config.outputDirectory; final packageRoot = config.packageRoot; await Directory.fromUri(outDir).create(recursive: true); From 33eda098ea9353452c2b6b101fa1bfb176e85fcb Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 9 Jul 2024 15:36:18 +0200 Subject: [PATCH 4/8] exercise not linking build hook --- .../test/build_runner/link_test.dart | 8 ++++++++ 1 file changed, 8 insertions(+) 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 1f99d280d..8527dd376 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_test.dart @@ -41,6 +41,14 @@ void main() async { buildResult: buildResult, ); expect(linkResult.assets.length, 2); + + final buildNoLinkResult = await build( + packageUri, + logger, + dartExecutable, + hasLinkPhase: false, + ); + expect(buildNoLinkResult.assets.length, 4); }); }, ); From 846ff19abd1fb59600d5364f7d1792cfd448e4bf Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 9 Jul 2024 16:09:05 +0200 Subject: [PATCH 5/8] add documentation on when link hooks are run --- .../lib/src/api/build_config.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkgs/native_assets_cli/lib/src/api/build_config.dart b/pkgs/native_assets_cli/lib/src/api/build_config.dart index d7d71d498..96771321b 100644 --- a/pkgs/native_assets_cli/lib/src/api/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/build_config.dart @@ -45,10 +45,19 @@ abstract final class BuildConfig implements HookConfig { /// Whether link hooks will be run after the build hooks. /// - /// If [hasLinkPhase] is true, [BuildOutput.addAsset] can be called with - /// the `linkInPackage` parameter. - /// If [hasLinkPhase] is false, no assets should be added with the - /// `linkInPackage` parameter set. + /// If [hasLinkPhase] is true, [BuildOutput.addAsset] can be called with the + /// `linkInPackage` parameter. If [hasLinkPhase] is false, no assets should be + /// added with the `linkInPackage` parameter set. + /// + /// Link hooks are only run for release builds initiated by the following + /// commands: + /// - `flutter build` (release mode) + /// - `flutter run --release` + /// - `dart build` (release mode) + /// + /// Link hooks are not run for the following commands: + /// - `dart run` + /// - `flutter run` (debug mode) bool get hasLinkPhase; /// The version of [BuildConfig]. From 520fb6c8f4f61b54304b3ace89e9d802dd5faba1 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 9 Jul 2024 18:49:39 +0200 Subject: [PATCH 6/8] `hasLinkPhase` -> `linkingAvailable` and address comments --- pkgs/native_assets_builder/CHANGELOG.md | 2 +- .../lib/src/build_runner/build_runner.dart | 30 +++++++-------- .../build_runner_build_dry_run_test.dart | 2 +- .../build_runner/build_runner_cycle_test.dart | 2 +- .../build_runner_reusability_test.dart | 8 ++-- .../test/build_runner/helpers.dart | 10 ++--- .../test/build_runner/link_dry_run_test.dart | 4 +- .../test/build_runner/link_test.dart | 8 ++-- .../test/build_runner/resources_test.dart | 2 +- .../test_data/add_asset_link/hook/build.dart | 2 +- .../test_data/complex_link/hook/build.dart | 2 +- .../complex_link_helper/hook/build.dart | 2 +- .../test_data/drop_dylib_link/hook/build.dart | 2 +- .../hook/build.dart | 2 +- .../test_data/simple_link/hook/build.dart | 2 +- pkgs/native_assets_cli/CHANGELOG.md | 2 +- .../link/package_with_assets/hook/build.dart | 2 +- .../lib/src/api/build_config.dart | 16 ++++---- .../lib/src/model/build_config.dart | 30 +++++++-------- .../lib/src/model/build_config_CHANGELOG.md | 4 +- .../lib/src/model/hook_config.dart | 4 +- .../test/api/build_config_test.dart | 28 +++++++------- .../test/api/build_test.dart | 2 +- .../test/model/build_config_test.dart | 38 +++++++++---------- .../test/model/build_output_test.dart | 4 +- .../test/model/checksum_test.dart | 12 +++--- .../lib/src/cbuilder/cbuilder.dart | 5 ++- .../cbuilder/cbuilder_build_failure_test.dart | 2 +- .../cbuilder/cbuilder_cross_android_test.dart | 2 +- .../cbuilder/cbuilder_cross_ios_test.dart | 4 +- .../cbuilder_cross_linux_host_test.dart | 2 +- .../cbuilder_cross_macos_host_test.dart | 4 +- .../cbuilder_cross_windows_host_test.dart | 2 +- .../test/cbuilder/cbuilder_test.dart | 18 ++++----- .../test/cbuilder/compiler_resolver_test.dart | 4 +- .../test/cbuilder/objective_c_test.dart | 2 +- 36 files changed, 135 insertions(+), 132 deletions(-) diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index 9ba2fbeba..fff069049 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.8.0-wip - `BuildRunner.build` and `BuildRunner.buildDryRun` now have a required - `hasLinkPhase` parameter. + `linkingAvailable` parameter. ## 0.7.1 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 36f34f662..e6159d484 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 @@ -54,7 +54,7 @@ class NativeAssetsBuildRunner { PackageLayout? packageLayout, String? runPackageName, Iterable? supportedAssetTypes, - required bool hasLinkPhase, + required bool linkingAvailable, }) async => _run( hook: Hook.build, @@ -71,7 +71,7 @@ class NativeAssetsBuildRunner { packageLayout: packageLayout, runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); /// [workingDirectory] is expected to contain `.dart_tool`. @@ -135,10 +135,10 @@ class NativeAssetsBuildRunner { String? runPackageName, Iterable? supportedAssetTypes, BuildResult? buildResult, - bool? hasLinkPhase, + bool? linkingAvailable, }) async { assert(hook == Hook.link || buildResult == null); - assert(hook == Hook.build || hasLinkPhase == null); + assert(hook == Hook.build || linkingAvailable == null); packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final (buildPlan, packageGraph, planSuccess) = await _makePlan( @@ -172,7 +172,7 @@ class NativeAssetsBuildRunner { buildMode, linkModePreference, dependencyMetadata, - hasLinkPhase, + linkingAvailable, cCompilerConfig, targetIOSSdk, targetAndroidNdkApi, @@ -206,7 +206,7 @@ class NativeAssetsBuildRunner { BuildModeImpl buildMode, LinkModePreferenceImpl linkModePreference, DependencyMetadata? dependencyMetadata, - bool? hasLinkPhase, + bool? linkingAvailable, CCompilerConfigImpl? cCompilerConfig, IOSSdkImpl? targetIOSSdk, int? targetAndroidNdkApi, @@ -230,7 +230,7 @@ class NativeAssetsBuildRunner { targetAndroidNdkApi: targetAndroidNdkApi, supportedAssetTypes: supportedAssetTypes, hook: hook, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); final buildDirUri = packageLayout.dartToolNativeAssetsBuilder.resolve('$buildDirName/'); @@ -280,7 +280,7 @@ class NativeAssetsBuildRunner { targetMacOSVersion: targetMacOSVersion, cCompiler: cCompilerConfig, dependencyMetadata: dependencyMetadata, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, targetAndroidNdkApi: targetAndroidNdkApi, ); } @@ -298,7 +298,7 @@ class NativeAssetsBuildRunner { required OSImpl targetOS, required Uri workingDirectory, required bool includeParentEnvironment, - required bool hasLinkPhase, + required bool linkingAvailable, PackageLayout? packageLayout, String? runPackageName, Iterable? supportedAssetTypes, @@ -312,7 +312,7 @@ class NativeAssetsBuildRunner { packageLayout: packageLayout, runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); /// [workingDirectory] is expected to contain `.dart_tool`. @@ -342,7 +342,7 @@ class NativeAssetsBuildRunner { runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, buildDryRunResult: buildDryRunResult, - hasLinkPhase: null, + linkingAvailable: null, ); Future _runDryRun({ @@ -355,7 +355,7 @@ class NativeAssetsBuildRunner { Iterable? supportedAssetTypes, required Hook hook, BuildDryRunResult? buildDryRunResult, - required bool? hasLinkPhase, + required bool? linkingAvailable, }) async { packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final (buildPlan, _, planSuccess) = await _makePlan( @@ -379,7 +379,7 @@ class NativeAssetsBuildRunner { supportedAssetTypes: supportedAssetTypes, hook: hook, buildDryRunResult: buildDryRunResult, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); var (buildOutput, packageSuccess) = await _runHookForPackage( hook, @@ -551,7 +551,7 @@ ${e.message} required Hook hook, BuildDryRunResult? buildDryRunResult, Iterable? supportedAssetTypes, - required bool? hasLinkPhase, + required bool? linkingAvailable, }) async { final hookDirName = 'dry_run_${hook.name}_${targetOS}_$linkMode'; final outDirUri = buildParentDir.resolve('$hookDirName/out/'); @@ -568,7 +568,7 @@ ${e.message} targetOS: targetOS, linkModePreference: linkMode, supportedAssetTypes: supportedAssetTypes, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); case Hook.link: return LinkConfigImpl.dryRun( diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart index 9a30e1e3a..6be3c0bd9 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart @@ -28,7 +28,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: false, + linkingAvailable: false, ); final dryRunAssets = dryRunResult.assets.toList(); final result = await build( 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 3e06df284..33f4cf641 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 @@ -26,7 +26,7 @@ void main() async { packageUri, createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, - hasLinkPhase: false, + linkingAvailable: false, ); final fullLog = logMessages.join('\n'); expect(result.success, false); 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 f10f66cf3..350f43ece 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 @@ -33,14 +33,14 @@ void main() async { linkModePreference: LinkModePreferenceImpl.dynamic, workingDirectory: packageUri, includeParentEnvironment: true, - hasLinkPhase: false, + linkingAvailable: false, ); await buildRunner.buildDryRun( targetOS: Target.current.os, linkModePreference: LinkModePreferenceImpl.dynamic, workingDirectory: packageUri, includeParentEnvironment: true, - hasLinkPhase: false, + linkingAvailable: false, ); await buildRunner.build( buildMode: BuildModeImpl.release, @@ -48,7 +48,7 @@ void main() async { target: Target.current, workingDirectory: packageUri, includeParentEnvironment: true, - hasLinkPhase: false, + linkingAvailable: false, ); await buildRunner.build( buildMode: BuildModeImpl.release, @@ -56,7 +56,7 @@ void main() async { target: Target.current, workingDirectory: packageUri, includeParentEnvironment: true, - hasLinkPhase: false, + linkingAvailable: false, ); }); }); diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index d2900f8d2..26dcfa6b3 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -46,7 +46,7 @@ Future build( int? targetMacOSVersion, int? targetAndroidNdkApi, Target? target, - bool hasLinkPhase = false, + bool linkingAvailable = false, }) async => await runWithLog(capturedLogs, () async { final result = await NativeAssetsBuildRunner( @@ -65,7 +65,7 @@ Future build( targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, targetAndroidNdkApi: targetAndroidNdkApi, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); if (result.success) { @@ -157,7 +157,7 @@ Future<(BuildResult, LinkResult)> buildAndLink( targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, targetAndroidNdkApi: targetAndroidNdkApi, - hasLinkPhase: true, + linkingAvailable: true, ); if (!buildResult.success) { @@ -220,7 +220,7 @@ Future buildDryRun( bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, - required bool hasLinkPhase, + required bool linkingAvailable, }) async => runWithLog(capturedLogs, () async { final result = await NativeAssetsBuildRunner( @@ -232,7 +232,7 @@ Future buildDryRun( workingDirectory: packageUri, includeParentEnvironment: includeParentEnvironment, packageLayout: packageLayout, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); return result; }); diff --git a/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart b/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart index ff7e24407..a3b495e19 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart @@ -30,7 +30,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: true, + linkingAvailable: true, ); expect(buildResult.assets.length, 0); @@ -71,7 +71,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: true, + linkingAvailable: true, ); expect(buildResult.success, true); expect(_getNames(buildResult.assets), orderedEquals(builtHelperAssets)); 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 8527dd376..84a5ca800 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_test.dart @@ -30,7 +30,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: true, + linkingAvailable: true, ); expect(buildResult.assets.length, 0); @@ -46,7 +46,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: false, + linkingAvailable: false, ); expect(buildNoLinkResult.assets.length, 4); }); @@ -79,7 +79,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: true, + linkingAvailable: true, ); expect(buildResult.success, true); expect(_getNames(buildResult.assets), orderedEquals(builtHelperAssets)); @@ -116,7 +116,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: true, + linkingAvailable: true, ); expect(buildResult.assets.length, 0); expect(buildResult.assetsForLinking.length, 0); 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 834c37f86..9c8596e47 100644 --- a/pkgs/native_assets_builder/test/build_runner/resources_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/resources_test.dart @@ -33,7 +33,7 @@ void main() async { packageUri, logger, dartExecutable, - hasLinkPhase: true, + linkingAvailable: true, ); Iterable buildFiles() => Directory.fromUri( 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 0b7dfeb38..04b214d71 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 @@ -8,7 +8,7 @@ import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { await build(arguments, (config, output) async { - if (!config.hasLinkPhase) { + if (!config.linkingAvailable) { throw Exception('Link hook must be run!'); } final logger = Logger('') 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 3fd2c65cb..3e7e0d8a2 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 @@ -17,6 +17,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: config.hasLinkPhase ? 'complex_link' : null, + linkInPackage: config.linkingAvailable ? 'complex_link' : null, ); }); 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 5a688b594..885055971 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 @@ -29,6 +29,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: config.hasLinkPhase ? 'complex_link' : null, + linkInPackage: config.linkingAvailable ? 'complex_link' : null, ); }); 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 dc3ff5d4f..066084603 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 @@ -15,7 +15,7 @@ void main(List arguments) async { ..onRecord.listen((record) { print('${record.level.name}: ${record.time}: ${record.message}'); }); - final linkInPackage = config.hasLinkPhase ? packageName : null; + final linkInPackage = config.linkingAvailable ? packageName : null; await CBuilder.library( name: 'add', assetName: 'dylib_add', 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 86b93beed..200e9518f 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 @@ -13,7 +13,7 @@ void main(List arguments) async { package: config.packageName, ), linkInPackage: - config.hasLinkPhase ? 'fail_on_os_sdk_version_linker' : null, + config.linkingAvailable ? 'fail_on_os_sdk_version_linker' : null, ); }); } 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 9dbf4fe63..cfbfd2ac7 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 @@ -17,6 +17,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: config.hasLinkPhase ? 'simple_link' : null, + linkInPackage: config.linkingAvailable ? 'simple_link' : null, ); }); diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index 454f49629..948e5e616 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.7.0-wip -- `BuildConfig` constructors now have a required `hasLinkPhase` parameter. +- `BuildConfig` constructors now have a required `linkingAvailable` parameter. ## 0.6.1 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 437644099..49e2142bf 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 @@ -21,7 +21,7 @@ void main(List args) async { ]; output.addAssets( allAssets, - linkInPackage: config.hasLinkPhase ? packageName : null, + linkInPackage: config.linkingAvailable ? packageName : null, ); }); } diff --git a/pkgs/native_assets_cli/lib/src/api/build_config.dart b/pkgs/native_assets_cli/lib/src/api/build_config.dart index 96771321b..0cf23c34a 100644 --- a/pkgs/native_assets_cli/lib/src/api/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/build_config.dart @@ -45,9 +45,9 @@ abstract final class BuildConfig implements HookConfig { /// Whether link hooks will be run after the build hooks. /// - /// If [hasLinkPhase] is true, [BuildOutput.addAsset] can be called with the - /// `linkInPackage` parameter. If [hasLinkPhase] is false, no assets should be - /// added with the `linkInPackage` parameter set. + /// If [linkingAvailable] is true, [BuildOutput.addAsset] can be called with + /// the `linkInPackage` parameter. If [linkingAvailable] is false, no assets + /// should be added with the `linkInPackage` parameter set. /// /// Link hooks are only run for release builds initiated by the following /// commands: @@ -58,7 +58,7 @@ abstract final class BuildConfig implements HookConfig { /// Link hooks are not run for the following commands: /// - `dart run` /// - `flutter run` (debug mode) - bool get hasLinkPhase; + bool get linkingAvailable; /// The version of [BuildConfig]. /// @@ -121,7 +121,7 @@ abstract final class BuildConfig implements HookConfig { required LinkModePreference linkModePreference, Map>? dependencyMetadata, Iterable? supportedAssetTypes, - required bool hasLinkPhase, + required bool linkingAvailable, }) => BuildConfigImpl( outputDirectory: outputDirectory, @@ -142,7 +142,7 @@ abstract final class BuildConfig implements HookConfig { entry.key: Metadata(entry.value.cast()) } : null, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, supportedAssetTypes: supportedAssetTypes, ); @@ -159,7 +159,7 @@ abstract final class BuildConfig implements HookConfig { required Uri packageRoot, required OS targetOS, required LinkModePreference linkModePreference, - required bool hasLinkPhase, + required bool linkingAvailable, Iterable? supportedAssetTypes, }) => BuildConfigImpl.dryRun( @@ -169,6 +169,6 @@ abstract final class BuildConfig implements HookConfig { targetOS: targetOS as OSImpl, linkModePreference: linkModePreference as LinkModePreferenceImpl, supportedAssetTypes: supportedAssetTypes, - hasLinkPhase: hasLinkPhase, + linkingAvailable: linkingAvailable, ); } diff --git a/pkgs/native_assets_cli/lib/src/model/build_config.dart b/pkgs/native_assets_cli/lib/src/model/build_config.dart index 8ef1128ba..aed683a80 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/build_config.dart @@ -35,17 +35,17 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { final Map? _dependencyMetadata; @override - bool get hasLinkPhase { + bool get linkingAvailable { if (version <= Version(1, 2, 0)) { return false; } if (version == Version(1, 3, 0)) { return true; } - return _hasLinkPhase as bool; + return _linkingAvailable as bool; } - final bool? _hasLinkPhase; + final bool? _linkingAvailable; static List _supportedAssetTypesBackwardsCompatibility( Iterable? supportedAssetTypes, @@ -68,10 +68,10 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { required super.targetOS, required super.linkModePreference, Map? dependencyMetadata, - required bool? hasLinkPhase, + required bool? linkingAvailable, super.dryRun, }) : _dependencyMetadata = dependencyMetadata, - _hasLinkPhase = hasLinkPhase, + _linkingAvailable = linkingAvailable, super( hook: Hook.build, version: version ?? HookConfigImpl.latestVersion, @@ -79,9 +79,9 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { _supportedAssetTypesBackwardsCompatibility(supportedAssetTypes), ) { if (this.version < Version(1, 4, 0)) { - assert(hasLinkPhase == null); + assert(linkingAvailable == null); } else { - assert(hasLinkPhase != null); + assert(linkingAvailable != null); } } @@ -91,10 +91,10 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { required super.packageRoot, required super.targetOS, required super.linkModePreference, - required bool? hasLinkPhase, + required bool? linkingAvailable, Iterable? supportedAssetTypes, }) : _dependencyMetadata = null, - _hasLinkPhase = hasLinkPhase, + _linkingAvailable = linkingAvailable, super.dryRun( hook: Hook.build, version: HookConfigImpl.latestVersion, @@ -123,7 +123,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { static const dependencyMetadataConfigKey = 'dependency_metadata'; - static const hasLinkPhaseKey = 'has_link_phase'; + static const linkingAvailableKey = 'linking_available'; static BuildConfigImpl _readFieldsFromConfig(Config config) { final dryRun = HookConfigImpl.parseDryRun(config) ?? false; @@ -138,7 +138,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { HookConfigImpl.parseTargetArchitecture(config, dryRun, targetOS), linkModePreference: HookConfigImpl.parseLinkModePreference(config), dependencyMetadata: parseDependencyMetadata(config), - hasLinkPhase: parseHasLinkPhase(config), + linkingAvailable: parseHasLinkPhase(config), version: HookConfigImpl.parseVersion(config), cCompiler: HookConfigImpl.parseCCompiler(config, dryRun), supportedAssetTypes: HookConfigImpl.parseSupportedAssetTypes(config), @@ -179,7 +179,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { } static bool? parseHasLinkPhase(Config config) => - config.optionalBool(hasLinkPhaseKey); + config.optionalBool(linkingAvailableKey); static BuildConfigImpl fromJson(Map buildConfigJson) => BuildConfigImpl._fromConfig(Config(fileParsed: buildConfigJson)); @@ -194,7 +194,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { MapEntry(packageName, metadata.toJson()), ), }, - if (version >= Version(1, 4, 0)) hasLinkPhaseKey: hasLinkPhase, + if (version >= Version(1, 4, 0)) linkingAvailableKey: linkingAvailable, }.sortOnKey(); @override @@ -210,7 +210,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { .equals(other._dependencyMetadata, _dependencyMetadata)) { return false; } - if (_hasLinkPhase != other._hasLinkPhase) { + if (_linkingAvailable != other._linkingAvailable) { return false; } return true; @@ -220,7 +220,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { int get hashCode => Object.hashAll([ super.hashCode, linkModePreference, - hasLinkPhase, + linkingAvailable, if (!dryRun) ...[ const DeepCollectionEquality().hash(_dependencyMetadata), ], diff --git a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md index 9c8bac9d7..4ca9c9a19 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md +++ b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md @@ -1,8 +1,8 @@ ## 1.4.0 -- Link hooks are not always run. `BuildConfig.hasLinkPhase` communicates +- Link hooks are not always run. `BuildConfig.linkingAvailable` communicates whether link hooks are run. - Compatibility with older SDKs: the `hasLinkPhase` is false with v1.2.0 and + Compatibility with older SDKs: the `linkingAvailable` is false with v1.2.0 and older, and true with v1.3.0. ## 1.3.0 diff --git a/pkgs/native_assets_cli/lib/src/model/hook_config.dart b/pkgs/native_assets_cli/lib/src/model/hook_config.dart index 8535778eb..18433eea2 100644 --- a/pkgs/native_assets_cli/lib/src/model/hook_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/hook_config.dart @@ -514,7 +514,7 @@ can _only_ depend on OS.'''); Iterable? supportedAssetTypes, Version? version, required Hook hook, - required bool? hasLinkPhase, + required bool? linkingAvailable, }) { final input = [ version ?? latestVersion, @@ -537,7 +537,7 @@ can _only_ depend on OS.'''); ], ...supportedAssetTypes ?? [NativeCodeAsset.type], hook.name, - hasLinkPhase, + linkingAvailable, ].join('###'); final sha256String = sha256.convert(utf8.encode(input)).toString(); // 256 bit hashes lead to 64 hex character strings. diff --git a/pkgs/native_assets_cli/test/api/build_config_test.dart b/pkgs/native_assets_cli/test/api/build_config_test.dart index 6300f469e..794430758 100644 --- a/pkgs/native_assets_cli/test/api/build_config_test.dart +++ b/pkgs/native_assets_cli/test/api/build_config_test.dart @@ -61,7 +61,7 @@ void main() async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], - hasLinkPhase: false, + linkingAvailable: false, ); final config2 = BuildConfig.build( @@ -74,7 +74,7 @@ void main() async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], - hasLinkPhase: false, + linkingAvailable: false, ); expect(config1, equals(config1)); @@ -94,7 +94,7 @@ void main() async { expect(config1.cCompiler != config2.cCompiler, true); expect(config1.linkModePreference, config2.linkModePreference); expect(config1.supportedAssetTypes, config2.supportedAssetTypes); - expect(config1.hasLinkPhase, config2.hasLinkPhase); + expect(config1.linkingAvailable, config2.linkingAvailable); }); test('BuildConfig fromConfig', () { @@ -107,13 +107,13 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); final config = { 'build_mode': 'release', 'dry_run': false, - 'has_link_phase': false, + 'linking_available': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -136,12 +136,12 @@ void main() async { targetOS: OS.android, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], - hasLinkPhase: true, + linkingAvailable: true, ); final config = { 'dry_run': true, - 'has_link_phase': true, + 'linking_available': true, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -173,7 +173,7 @@ void main() async { 'key': 321, }, }, - hasLinkPhase: false, + linkingAvailable: false, ); final buildConfig2 = BuildConfig.build( @@ -193,7 +193,7 @@ void main() async { 'key': 123, }, }, - hasLinkPhase: false, + linkingAvailable: false, ); expect(buildConfig1, equals(buildConfig1)); @@ -212,7 +212,7 @@ void main() async { targetOS: OS.windows, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - hasLinkPhase: true, + linkingAvailable: true, ); final buildConfig2 = BuildConfig.build( @@ -223,12 +223,12 @@ void main() async { targetOS: OS.windows, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); expect(buildConfig1, equals(buildConfig1)); - expect(buildConfig1.hashCode == buildConfig2.hashCode, false); - expect(buildConfig1, isNot(equals(buildConfig2))); + expect(buildConfig1.hashCode, isNot(buildConfig2.hashCode)); + expect(buildConfig1, isNot(buildConfig2)); }); test('BuildConfig fromArgs', () async { @@ -241,7 +241,7 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); final configFileContents = (buildConfig as BuildConfigImpl).toJsonString(); final configUri = tempUri.resolve('config.json'); diff --git a/pkgs/native_assets_cli/test/api/build_test.dart b/pkgs/native_assets_cli/test/api/build_test.dart index 6edca0772..f88a7f068 100644 --- a/pkgs/native_assets_cli/test/api/build_test.dart +++ b/pkgs/native_assets_cli/test/api/build_test.dart @@ -54,7 +54,7 @@ void main() async { ), buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferDynamic, - hasLinkPhase: false, + linkingAvailable: false, ); final configJson = (config1 as BuildConfigImpl).toJsonString(); buildConfigUri = tempUri.resolve('build_config.json'); diff --git a/pkgs/native_assets_cli/test/model/build_config_test.dart b/pkgs/native_assets_cli/test/model/build_config_test.dart index 92f26928e..0aeb0fc6a 100644 --- a/pkgs/native_assets_cli/test/model/build_config_test.dart +++ b/pkgs/native_assets_cli/test/model/build_config_test.dart @@ -62,7 +62,7 @@ void main() async { ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); final config2 = BuildConfigImpl( @@ -74,7 +74,7 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); expect(config1, equals(config1)); @@ -93,7 +93,7 @@ void main() async { true); expect(config1.cCompiler != config2.cCompiler, true); expect(config1.linkModePreference, config2.linkModePreference); - expect(config1.hasLinkPhase, config2.hasLinkPhase); + expect(config1.linkingAvailable, config2.linkingAvailable); }); test('BuildConfig fromConfig', () { @@ -106,13 +106,13 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); final config = { 'build_mode': 'release', 'dry_run': false, - 'has_link_phase': false, + 'linking_available': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -134,12 +134,12 @@ void main() async { packageRoot: packageRootUri, targetOS: OSImpl.android, linkModePreference: LinkModePreferenceImpl.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); final config = { 'dry_run': true, - 'has_link_phase': false, + 'linking_available': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -166,7 +166,7 @@ void main() async { ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); final configFile = buildConfig1.toJson(); @@ -193,7 +193,7 @@ void main() async { 'key': 321, }), }, - hasLinkPhase: false, + linkingAvailable: false, ); final buildConfig2 = BuildConfigImpl( @@ -213,7 +213,7 @@ void main() async { 'key': 123, }), }, - hasLinkPhase: false, + linkingAvailable: false, ); expect(buildConfig1, equals(buildConfig1)); @@ -246,7 +246,7 @@ void main() async { 'key': 'value', }), }, - hasLinkPhase: false, + linkingAvailable: false, ); final jsonObject = buildConfig1.toJson(); @@ -260,7 +260,7 @@ void main() async { 'z': ['z', 'a'] } }, - 'has_link_phase': false, + 'linking_available': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, @@ -326,7 +326,7 @@ version: 1.0.0'''; }), }, version: Version(1, 0, 0), - hasLinkPhase: null, + linkingAvailable: null, ); final buildConfig2 = BuildConfigImpl.fromJson( @@ -423,7 +423,7 @@ version: 1.0.0'''; ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); config.toString(); }); @@ -438,7 +438,7 @@ version: 1.0.0'''; targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - hasLinkPhase: false, + linkingAvailable: false, ); final configFileContents = buildConfig.toJsonString(); final configUri = tempUri.resolve('config.yaml'); @@ -465,7 +465,7 @@ version: 1.0.0'''; ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.dynamic, - hasLinkPhase: false, + linkingAvailable: false, ); final configFile = buildConfig1.toJson(); @@ -543,7 +543,7 @@ version: 1.0.0'''; final outDir = outDirUri; final config = { 'dry_run': true, - 'has_link_phase': true, + 'linking_available': true, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, @@ -564,7 +564,7 @@ version: 1.0.0'''; final outDir = outDirUri; final config = { 'dry_run': true, - 'has_link_phase': false, + 'linking_available': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, @@ -583,7 +583,7 @@ version: 1.0.0'''; packageRoot: tempUri, targetOS: OSImpl.windows, linkModePreference: LinkModePreferenceImpl.dynamic, - hasLinkPhase: false, + linkingAvailable: false, ); buildConfig.toJsonString(); // No crash. diff --git a/pkgs/native_assets_cli/test/model/build_output_test.dart b/pkgs/native_assets_cli/test/model/build_output_test.dart index 073709f22..5095a12f0 100644 --- a/pkgs/native_assets_cli/test/model/build_output_test.dart +++ b/pkgs/native_assets_cli/test/model/build_output_test.dart @@ -213,7 +213,7 @@ version: 1.0.0'''; targetArchitecture: ArchitectureImpl.arm64, targetOS: OSImpl.macOS, linkModePreference: LinkModePreferenceImpl.dynamic, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = getBuildOutput(); await buildOutput.writeToFile(config: config); @@ -235,7 +235,7 @@ version: 1.0.0'''; targetOS: OSImpl.macOS, linkModePreference: LinkModePreferenceImpl.dynamic, version: Version(1, 1, 0), - hasLinkPhase: null, // version < 1.4.0 + linkingAvailable: null, // version < 1.4.0 ); final buildOutput = getBuildOutput(withLinkedAssets: false); await buildOutput.writeToFile(config: config); diff --git a/pkgs/native_assets_cli/test/model/checksum_test.dart b/pkgs/native_assets_cli/test/model/checksum_test.dart index 7c6a20bd5..27305b729 100644 --- a/pkgs/native_assets_cli/test/model/checksum_test.dart +++ b/pkgs/native_assets_cli/test/model/checksum_test.dart @@ -28,7 +28,7 @@ void main() { supportedAssetTypes: [NativeCodeAsset.type], hook: Hook.build, version: HookConfigImpl.latestVersion, - hasLinkPhase: true, + linkingAvailable: true, ); // Using the checksum for a build folder should be stable. @@ -47,7 +47,7 @@ void main() { }, hook: Hook.build, version: HookConfigImpl.latestVersion, - hasLinkPhase: true, + linkingAvailable: true, ); printOnFailure([name1, name2].toString()); expect(name1 != name2, true); @@ -65,7 +65,7 @@ void main() { ), hook: Hook.build, version: HookConfigImpl.latestVersion, - hasLinkPhase: true, + linkingAvailable: true, ); printOnFailure([name1, name3].toString()); expect(name1 != name3, true); @@ -83,7 +83,7 @@ void main() { ), hook: Hook.link, version: HookConfigImpl.latestVersion, - hasLinkPhase: true, + linkingAvailable: true, ); printOnFailure([name1, name4].toString()); expect(name1 != name4, true); @@ -99,10 +99,10 @@ void main() { supportedAssetTypes: [NativeCodeAsset.type], hook: Hook.build, version: HookConfigImpl.latestVersion, - hasLinkPhase: false, + linkingAvailable: false, ); printOnFailure([name1, name5].toString()); - expect(name1 != name5, true); + expect(name1, isNot(name5)); }); }); } diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index d2308efab..fa286f603 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -220,7 +220,10 @@ class CBuilder implements Builder { required Logger? logger, String? linkInPackage, }) async { - assert(config.hasLinkPhase == true || linkInPackage == null); + assert( + config.linkingAvailable || linkInPackage == null, + 'linkInPackage can only be provided if config.linkingAvailable is true.', + ); final outDir = config.outputDirectory; final packageRoot = config.packageRoot; await Directory.fromUri(outDir).create(recursive: true); 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 b826a9016..d777aea0c 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 @@ -42,7 +42,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); 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 5421a24b2..69db989ab 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 @@ -135,7 +135,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); 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 6540e36d4..e2c63cce4 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,7 +73,7 @@ void main() { ? LinkModePreference.dynamic : LinkModePreference.static, targetIOSSdk: targetIOSSdk, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); @@ -210,7 +210,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); 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 497cbecfd..c3709a323 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 @@ -54,7 +54,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); 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 e3cf7a955..e915b499e 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 @@ -58,7 +58,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); @@ -139,7 +139,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); 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 15c4230c4..6504dabd7 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 @@ -64,7 +64,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index 9ae91df28..417e62921 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -57,7 +57,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( @@ -123,7 +123,7 @@ void main() { packageRoot: tempUri, targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, - hasLinkPhase: false, + linkingAvailable: false, ) : BuildConfig.build( outputDirectory: tempUri, @@ -138,7 +138,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); @@ -233,7 +233,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); @@ -292,7 +292,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); @@ -339,7 +339,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); @@ -400,7 +400,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); @@ -466,7 +466,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( @@ -539,7 +539,7 @@ Future testDefines({ envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( 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 7fe71b5f8..00bbe2322 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart @@ -54,7 +54,7 @@ void main() { linker: ld, envScript: envScript, ), - hasLinkPhase: false, + linkingAvailable: false, ); final resolver = CompilerResolver(buildConfig: buildConfig, logger: logger); final compiler = await resolver.resolveCompiler(); @@ -73,7 +73,7 @@ void main() { targetOS: OS.windows, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - hasLinkPhase: false, + linkingAvailable: false, ); final resolver = CompilerResolver( buildConfig: buildConfig, 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 683df4559..733e49b65 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart @@ -48,7 +48,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - hasLinkPhase: false, + linkingAvailable: false, ); final buildOutput = BuildOutput(); From e92a9e932df0da501a7f2372e215f2745e48167b Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 10 Jul 2024 10:37:09 +0200 Subject: [PATCH 7/8] `linkingAvailable` -> `linkingEnabled` --- pkgs/native_assets_builder/CHANGELOG.md | 2 +- .../lib/src/build_runner/build_runner.dart | 30 +++++++-------- .../build_runner_build_dry_run_test.dart | 2 +- .../build_runner/build_runner_cycle_test.dart | 2 +- .../build_runner_reusability_test.dart | 8 ++-- .../test/build_runner/helpers.dart | 10 ++--- .../test/build_runner/link_dry_run_test.dart | 4 +- .../test/build_runner/link_test.dart | 8 ++-- .../test/build_runner/resources_test.dart | 2 +- .../test_data/add_asset_link/hook/build.dart | 2 +- .../test_data/complex_link/hook/build.dart | 2 +- .../complex_link_helper/hook/build.dart | 2 +- .../test_data/drop_dylib_link/hook/build.dart | 2 +- .../hook/build.dart | 2 +- .../test_data/simple_link/hook/build.dart | 2 +- pkgs/native_assets_cli/CHANGELOG.md | 2 +- .../link/package_with_assets/hook/build.dart | 2 +- .../lib/src/api/build_config.dart | 14 +++---- .../lib/src/model/build_config.dart | 30 +++++++-------- .../lib/src/model/build_config_CHANGELOG.md | 4 +- .../lib/src/model/hook_config.dart | 4 +- .../test/api/build_config_test.dart | 24 ++++++------ .../test/api/build_test.dart | 2 +- .../test/model/build_config_test.dart | 38 +++++++++---------- .../test/model/build_output_test.dart | 4 +- .../test/model/checksum_test.dart | 10 ++--- .../lib/src/cbuilder/cbuilder.dart | 4 +- .../cbuilder/cbuilder_build_failure_test.dart | 2 +- .../cbuilder/cbuilder_cross_android_test.dart | 2 +- .../cbuilder/cbuilder_cross_ios_test.dart | 4 +- .../cbuilder_cross_linux_host_test.dart | 2 +- .../cbuilder_cross_macos_host_test.dart | 4 +- .../cbuilder_cross_windows_host_test.dart | 2 +- .../test/cbuilder/cbuilder_test.dart | 18 ++++----- .../test/cbuilder/compiler_resolver_test.dart | 4 +- .../test/cbuilder/objective_c_test.dart | 2 +- 36 files changed, 129 insertions(+), 129 deletions(-) diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index fff069049..413468d17 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.8.0-wip - `BuildRunner.build` and `BuildRunner.buildDryRun` now have a required - `linkingAvailable` parameter. + `linkingEnabled` parameter. ## 0.7.1 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 e6159d484..faa0b6e9c 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 @@ -54,7 +54,7 @@ class NativeAssetsBuildRunner { PackageLayout? packageLayout, String? runPackageName, Iterable? supportedAssetTypes, - required bool linkingAvailable, + required bool linkingEnabled, }) async => _run( hook: Hook.build, @@ -71,7 +71,7 @@ class NativeAssetsBuildRunner { packageLayout: packageLayout, runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); /// [workingDirectory] is expected to contain `.dart_tool`. @@ -135,10 +135,10 @@ class NativeAssetsBuildRunner { String? runPackageName, Iterable? supportedAssetTypes, BuildResult? buildResult, - bool? linkingAvailable, + bool? linkingEnabled, }) async { assert(hook == Hook.link || buildResult == null); - assert(hook == Hook.build || linkingAvailable == null); + assert(hook == Hook.build || linkingEnabled == null); packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final (buildPlan, packageGraph, planSuccess) = await _makePlan( @@ -172,7 +172,7 @@ class NativeAssetsBuildRunner { buildMode, linkModePreference, dependencyMetadata, - linkingAvailable, + linkingEnabled, cCompilerConfig, targetIOSSdk, targetAndroidNdkApi, @@ -206,7 +206,7 @@ class NativeAssetsBuildRunner { BuildModeImpl buildMode, LinkModePreferenceImpl linkModePreference, DependencyMetadata? dependencyMetadata, - bool? linkingAvailable, + bool? linkingEnabled, CCompilerConfigImpl? cCompilerConfig, IOSSdkImpl? targetIOSSdk, int? targetAndroidNdkApi, @@ -230,7 +230,7 @@ class NativeAssetsBuildRunner { targetAndroidNdkApi: targetAndroidNdkApi, supportedAssetTypes: supportedAssetTypes, hook: hook, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); final buildDirUri = packageLayout.dartToolNativeAssetsBuilder.resolve('$buildDirName/'); @@ -280,7 +280,7 @@ class NativeAssetsBuildRunner { targetMacOSVersion: targetMacOSVersion, cCompiler: cCompilerConfig, dependencyMetadata: dependencyMetadata, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, targetAndroidNdkApi: targetAndroidNdkApi, ); } @@ -298,7 +298,7 @@ class NativeAssetsBuildRunner { required OSImpl targetOS, required Uri workingDirectory, required bool includeParentEnvironment, - required bool linkingAvailable, + required bool linkingEnabled, PackageLayout? packageLayout, String? runPackageName, Iterable? supportedAssetTypes, @@ -312,7 +312,7 @@ class NativeAssetsBuildRunner { packageLayout: packageLayout, runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); /// [workingDirectory] is expected to contain `.dart_tool`. @@ -342,7 +342,7 @@ class NativeAssetsBuildRunner { runPackageName: runPackageName, supportedAssetTypes: supportedAssetTypes, buildDryRunResult: buildDryRunResult, - linkingAvailable: null, + linkingEnabled: null, ); Future _runDryRun({ @@ -355,7 +355,7 @@ class NativeAssetsBuildRunner { Iterable? supportedAssetTypes, required Hook hook, BuildDryRunResult? buildDryRunResult, - required bool? linkingAvailable, + required bool? linkingEnabled, }) async { packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); final (buildPlan, _, planSuccess) = await _makePlan( @@ -379,7 +379,7 @@ class NativeAssetsBuildRunner { supportedAssetTypes: supportedAssetTypes, hook: hook, buildDryRunResult: buildDryRunResult, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); var (buildOutput, packageSuccess) = await _runHookForPackage( hook, @@ -551,7 +551,7 @@ ${e.message} required Hook hook, BuildDryRunResult? buildDryRunResult, Iterable? supportedAssetTypes, - required bool? linkingAvailable, + required bool? linkingEnabled, }) async { final hookDirName = 'dry_run_${hook.name}_${targetOS}_$linkMode'; final outDirUri = buildParentDir.resolve('$hookDirName/out/'); @@ -568,7 +568,7 @@ ${e.message} targetOS: targetOS, linkModePreference: linkMode, supportedAssetTypes: supportedAssetTypes, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); case Hook.link: return LinkConfigImpl.dryRun( diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart index 6be3c0bd9..fa3327d6a 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart @@ -28,7 +28,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: false, + linkingEnabled: false, ); final dryRunAssets = dryRunResult.assets.toList(); final result = await build( 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 33f4cf641..f99251865 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 @@ -26,7 +26,7 @@ void main() async { packageUri, createCapturingLogger(logMessages, level: Level.SEVERE), dartExecutable, - linkingAvailable: false, + linkingEnabled: false, ); final fullLog = logMessages.join('\n'); expect(result.success, false); 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 350f43ece..2472cf3d6 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 @@ -33,14 +33,14 @@ void main() async { linkModePreference: LinkModePreferenceImpl.dynamic, workingDirectory: packageUri, includeParentEnvironment: true, - linkingAvailable: false, + linkingEnabled: false, ); await buildRunner.buildDryRun( targetOS: Target.current.os, linkModePreference: LinkModePreferenceImpl.dynamic, workingDirectory: packageUri, includeParentEnvironment: true, - linkingAvailable: false, + linkingEnabled: false, ); await buildRunner.build( buildMode: BuildModeImpl.release, @@ -48,7 +48,7 @@ void main() async { target: Target.current, workingDirectory: packageUri, includeParentEnvironment: true, - linkingAvailable: false, + linkingEnabled: false, ); await buildRunner.build( buildMode: BuildModeImpl.release, @@ -56,7 +56,7 @@ void main() async { target: Target.current, workingDirectory: packageUri, includeParentEnvironment: true, - linkingAvailable: false, + linkingEnabled: false, ); }); }); diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index 26dcfa6b3..447176665 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -46,7 +46,7 @@ Future build( int? targetMacOSVersion, int? targetAndroidNdkApi, Target? target, - bool linkingAvailable = false, + bool linkingEnabled = false, }) async => await runWithLog(capturedLogs, () async { final result = await NativeAssetsBuildRunner( @@ -65,7 +65,7 @@ Future build( targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, targetAndroidNdkApi: targetAndroidNdkApi, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); if (result.success) { @@ -157,7 +157,7 @@ Future<(BuildResult, LinkResult)> buildAndLink( targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, targetAndroidNdkApi: targetAndroidNdkApi, - linkingAvailable: true, + linkingEnabled: true, ); if (!buildResult.success) { @@ -220,7 +220,7 @@ Future buildDryRun( bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, - required bool linkingAvailable, + required bool linkingEnabled, }) async => runWithLog(capturedLogs, () async { final result = await NativeAssetsBuildRunner( @@ -232,7 +232,7 @@ Future buildDryRun( workingDirectory: packageUri, includeParentEnvironment: includeParentEnvironment, packageLayout: packageLayout, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); return result; }); diff --git a/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart b/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart index a3b495e19..02db2e71f 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart @@ -30,7 +30,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: true, + linkingEnabled: true, ); expect(buildResult.assets.length, 0); @@ -71,7 +71,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: true, + linkingEnabled: true, ); expect(buildResult.success, true); expect(_getNames(buildResult.assets), orderedEquals(builtHelperAssets)); 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 84a5ca800..7ce2cf1b7 100644 --- a/pkgs/native_assets_builder/test/build_runner/link_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/link_test.dart @@ -30,7 +30,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: true, + linkingEnabled: true, ); expect(buildResult.assets.length, 0); @@ -46,7 +46,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: false, + linkingEnabled: false, ); expect(buildNoLinkResult.assets.length, 4); }); @@ -79,7 +79,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: true, + linkingEnabled: true, ); expect(buildResult.success, true); expect(_getNames(buildResult.assets), orderedEquals(builtHelperAssets)); @@ -116,7 +116,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: true, + linkingEnabled: true, ); expect(buildResult.assets.length, 0); expect(buildResult.assetsForLinking.length, 0); 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 9c8596e47..a46027f34 100644 --- a/pkgs/native_assets_builder/test/build_runner/resources_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/resources_test.dart @@ -33,7 +33,7 @@ void main() async { packageUri, logger, dartExecutable, - linkingAvailable: true, + linkingEnabled: true, ); Iterable buildFiles() => Directory.fromUri( 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 04b214d71..42f8cecb3 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 @@ -8,7 +8,7 @@ import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List arguments) async { await build(arguments, (config, output) async { - if (!config.linkingAvailable) { + if (!config.linkingEnabled) { throw Exception('Link hook must be run!'); } final logger = Logger('') 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 3e7e0d8a2..6f01c4cf1 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 @@ -17,6 +17,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: config.linkingAvailable ? 'complex_link' : null, + linkInPackage: config.linkingEnabled ? 'complex_link' : null, ); }); 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 885055971..c7320cc54 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 @@ -29,6 +29,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: config.linkingAvailable ? 'complex_link' : null, + linkInPackage: config.linkingEnabled ? 'complex_link' : null, ); }); 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 066084603..9c5e40c41 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 @@ -15,7 +15,7 @@ void main(List arguments) async { ..onRecord.listen((record) { print('${record.level.name}: ${record.time}: ${record.message}'); }); - final linkInPackage = config.linkingAvailable ? packageName : null; + final linkInPackage = config.linkingEnabled ? packageName : null; await CBuilder.library( name: 'add', assetName: 'dylib_add', 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 200e9518f..3cece99b0 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 @@ -13,7 +13,7 @@ void main(List arguments) async { package: config.packageName, ), linkInPackage: - config.linkingAvailable ? 'fail_on_os_sdk_version_linker' : null, + config.linkingEnabled ? 'fail_on_os_sdk_version_linker' : null, ); }); } 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 cfbfd2ac7..76d75975b 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 @@ -17,6 +17,6 @@ void main(List args) async => build(args, (config, output) async { package: packageName, ), ), - linkInPackage: config.linkingAvailable ? 'simple_link' : null, + linkInPackage: config.linkingEnabled ? 'simple_link' : null, ); }); diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index 948e5e616..614030b9d 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.7.0-wip -- `BuildConfig` constructors now have a required `linkingAvailable` parameter. +- `BuildConfig` constructors now have a required `linkingEnabled` parameter. ## 0.6.1 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 49e2142bf..401f52bf8 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 @@ -21,7 +21,7 @@ void main(List args) async { ]; output.addAssets( allAssets, - linkInPackage: config.linkingAvailable ? packageName : null, + linkInPackage: config.linkingEnabled ? packageName : null, ); }); } diff --git a/pkgs/native_assets_cli/lib/src/api/build_config.dart b/pkgs/native_assets_cli/lib/src/api/build_config.dart index 0cf23c34a..96b4b1635 100644 --- a/pkgs/native_assets_cli/lib/src/api/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/build_config.dart @@ -45,8 +45,8 @@ abstract final class BuildConfig implements HookConfig { /// Whether link hooks will be run after the build hooks. /// - /// If [linkingAvailable] is true, [BuildOutput.addAsset] can be called with - /// the `linkInPackage` parameter. If [linkingAvailable] is false, no assets + /// If [linkingEnabled] is true, [BuildOutput.addAsset] can be called with + /// the `linkInPackage` parameter. If [linkingEnabled] is false, no assets /// should be added with the `linkInPackage` parameter set. /// /// Link hooks are only run for release builds initiated by the following @@ -58,7 +58,7 @@ abstract final class BuildConfig implements HookConfig { /// Link hooks are not run for the following commands: /// - `dart run` /// - `flutter run` (debug mode) - bool get linkingAvailable; + bool get linkingEnabled; /// The version of [BuildConfig]. /// @@ -121,7 +121,7 @@ abstract final class BuildConfig implements HookConfig { required LinkModePreference linkModePreference, Map>? dependencyMetadata, Iterable? supportedAssetTypes, - required bool linkingAvailable, + required bool linkingEnabled, }) => BuildConfigImpl( outputDirectory: outputDirectory, @@ -142,7 +142,7 @@ abstract final class BuildConfig implements HookConfig { entry.key: Metadata(entry.value.cast()) } : null, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, supportedAssetTypes: supportedAssetTypes, ); @@ -159,7 +159,7 @@ abstract final class BuildConfig implements HookConfig { required Uri packageRoot, required OS targetOS, required LinkModePreference linkModePreference, - required bool linkingAvailable, + required bool linkingEnabled, Iterable? supportedAssetTypes, }) => BuildConfigImpl.dryRun( @@ -169,6 +169,6 @@ abstract final class BuildConfig implements HookConfig { targetOS: targetOS as OSImpl, linkModePreference: linkModePreference as LinkModePreferenceImpl, supportedAssetTypes: supportedAssetTypes, - linkingAvailable: linkingAvailable, + linkingEnabled: linkingEnabled, ); } diff --git a/pkgs/native_assets_cli/lib/src/model/build_config.dart b/pkgs/native_assets_cli/lib/src/model/build_config.dart index aed683a80..489417740 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/build_config.dart @@ -35,17 +35,17 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { final Map? _dependencyMetadata; @override - bool get linkingAvailable { + bool get linkingEnabled { if (version <= Version(1, 2, 0)) { return false; } if (version == Version(1, 3, 0)) { return true; } - return _linkingAvailable as bool; + return _linkingEnabled as bool; } - final bool? _linkingAvailable; + final bool? _linkingEnabled; static List _supportedAssetTypesBackwardsCompatibility( Iterable? supportedAssetTypes, @@ -68,10 +68,10 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { required super.targetOS, required super.linkModePreference, Map? dependencyMetadata, - required bool? linkingAvailable, + required bool? linkingEnabled, super.dryRun, }) : _dependencyMetadata = dependencyMetadata, - _linkingAvailable = linkingAvailable, + _linkingEnabled = linkingEnabled, super( hook: Hook.build, version: version ?? HookConfigImpl.latestVersion, @@ -79,9 +79,9 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { _supportedAssetTypesBackwardsCompatibility(supportedAssetTypes), ) { if (this.version < Version(1, 4, 0)) { - assert(linkingAvailable == null); + assert(linkingEnabled == null); } else { - assert(linkingAvailable != null); + assert(linkingEnabled != null); } } @@ -91,10 +91,10 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { required super.packageRoot, required super.targetOS, required super.linkModePreference, - required bool? linkingAvailable, + required bool? linkingEnabled, Iterable? supportedAssetTypes, }) : _dependencyMetadata = null, - _linkingAvailable = linkingAvailable, + _linkingEnabled = linkingEnabled, super.dryRun( hook: Hook.build, version: HookConfigImpl.latestVersion, @@ -123,7 +123,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { static const dependencyMetadataConfigKey = 'dependency_metadata'; - static const linkingAvailableKey = 'linking_available'; + static const linkingEnabledKey = 'linking_enabled'; static BuildConfigImpl _readFieldsFromConfig(Config config) { final dryRun = HookConfigImpl.parseDryRun(config) ?? false; @@ -138,7 +138,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { HookConfigImpl.parseTargetArchitecture(config, dryRun, targetOS), linkModePreference: HookConfigImpl.parseLinkModePreference(config), dependencyMetadata: parseDependencyMetadata(config), - linkingAvailable: parseHasLinkPhase(config), + linkingEnabled: parseHasLinkPhase(config), version: HookConfigImpl.parseVersion(config), cCompiler: HookConfigImpl.parseCCompiler(config, dryRun), supportedAssetTypes: HookConfigImpl.parseSupportedAssetTypes(config), @@ -179,7 +179,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { } static bool? parseHasLinkPhase(Config config) => - config.optionalBool(linkingAvailableKey); + config.optionalBool(linkingEnabledKey); static BuildConfigImpl fromJson(Map buildConfigJson) => BuildConfigImpl._fromConfig(Config(fileParsed: buildConfigJson)); @@ -194,7 +194,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { MapEntry(packageName, metadata.toJson()), ), }, - if (version >= Version(1, 4, 0)) linkingAvailableKey: linkingAvailable, + if (version >= Version(1, 4, 0)) linkingEnabledKey: linkingEnabled, }.sortOnKey(); @override @@ -210,7 +210,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { .equals(other._dependencyMetadata, _dependencyMetadata)) { return false; } - if (_linkingAvailable != other._linkingAvailable) { + if (_linkingEnabled != other._linkingEnabled) { return false; } return true; @@ -220,7 +220,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig { int get hashCode => Object.hashAll([ super.hashCode, linkModePreference, - linkingAvailable, + linkingEnabled, if (!dryRun) ...[ const DeepCollectionEquality().hash(_dependencyMetadata), ], diff --git a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md index 4ca9c9a19..34cd84ed3 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md +++ b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md @@ -1,8 +1,8 @@ ## 1.4.0 -- Link hooks are not always run. `BuildConfig.linkingAvailable` communicates +- Link hooks are not always run. `BuildConfig.linkingEnabled` communicates whether link hooks are run. - Compatibility with older SDKs: the `linkingAvailable` is false with v1.2.0 and + Compatibility with older SDKs: the `linkingEnabled` is false with v1.2.0 and older, and true with v1.3.0. ## 1.3.0 diff --git a/pkgs/native_assets_cli/lib/src/model/hook_config.dart b/pkgs/native_assets_cli/lib/src/model/hook_config.dart index 18433eea2..46506fd50 100644 --- a/pkgs/native_assets_cli/lib/src/model/hook_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/hook_config.dart @@ -514,7 +514,7 @@ can _only_ depend on OS.'''); Iterable? supportedAssetTypes, Version? version, required Hook hook, - required bool? linkingAvailable, + required bool? linkingEnabled, }) { final input = [ version ?? latestVersion, @@ -537,7 +537,7 @@ can _only_ depend on OS.'''); ], ...supportedAssetTypes ?? [NativeCodeAsset.type], hook.name, - linkingAvailable, + linkingEnabled, ].join('###'); final sha256String = sha256.convert(utf8.encode(input)).toString(); // 256 bit hashes lead to 64 hex character strings. diff --git a/pkgs/native_assets_cli/test/api/build_config_test.dart b/pkgs/native_assets_cli/test/api/build_config_test.dart index 794430758..20dc884d8 100644 --- a/pkgs/native_assets_cli/test/api/build_config_test.dart +++ b/pkgs/native_assets_cli/test/api/build_config_test.dart @@ -61,7 +61,7 @@ void main() async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], - linkingAvailable: false, + linkingEnabled: false, ); final config2 = BuildConfig.build( @@ -74,7 +74,7 @@ void main() async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], - linkingAvailable: false, + linkingEnabled: false, ); expect(config1, equals(config1)); @@ -94,7 +94,7 @@ void main() async { expect(config1.cCompiler != config2.cCompiler, true); expect(config1.linkModePreference, config2.linkModePreference); expect(config1.supportedAssetTypes, config2.supportedAssetTypes); - expect(config1.linkingAvailable, config2.linkingAvailable); + expect(config1.linkingEnabled, config2.linkingEnabled); }); test('BuildConfig fromConfig', () { @@ -107,13 +107,13 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); final config = { 'build_mode': 'release', 'dry_run': false, - 'linking_available': false, + 'linking_enabled': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -136,12 +136,12 @@ void main() async { targetOS: OS.android, linkModePreference: LinkModePreference.preferStatic, supportedAssetTypes: [NativeCodeAsset.type], - linkingAvailable: true, + linkingEnabled: true, ); final config = { 'dry_run': true, - 'linking_available': true, + 'linking_enabled': true, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -173,7 +173,7 @@ void main() async { 'key': 321, }, }, - linkingAvailable: false, + linkingEnabled: false, ); final buildConfig2 = BuildConfig.build( @@ -193,7 +193,7 @@ void main() async { 'key': 123, }, }, - linkingAvailable: false, + linkingEnabled: false, ); expect(buildConfig1, equals(buildConfig1)); @@ -212,7 +212,7 @@ void main() async { targetOS: OS.windows, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - linkingAvailable: true, + linkingEnabled: true, ); final buildConfig2 = BuildConfig.build( @@ -223,7 +223,7 @@ void main() async { targetOS: OS.windows, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); expect(buildConfig1, equals(buildConfig1)); @@ -241,7 +241,7 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); final configFileContents = (buildConfig as BuildConfigImpl).toJsonString(); final configUri = tempUri.resolve('config.json'); diff --git a/pkgs/native_assets_cli/test/api/build_test.dart b/pkgs/native_assets_cli/test/api/build_test.dart index f88a7f068..ce62f8777 100644 --- a/pkgs/native_assets_cli/test/api/build_test.dart +++ b/pkgs/native_assets_cli/test/api/build_test.dart @@ -54,7 +54,7 @@ void main() async { ), buildMode: BuildMode.release, linkModePreference: LinkModePreference.preferDynamic, - linkingAvailable: false, + linkingEnabled: false, ); final configJson = (config1 as BuildConfigImpl).toJsonString(); buildConfigUri = tempUri.resolve('build_config.json'); diff --git a/pkgs/native_assets_cli/test/model/build_config_test.dart b/pkgs/native_assets_cli/test/model/build_config_test.dart index 0aeb0fc6a..1c93316b4 100644 --- a/pkgs/native_assets_cli/test/model/build_config_test.dart +++ b/pkgs/native_assets_cli/test/model/build_config_test.dart @@ -62,7 +62,7 @@ void main() async { ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); final config2 = BuildConfigImpl( @@ -74,7 +74,7 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); expect(config1, equals(config1)); @@ -93,7 +93,7 @@ void main() async { true); expect(config1.cCompiler != config2.cCompiler, true); expect(config1.linkModePreference, config2.linkModePreference); - expect(config1.linkingAvailable, config2.linkingAvailable); + expect(config1.linkingEnabled, config2.linkingEnabled); }); test('BuildConfig fromConfig', () { @@ -106,13 +106,13 @@ void main() async { targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); final config = { 'build_mode': 'release', 'dry_run': false, - 'linking_available': false, + 'linking_enabled': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -134,12 +134,12 @@ void main() async { packageRoot: packageRootUri, targetOS: OSImpl.android, linkModePreference: LinkModePreferenceImpl.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); final config = { 'dry_run': true, - 'linking_available': false, + 'linking_enabled': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDirUri.toFilePath(), 'package_name': packageName, @@ -166,7 +166,7 @@ void main() async { ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); final configFile = buildConfig1.toJson(); @@ -193,7 +193,7 @@ void main() async { 'key': 321, }), }, - linkingAvailable: false, + linkingEnabled: false, ); final buildConfig2 = BuildConfigImpl( @@ -213,7 +213,7 @@ void main() async { 'key': 123, }), }, - linkingAvailable: false, + linkingEnabled: false, ); expect(buildConfig1, equals(buildConfig1)); @@ -246,7 +246,7 @@ void main() async { 'key': 'value', }), }, - linkingAvailable: false, + linkingEnabled: false, ); final jsonObject = buildConfig1.toJson(); @@ -260,7 +260,7 @@ void main() async { 'z': ['z', 'a'] } }, - 'linking_available': false, + 'linking_enabled': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, @@ -326,7 +326,7 @@ version: 1.0.0'''; }), }, version: Version(1, 0, 0), - linkingAvailable: null, + linkingEnabled: null, ); final buildConfig2 = BuildConfigImpl.fromJson( @@ -423,7 +423,7 @@ version: 1.0.0'''; ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); config.toString(); }); @@ -438,7 +438,7 @@ version: 1.0.0'''; targetAndroidNdkApi: 30, buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.preferStatic, - linkingAvailable: false, + linkingEnabled: false, ); final configFileContents = buildConfig.toJsonString(); final configUri = tempUri.resolve('config.yaml'); @@ -465,7 +465,7 @@ version: 1.0.0'''; ), buildMode: BuildModeImpl.release, linkModePreference: LinkModePreferenceImpl.dynamic, - linkingAvailable: false, + linkingEnabled: false, ); final configFile = buildConfig1.toJson(); @@ -543,7 +543,7 @@ version: 1.0.0'''; final outDir = outDirUri; final config = { 'dry_run': true, - 'linking_available': true, + 'linking_enabled': true, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, @@ -564,7 +564,7 @@ version: 1.0.0'''; final outDir = outDirUri; final config = { 'dry_run': true, - 'linking_available': false, + 'linking_enabled': false, 'link_mode_preference': 'prefer-static', 'out_dir': outDir.toFilePath(), 'package_name': packageName, @@ -583,7 +583,7 @@ version: 1.0.0'''; packageRoot: tempUri, targetOS: OSImpl.windows, linkModePreference: LinkModePreferenceImpl.dynamic, - linkingAvailable: false, + linkingEnabled: false, ); buildConfig.toJsonString(); // No crash. diff --git a/pkgs/native_assets_cli/test/model/build_output_test.dart b/pkgs/native_assets_cli/test/model/build_output_test.dart index 5095a12f0..9d0b27d86 100644 --- a/pkgs/native_assets_cli/test/model/build_output_test.dart +++ b/pkgs/native_assets_cli/test/model/build_output_test.dart @@ -213,7 +213,7 @@ version: 1.0.0'''; targetArchitecture: ArchitectureImpl.arm64, targetOS: OSImpl.macOS, linkModePreference: LinkModePreferenceImpl.dynamic, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = getBuildOutput(); await buildOutput.writeToFile(config: config); @@ -235,7 +235,7 @@ version: 1.0.0'''; targetOS: OSImpl.macOS, linkModePreference: LinkModePreferenceImpl.dynamic, version: Version(1, 1, 0), - linkingAvailable: null, // version < 1.4.0 + linkingEnabled: null, // version < 1.4.0 ); final buildOutput = getBuildOutput(withLinkedAssets: false); await buildOutput.writeToFile(config: config); diff --git a/pkgs/native_assets_cli/test/model/checksum_test.dart b/pkgs/native_assets_cli/test/model/checksum_test.dart index 27305b729..02b901ff4 100644 --- a/pkgs/native_assets_cli/test/model/checksum_test.dart +++ b/pkgs/native_assets_cli/test/model/checksum_test.dart @@ -28,7 +28,7 @@ void main() { supportedAssetTypes: [NativeCodeAsset.type], hook: Hook.build, version: HookConfigImpl.latestVersion, - linkingAvailable: true, + linkingEnabled: true, ); // Using the checksum for a build folder should be stable. @@ -47,7 +47,7 @@ void main() { }, hook: Hook.build, version: HookConfigImpl.latestVersion, - linkingAvailable: true, + linkingEnabled: true, ); printOnFailure([name1, name2].toString()); expect(name1 != name2, true); @@ -65,7 +65,7 @@ void main() { ), hook: Hook.build, version: HookConfigImpl.latestVersion, - linkingAvailable: true, + linkingEnabled: true, ); printOnFailure([name1, name3].toString()); expect(name1 != name3, true); @@ -83,7 +83,7 @@ void main() { ), hook: Hook.link, version: HookConfigImpl.latestVersion, - linkingAvailable: true, + linkingEnabled: true, ); printOnFailure([name1, name4].toString()); expect(name1 != name4, true); @@ -99,7 +99,7 @@ void main() { supportedAssetTypes: [NativeCodeAsset.type], hook: Hook.build, version: HookConfigImpl.latestVersion, - linkingAvailable: false, + linkingEnabled: false, ); printOnFailure([name1, name5].toString()); expect(name1, isNot(name5)); diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index fa286f603..b88ffe7c3 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -221,8 +221,8 @@ class CBuilder implements Builder { String? linkInPackage, }) async { assert( - config.linkingAvailable || linkInPackage == null, - 'linkInPackage can only be provided if config.linkingAvailable is true.', + config.linkingEnabled || linkInPackage == null, + 'linkInPackage can only be provided if config.linkingEnabled is true.', ); final outDir = config.outputDirectory; final packageRoot = config.packageRoot; 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 d777aea0c..540b2f269 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 @@ -42,7 +42,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); 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 69db989ab..bd24e0614 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 @@ -135,7 +135,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); 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 e2c63cce4..736fe7cbe 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,7 +73,7 @@ void main() { ? LinkModePreference.dynamic : LinkModePreference.static, targetIOSSdk: targetIOSSdk, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -210,7 +210,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); 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 c3709a323..efed28c87 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 @@ -54,7 +54,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); 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 e915b499e..d6da1717f 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 @@ -58,7 +58,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -139,7 +139,7 @@ Future buildLib( linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); 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 6504dabd7..2b1af278c 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 @@ -64,7 +64,7 @@ void main() { linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic : LinkModePreference.static, - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index 417e62921..4d440085c 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -57,7 +57,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( @@ -123,7 +123,7 @@ void main() { packageRoot: tempUri, targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, - linkingAvailable: false, + linkingEnabled: false, ) : BuildConfig.build( outputDirectory: tempUri, @@ -138,7 +138,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -233,7 +233,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -292,7 +292,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -339,7 +339,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -400,7 +400,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -466,7 +466,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( @@ -539,7 +539,7 @@ Future testDefines({ envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); final cbuilder = CBuilder.executable( 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 00bbe2322..a30a94c1d 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart @@ -54,7 +54,7 @@ void main() { linker: ld, envScript: envScript, ), - linkingAvailable: false, + linkingEnabled: false, ); final resolver = CompilerResolver(buildConfig: buildConfig, logger: logger); final compiler = await resolver.resolveCompiler(); @@ -73,7 +73,7 @@ void main() { targetOS: OS.windows, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - linkingAvailable: false, + linkingEnabled: false, ); final resolver = CompilerResolver( buildConfig: buildConfig, 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 733e49b65..c76ac14d2 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart @@ -48,7 +48,7 @@ void main() { envScript: envScript, envScriptArgs: envScriptArgs, ), - linkingAvailable: false, + linkingEnabled: false, ); final buildOutput = BuildOutput(); From dcd64e90f3672f394879ce7b807e967d9336217d Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 10 Jul 2024 10:41:55 +0200 Subject: [PATCH 8/8] more doc comments --- .../lib/src/api/build_config.dart | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkgs/native_assets_cli/lib/src/api/build_config.dart b/pkgs/native_assets_cli/lib/src/api/build_config.dart index 96b4b1635..653168b7a 100644 --- a/pkgs/native_assets_cli/lib/src/api/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/build_config.dart @@ -45,17 +45,18 @@ abstract final class BuildConfig implements HookConfig { /// Whether link hooks will be run after the build hooks. /// - /// If [linkingEnabled] is true, [BuildOutput.addAsset] can be called with - /// the `linkInPackage` parameter. If [linkingEnabled] is false, no assets - /// should be added with the `linkInPackage` parameter set. - /// - /// Link hooks are only run for release builds initiated by the following - /// commands: - /// - `flutter build` (release mode) + /// If [linkingEnabled] is true, [BuildOutput.addAsset] may be called with the + /// `linkInPackage` parameter so that assets can be linked in a link hook. + /// Linking is enabled in Flutter release builds and Dart AOT configurations. + /// These configurations are optimized for app size. + /// - `flutter build` /// - `flutter run --release` - /// - `dart build` (release mode) + /// - `dart build` /// - /// Link hooks are not run for the following commands: + /// If [linkingEnabled] is false, no assets should be added with the + /// `linkInPackage` parameter set. All assets must be ready for bundling. + /// Linking is disabled in Flutter debug builds and Dart JIT configurations. + /// These configurations are optimized for development speed. /// - `dart run` /// - `flutter run` (debug mode) bool get linkingEnabled;