Skip to content

Commit 027d09e

Browse files
committed
[native_assets_cli] Stop reading version
1 parent 03d3fff commit 027d09e

14 files changed

+27
-305
lines changed

Diff for: pkgs/hooks/doc/schema/sdk/shared_definitions.schema.json

-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
"HookOutput": {},
3737
"LinkInput": {
3838
"$ref": "../shared/shared_definitions.schema.json#/definitions/LinkInput",
39-
"required": [
40-
"out_file",
41-
"version"
42-
],
4339
"unevaluatedProperties": false
4440
},
4541
"LinkOutput": {}

Diff for: pkgs/hooks/doc/schema/shared/shared_definitions.schema.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@
139139
"out_dir",
140140
"out_dir_shared",
141141
"package_name",
142-
"package_root",
143-
"version"
142+
"package_root"
144143
]
145144
},
146145
"HookOutput": {
@@ -169,8 +168,7 @@
169168
}
170169
},
171170
"required": [
172-
"timestamp",
173-
"version"
171+
"timestamp"
174172
]
175173
},
176174
"LinkInput": {

Diff for: pkgs/hooks/test/schema/helpers.dart

+10-5
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,21 @@ FieldsReturn _hookFields({
288288
required Party party,
289289
}) {
290290
void versionMissingExpectation(ValidationResults result) {
291-
if ((party == Party.sdk && inputOrOutput == InputOrOutput.input) ||
292-
(party == Party.hook && inputOrOutput == InputOrOutput.output)) {
291+
if (party == Party.sdk && inputOrOutput == InputOrOutput.input) {
293292
// The writer must output this field. SDK must support older hooks reading
294293
// it.
295294
expect(result.isValid, isFalse);
295+
} else if (party == Party.hook && inputOrOutput == InputOrOutput.output) {
296+
// The writer must output this field. SDK must support older hooks reading
297+
// it.
298+
// Note: For some reason party:hook output does not register as required
299+
// `package:json_schema`, but the JSON validator in vscode does properly
300+
// mark it as required.
301+
// Ignore this issue for now, we'll remove version soon.
302+
// expect(result.isValid, isFalse);
296303
} else {
297304
// Newer hooks must support future SDKs not outputting a this field.
298-
// TODO: Stop requiring version in the reader.
299-
// expect(result.isValid, isTrue);
300-
expect(result.isValid, isFalse);
305+
expect(result.isValid, isTrue);
301306
}
302307
}
303308

Diff for: pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart

-57
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:logging/logging.dart';
1111
import 'package:meta/meta.dart';
1212
import 'package:native_assets_cli/native_assets_cli_internal.dart';
1313
import 'package:package_config/package_config.dart';
14-
import 'package:pub_semver/pub_semver.dart';
1514

1615
import '../dependencies_hash_file/dependencies_hash_file.dart';
1716
import '../locking/locking.dart';
@@ -91,10 +90,6 @@ class NativeAssetsBuildRunner {
9190
);
9291
if (buildPlan == null) return null;
9392

94-
if (!await _ensureNativeAssetsCliProtocolVersion()) {
95-
return null;
96-
}
97-
9893
var hookResult = HookResult();
9994
final globalMetadata = <String, Metadata>{};
10095
for (final package in buildPlan) {
@@ -833,58 +828,6 @@ ${compileResult.stdout}
833828
? BuildOutput(hookOutputJson)
834829
: LinkOutput(hookOutputJson);
835830
}
836-
837-
Future<bool> _ensureNativeAssetsCliProtocolVersion() async {
838-
final package =
839-
packageLayout.packageConfig['native_assets_cli'] ??
840-
packageLayout.packageConfig['hook']; // Anticipate rename.
841-
if (package == null) {
842-
// No dependencies with a hook or using a different protocol helper
843-
// package.
844-
return true;
845-
}
846-
final packageRoot = package.root.normalizePath();
847-
final hookVersion = await _nativeAssetsCliProtocolVersion(packageRoot);
848-
if (hookVersion == null) {
849-
logger.fine(
850-
'Could not determine the protocol version of '
851-
'${packageRoot.toFilePath()}.',
852-
);
853-
// This is most likely due to a newer version of the package.
854-
return true;
855-
}
856-
if (latestParsableVersion > hookVersion) {
857-
// The hook is too old.
858-
logger.shout(
859-
'The protocol version of ${packageRoot.toFilePath()} is '
860-
'$hookVersion, which is no longer supported. Please update your '
861-
'dependencies.',
862-
);
863-
return false;
864-
}
865-
return true;
866-
}
867-
868-
Future<Version?> _nativeAssetsCliProtocolVersion(Uri packageRoot) async {
869-
const files = ['lib/src/config.dart', 'lib/src/model/hook_config.dart'];
870-
for (final fileName in files) {
871-
final file = _fileSystem.file(packageRoot.resolve(fileName));
872-
if (!await file.exists()) {
873-
continue;
874-
}
875-
final contents = await file.readAsString();
876-
final regex = RegExp(r'latestVersion = Version\((\d+), (\d+), (\d+)\);');
877-
final match = regex.firstMatch(contents);
878-
if (match == null) {
879-
continue;
880-
}
881-
final major = int.parse(match.group(1)!);
882-
final minor = int.parse(match.group(2)!);
883-
final patch = int.parse(match.group(3)!);
884-
return Version(major, minor, patch);
885-
}
886-
return null;
887-
}
888831
}
889832

890833
/// Parses depfile contents.

Diff for: pkgs/native_assets_builder/test/build_runner/version_skew_test.dart

+1-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ void main() async {
5353
expect(result, isNull);
5454
expect(
5555
logMessages.join('\n'),
56-
stringContainsInOrder([
57-
'The protocol version of ',
58-
'native_assets_cli',
59-
' is 1.3.0, which is no longer supported.',
60-
'Please update your dependencies.',
61-
]),
56+
stringContainsInOrder(['Unhandled exception']),
6257
);
6358
});
6459
},

