Skip to content

Commit

Permalink
Remove link-dry-run related code (which seems not used anywhere in fl…
Browse files Browse the repository at this point in the history
…utter & dart) (#1613)

It seems neither Flutter Tools nor Dart SDK uses or needs the
link-dry-run functionality. So I think we can simplify the code by
removing this.
  • Loading branch information
mkustermann authored Sep 27, 2024
1 parent 5405028 commit 5d79761
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 251 deletions.
1 change: 1 addition & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Dart CI test runner to the `package:native_assets_builder` for testing the
dart-lang/native repository to make it clear those are not intended to be used
by end-users.
- Remove link-dry-run concept as it's unused by Flutter Tools & Dart SDK

## 0.8.3

Expand Down
1 change: 0 additions & 1 deletion pkgs/native_assets_builder/lib/native_assets_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export 'package:native_assets_builder/src/build_runner/build_runner.dart';
export 'package:native_assets_builder/src/model/build_dry_run_result.dart';
export 'package:native_assets_builder/src/model/build_result.dart';
export 'package:native_assets_builder/src/model/kernel_assets.dart';
export 'package:native_assets_builder/src/model/link_dry_run_result.dart';
export 'package:native_assets_builder/src/model/link_result.dart';
export 'package:native_assets_builder/src/package_layout/package_layout.dart';
100 changes: 13 additions & 87 deletions pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import '../locking/locking.dart';
import '../model/build_dry_run_result.dart';
import '../model/build_result.dart';
import '../model/hook_result.dart';
import '../model/link_dry_run_result.dart';
import '../model/link_result.dart';
import '../package_layout/package_layout.dart';
import '../utils/file.dart';
Expand Down Expand Up @@ -379,66 +378,12 @@ class NativeAssetsBuildRunner {
PackageLayout? packageLayout,
String? runPackageName,
Iterable<String>? supportedAssetTypes,
}) =>
_runDryRun(
hook: Hook.build,
linkModePreference: linkModePreference,
targetOS: targetOS,
workingDirectory: workingDirectory,
includeParentEnvironment: includeParentEnvironment,
packageLayout: packageLayout,
runPackageName: runPackageName,
supportedAssetTypes: supportedAssetTypes,
linkingEnabled: linkingEnabled,
);

/// [workingDirectory] is expected to contain `.dart_tool`.
///
/// This method is invoked by launchers such as dartdev (for `dart run`) and
/// flutter_tools (for `flutter run` and `flutter build`).
///
/// If provided, only native assets of all transitive dependencies of
/// [runPackageName] are built.
Future<LinkDryRunResult> linkDryRun({
required LinkModePreferenceImpl linkModePreference,
required OSImpl targetOS,
required Uri workingDirectory,
required bool includeParentEnvironment,
PackageLayout? packageLayout,
String? runPackageName,
Iterable<String>? supportedAssetTypes,
required BuildDryRunResult buildDryRunResult,
}) =>
_runDryRun(
hook: Hook.link,
linkModePreference: linkModePreference,
targetOS: targetOS,
workingDirectory: workingDirectory,
includeParentEnvironment: includeParentEnvironment,
packageLayout: packageLayout,
runPackageName: runPackageName,
supportedAssetTypes: supportedAssetTypes,
buildDryRunResult: buildDryRunResult,
linkingEnabled: null,
);

