Skip to content

Commit

Permalink
Revert linkable assets
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Apr 12, 2024
1 parent 4b0df6a commit c19dc83
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import 'package:native_assets_cli/native_assets_cli.dart';
void main(List<String> args) async {
await link(
args,
(config, output) async => output.linkAssets(shake(config.assets)),
(config, output) async => output.addAssets(shake(config.assets)),
);
}

List<LinkableAsset> shake(List<LinkableAsset> assets) =>
assets.skip(1).toList();
List<Asset> shake(List<Asset> assets) => assets.skip(1).toList();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import 'package:native_assets_cli/native_assets_cli.dart';
void main(List<String> args) async {
await link(
args,
(config, output) async => output.linkAssets(shake(config.assets)),
(config, output) async => output.addAssets(shake(config.assets)),
);
}

List<LinkableAsset> shake(List<LinkableAsset> assets) =>
assets.skip(2).toList();
List<Asset> shake(List<Asset> assets) => assets.skip(2).toList();
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ void main(List<String> arguments) async {
dynamicLibrary,
staticLibrary,
);
output.linkAsset(dynamicLibrary);
output.addAsset(dynamicLibrary);
output.addDependency(config.packageRoot.resolve('hook/link.dart'));
});
}

Future<void> _treeshakeStaticLibrary(
Iterable<String> symbols,
Uri symbolsUri,
LinkableAsset dynamicLibrary,
LinkableAsset staticLibrary,
Asset dynamicLibrary,
Asset staticLibrary,
) async {
final arguments = [
'-fPIC',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import 'package:native_assets_cli/native_assets_cli.dart';

void main(List<String> args) async {
await link(args, (config, output) async {
final assetsWithResource = config.assets
.whereType<LinkableDataAsset>()
.where((asset) => config.resources
final assetsWithResource = config.assets.whereType<DataAsset>().where(
(asset) => config.resources
.any((resource) => resource.metadata == asset.name));
output.linkAssets(assetsWithResource);
output.addAssets(assetsWithResource);
});
}
2 changes: 0 additions & 2 deletions pkgs/native_assets_cli/lib/native_assets_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ export 'src/api/ios_sdk.dart' show IOSSdk;
export 'src/api/link.dart';
export 'src/api/link_config.dart' show LinkConfig;
export 'src/api/link_mode_preference.dart' show LinkModePreference;
export 'src/api/linkable_asset.dart'
show LinkableAsset, LinkableCodeAsset, LinkableDataAsset;
export 'src/api/os.dart' show OS;
export 'src/api/resource.dart';
2 changes: 0 additions & 2 deletions pkgs/native_assets_cli/lib/native_assets_cli_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export 'src/api/build_output.dart' show HookOutputImpl;
export 'src/api/ios_sdk.dart' show IOSSdkImpl;
export 'src/api/link_config.dart' show LinkConfigImpl;
export 'src/api/link_mode_preference.dart' show LinkModePreferenceImpl;
export 'src/api/linkable_asset.dart'
show LinkableAssetImpl, LinkableCodeAssetImpl, LinkableDataAssetImpl;
export 'src/api/os.dart' show OSImpl;
export 'src/api/resource.dart';
export 'src/model/dependencies.dart';
Expand Down
1 change: 0 additions & 1 deletion pkgs/native_assets_cli/lib/src/api/build_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import '../utils/map.dart';
import 'architecture.dart';
import 'asset.dart';
import 'build_config.dart';
import 'linkable_asset.dart';
import 'os.dart';

part '../model/hook_output.dart';
Expand Down
4 changes: 2 additions & 2 deletions pkgs/native_assets_cli/lib/src/api/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import 'link_config.dart';
/// void main(List<String> args) async {
/// await link(args, (config, output) async {
/// final assetsWithResource = config.assets
/// .whereType<LinkableDataAsset>()
/// .whereType<DataAsset>()
/// .where((asset) => config.resources
/// .any((resource) => resource.metadata == asset.name));
/// output.linkAssets(assetsWithResource);
/// output.addAssets(assetsWithResource);
/// });
/// }
/// ```
Expand Down
3 changes: 1 addition & 2 deletions pkgs/native_assets_cli/lib/src/api/link_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'build_config.dart';
import 'build_mode.dart';
import 'hook_config.dart';
import 'ios_sdk.dart';
import 'linkable_asset.dart';
import 'os.dart';

part '../model/link_config.dart';
Expand Down Expand Up @@ -45,7 +44,7 @@ abstract class LinkConfig implements HookConfig {

/// The list of assets to be linked. These are the assets generated by a
/// `build.dart` script destined for this packages `link.dart`.
List<LinkableAsset> get assets;
List<Asset> get assets;

/// A collection of methods annotated with `@ResourceIdentifier`, which are
/// called in the tree-shaken Dart code. This information can be used to
Expand Down
4 changes: 2 additions & 2 deletions pkgs/native_assets_cli/lib/src/api/link_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ abstract final class LinkOutput {
void addDependencies(Iterable<Uri> dependencies);

/// Adds [Asset]s produced by this link or dry run.
void linkAsset(LinkableAsset asset);
void addAsset(Asset asset);

/// Adds [Asset]s produced by this link or dry run.
void linkAssets(Iterable<LinkableAsset> assets);
void addAssets(Iterable<Asset> assets);

factory LinkOutput({
List<AssetImpl>? assets,
Expand Down
23 changes: 0 additions & 23 deletions pkgs/native_assets_cli/lib/src/api/linkable_asset.dart

This file was deleted.

12 changes: 0 additions & 12 deletions pkgs/native_assets_cli/lib/src/model/hook_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,4 @@ final class HookOutputImpl implements BuildOutput, LinkOutput {
List<AssetImpl> _getAssetList(String? linkInPackage) => linkInPackage == null
? _assets
: (_assetsForLinking[linkInPackage] ??= []);

@override
void linkAsset(LinkableAsset asset) {
addAsset((asset as LinkableAssetImpl).asset);
}

@override
void linkAssets(Iterable<LinkableAsset> assets) {
addAssets(assets
.whereType<LinkableAssetImpl>()
.map((linkableAsset) => linkableAsset.asset));
}
}
12 changes: 2 additions & 10 deletions pkgs/native_assets_cli/lib/src/model/link_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ part of '../api/link_config.dart';
/// kernel compilation.
class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
@override
final List<LinkableAsset> assets;
final List<AssetImpl> assets;

final BuildConfigImpl _buildConfig;

Expand Down Expand Up @@ -156,15 +156,7 @@ class _LinkConfigArgs {
resourceIdentifiers: resourceIdentifierUri != null
? ResourceIdentifiers.fromFile(resourceIdentifierUri!.toFilePath())
: null,
assets: assetsForLinking
.map(
(asset) => switch (asset) {
DataAssetImpl() => LinkableDataAssetImpl(asset),
NativeCodeAssetImpl() => LinkableCodeAssetImpl(asset),
AssetImpl() => throw UnimplementedError(),
},
)
.toList(),
assets: assetsForLinking,
);

Map<String, Object> toJson() => {
Expand Down
51 changes: 0 additions & 51 deletions pkgs/native_assets_cli/lib/src/model/linkable_asset.dart

This file was deleted.

0 comments on commit c19dc83

Please sign in to comment.