Skip to content

Commit 5f974c6

Browse files
committed
Remove v1.0 / v1.1 serialization format code. Require 3.6.0+ (which has newest serialization format) via increased Dart SDK constraint
1 parent 117cc75 commit 5f974c6

11 files changed

+27
-340
lines changed

pkgs/native_assets_cli/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
## 0.8.1-wip
1+
## 0.9.0-wip
22

33
- Add `BuildConfig` and `LinkConfig` `outputDirectoryShared`.
44
- Remove `package:native_assets_cli/locking.dart` with `runUnderDirectoryLock`.
55
Hook writers should not use this, the `native_assets_builder` does this.
66
- Fix example packages with RecordUse annotations
77
[#1586](https://github.com/dart-lang/native/issues/1586).
8+
- Remove v1.0 / v1.1 related serialization
89

910
## 0.8.0
1011

pkgs/native_assets_cli/lib/src/api/asset.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'package:pub_semver/pub_semver.dart';
66

7-
import '../model/target.dart';
87
import '../utils/json.dart';
98
import '../utils/map.dart';
109
import 'architecture.dart';

pkgs/native_assets_cli/lib/src/model/asset.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ abstract final class AssetImpl implements Asset {
1515
final type = jsonMap[NativeCodeAssetImpl.typeKey];
1616
switch (type) {
1717
case NativeCodeAsset.type:
18-
case null: // Backwards compatibility with v1.0.0.
1918
assets.add(NativeCodeAssetImpl.fromJson(jsonMap));
2019
case DataAsset.type:
2120
assets.add(DataAssetImpl.fromJson(jsonMap));

pkgs/native_assets_cli/lib/src/model/build_config.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ final class BuildConfigImpl extends HookConfigImpl implements BuildConfig {
2020
}
2121

2222
@override
23-
String get outputName =>
24-
version > Version(1, 1, 0) ? 'build_output.json' : outputNameV1_1_0;
25-
26-
@override
27-
String get outputNameV1_1_0 => 'build_output.yaml';
23+
String get outputName => 'build_output.json';
2824

2925
@override
3026
Object? metadatum(String packageName, String key) {

pkgs/native_assets_cli/lib/src/model/hook_config.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ abstract class HookConfigImpl implements HookConfig {
104104
/// Makes newer build hooks work with older Dart SDKs.
105105
String get outputName;
106106

107-
/// Legacy output file name.
108-
///
109-
/// Older build hooks output a yaml file, ignoring the newer protocol version
110-
/// in the config.
111-
String? get outputNameV1_1_0;
112-
113107
HookConfigImpl({
114108
required this.hook,
115109
required this.outputDirectory,
@@ -157,10 +151,6 @@ abstract class HookConfigImpl implements HookConfig {
157151

158152
Uri get outputFile => outputDirectory.resolve(outputName);
159153

160-
Uri? get outputFileV1_1_0 => outputNameV1_1_0 == null
161-
? null
162-
: outputDirectory.resolve(outputNameV1_1_0!);
163-
164154
// This is currently overriden by [BuildConfig], do account for older versions
165155
// still using a top-level build.dart.
166156
Uri get script => packageRoot.resolve('hook/').resolve(hook.scriptName);
@@ -484,7 +474,9 @@ can _only_ depend on OS.''');
484474
if (other.targetOS != targetOS) return false;
485475
if (other.linkModePreference != linkModePreference) return false;
486476
if (!const DeepCollectionEquality()
487-
.equals(other.supportedAssetTypes, supportedAssetTypes)) return false;
477+
.equals(other.supportedAssetTypes, supportedAssetTypes)) {
478+
return false;
479+
}
488480
if (!dryRun) {
489481
if (other.buildMode != buildMode) return false;
490482
if (other.targetArchitecture != targetArchitecture) return false;

pkgs/native_assets_cli/lib/src/model/link_config.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
6969
@override
7070
String get outputName => 'link_output.json';
7171

72-
@override
73-
String? get outputNameV1_1_0 => null;
74-
7572
@override
7673
Map<String, Object> toJson() => {
7774
...hookToJson(),

pkgs/native_assets_cli/lib/src/model/native_code_asset.dart

Lines changed: 14 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
part of '../api/asset.dart';
66

77
abstract final class LinkModeImpl implements LinkMode {
8-
/// Serialization of v1.1.0 and newer
8+
/// Serialization of a link mode.
99
///
1010
/// Does not include the toplevel keys.
1111
///
@@ -15,30 +15,14 @@ abstract final class LinkModeImpl implements LinkMode {
1515
/// ```
1616
Map<String, Object> toJson();
1717

18-
/// Backwards compatibility with v1.0.0 of the protocol
19-
///
20-
/// Includes the parent keys.
21-
///
22-
/// ```
23-
/// link_mode: dynamic
24-
/// path:
25-
/// path_type: system
26-
/// uri: ${foo3Uri.toFilePath()}
27-
/// ```
28-
Map<String, Object> toJsonV1_0_0(Uri? file);
29-
3018
factory LinkModeImpl(String type, Uri? uri) {
3119
switch (type) {
32-
case DynamicLoadingBundledImpl._typeValueV1_0_0:
3320
case DynamicLoadingBundledImpl._typeValue:
3421
return DynamicLoadingBundledImpl();
35-
case DynamicLoadingSystemImpl._typeValueV1_0_0:
3622
case DynamicLoadingSystemImpl._typeValue:
3723
return DynamicLoadingSystemImpl(uri!);
38-
case LookupInExecutableImpl._typeValueV1_0_0:
3924
case LookupInExecutableImpl._typeValue:
4025
return LookupInExecutableImpl();
41-
case LookupInProcessImpl._typeValueV1_0_0:
4226
case LookupInProcessImpl._typeValue:
4327
return LookupInProcessImpl();
4428
case StaticLinkingImpl._typeValue:
@@ -47,7 +31,6 @@ abstract final class LinkModeImpl implements LinkMode {
4731
throw FormatException('Unknown type: $type.');
4832
}
4933

50-
/// v1.1.0 and newer.
5134
factory LinkModeImpl.fromJson(Map<Object?, Object?> jsonMap) {
5235
final type = get<String>(jsonMap, _typeKey);
5336
final uriString = get<String?>(jsonMap, _uriKey);
@@ -61,11 +44,8 @@ abstract final class LinkModeImpl implements LinkMode {
6144

6245
abstract final class DynamicLoadingImpl
6346
implements LinkModeImpl, DynamicLoading {
64-
static const _pathTypeKeyV1_0_0 = 'path_type';
6547
static const _typeKey = 'type';
6648
static const _uriKey = 'uri';
67-
68-
static const _typeValueV1_0_0 = 'dynamic';
6949
}
7050

7151
final class DynamicLoadingBundledImpl
@@ -77,23 +57,13 @@ final class DynamicLoadingBundledImpl
7757

7858
factory DynamicLoadingBundledImpl() => _singleton;
7959

80-
static const _typeValueV1_0_0 = 'absolute';
8160
static const _typeValue = 'dynamic_loading_bundle';
8261

8362
@override
8463
Map<String, Object> toJson() => {
8564
DynamicLoadingImpl._typeKey: _typeValue,
8665
};
8766

88-
@override
89-
Map<String, Object> toJsonV1_0_0(Uri? file) => {
90-
NativeCodeAssetImpl._linkModeKey: DynamicLoadingImpl._typeValueV1_0_0,
91-
NativeCodeAssetImpl._pathKey: {
92-
DynamicLoadingImpl._pathTypeKeyV1_0_0: _typeValueV1_0_0,
93-
DynamicLoadingImpl._uriKey: file!.toFilePath(),
94-
}
95-
};
96-
9767
@override
9868
String toString() => _typeValue;
9969
}
@@ -106,23 +76,13 @@ final class DynamicLoadingSystemImpl
10676
DynamicLoadingSystemImpl(this.uri);
10777

10878
static const _typeValue = 'dynamic_loading_system';
109-
static const _typeValueV1_0_0 = 'system';
11079

11180
@override
11281
Map<String, Object> toJson() => {
11382
DynamicLoadingImpl._typeKey: _typeValue,
11483
DynamicLoadingImpl._uriKey: uri.toFilePath(),
11584
};
11685

117-
@override
118-
Map<String, Object> toJsonV1_0_0(Uri? file) => {
119-
NativeCodeAssetImpl._linkModeKey: DynamicLoadingImpl._typeValueV1_0_0,
120-
NativeCodeAssetImpl._pathKey: {
121-
DynamicLoadingImpl._pathTypeKeyV1_0_0: _typeValueV1_0_0,
122-
DynamicLoadingImpl._uriKey: uri.toFilePath(),
123-
}
124-
};
125-
12686
@override
12787
int get hashCode => Object.hash(uri, 133723);
12888

@@ -146,21 +106,12 @@ final class LookupInProcessImpl implements DynamicLoadingImpl, LookupInProcess {
146106
factory LookupInProcessImpl() => _singleton;
147107

148108
static const _typeValue = 'dynamic_loading_process';
149-
static const _typeValueV1_0_0 = 'process';
150109

151110
@override
152111
Map<String, Object> toJson() => {
153112
DynamicLoadingImpl._typeKey: _typeValue,
154113
};
155114

156-
@override
157-
Map<String, Object> toJsonV1_0_0(Uri? file) => {
158-
NativeCodeAssetImpl._linkModeKey: DynamicLoadingImpl._typeValueV1_0_0,
159-
NativeCodeAssetImpl._pathKey: {
160-
DynamicLoadingImpl._pathTypeKeyV1_0_0: _typeValueV1_0_0,
161-
}
162-
};
163-
164115
@override
165116
String toString() => _typeValue;
166117
}
@@ -174,20 +125,11 @@ final class LookupInExecutableImpl
174125
factory LookupInExecutableImpl() => _singleton;
175126

176127
static const _typeValue = 'dynamic_loading_executable';
177-
static const _typeValueV1_0_0 = 'executable';
178128

179129
@override
180130
Map<String, Object> toJson() => {
181131
DynamicLoadingImpl._typeKey: _typeValue,
182132
};
183-
184-
@override
185-
Map<String, Object> toJsonV1_0_0(Uri? file) => {
186-
NativeCodeAssetImpl._linkModeKey: DynamicLoadingImpl._typeValueV1_0_0,
187-
NativeCodeAssetImpl._pathKey: {
188-
DynamicLoadingImpl._pathTypeKeyV1_0_0: _typeValueV1_0_0,
189-
}
190-
};
191133
}
192134

193135
final class StaticLinkingImpl implements LinkModeImpl, StaticLinking {
@@ -204,11 +146,6 @@ final class StaticLinkingImpl implements LinkModeImpl, StaticLinking {
204146
DynamicLoadingImpl._typeKey: _typeValue,
205147
};
206148

207-
@override
208-
Map<String, Object> toJsonV1_0_0(Uri? file) => {
209-
NativeCodeAssetImpl._linkModeKey: _typeValue,
210-
};
211-
212149
@override
213150
String toString() => _typeValue;
214151
}
@@ -248,56 +185,24 @@ final class NativeCodeAssetImpl implements NativeCodeAsset, AssetImpl {
248185
}
249186

250187
factory NativeCodeAssetImpl.fromJson(Map<Object?, Object?> jsonMap) {
251-
final LinkModeImpl linkMode;
252188
final linkModeJson = jsonMap[_linkModeKey];
253-
if (linkModeJson is String) {
254-
// v1.0.0
255-
if (linkModeJson == StaticLinkingImpl._typeValue) {
256-
linkMode = StaticLinkingImpl();
257-
} else {
258-
assert(linkModeJson == DynamicLoadingImpl._typeValueV1_0_0);
259-
final pathJson = get<Map<Object?, Object?>>(jsonMap, _pathKey);
260-
final type =
261-
as<String>(pathJson[DynamicLoadingImpl._pathTypeKeyV1_0_0]);
262-
final uriString = as<String?>(pathJson[DynamicLoadingImpl._uriKey]);
263-
final uri = uriString != null ? Uri(path: uriString) : null;
264-
linkMode = LinkModeImpl(type, uri);
265-
}
266-
} else {
267-
// v1.1.0 and newer.
268-
linkMode = LinkModeImpl.fromJson(as<Map<Object?, Object?>>(linkModeJson));
269-
}
189+
final linkMode =
190+
LinkModeImpl.fromJson(as<Map<Object?, Object?>>(linkModeJson));
270191

271192
final fileString = get<String?>(jsonMap, _fileKey);
272193
final Uri? file;
273194
if (fileString != null) {
274195
file = Uri(path: fileString);
275-
} else if ((linkMode is DynamicLoadingBundledImpl ||
276-
linkMode is StaticLinkingImpl) &&
277-
jsonMap[_pathKey] != null) {
278-
// Compatibility with v1.0.0.
279-
final oldPath = as<String?>((jsonMap[_pathKey]
280-
as Map<Object?, Object?>)[DynamicLoadingImpl._uriKey]);
281-
file = oldPath != null ? Uri(path: oldPath) : null;
282196
} else {
283197
file = null;
284198
}
285-
final targetString = get<String?>(jsonMap, _targetKey);
286199
final ArchitectureImpl? architecture;
287-
final OSImpl os;
288-
if (targetString != null) {
289-
// Compatibility with v1.0.0.
290-
final target = Target.fromString(targetString);
291-
os = target.os;
292-
architecture = target.architecture;
200+
final os = OSImpl.fromString(get<String>(jsonMap, _osKey));
201+
final architectureString = get<String?>(jsonMap, _architectureKey);
202+
if (architectureString != null) {
203+
architecture = ArchitectureImpl.fromString(architectureString);
293204
} else {
294-
os = OSImpl.fromString(get<String>(jsonMap, _osKey));
295-
final architectureString = get<String?>(jsonMap, _architectureKey);
296-
if (architectureString != null) {
297-
architecture = ArchitectureImpl.fromString(architectureString);
298-
} else {
299-
architecture = null;
300-
}
205+
architecture = null;
301206
}
302207

303208
return NativeCodeAssetImpl(
@@ -346,29 +251,19 @@ final class NativeCodeAssetImpl implements NativeCodeAsset, AssetImpl {
346251
);
347252

348253
@override
349-
Map<String, Object> toJson(Version version) {
350-
if (version == Version(1, 0, 0)) {
351-
return {
254+
Map<String, Object> toJson(Version version) => {
255+
if (architecture != null) _architectureKey: architecture.toString(),
256+
if (file != null) _fileKey: file!.toFilePath(),
352257
_idKey: id,
353-
...linkMode.toJsonV1_0_0(file),
354-
_targetKey: Target.fromArchitectureAndOS(architecture!, os).toString(),
258+
_linkModeKey: linkMode.toJson(),
259+
_osKey: os.toString(),
260+
typeKey: NativeCodeAsset.type,
355261
}..sortOnKey();
356-
}
357-
return {
358-
if (architecture != null) _architectureKey: architecture.toString(),
359-
if (file != null) _fileKey: file!.toFilePath(),
360-
_idKey: id,
361-
_linkModeKey: linkMode.toJson(),
362-
_osKey: os.toString(),
363-
typeKey: NativeCodeAsset.type,
364-
}..sortOnKey();
365-
}
366262

367263
static const typeKey = 'type';
368264
static const _idKey = 'id';
369265
static const _linkModeKey = 'link_mode';
370266
static const _pathKey = 'path';
371-
static const _targetKey = 'target';
372267
static const _fileKey = 'file';
373268
static const _osKey = 'os';
374269
static const _architectureKey = 'architecture';

pkgs/native_assets_cli/pubspec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >-
44
native assets CLI.
55
66
# Note: Bump BuildConfig.version and BuildOutput.version on breaking changes!
7-
version: 0.8.1-wip
7+
version: 0.9.0-wip
88
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli
99

1010
topics:
@@ -13,7 +13,9 @@ topics:
1313
- native-assets
1414

1515
environment:
16-
sdk: '>=3.3.0 <4.0.0'
16+
# Allow any pre-release version of 3.6.0 and onwards
17+
# (i.e. 3.6.0-edge*, 3.6.0-dev*, 3.6.0-beta*, ...)
18+
sdk: '>=3.6.0-0 <4.0.0'
1719

1820
dependencies:
1921
args: ^2.4.2

0 commit comments

Comments
 (0)