Skip to content

Commit baec0f7

Browse files
committed
[native_assets_cli] Stop reading version
1 parent b91277d commit baec0f7

File tree

10 files changed

+12
-157
lines changed

10 files changed

+12
-157
lines changed

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

+1-2
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": {

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

+4-4
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(),

Diff for: pkgs/native_assets_cli/test/build_input_test.dart

+1-11
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,7 @@ void main() async {
9595
test('BuildInput version $version', () {
9696
final input = inputJson;
9797
input['version'] = version;
98-
expect(
99-
() => BuildInput(input),
100-
throwsA(
101-
predicate(
102-
(e) =>
103-
e is FormatException &&
104-
e.message.contains(version) &&
105-
e.message.contains(latestVersion.toString()),
106-
),
107-
),
108-
);
98+
expect(() => BuildInput(input), isNot(throwsException));
10999
});
110100
}
111101

Diff for: pkgs/native_assets_cli/test/build_output_test.dart

+1-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// ignore_for_file: deprecated_member_use_from_same_package
66

77
import 'package:native_assets_cli/native_assets_cli_builder.dart';
8-
import 'package:native_assets_cli/src/config.dart';
98
import 'package:native_assets_cli/src/utils/datetime.dart';
109
import 'package:test/test.dart';
1110

@@ -94,17 +93,7 @@ void main() {
9493

9594
for (final version in ['9001.0.0', '0.0.1']) {
9695
test('BuildOutput version $version', () {
97-
expect(
98-
() => BuildOutput({'version': version}),
99-
throwsA(
100-
predicate(
101-
(e) =>
102-
e is FormatException &&
103-
e.message.contains(version) &&
104-
e.message.contains(latestVersion.toString()),
105-
),
106-
),
107-
);
96+
expect(() => BuildOutput({'version': version}), isNot(throwsException));
10897
});
10998
}
11099
}

Diff for: pkgs/native_assets_cli/test/link_input_test.dart

+1-11
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,7 @@ void main() async {
7878
test('LinkInput version $version', () {
7979
final input = inputJson;
8080
input['version'] = version;
81-
expect(
82-
() => LinkInput(input),
83-
throwsA(
84-
predicate(
85-
(e) =>
86-
e is FormatException &&
87-
e.message.contains(version) &&
88-
e.message.contains(latestVersion.toString()),
89-
),
90-
),
91-
);
81+
expect(() => LinkInput(input), isNot(throwsException));
9282
});
9383
}
9484

Diff for: pkgs/native_assets_cli/test/link_output_test.dart

+1-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:native_assets_cli/native_assets_cli_builder.dart';
6-
import 'package:native_assets_cli/src/config.dart';
76
import 'package:native_assets_cli/src/utils/datetime.dart';
87
import 'package:test/test.dart';
98

@@ -60,17 +59,7 @@ void main() {
6059

6160
for (final version in ['9001.0.0', '0.0.1']) {
6261
test('LinkOutput version $version', () {
63-
expect(
64-
() => LinkOutput({'version': version}),
65-
throwsA(
66-
predicate(
67-
(e) =>
68-
e is FormatException &&
69-
e.message.contains(version) &&
70-
e.message.contains(latestVersion.toString()),
71-
),
72-
),
73-
);
62+
expect(() => LinkOutput({'version': version}), isNot(throwsException));
7463
});
7564
}
7665
}

0 commit comments

Comments
 (0)