Skip to content

Commit 4111cde

Browse files
authored
[native_assets_builder] Cleanup old file fallbacks (#2228)
* `$package/build.dart` has been migrated to `$package/hooks/build.dart` a long time ago, remove the fallback. * `out_file` has been part of the protocol for a long time, remove the fallback.
1 parent ea1584b commit 4111cde

File tree

4 files changed

+8
-46
lines changed

4 files changed

+8
-46
lines changed

pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ class NativeAssetsBuildPlanner {
7474
///
7575
/// Whether a package has native assets is defined by whether it contains
7676
/// a `hook/build.dart` or `hook/link.dart`.
77-
///
78-
/// For backwards compatibility, a toplevel `build.dart` is also supported.
79-
// TODO(https://github.com/dart-lang/native/issues/823): Remove fallback when
80-
// everyone has migrated. (Probably once we stop backwards compatibility of
81-
// the protocol version pre 1.2.0 on some future version.)
8277
Future<List<Package>> packagesWithHook(Hook hook) async => switch (hook) {
8378
Hook.build => _packagesWithBuildHook ??= await _runPackagesWithHook(hook),
8479
Hook.link => _packagesWithLinkHook ??= await _runPackagesWithHook(hook),
@@ -97,11 +92,8 @@ class NativeAssetsBuildPlanner {
9792
final packageRoot = package.root;
9893
if (packageRoot.scheme == 'file') {
9994
if (await fileSystem
100-
.file(packageRoot.resolve('hook/').resolve(hook.scriptName))
101-
.exists() ||
102-
await fileSystem
103-
.file(packageRoot.resolve(hook.scriptName))
104-
.exists()) {
95+
.file(packageRoot.resolve('hook/').resolve(hook.scriptName))
96+
.exists()) {
10597
result.add(package);
10698
}
10799
}

pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,6 @@ class NativeAssetsBuildRunner {
363363
final (hookKernelFile, hookHashes) = hookCompileResult;
364364

365365
final buildOutputFile = _fileSystem.file(input.outputFile);
366-
final buildOutputFileDeprecated = _fileSystem
367-
// ignore: deprecated_member_use
368-
.file(outputDirectory.resolve(hook.outputNameDeprecated));
369366

370367
final dependenciesHashFile = buildDirUri.resolve(
371368
'dependencies.dependencies_hash_file.json',
@@ -375,16 +372,10 @@ class NativeAssetsBuildRunner {
375372
fileUri: dependenciesHashFile,
376373
);
377374
final lastModifiedCutoffTime = DateTime.now();
378-
if ((buildOutputFile.existsSync() ||
379-
buildOutputFileDeprecated.existsSync()) &&
380-
await dependenciesHashes.exists()) {
375+
if ((buildOutputFile.existsSync()) && await dependenciesHashes.exists()) {
381376
late final HookOutput output;
382377
try {
383-
output = _readHookOutputFromUri(
384-
hook,
385-
buildOutputFile,
386-
buildOutputFileDeprecated,
387-
);
378+
output = _readHookOutputFromUri(hook, buildOutputFile);
388379
} on FormatException catch (e) {
389380
logger.severe('''
390381
Building assets for package:${input.packageName} failed.
@@ -488,14 +479,6 @@ ${e.message}
488479
// Ensure we'll never read outdated build results.
489480
await hookOutputFile.delete();
490481
}
491-
final hookOutputUriDeprecated =
492-
// ignore: deprecated_member_use
493-
outputDirectory.resolve(hook.outputNameDeprecated);
494-
final hookOutputFileDeprecated = _fileSystem.file(hookOutputUriDeprecated);
495-
if (await hookOutputFileDeprecated.exists()) {
496-
// Ensure we'll never read outdated build results.
497-
await hookOutputFileDeprecated.delete();
498-
}
499482

500483
final arguments = [
501484
'--packages=${packageLayout.packageConfigUri.toFilePath()}',
@@ -540,11 +523,7 @@ ${e.message}
540523
return null;
541524
}
542525

543-
final output = _readHookOutputFromUri(
544-
hook,
545-
hookOutputFile,
546-
hookOutputFileDeprecated,
547-
);
526+
final output = _readHookOutputFromUri(hook, hookOutputFile);
548527
final errors = await _validate(input, output, validator);
549528
if (errors.isNotEmpty) {
550529
_printErrors(
@@ -852,14 +831,8 @@ ${compileResult.stdout}
852831
return (buildPlan, packageGraph);
853832
}
854833

855-
HookOutput _readHookOutputFromUri(
856-
Hook hook,
857-
File hookOutputFile,
858-
// TODO(dcharkes): Remove when hooks with 1.7.0 are no longer supported.
859-
File hookOutputFileDeprecated,
860-
) {
861-
final file =
862-
hookOutputFile.existsSync() ? hookOutputFile : hookOutputFileDeprecated;
834+
HookOutput _readHookOutputFromUri(Hook hook, File hookOutputFile) {
835+
final file = hookOutputFile;
863836
final fileContents = file.readAsStringSync();
864837
logger.info('output.json contents:\n$fileContents');
865838
final hookOutputJson = jsonDecode(fileContents) as Map<String, Object?>;

pkgs/native_assets_builder/test_data/use_all_api/hook/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: unnecessary_statements, deprecated_member_use
5+
// ignore_for_file: unnecessary_statements
66

77
import 'package:native_assets_cli/code_assets.dart';
88
import 'package:native_assets_cli/data_assets.dart';

pkgs/native_assets_cli/lib/src/model/hook.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,4 @@ enum Hook {
1515
const Hook(this._scriptName);
1616

1717
String get scriptName => '$_scriptName.dart';
18-
19-
@Deprecated('Use HookInput.outputFile instead.')
20-
String get outputNameDeprecated => '${_scriptName}_output.json';
2118
}

0 commit comments

Comments
 (0)