Skip to content

Commit

Permalink
Fix errors with new package:meta (#1587)
Browse files Browse the repository at this point in the history
* Fix errors with new package:meta

* Add changelog
  • Loading branch information
mosuem authored Sep 23, 2024
1 parent 9d01cfd commit 82c0aac
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Also lock `BuildConfig` and `LinkConfig` `outputDirectoryShared` when invoking
hooks to prevent concurrency issues with shared output caching.
- Fix test packages with RecordUse annotations
[#1586](https://github.com/dart-lang/native/issues/1586).

## 0.8.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:meta/meta.dart';

import 'drop_dylib_link_bindings.dart' as bindings;

class MyMath {
@ResourceIdentifier('add')
static int add(int a, int b) => bindings.add(a, b);

@ResourceIdentifier('multiply')
static int multiply(int a, int b) => bindings.multiply(a, b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ environment:

dependencies:
logging: ^1.1.1
meta: ^1.12.0
# native_assets_cli: ^0.8.0
native_assets_cli:
path: ../../../native_assets_cli/
Expand Down
2 changes: 2 additions & 0 deletions pkgs/native_assets_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- Add `BuildConfig` and `LinkConfig` `outputDirectoryShared`.
- Remove `package:native_assets_cli/locking.dart` with `runUnderDirectoryLock`.
Hook writers should not use this, the `native_assets_builder` does this.
- Fix example packages with RecordUse annotations
[#1586](https://github.com/dart-lang/native/issues/1586).

## 0.8.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:record_use/record_use.dart';

const multiplyIdentifier = Identifier(
importUri: 'package:package_with_assets/package_with_assets.dart',
name: 'AssetUsed',
);

void main(List<String> args) async {
await link(args, (config, output) async {
//TODO: Add tree shaking by reading the resources.json produced by the SDK.
final dataAssets = config.assets.whereType<DataAsset>();
output.addAssets(dataAssets);
final usages = config.usages;

final usedAssets = (usages.instancesOf(multiplyIdentifier) ?? []).map((e) =>
(e.instanceConstant.fields.values.first as StringConstant).value);

output.addAssets(config.assets
.whereType<DataAsset>()
.where((asset) => usedAssets.contains(asset.name)));
});
}

extension on LinkConfig {
RecordedUsages get usages {
final usagesFile = recordedUsagesFile;
final usagesContent = File.fromUri(usagesFile!).readAsStringSync();
final usagesJson = jsonDecode(usagesContent) as Map<String, dynamic>;
final usages = RecordedUsages.fromJson(usagesJson);
return usages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ import 'package:meta/meta.dart';

//TODO: Actually use the assets, needs the AssetBundle interface for Dart. See
//also https://github.com/dart-lang/sdk/issues/54003.
@ResourceIdentifier('assets/used_asset.json')
@AssetUsed('assets/used_asset.json')
String someMethod() => 'Using used_asset';

@ResourceIdentifier('assets/unused_asset.json')
@AssetUsed('assets/unused_asset.json')
String someOtherMethod() => 'Using unused_asset';

@RecordUse()
class AssetUsed {
final String assetName;

const AssetUsed(this.assetName);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
publish_to: none

name: package_with_assets
description: A starting point for Dart libraries or applications.
description: An example of using a package with assets.
version: 1.0.0
# repository: https://github.com/my_org/my_repo

Expand All @@ -14,6 +14,7 @@ dependencies:
# native_assets_cli: ^0.8.0
native_assets_cli:
path: ../../../../native_assets_cli/
record_use: ^0.3.0

dev_dependencies:
lints: ^3.0.0
Expand Down

0 comments on commit 82c0aac

Please sign in to comment.