Skip to content

Commit 3f5bd87

Browse files
committed
Remove resources from protocol
1 parent 49914d7 commit 3f5bd87

File tree

11 files changed

+12
-150
lines changed

11 files changed

+12
-150
lines changed

pkgs/native_assets_builder/test_data/treeshaking_native_assets/hook/link.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const packageName = 'treeshaking_native_assets';
1010

1111
void main(List<String> arguments) async {
1212
await link(arguments, (config, output) async {
13-
final usedSymbols = config.treeshakingInformation
14-
?.map((resource) => resource.metadata.toString());
13+
final List<String>? usedSymbols = [];
1514
final dynamicLibrary = config.assets.firstWhere((asset) =>
1615
asset.id == 'package:$packageName/src/${packageName}_bindings.dart');
1716
final staticLibrary = config.assets

pkgs/native_assets_cli/example/link/package_with_assets/hook/link.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import 'package:native_assets_cli/native_assets_cli.dart';
66

77
void main(List<String> args) async {
88
await link(args, (config, output) async {
9-
final assetsWithResource = config.assets.whereType<DataAsset>().where(
10-
(asset) =>
11-
config.treeshakingInformation
12-
?.any((resource) => resource.metadata == asset.name) ??
13-
true);
14-
output.addAssets(assetsWithResource);
9+
final dataAssets = config.assets.whereType<DataAsset>();
10+
output.addAssets(dataAssets);
1511
});
1612
}

pkgs/native_assets_cli/lib/native_assets_cli.dart

-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ export 'src/api/link.dart';
2828
export 'src/api/link_config.dart' show LinkConfig;
2929
export 'src/api/link_mode_preference.dart' show LinkModePreference;
3030
export 'src/api/os.dart' show OS;
31-
export 'src/api/resource.dart';

pkgs/native_assets_cli/lib/native_assets_cli_internal.dart

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export 'src/api/ios_sdk.dart' show IOSSdkImpl;
3636
export 'src/api/link_config.dart' show LinkConfigImpl;
3737
export 'src/api/link_mode_preference.dart' show LinkModePreferenceImpl;
3838
export 'src/api/os.dart' show OSImpl;
39-
export 'src/api/resource.dart';
4039
export 'src/model/dependencies.dart';
4140
export 'src/model/hook.dart';
4241
export 'src/model/metadata.dart';

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

+3-10
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@ import 'link_config.dart';
1515
/// through [LinkConfig.assets]. They will only be bundled with the final
1616
/// application if included in the [LinkOutput].
1717
///
18-
/// As the linking runs after kernel compilation, you can use treeshaking
19-
/// information provided through [LinkConfig.treeshakingInformation] to decide
20-
/// which assets to include. The resources are only collected in AOT mode,
21-
/// therefore the field is null in JIT mode.
22-
///
2318
///
2419
/// ```dart
2520
/// import 'package:native_assets_cli/native_assets_cli.dart';
2621
///
2722
/// void main(List<String> args) async {
2823
/// await link(args, (config, output) async {
29-
/// final assetsWithResource = config.assets
30-
/// .whereType<DataAsset>()
31-
/// .where((asset) => config.resources
32-
/// .any((resource) => resource.metadata == asset.name));
33-
/// output.addAssets(assetsWithResource);
24+
/// final dataAssets = config.assets
25+
/// .whereType<DataAsset>();
26+
/// output.addAssets(dataAssets);
3427
/// });
3528
/// }
3629
/// ```

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

+1-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:collection/collection.dart';
1010
import 'package:pub_semver/pub_semver.dart';
1111

1212
import '../model/hook.dart';
13-
import '../model/resource_identifiers.dart';
1413
import '../utils/map.dart';
1514
import 'architecture.dart';
1615
import 'asset.dart';
@@ -20,28 +19,18 @@ import 'hook_config.dart';
2019
import 'ios_sdk.dart';
2120
import 'link_mode_preference.dart';
2221
import 'os.dart';
23-
import 'resource.dart';
2422

2523
part '../model/link_config.dart';
2624

2725
/// The configuration for a link hook (`hook/link.dart`) invocation.
2826
///
2927
/// It consists of a subset of the fields from the [BuildConfig] already passed
30-
/// to the build hook, the [assets] from the build step, and the
31-
/// [treeshakingInformation] generated during the kernel compilation.
28+
/// to the build hook and the [assets] from the build step.
3229
abstract class LinkConfig implements HookConfig {
3330
/// The list of assets to be linked. These are the assets generated by a
3431
/// `build.dart` script destined for this packages `link.dart`.
3532
Iterable<Asset> get assets;
3633

37-
/// A collection of methods annotated with `@ResourceIdentifier`, which are
38-
/// called in the tree-shaken Dart code. This information can be used to
39-
/// dispose unused [assets].
40-
///
41-
/// This is `null` in JIT mode, where no resources are collected, or in a dry
42-
/// run.
43-
Iterable<Resource>? get treeshakingInformation;
44-
4534
/// Generate the [LinkConfig] from the input arguments to the linking script.
4635
factory LinkConfig.fromArguments(List<String> arguments) =>
4736
LinkConfigImpl.fromArguments(arguments);
@@ -58,14 +47,12 @@ abstract class LinkConfig implements HookConfig {
5847
List<String>? supportedAssetTypes,
5948
int? targetAndroidNdkApi,
6049
required Iterable<Asset> assets,
61-
Uri? resourceIdentifierUri,
6250
required LinkModePreference linkModePreference,
6351
bool? dryRun,
6452
Version? version,
6553
}) =>
6654
LinkConfigImpl(
6755
assets: assets.cast(),
68-
resourceIdentifierUri: resourceIdentifierUri,
6956
outputDirectory: outputDirectory,
7057
packageName: packageName,
7158
packageRoot: packageRoot,
@@ -88,13 +75,11 @@ abstract class LinkConfig implements HookConfig {
8875
required OS targetOS,
8976
List<String>? supportedAssetTypes,
9077
required Iterable<Asset> assets,
91-
Uri? resourceIdentifierUri,
9278
required LinkModePreference linkModePreference,
9379
Version? version,
9480
}) =>
9581
LinkConfigImpl.dryRun(
9682
assets: assets.cast(),
97-
resourceIdentifierUri: resourceIdentifierUri,
9883
outputDirectory: outputDirectory,
9984
packageName: packageName,
10085
packageRoot: packageRoot,

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

-45
This file was deleted.

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

+4-23
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44

55
part of '../api/link_config.dart';
66

7-
List<Resource>? fromIdentifiers(ResourceIdentifiers resourceIdentifiers) =>
8-
resourceIdentifiers.identifiers
9-
.map((e) => Resource(name: e.name, metadata: e.id))
10-
.toList();
11-
127
/// The input to the linking script.
138
///
14-
/// It consists of the fields inherited from the [HookConfig], the [assets] from
15-
/// the build step, and the [treeshakingInformation] generated during the kernel
16-
/// compilation.
9+
/// It consists of the fields inherited from the [HookConfig] and the [assets]
10+
/// from the build step.
1711
class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
1812
static const resourceIdentifierKey = 'resource_identifiers';
1913

@@ -22,17 +16,8 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
2216
@override
2317
final Iterable<AssetImpl> assets;
2418

25-
Iterable<Resource>? _treeshakingInformation;
26-
27-
@override
28-
Iterable<Resource>? get treeshakingInformation {
29-
if (_resourceIdentifierUri != null && _treeshakingInformation == null) {
30-
_treeshakingInformation = fromIdentifiers(
31-
ResourceIdentifiers.fromFile(_resourceIdentifierUri.toFilePath()));
32-
}
33-
return _treeshakingInformation;
34-
}
35-
19+
// TODO: Placeholder for the resources.json file URL. We don't want to change
20+
// native_assets_builder when implementing the parsing.
3621
final Uri? _resourceIdentifierUri;
3722

3823
LinkConfigImpl({
@@ -69,10 +54,6 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
6954
required super.linkModePreference,
7055
required super.targetOS,
7156
}) : _resourceIdentifierUri = resourceIdentifierUri,
72-
_treeshakingInformation = resourceIdentifierUri != null
73-
? fromIdentifiers(ResourceIdentifiers.fromFile(
74-
resourceIdentifierUri.toFilePath()))
75-
: null,
7657
super.dryRun(
7758
hook: Hook.link,
7859
version: version ?? HookConfigImpl.latestVersion,

pkgs/native_assets_cli/test/api/resource_data.dart

-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:native_assets_cli/src/api/resource.dart';
65
import 'package:native_assets_cli/src/model/resource_identifiers.dart';
76

8-
final resourceList = [
9-
Resource(name: 'methodName1', metadata: 'someMetadata'),
10-
Resource(name: 'methodName2', metadata: 'someOtherMetadata'),
11-
];
12-
137
const resourceFile = '''{
148
"_comment": "Resources referenced by annotated resource identifiers",
159
"AppTag": "TBD",

pkgs/native_assets_cli/test/api/resource_test.dart

-14
This file was deleted.

pkgs/native_assets_cli/test/model/link_config_test.dart

+1-26
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:convert';
65
import 'dart:io';
76

87
import 'package:native_assets_cli/native_assets_cli.dart';
98
import 'package:native_assets_cli/native_assets_cli_internal.dart';
109
import 'package:native_assets_cli/src/api/asset.dart';
1110
import 'package:test/test.dart';
1211

13-
import '../api/resource_data.dart';
14-
1512
void main() async {
1613
late Uri tempUri;
1714
late Uri outDirUri;
@@ -59,8 +56,7 @@ void main() async {
5956
fakeVcVars = tempUri.resolve('vcvarsall.bat');
6057
await File.fromUri(fakeVcVars).create();
6158
resources = tempUri.resolve('resources.json');
62-
final file = File.fromUri(resources)..createSync();
63-
file.writeAsStringSync(jsonEncode(resourceIdentifiers));
59+
File.fromUri(resources).createSync();
6460
});
6561

6662
tearDown(() async {
@@ -115,8 +111,6 @@ void main() async {
115111
true);
116112
expect(config1.cCompiler != config2.cCompiler, true);
117113
expect(config1.assets != config2.assets, true);
118-
expect(
119-
config1.treeshakingInformation != config2.treeshakingInformation, true);
120114
});
121115

122116
test('LinkConfig fromConfig', () {
@@ -196,25 +190,6 @@ void main() async {
196190
final fromConfig = LinkConfigImpl.fromJson(configFile);
197191
expect(fromConfig, equals(buildConfig1));
198192
});
199-
test('LinkConfig fetch treeshaking information', () {
200-
final buildConfig1 = LinkConfigImpl(
201-
outputDirectory: outDirUri,
202-
packageName: packageName,
203-
packageRoot: packageRootUri,
204-
targetArchitecture: ArchitectureImpl.arm64,
205-
targetOS: OSImpl.iOS,
206-
targetIOSSdk: IOSSdkImpl.iPhoneOS,
207-
cCompiler: CCompilerConfigImpl(
208-
compiler: fakeClang,
209-
linker: fakeLd,
210-
),
211-
buildMode: BuildModeImpl.release,
212-
assets: assets,
213-
resourceIdentifierUri: resources,
214-
linkModePreference: LinkModePreferenceImpl.preferStatic,
215-
);
216-
expect(buildConfig1.treeshakingInformation, resourceList);
217-
});
218193

219194
test('LinkConfig toJson fromJson', () {
220195
final outDir = outDirUri;

0 commit comments

Comments
 (0)