Future<HookResult> _runDryRun({
required LinkModePreferenceImpl linkModePreference,
required OSImpl targetOS,
required Uri workingDirectory,
required bool includeParentEnvironment,
PackageLayout? packageLayout,
String? runPackageName,
Iterable<String>? supportedAssetTypes,
required Hook hook,
BuildDryRunResult? buildDryRunResult,
required bool? linkingEnabled,
}) async {
const hook = Hook.build;
packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory);
final (buildPlan, _, planSuccess) = await _makePlan(
hook: hook,
packageLayout: packageLayout,
buildDryRunResult: buildDryRunResult,
runPackageName: runPackageName,
);
if (!planSuccess) {
Expand All @@ -455,8 +400,6 @@ class NativeAssetsBuildRunner {
linkMode: linkModePreference,
buildParentDir: packageLayout.dartToolNativeAssetsBuilder,
supportedAssetTypes: supportedAssetTypes,
hook: hook,
buildDryRunResult: buildDryRunResult,
linkingEnabled: linkingEnabled,
);
final packageConfigUri = packageLayout.packageConfigUri;
Expand Down Expand Up @@ -820,11 +763,10 @@ ${compileResult.stdout}
required OSImpl targetOS,
required LinkModePreferenceImpl linkMode,
required Uri buildParentDir,
required Hook hook,
BuildDryRunResult? buildDryRunResult,
Iterable<String>? supportedAssetTypes,
required bool? linkingEnabled,
}) async {
const hook = Hook.build;
final buildDirName = HookConfigImpl.checksumDryRun(
packageName: package.name,
packageRoot: package.root,
Expand All @@ -850,30 +792,16 @@ ${compileResult.stdout}
await outDirShared.create(recursive: true);
}

switch (hook) {
case Hook.build:
return BuildConfigImpl.dryRun(
outputDirectory: outDirUri,
outputDirectoryShared: outputDirectoryShared,
packageName: packageName,
packageRoot: packageRoot,
targetOS: targetOS,
linkModePreference: linkMode,
supportedAssetTypes: supportedAssetTypes,
linkingEnabled: linkingEnabled,
);
case Hook.link:
return LinkConfigImpl.dryRun(
outputDirectory: outDirUri,
outputDirectoryShared: outputDirectoryShared,
packageName: packageName,
packageRoot: packageRoot,
targetOS: targetOS,
assets: buildDryRunResult!.assetsForLinking[packageName] ?? [],
supportedAssetTypes: supportedAssetTypes,
linkModePreference: linkMode,
);
}
return BuildConfigImpl.dryRun(
outputDirectory: outDirUri,
outputDirectoryShared: outputDirectoryShared,
packageName: packageName,
packageRoot: packageRoot,
targetOS: targetOS,
linkModePreference: linkMode,
supportedAssetTypes: supportedAssetTypes,
linkingEnabled: linkingEnabled,
);
}

DependencyMetadata? _metadataForPackage({
Expand Down Expand Up @@ -926,7 +854,6 @@ ${compileResult.stdout}
required Hook hook,
// TODO(dacoharkes): How to share these two? Make them extend each other?
BuildResult? buildResult,
BuildDryRunResult? buildDryRunResult,
}) async {
final packagesWithHook = await packageLayout.packagesWithAssets(hook);
final List<Package> buildPlan;
Expand Down Expand Up @@ -956,8 +883,7 @@ ${compileResult.stdout}
// Link hooks are skipped if no assets for linking are provided.
buildPlan = [];
final skipped = <String>[];
final assetsForLinking = buildResult?.assetsForLinking ??
buildDryRunResult?.assetsForLinking;
final assetsForLinking = buildResult?.assetsForLinking;
for (final package in packagesWithHook) {
if (assetsForLinking![package.name]?.isNotEmpty ?? false) {
buildPlan.add(package);
Expand Down
3 changes: 1 addition & 2 deletions pkgs/native_assets_builder/lib/src/model/hook_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import '../../native_assets_builder.dart';

/// The result from a [NativeAssetsBuildRunner.build] or
/// [NativeAssetsBuildRunner.link].
final class HookResult
implements BuildResult, BuildDryRunResult, LinkResult, LinkDryRunResult {
final class HookResult implements BuildResult, BuildDryRunResult, LinkResult {
/// The native assets produced by the hooks, which should be bundled.
@override
final List<AssetImpl> assets;
Expand Down
19 changes: 0 additions & 19 deletions pkgs/native_assets_builder/lib/src/model/link_dry_run_result.dart

This file was deleted.

28 changes: 0 additions & 28 deletions pkgs/native_assets_builder/test/build_runner/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,34 +246,6 @@ Future<BuildDryRunResult> buildDryRun(
return result;
});

Future<LinkDryRunResult> linkDryRun(
Uri packageUri,
Logger logger,
Uri dartExecutable, {
LinkModePreferenceImpl linkModePreference = LinkModePreferenceImpl.dynamic,
CCompilerConfigImpl? cCompilerConfig,
bool includeParentEnvironment = true,
List<String>? capturedLogs,
PackageLayout? packageLayout,
required BuildDryRunResult buildDryRunResult,
Iterable<String>? supportedAssetTypes,
}) async =>
runWithLog(capturedLogs, () async {
final result = await NativeAssetsBuildRunner(
logger: logger,
dartExecutable: dartExecutable,
).linkDryRun(
linkModePreference: linkModePreference,
targetOS: Target.current.os,
workingDirectory: packageUri,
includeParentEnvironment: includeParentEnvironment,
packageLayout: packageLayout,
buildDryRunResult: buildDryRunResult,
supportedAssetTypes: supportedAssetTypes,
);
return result;
});

Future<void> expectAssetsExist(List<AssetImpl> assets) async {
for (final asset in assets) {
expect(File.fromUri(asset.file!), exists);
Expand Down
114 changes: 0 additions & 114 deletions pkgs/native_assets_builder/test/build_runner/link_dry_run_test.dart

This file was deleted.

0 comments on commit 5d79761

Please sign in to comment.