Skip to content

Commit

Permalink
Remove asset type
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Nov 30, 2023
1 parent cd92f28 commit 217a340
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void main(List<String> args) async {
target: buildConfig.target,
path: AssetAbsolutePath(
buildConfig.packageRoot.resolve('data_asset_build.json')),
type: AssetType.data,
),
);

Expand Down
3 changes: 1 addition & 2 deletions pkgs/native_assets_cli/example/native_add_library/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ void main(List<String> args) async {
path: AssetAbsolutePath(
buildConfig.packageRoot.resolve('data_asset_link.json'),
),
type: AssetType.data,
),
);

Expand All @@ -38,5 +37,5 @@ class MyResourceShaker {
List<Asset> assets,
ResourceIdentifiers? resourceIdentifiers,
) =>
assets.where((asset) => asset.type != AssetType.data).toList();
assets.where((asset) => !asset.id.endsWith('.json')).toList();
}
20 changes: 2 additions & 18 deletions pkgs/native_assets_cli/lib/src/model/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class Asset {
final String id;
final Target target;
final AssetPath path;
final AssetType type;

/// The step at which the asset should be output. For example, if you want an
/// asset to be output after `build.dart`, choose [BuildStep]. If you want it
Expand All @@ -207,7 +206,6 @@ class Asset {
required this.linkMode,
required this.target,
required this.path,
required this.type,
this.step = const BuildStep(),
});

Expand All @@ -216,7 +214,6 @@ class Asset {
path: AssetPath.fromYaml(as<YamlMap>(yamlMap[_pathKey])),
target: Target.fromString(as<String>(yamlMap[_targetKey])),
linkMode: LinkMode.fromName(as<String>(yamlMap[_linkModeKey])),
type: AssetType.fromName(as<String>(yamlMap[_typeKey])),
);

static List<Asset> listFromYamlString(String yaml) {
Expand All @@ -240,14 +237,12 @@ class Asset {
String? id,
Target? target,
AssetPath? path,
AssetType? type,
}) =>
Asset(
id: id ?? this.id,
linkMode: linkMode ?? this.linkMode,
target: target ?? this.target,
path: path ?? this.path,
type: type ?? this.type,
);

@override
Expand All @@ -258,19 +253,17 @@ class Asset {
return other.id == id &&
other.linkMode == linkMode &&
other.target == target &&
other.path == path &&
other.type == type;
other.path == path;
}

@override
int get hashCode => Object.hash(id, linkMode, target, path, type);
int get hashCode => Object.hash(id, linkMode, target, path);

Map<String, Object> toYaml() => {
_idKey: id,
_linkModeKey: linkMode.name,
_pathKey: path.toYaml(),
_targetKey: target.toString(),
_typeKey: type.name,
};

Map<String, List<String>> toDartConst() => {
Expand All @@ -283,22 +276,13 @@ class Asset {
static const _linkModeKey = 'link_mode';
static const _pathKey = 'path';
static const _targetKey = 'target';
static const _typeKey = 'type';

Future<bool> exists() => path.exists();

@override
String toString() => 'Asset(${toYaml()})';
}

enum AssetType {
code,
data;

static AssetType fromName(String name) =>
AssetType.values.firstWhere((element) => element.name == name);
}

extension AssetIterable on Iterable<Asset> {
List<Object> toYaml() => [for (final item in this) item.toYaml()];

Expand Down
7 changes: 0 additions & 7 deletions pkgs/native_assets_cli/test/model/asset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,42 @@ void main() {
path: AssetAbsolutePath(fooUri),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
Asset(
id: 'foo2',
path: AssetRelativePath(foo2Uri),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
Asset(
id: 'foo3',
path: AssetSystemPath(foo3Uri),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
Asset(
id: 'foo4',
path: AssetInExecutable(),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
Asset(
id: 'foo5',
path: AssetInProcess(),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
Asset(
id: 'bar',
path: AssetAbsolutePath(barUri),
target: Target.linuxArm64,
linkMode: LinkMode.static,
type: AssetType.code,
),
Asset(
id: 'bla',
path: AssetAbsolutePath(blaUri),
target: Target.windowsX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
];

Expand Down
2 changes: 0 additions & 2 deletions pkgs/native_assets_cli/test/model/build_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ void main() {
path: AssetAbsolutePath(Uri(path: 'path/to/libfoo.so')),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
Asset(
id: 'foo2',
path: AssetRelativePath(Uri(path: 'path/to/libfoo2.so')),
target: Target.androidX64,
linkMode: LinkMode.dynamic,
type: AssetType.code,
),
],
dependencies: Dependencies([
Expand Down
1 change: 0 additions & 1 deletion pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ class CBuilder implements Builder {
linkMode: linkMode,
target: target,
path: AssetAbsolutePath(libUri),
type: AssetType.code,
));
}
}
Expand Down

0 comments on commit 217a340

Please sign in to comment.