diff --git a/pkgs/hooks/doc/schema/sdk/shared_definitions.schema.json b/pkgs/hooks/doc/schema/sdk/shared_definitions.schema.json index cd6f72856..2a6acce1f 100644 --- a/pkgs/hooks/doc/schema/sdk/shared_definitions.schema.json +++ b/pkgs/hooks/doc/schema/sdk/shared_definitions.schema.json @@ -36,10 +36,6 @@ "HookOutput": {}, "LinkInput": { "$ref": "../shared/shared_definitions.schema.json#/definitions/LinkInput", - "required": [ - "out_file", - "version" - ], "unevaluatedProperties": false }, "LinkOutput": {} diff --git a/pkgs/hooks/doc/schema/shared/shared_definitions.schema.json b/pkgs/hooks/doc/schema/shared/shared_definitions.schema.json index 1f3284382..962f983bd 100644 --- a/pkgs/hooks/doc/schema/shared/shared_definitions.schema.json +++ b/pkgs/hooks/doc/schema/shared/shared_definitions.schema.json @@ -139,8 +139,7 @@ "out_dir", "out_dir_shared", "package_name", - "package_root", - "version" + "package_root" ] }, "HookOutput": { @@ -169,8 +168,7 @@ } }, "required": [ - "timestamp", - "version" + "timestamp" ] }, "LinkInput": { diff --git a/pkgs/hooks/test/schema/helpers.dart b/pkgs/hooks/test/schema/helpers.dart index 25f39a922..862c5e83d 100644 --- a/pkgs/hooks/test/schema/helpers.dart +++ b/pkgs/hooks/test/schema/helpers.dart @@ -288,16 +288,21 @@ FieldsReturn _hookFields({ required Party party, }) { void versionMissingExpectation(ValidationResults result) { - if ((party == Party.sdk && inputOrOutput == InputOrOutput.input) || - (party == Party.hook && inputOrOutput == InputOrOutput.output)) { + if (party == Party.sdk && inputOrOutput == InputOrOutput.input) { // The writer must output this field. SDK must support older hooks reading // it. expect(result.isValid, isFalse); + } else if (party == Party.hook && inputOrOutput == InputOrOutput.output) { + // The writer must output this field. SDK must support older hooks reading + // it. + // Note: For some reason party:hook output does not register as required + // `package:json_schema`, but the JSON validator in vscode does properly + // mark it as required. + // Ignore this issue for now, we'll remove version soon. + // expect(result.isValid, isFalse); } else { // Newer hooks must support future SDKs not outputting a this field. - // TODO: Stop requiring version in the reader. - // expect(result.isValid, isTrue); - expect(result.isValid, isFalse); + expect(result.isValid, isTrue); } } 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 0ed99bae1..8d8e60597 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 @@ -11,7 +11,6 @@ import 'package:logging/logging.dart'; import 'package:meta/meta.dart'; import 'package:native_assets_cli/native_assets_cli_internal.dart'; import 'package:package_config/package_config.dart'; -import 'package:pub_semver/pub_semver.dart'; import '../dependencies_hash_file/dependencies_hash_file.dart'; import '../locking/locking.dart'; @@ -91,10 +90,6 @@ class NativeAssetsBuildRunner { ); if (buildPlan == null) return null; - if (!await _ensureNativeAssetsCliProtocolVersion()) { - return null; - } - var hookResult = HookResult(); final globalMetadata = {}; for (final package in buildPlan) { @@ -833,58 +828,6 @@ ${compileResult.stdout} ? BuildOutput(hookOutputJson) : LinkOutput(hookOutputJson); } - - Future _ensureNativeAssetsCliProtocolVersion() async { - final package = - packageLayout.packageConfig['native_assets_cli'] ?? - packageLayout.packageConfig['hook']; // Anticipate rename. - if (package == null) { - // No dependencies with a hook or using a different protocol helper - // package. - return true; - } - final packageRoot = package.root.normalizePath(); - final hookVersion = await _nativeAssetsCliProtocolVersion(packageRoot); - if (hookVersion == null) { - logger.fine( - 'Could not determine the protocol version of ' - '${packageRoot.toFilePath()}.', - ); - // This is most likely due to a newer version of the package. - return true; - } - if (latestParsableVersion > hookVersion) { - // The hook is too old. - logger.shout( - 'The protocol version of ${packageRoot.toFilePath()} is ' - '$hookVersion, which is no longer supported. Please update your ' - 'dependencies.', - ); - return false; - } - return true; - } - - Future _nativeAssetsCliProtocolVersion(Uri packageRoot) async { - const files = ['lib/src/config.dart', 'lib/src/model/hook_config.dart']; - for (final fileName in files) { - final file = _fileSystem.file(packageRoot.resolve(fileName)); - if (!await file.exists()) { - continue; - } - final contents = await file.readAsString(); - final regex = RegExp(r'latestVersion = Version\((\d+), (\d+), (\d+)\);'); - final match = regex.firstMatch(contents); - if (match == null) { - continue; - } - final major = int.parse(match.group(1)!); - final minor = int.parse(match.group(2)!); - final patch = int.parse(match.group(3)!); - return Version(major, minor, patch); - } - return null; - } } /// Parses depfile contents. diff --git a/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart b/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart index 5eb2ead9d..e3350f657 100644 --- a/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/version_skew_test.dart @@ -53,12 +53,7 @@ void main() async { expect(result, isNull); expect( logMessages.join('\n'), - stringContainsInOrder([ - 'The protocol version of ', - 'native_assets_cli', - ' is 1.3.0, which is no longer supported.', - 'Please update your dependencies.', - ]), + stringContainsInOrder(['Unhandled exception']), ); }); }, diff --git a/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart b/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart index 903e2c25c..55acd5848 100644 --- a/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart +++ b/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart @@ -6,5 +6,4 @@ library; export 'native_assets_cli_builder.dart'; -export 'src/config.dart' show latestParsableVersion; export 'src/model/hook.dart'; diff --git a/pkgs/native_assets_cli/lib/src/config.dart b/pkgs/native_assets_cli/lib/src/config.dart index 75e556d80..f9880ff0a 100644 --- a/pkgs/native_assets_cli/lib/src/config.dart +++ b/pkgs/native_assets_cli/lib/src/config.dart @@ -24,9 +24,6 @@ sealed class HookInput { /// The underlying json configuration of this [HookInput]. Map get json => _syntax.json; - /// The version of the [HookInput]. - Version get version => Version.parse(_syntax.version); - /// The directory in which output and intermediate artifacts that are unique /// to the [config] can be placed. /// @@ -82,13 +79,6 @@ sealed class HookInput { HookInput(Map json) : _syntax = syntax.HookInput.fromJson(json) { - if (version.major != latestVersion.major || - version < latestParsableVersion) { - throw FormatException( - 'Only compatible versions with $latestVersion are supported ' - '(was: $version).', - ); - } // Trigger validation, remove with cleanup. outputDirectory; outputDirectoryShared; @@ -290,9 +280,6 @@ sealed class HookOutput { /// The underlying json configuration of this [HookOutput]. Map get json => _syntax.json; - /// The version of the [HookInput]. - Version get version => Version.parse(_syntax.version); - /// Start time for the build of this output. /// /// The [timestamp] is rounded down to whole seconds, because @@ -316,15 +303,7 @@ sealed class HookOutput { syntax.HookOutput get _syntax; - HookOutput._(Map json) { - if (version.major != latestVersion.major || - version < latestParsableVersion) { - throw FormatException( - 'Only compatible versions with $latestVersion are supported ' - '(was: $version).', - ); - } - } + HookOutput._(Map json); @override String toString() => const JsonEncoder.withIndent(' ').convert(json); @@ -607,27 +586,9 @@ extension type EncodedAssetLinkOutputBuilder._(LinkOutputBuilder _builder) { syntax.LinkOutput.fromJson(_builder._syntax.json); } -/// The latest supported input version. -/// -/// We'll never bump the major version. Removing old keys from the input and -/// output is done via modifying [latestParsableVersion]. +// Deprecated, still emitted for backwards compatibility purposes. final latestVersion = Version(1, 9, 0); -/// The parser can deal with inputs and outputs down to this version. -/// -/// This version can be bumped when: -/// -/// 1. The stable version of Dart / Flutter uses a newer version _and_ the SDK -/// constraint is bumped in the pubspec of this package to that stable -/// version. (This prevents input parsing from failing.) -/// 2. A stable version of this package is published uses a newer version, _and_ -/// most users have migrated to it. (This prevents the output parsing from -/// failing.) -/// -/// When updating this number, update the version_skew_test.dart. (This test -/// catches issues with 2.) -final latestParsableVersion = Version(1, 7, 0); - /// The configuration for a build or link hook invocation. final class HookConfig { Map get json => _syntax.json; diff --git a/pkgs/native_assets_cli/lib/src/hooks/syntax.g.dart b/pkgs/native_assets_cli/lib/src/hooks/syntax.g.dart index 75f2134ab..95e45e784 100644 --- a/pkgs/native_assets_cli/lib/src/hooks/syntax.g.dart +++ b/pkgs/native_assets_cli/lib/src/hooks/syntax.g.dart @@ -350,7 +350,7 @@ class HookInput { required Uri? outFile, required String packageName, required Uri packageRoot, - required String version, + required String? version, }) : json = {}, path = const [] { this.config = config; @@ -428,14 +428,14 @@ class HookInput { List _validatePackageRoot() => _reader.validatePath('package_root'); - String get version => _reader.get('version'); + String? get version => _reader.get('version'); - set version(String value) { + set version(String? value) { json.setOrRemove('version', value); json.sortOnKey(); } - List _validateVersion() => _reader.validate('version'); + List _validateVersion() => _reader.validate('version'); List validate() => [ ..._validateConfig(), @@ -464,7 +464,7 @@ class HookOutput { required List? assets, required List? dependencies, required String timestamp, - required String version, + required String? version, }) : json = {}, path = const [] { this.assets = assets; @@ -528,14 +528,14 @@ class HookOutput { List _validateTimestamp() => _reader.validate('timestamp'); - String get version => _reader.get('version'); + String? get version => _reader.get('version'); - set version(String value) { + set version(String? value) { json.setOrRemove('version', value); json.sortOnKey(); } - List _validateVersion() => _reader.validate('version'); + List _validateVersion() => _reader.validate('version'); List validate() => [ ..._validateAssets(), 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 deleted file mode 100644 index 91fea0f1e..000000000 --- a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md +++ /dev/null @@ -1,76 +0,0 @@ -## 1.9.0 - -- `CCompilerConfig` now nests the Windows config under - `.windows.developerCommandPrompt`. - Compatibility with older hooks: Previous JSON structure is still emitted. - Compatibility with older SDKs: Still parse the old JSON. - -## 1.8.0 - -- Add `BuildInput.outputFile` to specify the outfile. This means the out file - can be outside the `outputDirectory` and avoid potential conflicts. - Compatibility with older hooks: If the file doesn't exist, try the previous - location. - Compatibility with older SDKs: Default the location to where it was. - -## 1.7.0 - -- Complete rewrite of JSON - Compatibility with older hooks: also emit old structure. - Compatibility with older SDKs: keep parsing old structure. - -## 1.6.0 - -- `BuildConfig.supportedAssetTypes` renamed to `BuildConfig.buildAssetTypes`. - Compatibility with older SDKs: Look for the old key. Compatibility with older - hooks: Also provide the old hook in the config. -- `BuildConfig.targetOS` is now only provided if `buildAssetTypes` contains the - code asset. - Compatibility with older SDKs: Fine, they always provide it. - Compatibility with older hooks: Currently, no embedders call hooks without - support for code assets. Once they do (data assets on web), existing hooks - will break. Mitigation: Update existing hooks to check for `buildAssetTypes` - and/or change `CBuilder` to be a no-op if `buildAssetTypes` does not contain - code assets. -- `BuildConfig.outputDirectoryShared` for sharing between hook invocations. - Compatibility with older SDKs: Create a sibling dir next to the output - directory. This does not facilitate caching, but should not break the hook. - Compatibility with older hooks: These will not read this field. -- `BuildConfig.buildMode` is removed. Instead it is specified by hook writers - in the `CBuilder` constructors. - Compatibility with older SDKs: The new hooks will not read the field. - Compatibility with older hooks: The field is now always passed as 'release' - until we can bump the SDK constraint in `package:native_assets_cli`. - -## 1.5.0 - -- No changes, but rev version due to BuildOutput change. - -## 1.4.0 - -- Link hooks are not always run. `BuildConfig.linkingEnabled` communicates - whether link hooks are run. - Compatibility with older SDKs: the `linkingEnabled` 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 - `BuildOutput.assetsForLinking`. In earlier versions the key will not be read - and the list of assets to be linked will be empty. - -## 1.2.0 - -- Changed default encoding to JSON. - Backwards compatibility: JSON is parsable as YAML. -- Changed default filename. - Compatibility: The filename is explicitly passed in with --config. - -## 1.1.0 - -- Added supported asset types. - Backwards compatibility: Defaults to a list with a single element: `native_code`. - -## 1.0.0 - -- Initial version. diff --git a/pkgs/native_assets_cli/lib/src/model/hook_config_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/hook_config_CHANGELOG.md deleted file mode 100644 index b295f1428..000000000 --- a/pkgs/native_assets_cli/lib/src/model/hook_config_CHANGELOG.md +++ /dev/null @@ -1,57 +0,0 @@ -## 1.6.0 - -- No changes, but rev version due to BuildConfig change. -- **Breaking change** Link hooks now have to explicitly add any file contents - they rely on via `output.addDependency()` to ensure they re-run if the - content of those files changes. (Previously if a linker script obtained code - or data assets, the files referred to by those assets were implicitly added as - a dependency, but adding custom asset types changed this behavior) - NOTE: Newer Dart & Flutter SDKs will no longer add those dependencies - implicitly which may make some older linker implementations that do not add - dependencies explicitly not work correctly anymore: The linker scripts have - to be updated to add those dependencies explicitly. - -## 1.5.0 - -- BuildOutput.dependencies no longer have to list Dart dependencies. - Backwards compatibility older SDKs: The caching will break. - Backwards compatibility older hooks: The Dart sources will be both in the - dependencies and in the native_assets_builder dependencies, which is fine. - -## 1.4.0 - -- No changes, 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. - Backwards compatibility older SDKs: These are ignored on older SDKs. - -## 1.2.0 - -- Changed default encoding to JSON. - Backwards compatibility: JSON is parsable as YAML. -- Changed filename from `build_output.yaml` to `build_output.json`. - Backwards compatibility older SDKs: write to the old file name if an older BuildConfig was passed in. - Backwards compatibility: Try to read yaml file if json doesn't exist. - -## 1.1.0 - -- Assets now have a `type`. - Backwards compatibility: assets without a type are interpreted as `native_code` assets. -- Assets now have an optional `file`. - Backwards compatibility: assets that have an `AssetAbsolutePath` will have that path used as `file`. -- **Breaking change** Assets now have a `dynamic_loading` field instead of `path_type`. - The `absolute` path_type is renamed to `bundled` as dynamic loading type. - Backwards compatibility: `path` is parsed as `dynamic_linking`. - Backwards compatibility: the nested `path_type` is parsed as `type`. - Backwards compatibility older SDKs: emit the old format if an older BuildConfig was passed in. -- Added `DataAsset`s. - Backwards compatibility: These are ignored on older SDKs. -- `architecture` is optional. - Backwards compatibility older SDKs: expand the assets to include all architectures. - -## 1.0.0 - -- Initial version. diff --git a/pkgs/native_assets_cli/test/build_input_test.dart b/pkgs/native_assets_cli/test/build_input_test.dart index 0cf6c696b..78b91bec2 100644 --- a/pkgs/native_assets_cli/test/build_input_test.dart +++ b/pkgs/native_assets_cli/test/build_input_test.dart @@ -95,17 +95,7 @@ void main() async { test('BuildInput version $version', () { final input = inputJson; input['version'] = version; - expect( - () => BuildInput(input), - throwsA( - predicate( - (e) => - e is FormatException && - e.message.contains(version) && - e.message.contains(latestVersion.toString()), - ), - ), - ); + expect(() => BuildInput(input), isNot(throwsException)); }); } diff --git a/pkgs/native_assets_cli/test/build_output_test.dart b/pkgs/native_assets_cli/test/build_output_test.dart index 92aa76acd..0c2bf54c7 100644 --- a/pkgs/native_assets_cli/test/build_output_test.dart +++ b/pkgs/native_assets_cli/test/build_output_test.dart @@ -5,7 +5,6 @@ // ignore_for_file: deprecated_member_use_from_same_package import 'package:native_assets_cli/native_assets_cli_builder.dart'; -import 'package:native_assets_cli/src/config.dart'; import 'package:native_assets_cli/src/utils/datetime.dart'; import 'package:test/test.dart'; @@ -94,17 +93,7 @@ void main() { for (final version in ['9001.0.0', '0.0.1']) { test('BuildOutput version $version', () { - expect( - () => BuildOutput({'version': version}), - throwsA( - predicate( - (e) => - e is FormatException && - e.message.contains(version) && - e.message.contains(latestVersion.toString()), - ), - ), - ); + expect(() => BuildOutput({'version': version}), isNot(throwsException)); }); } } diff --git a/pkgs/native_assets_cli/test/link_input_test.dart b/pkgs/native_assets_cli/test/link_input_test.dart index 2057e377f..48f29d14f 100644 --- a/pkgs/native_assets_cli/test/link_input_test.dart +++ b/pkgs/native_assets_cli/test/link_input_test.dart @@ -78,17 +78,7 @@ void main() async { test('LinkInput version $version', () { final input = inputJson; input['version'] = version; - expect( - () => LinkInput(input), - throwsA( - predicate( - (e) => - e is FormatException && - e.message.contains(version) && - e.message.contains(latestVersion.toString()), - ), - ), - ); + expect(() => LinkInput(input), isNot(throwsException)); }); } diff --git a/pkgs/native_assets_cli/test/link_output_test.dart b/pkgs/native_assets_cli/test/link_output_test.dart index 587c4add6..954ea3573 100644 --- a/pkgs/native_assets_cli/test/link_output_test.dart +++ b/pkgs/native_assets_cli/test/link_output_test.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:native_assets_cli/native_assets_cli_builder.dart'; -import 'package:native_assets_cli/src/config.dart'; import 'package:native_assets_cli/src/utils/datetime.dart'; import 'package:test/test.dart'; @@ -60,17 +59,7 @@ void main() { for (final version in ['9001.0.0', '0.0.1']) { test('LinkOutput version $version', () { - expect( - () => LinkOutput({'version': version}), - throwsA( - predicate( - (e) => - e is FormatException && - e.message.contains(version) && - e.message.contains(latestVersion.toString()), - ), - ), - ); + expect(() => LinkOutput({'version': version}), isNot(throwsException)); }); } }