Repository navigation
Conversation
ce610e8 to
79abad9
Compare
| ); | ||
| } | ||
|
|
||
| bool _isTestTarget(Environment environment) { |
There was a problem hiding this comment.
@bkonyi I am surprised we have nothing like this yet in the codebase. It seems that the usual logic on dev deps or not is dependent on release mode, but that is too strict if you want to use dev deps in tests or integration tests in release mode.
There was a problem hiding this comment.
- There is no existing shared helper in
flutter_toolsthat checks whetherkTargetFileis a test target acrossintegration_test/,test_driver/, andtest/:_shouldRunAsIntegrationTestsintest.dartonly checksintegration_test/.DriveCommand.runCommandindrive.dartonly checks_fileSystem.path.isWithin('test_driver', targetFile)for an error message.RunCommandinrun.dartonly checkstargetFile.endsWith('_test.dart')for analytics.- The closest related helper in
flutter_toolsisPackageConfigWorkspaceExtension.toPackageUriForWorkspace(used inWebEntrypointTarget.buildandKernelCompiler.compile), which returnsnullwhenever the entrypoint is outsidelib/.
…mpty (flutter#193434) When `flutterManifest.isEmpty` (for example, a `pubspec.yaml` without a `flutter:` section), `ManifestAssetBundle.build` previously returned early with an empty `AssetManifest.bin`, ignoring any data assets produced by build/link hooks (`flutterHookResult.dataAssets`). Bug: * flutter#146264 ### Changes - Only short-circuit with an empty manifest in `ManifestAssetBundle.build` when both `flutterManifest.isEmpty` and `flutterHookResult?.dataAssets.isEmpty ?? true`. - Skip `computeTransitiveDependencies` when `flutterManifest.isEmpty`. - Add a unit test in `asset_bundle_test.dart` verifying that data assets from hooks are bundled when `pubspec.yaml` is empty. ### PR Stack | # | PR | Branch | Commit | | :-: | :--- | :--- | :--- | | **1** | **👉 flutter#193434 (this PR)** | `data-assets-empty-pubspec` | flutter@62199c4 | | 2 | flutter#193435 | `data-assets-flutter-test` | flutter@25be1ab | | 3 | flutter#193436 | `data-assets-dev-dependencies-release-test` | flutter@79abad9 | | 4 | flutter#193437 | `data-assets-widget-preview` | flutter@98f1001 | ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
4e9c425 to
76799a8
Compare
…r#193435) Previously, `flutter test` ran native assets hooks via `TestCompilerNativeAssetsBuilder.build(buildInfo)`, which only returned the `NativeAssetsManifest.json` URI and discarded the `FlutterHookResult` containing hook-generated data assets. Bug: * flutter#146264 ### Changes - Add `buildWithHookResult` to `TestCompilerNativeAssetsBuilder` returning both `nativeAssetsManifest` and `flutterHookResult`. - Pass `flutterHookResult` to `_buildTestAsset` / `assetBundle.build` in `TestCommand`. - Update `TestCommand._needsRebuild` to check if bundled asset files exist on disk, guard `pub.existsSync()`, and check `flutterHookResult.dependencies` modification timestamps. - Add a hermetic test in `test_test.dart` verifying that `flutter test` bundles data assets from hooks into `build/unit_test_assets`. ### PR Stack | # | PR | Branch | Commit | | :-: | :--- | :--- | :--- | | 1 | flutter#193434 | `data-assets-empty-pubspec` | flutter@62199c4 | | **2** | **👉 flutter#193435 (this PR)** | `data-assets-flutter-test` | flutter@390c757 | | 3 | flutter#193436 | `data-assets-dev-dependencies-release-test` | flutter@cca04e9 | | 4 | flutter#193437 | `data-assets-widget-preview` | flutter@0a5a8e9 | > **Note:** This PR is stacked on flutter#193434. To review only this PR's diff before the base PR lands, view commit flutter@390c757. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
76799a8 to
bd93510
Compare
There was a problem hiding this comment.
Code Review
This pull request updates the native assets build runner to include dev dependencies for release test targets, such as those located in the integration_test, test_driver, or test directories, and adds corresponding tests. Feedback suggests wrapping the relative path calculation in a try-catch block to prevent potential PathException crashes on Windows when paths are on different drives, as well as using triple-slash (///) comments for private member documentation per the style guide.
| bool _isTestTarget(Environment environment) { | ||
| final String? targetFile = environment.defines[kTargetFile]; | ||
| if (targetFile == null) { | ||
| return false; | ||
| } | ||
| final String absoluteTargetPath = environment.fileSystem.path.isAbsolute(targetFile) | ||
| ? targetFile | ||
| : environment.fileSystem.path.join(environment.projectDir.path, targetFile); | ||
| final String relativePath = environment.fileSystem.path.relative( | ||
| environment.fileSystem.path.normalize(absoluteTargetPath), | ||
| from: environment.projectDir.path, | ||
| ); | ||
| final List<String> parts = environment.fileSystem.path.split(relativePath); | ||
| return parts.isNotEmpty && | ||
| const <String>{'integration_test', 'test_driver', 'test'}.contains(parts.first); | ||
| } |
There was a problem hiding this comment.
To prevent potential crashes on Windows when targetFile and environment.projectDir.path are on different drives (which causes path.relative to throw a PathException), we should wrap the relative path computation in a try-catch block.
Additionally, per the Flutter Style Guide, we should use /// for public-quality documentation, even on private members.
/// Returns whether the target file in the [environment] is a test target.
///
/// This checks if the target file is located within the test, test_driver,
/// or integration_test directories of the project.
bool _isTestTarget(Environment environment) {
final String? targetFile = environment.defines[kTargetFile];
if (targetFile == null) {
return false;
}
final String absoluteTargetPath = environment.fileSystem.path.isAbsolute(targetFile)
? targetFile
: environment.fileSystem.path.join(environment.projectDir.path, targetFile);
try {
final String relativePath = environment.fileSystem.path.relative(
environment.fileSystem.path.normalize(absoluteTargetPath),
from: environment.projectDir.path,
);
final List<String> parts = environment.fileSystem.path.split(relativePath);
return parts.isNotEmpty &&
const <String>{'integration_test', 'test_driver', 'test'}.contains(parts.first);
} catch (_) {
return false;
}
}References
- Use
///for public-quality documentation, even on private members. (link)
There was a problem hiding this comment.
path.relative across drives on Windows (try-catch) — False (Python hallucination):
- Unlike Python's
os.path.relpath(which raisesValueErroracross drives), Dart'spackage:pathContext.relativedoes not throw aPathExceptionwhen two absolute paths are on different Windows drives (C:\...vsD:\...). - Instead,
package:pathchecksif (fromParsed.root != pathParsed.root) return path;and simply returnsD:\...unchanged, soparts.firstis'D:\\'and_isTestTargetreturnsfalse. - (
Context.relativeonly throwsPathExceptionif a root-relative Windows path like\foowithout a drive letter is compared againstC:\barwhencurrenthas no drive letter.)
bkonyi
left a comment
There was a problem hiding this comment.
LGTM overall with one question.
| } | ||
|
|
||
| testUsingContext( | ||
| 'createFlutterNativeAssetsBuildRunner includes dev dependencies for release test targets', |
There was a problem hiding this comment.
Do we need another case here for test/?
bd93510 to
596124d
Compare
When running release-mode tests (such as
flutter test integration_test --release),createFlutterNativeAssetsBuildRunnerpreviously setincludeDevDependencies = !buildMode.isRelease, which excluded hooks fromdev_dependencies.Bug:
hook/build.dartData assets support #146264Changes
_isTestTarget(environment)(whetherkTargetFileis underintegration_test/,test_driver/, ortest/) soincludeDevDependenciesistruefor test targets even in release mode.native_assets_test.dartverifyingincludeDevDependenciesisfalseforlib/main.dartin release mode andtrueforintegration_test/app_test.dart,test_driver/app.dart, andtest/app_test.dart.PR Stack
data-assets-empty-pubspecdata-assets-flutter-testdata-assets-dev-dependencies-release-testdata-assets-widget-previewPre-launch Checklist
///).