Diff for: pkgs/native_assets_cli/lib/native_assets_cli_internal.dart

-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
library;
77

88
export 'native_assets_cli_builder.dart';
9-
export 'src/config.dart' show latestParsableVersion;
109
export 'src/model/hook.dart';

Diff for: pkgs/native_assets_cli/lib/src/config.dart

+2-41
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ sealed class HookInput {
2424
/// The underlying json configuration of this [HookInput].
2525
Map<String, Object?> get json => _syntax.json;
2626

27-
/// The version of the [HookInput].
28-
Version get version => Version.parse(_syntax.version);
29-
3027
/// The directory in which output and intermediate artifacts that are unique
3128
/// to the [config] can be placed.
3229
///
@@ -82,13 +79,6 @@ sealed class HookInput {
8279

8380
HookInput(Map<String, Object?> json)
8481
: _syntax = syntax.HookInput.fromJson(json) {
85-
if (version.major != latestVersion.major ||
86-
version < latestParsableVersion) {
87-
throw FormatException(
88-
'Only compatible versions with $latestVersion are supported '
89-
'(was: $version).',
90-
);
91-
}
9282
// Trigger validation, remove with cleanup.
9383
outputDirectory;
9484
outputDirectoryShared;
@@ -290,9 +280,6 @@ sealed class HookOutput {
290280
/// The underlying json configuration of this [HookOutput].
291281
Map<String, Object?> get json => _syntax.json;
292282

293-
/// The version of the [HookInput].
294-
Version get version => Version.parse(_syntax.version);
295-
296283
/// Start time for the build of this output.
297284
///
298285
/// The [timestamp] is rounded down to whole seconds, because
@@ -316,15 +303,7 @@ sealed class HookOutput {
316303

317304
syntax.HookOutput get _syntax;
318305

319-
HookOutput._(Map<String, Object?> json) {
320-
if (version.major != latestVersion.major ||
321-
version < latestParsableVersion) {
322-
throw FormatException(
323-
'Only compatible versions with $latestVersion are supported '
324-
'(was: $version).',
325-
);
326-
}
327-
}
306+
HookOutput._(Map<String, Object?> json);
328307

329308
@override
330309
String toString() => const JsonEncoder.withIndent(' ').convert(json);
@@ -607,27 +586,9 @@ extension type EncodedAssetLinkOutputBuilder._(LinkOutputBuilder _builder) {
607586
syntax.LinkOutput.fromJson(_builder._syntax.json);
608587
}
609588

610-
/// The latest supported input version.
611-
///
612-
/// We'll never bump the major version. Removing old keys from the input and
613-
/// output is done via modifying [latestParsableVersion].
589+
// Deprecated, still emitted for backwards compatibility purposes.
614590
final latestVersion = Version(1, 9, 0);
615591

616-
/// The parser can deal with inputs and outputs down to this version.
617-
///
618-
/// This version can be bumped when:
619-
///
620-
/// 1. The stable version of Dart / Flutter uses a newer version _and_ the SDK
621-
/// constraint is bumped in the pubspec of this package to that stable
622-
/// version. (This prevents input parsing from failing.)
623-
/// 2. A stable version of this package is published uses a newer version, _and_
624-
/// most users have migrated to it. (This prevents the output parsing from
625-
/// failing.)
626-
///
627-
/// When updating this number, update the version_skew_test.dart. (This test
628-
/// catches issues with 2.)
629-
final latestParsableVersion = Version(1, 7, 0);
630-
631592
/// The configuration for a build or link hook invocation.
632593
final class HookConfig {
633594
Map<String, Object?> get json => _syntax.json;

Diff for: pkgs/native_assets_cli/lib/src/hooks/syntax.g.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class HookInput {
350350
required Uri? outFile,
351351
required String packageName,
352352
required Uri packageRoot,
353-
required String version,
353+
required String? version,
354354
}) : json = {},
355355
path = const [] {
356356
this.config = config;
@@ -428,14 +428,14 @@ class HookInput {
428428

429429
List<String> _validatePackageRoot() => _reader.validatePath('package_root');
430430

431-
String get version => _reader.get<String>('version');
431+
String? get version => _reader.get<String?>('version');
432432

433-
set version(String value) {
433+
set version(String? value) {
434434
json.setOrRemove('version', value);
435435
json.sortOnKey();
436436
}
437437

438-
List<String> _validateVersion() => _reader.validate<String>('version');
438+
List<String> _validateVersion() => _reader.validate<String?>('version');
439439

440440
List<String> validate() => [
441441
..._validateConfig(),
@@ -464,7 +464,7 @@ class HookOutput {
464464
required List<Asset>? assets,
465465
required List<Uri>? dependencies,
466466
required String timestamp,
467-
required String version,
467+
required String? version,
468468
}) : json = {},
469469
path = const [] {
470470
this.assets = assets;
@@ -528,14 +528,14 @@ class HookOutput {
528528

529529
List<String> _validateTimestamp() => _reader.validate<String>('timestamp');
530530

531-
String get version => _reader.get<String>('version');
531+
String? get version => _reader.get<String?>('version');
532532

533-
set version(String value) {
533+
set version(String? value) {
534534
json.setOrRemove('version', value);
535535
json.sortOnKey();
536536
}
537537

538-
List<String> _validateVersion() => _reader.validate<String>('version');
538+
List<String> _validateVersion() => _reader.validate<String?>('version');
539539

540540
List<String> validate() => [
541541
..._validateAssets(),

Diff for: pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md

-76
This file was deleted.

0 commit comments

Comments
 (0)