Skip to content

[native_assets_builder] Cleanup old file fallbacks #2228

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

Merged
merged 1 commit into from
Apr 23, 2025
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
12 changes: 2 additions & 10 deletions pkgs/native_assets_builder/lib/src/build_runner/build_planner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ class NativeAssetsBuildPlanner {
///
/// Whether a package has native assets is defined by whether it contains
/// a `hook/build.dart` or `hook/link.dart`.
///
/// For backwards compatibility, a toplevel `build.dart` is also supported.
// TODO(https://github.com/dart-lang/native/issues/823): Remove fallback when
// everyone has migrated. (Probably once we stop backwards compatibility of
// the protocol version pre 1.2.0 on some future version.)
Future<List<Package>> packagesWithHook(Hook hook) async => switch (hook) {
Hook.build => _packagesWithBuildHook ??= await _runPackagesWithHook(hook),
Hook.link => _packagesWithLinkHook ??= await _runPackagesWithHook(hook),
Expand All @@ -97,11 +92,8 @@ class NativeAssetsBuildPlanner {
final packageRoot = package.root;
if (packageRoot.scheme == 'file') {
if (await fileSystem
.file(packageRoot.resolve('hook/').resolve(hook.scriptName))
.exists() ||
await fileSystem
.file(packageRoot.resolve(hook.scriptName))
.exists()) {
.file(packageRoot.resolve('hook/').resolve(hook.scriptName))
.exists()) {
result.add(package);
}
}
Expand Down
37 changes: 5 additions & 32 deletions pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ class NativeAssetsBuildRunner {
final (hookKernelFile, hookHashes) = hookCompileResult;

final buildOutputFile = _fileSystem.file(input.outputFile);
final buildOutputFileDeprecated = _fileSystem
// ignore: deprecated_member_use
.file(outputDirectory.resolve(hook.outputNameDeprecated));

final dependenciesHashFile = buildDirUri.resolve(
'dependencies.dependencies_hash_file.json',
Expand All @@ -375,16 +372,10 @@ class NativeAssetsBuildRunner {
fileUri: dependenciesHashFile,
);
final lastModifiedCutoffTime = DateTime.now();
if ((buildOutputFile.existsSync() ||
buildOutputFileDeprecated.existsSync()) &&
await dependenciesHashes.exists()) {
if ((buildOutputFile.existsSync()) && await dependenciesHashes.exists()) {
late final HookOutput output;
try {
output = _readHookOutputFromUri(
hook,
buildOutputFile,
buildOutputFileDeprecated,
);
output = _readHookOutputFromUri(hook, buildOutputFile);
} on FormatException catch (e) {
logger.severe('''
Building assets for package:${input.packageName} failed.
Expand Down Expand Up @@ -488,14 +479,6 @@ ${e.message}
// Ensure we'll never read outdated build results.
await hookOutputFile.delete();
}
final hookOutputUriDeprecated =
// ignore: deprecated_member_use
outputDirectory.resolve(hook.outputNameDeprecated);
final hookOutputFileDeprecated = _fileSystem.file(hookOutputUriDeprecated);
if (await hookOutputFileDeprecated.exists()) {
// Ensure we'll never read outdated build results.
await hookOutputFileDeprecated.delete();
}

final arguments = [
'--packages=${packageLayout.packageConfigUri.toFilePath()}',
Expand Down Expand Up @@ -540,11 +523,7 @@ ${e.message}
return null;
}

final output = _readHookOutputFromUri(
hook,
hookOutputFile,
hookOutputFileDeprecated,
);
final output = _readHookOutputFromUri(hook, hookOutputFile);
final errors = await _validate(input, output, validator);
if (errors.isNotEmpty) {
_printErrors(
Expand Down Expand Up @@ -852,14 +831,8 @@ ${compileResult.stdout}
return (buildPlan, packageGraph);
}

HookOutput _readHookOutputFromUri(
Hook hook,
File hookOutputFile,
// TODO(dcharkes): Remove when hooks with 1.7.0 are no longer supported.
File hookOutputFileDeprecated,
) {
final file =
hookOutputFile.existsSync() ? hookOutputFile : hookOutputFileDeprecated;
HookOutput _readHookOutputFromUri(Hook hook, File hookOutputFile) {
final file = hookOutputFile;
final fileContents = file.readAsStringSync();
logger.info('output.json contents:\n$fileContents');
final hookOutputJson = jsonDecode(fileContents) as Map<String, Object?>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.

// ignore_for_file: unnecessary_statements, deprecated_member_use
// ignore_for_file: unnecessary_statements

import 'package:native_assets_cli/code_assets.dart';
import 'package:native_assets_cli/data_assets.dart';
Expand Down
3 changes: 0 additions & 3 deletions pkgs/native_assets_cli/lib/src/model/hook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ enum Hook {
const Hook(this._scriptName);

String get scriptName => '$_scriptName.dart';

@Deprecated('Use HookInput.outputFile instead.')
String get outputNameDeprecated => '${_scriptName}_output.json';
}
Loading