Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recorded usages URI to API #1502

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class NativeAssetsBuildRunner {
targetMacOSVersion: targetMacOSVersion,
cCompiler: cCompilerConfig,
targetAndroidNdkApi: targetAndroidNdkApi,
resourceIdentifierUri: resourcesFile?.uri,
recordedUsagesFile: resourcesFile?.uri,
assets: buildResult!.assetsForLinking[package.name] ?? [],
supportedAssetTypes: supportedAssetTypes,
linkModePreference: linkModePreference,
Expand Down
4 changes: 2 additions & 2 deletions pkgs/native_assets_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.7.4-wip
## 0.8.0-wip

- Nothing yet.
- Add URI for the recorded usages file to the `LinkConfig`.

## 0.7.3

Expand Down
7 changes: 7 additions & 0 deletions pkgs/native_assets_cli/lib/src/api/link_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:cli_config/cli_config.dart';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';

import '../model/hook.dart';
Expand All @@ -31,6 +32,12 @@ abstract class LinkConfig implements HookConfig {
/// `build.dart` script destined for this packages `link.dart`.
Iterable<Asset> get assets;

/// The path to the file containing recorded uses after kernel tree-shaking.
///
/// The file contents can be parsed using `package:record_use`.
@experimental
Uri? get recordedUsagesFile;

/// Generate the [LinkConfig] from the input arguments to the linking script.
factory LinkConfig.fromArguments(List<String> arguments) =>
LinkConfigImpl.fromArguments(arguments);
Expand Down
19 changes: 10 additions & 9 deletions pkgs/native_assets_cli/lib/src/model/link_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {

// TODO: Placeholder for the resources.json file URL. We don't want to change
// native_assets_builder when implementing the parsing.
final Uri? resourceIdentifierUri;
mosuem marked this conversation as resolved.
Show resolved Hide resolved
@override
final Uri? recordedUsagesFile;

LinkConfigImpl({
required this.assets,
this.resourceIdentifierUri,
this.recordedUsagesFile,
required super.outputDirectory,
required super.packageName,
required super.packageRoot,
Expand All @@ -46,7 +47,7 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {

LinkConfigImpl.dryRun({
required this.assets,
this.resourceIdentifierUri,
this.recordedUsagesFile,
required super.outputDirectory,
required super.packageName,
required super.packageRoot,
Expand All @@ -72,8 +73,8 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
@override
Map<String, Object> toJson() => {
...hookToJson(),
if (resourceIdentifierUri != null)
resourceIdentifierKey: resourceIdentifierUri!.toFilePath(),
if (recordedUsagesFile != null)
resourceIdentifierKey: recordedUsagesFile!.toFilePath(),
assetsKey: AssetImpl.listToJson(assets, version),
}.sortOnKey();

Expand Down Expand Up @@ -114,12 +115,12 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
targetMacOSVersion:
HookConfigImpl.parseTargetMacOSVersion(config, dryRun, targetOS),
assets: parseAssets(config),
resourceIdentifierUri: parseResourceIdentifier(config),
recordedUsagesFile: parseRecordedUsagesUri(config),
dryRun: dryRun,
);
}

static Uri? parseResourceIdentifier(Config config) =>
static Uri? parseRecordedUsagesUri(Config config) =>
config.optionalPath(resourceIdentifierKey);

static List<AssetImpl> parseAssets(Config config) =>
Expand All @@ -133,7 +134,7 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
if (other is! LinkConfigImpl) {
return false;
}
if (other.resourceIdentifierUri != resourceIdentifierUri) {
if (other.recordedUsagesFile != recordedUsagesFile) {
return false;
}
if (!const DeepCollectionEquality().equals(other.assets, assets)) {
Expand All @@ -145,7 +146,7 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
@override
int get hashCode => Object.hashAll([
super.hashCode,
resourceIdentifierUri,
recordedUsagesFile,
const DeepCollectionEquality().hash(assets),
]);

Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_cli/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: >-
native assets CLI.

# Note: Bump BuildConfig.version and BuildOutput.version on breaking changes!
version: 0.7.4-wip
version: 0.8.0-wip
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli

topics:
Expand Down
12 changes: 6 additions & 6 deletions pkgs/native_assets_cli/test/model/link_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() async {
late Uri fakeAr;
late Uri fakeCl;
late Uri fakeVcVars;
late Uri resources;
late Uri recordedUsagesFile;
final assets = [
DataAsset(
package: packageName,
Expand Down Expand Up @@ -55,8 +55,8 @@ void main() async {
await File.fromUri(fakeCl).create();
fakeVcVars = tempUri.resolve('vcvarsall.bat');
await File.fromUri(fakeVcVars).create();
resources = tempUri.resolve('resources.json');
File.fromUri(resources).createSync();
recordedUsagesFile = tempUri.resolve('recorded_usages.json');
File.fromUri(recordedUsagesFile).createSync();
});

tearDown(() async {
Expand All @@ -78,7 +78,7 @@ void main() async {
),
buildMode: BuildModeImpl.release,
assets: assets,
resourceIdentifierUri: resources,
recordedUsagesFile: recordedUsagesFile,
linkModePreference: LinkModePreferenceImpl.preferStatic,
);

Expand All @@ -91,7 +91,7 @@ void main() async {
targetAndroidNdkApi: 30,
buildMode: BuildModeImpl.release,
assets: [],
resourceIdentifierUri: null,
recordedUsagesFile: null,
linkModePreference: LinkModePreferenceImpl.preferStatic,
);

Expand Down Expand Up @@ -330,7 +330,7 @@ void main() async {
targetAndroidNdkApi: 30,
buildMode: BuildModeImpl.release,
assets: assets,
resourceIdentifierUri: resources,
recordedUsagesFile: recordedUsagesFile,
linkModePreference: LinkModePreferenceImpl.preferStatic,
);
final configFileContents = buildConfig.toJsonString();
Expand Down