Skip to content

Commit a0924c7

Browse files
authored
Reland "[data_assets] Cleanup tests" (flutter#184714)
Relands flutter#184209 adding a mac shard as suggested in flutter#184209 (comment). For adding a shard, I followed flutter#154444, which suggests it's contained in the single `.ci.yaml` file, and the new shard names need to have `bringup: true`. ---- Original PR description: This cleans up the data_assets experiment testing. * Use integration test projects, which are statically analyzed, formatted, etc. * This forces us to be explicit about the `package:data_assets` dependency. * This means the test projects will roll their dependencies with the dependency auto roller. (The test project was still using `native_assets_cli` which has been replaced with `hooks` and `data_assets`.) * Pin `package:data_assets`, because it's experimental, and we might do breaking changes. Also makes the test projects more useful: * The `data_assets_app` now displays the assets in the UI. (Not only prints to the console for the integration tests.) * The `data_assets_package` now actually uses its asset. And cleans up the test projects: * Move the test files into the `data/` dir. * Give the test data assets a proper extension. I saw weird behavior on Windows: * DevFS doesn't pick up the writes to the Dart files, not even with flushing or sleeps: `Compiling dart to kernel with 0 updated files` leading to a state where the Dart variable contents don't get updated while the data assets do. This integration test is not really about Dart hot restart, so I've skipped those checks on Windows. * This reproduces locally in the integration test, but not when running the app and editing the file. The checks in dev/bots/analyze.dart also required some updates: * The template files check didn't allow for the HTML license. P.S. Sorry for all the generated Flutter scaffolding. It seems that that is the way it's done in the integration test directory. (The package with the data assets is clean, but the Flutter app ...)
1 parent 92d81d3 commit a0924c7

66 files changed

Lines changed: 3597 additions & 205 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.ci.yaml‎

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,8 +3673,9 @@ targets:
36733673
- engine/**
36743674
- DEPS
36753675

3676-
- name: Mac_x64 build_tests_1_4
3676+
- name: Mac_x64 build_tests_1_5
36773677
recipe: flutter/flutter_drone
3678+
bringup: true
36783679
presubmit: false # Rely on Mac_arm build_tests in presubmit.
36793680
timeout: 60
36803681
properties:
@@ -3687,12 +3688,13 @@ targets:
36873688
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
36883689
]
36893690
shard: build_tests
3690-
subshard: "1_4"
3691+
subshard: "1_5"
36913692
tags: >
36923693
["framework", "hostonly", "shard", "mac"]
36933694
3694-
- name: Mac_x64 build_tests_2_4
3695+
- name: Mac_x64 build_tests_2_5
36953696
recipe: flutter/flutter_drone
3697+
bringup: true
36963698
presubmit: false # Rely on Mac_arm build_tests in presubmit.
36973699
timeout: 60
36983700
properties:
@@ -3705,12 +3707,13 @@ targets:
37053707
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
37063708
]
37073709
shard: build_tests
3708-
subshard: "2_4"
3710+
subshard: "2_5"
37093711
tags: >
37103712
["framework", "hostonly", "shard", "mac"]
37113713
3712-
- name: Mac_x64 build_tests_3_4
3714+
- name: Mac_x64 build_tests_3_5
37133715
recipe: flutter/flutter_drone
3716+
bringup: true
37143717
presubmit: false # Rely on Mac_arm build_tests in presubmit.
37153718
timeout: 60
37163719
properties:
@@ -3723,12 +3726,13 @@ targets:
37233726
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
37243727
]
37253728
shard: build_tests
3726-
subshard: "3_4"
3729+
subshard: "3_5"
37273730
tags: >
37283731
["framework", "hostonly", "shard", "mac"]
37293732
3730-
- name: Mac_x64 build_tests_4_4
3733+
- name: Mac_x64 build_tests_4_5
37313734
recipe: flutter/flutter_drone
3735+
bringup: true
37323736
presubmit: false # Rely on Mac_arm build_tests in presubmit.
37333737
timeout: 60
37343738
properties:
@@ -3741,12 +3745,32 @@ targets:
37413745
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
37423746
]
37433747
shard: build_tests
3744-
subshard: "4_4"
3748+
subshard: "4_5"
37453749
tags: >
37463750
["framework", "hostonly", "shard", "mac"]
37473751
3748-
- name: Mac_arm64 build_tests_1_4
3752+
- name: Mac_x64 build_tests_5_5
37493753
recipe: flutter/flutter_drone
3754+
bringup: true
3755+
presubmit: false # Rely on Mac_arm build_tests in presubmit.
3756+
timeout: 60
3757+
properties:
3758+
add_recipes_cq: "true"
3759+
dependencies: >-
3760+
[
3761+
{"dependency": "android_sdk", "version": "version:36v8unmodified"},
3762+
{"dependency": "open_jdk", "version": "version:21"},
3763+
{"dependency": "ruby", "version": "ruby_3.1-pod_1.13"},
3764+
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
3765+
]
3766+
shard: build_tests
3767+
subshard: "5_5"
3768+
tags: >
3769+
["framework", "hostonly", "shard", "mac"]
3770+
3771+
- name: Mac_arm64 build_tests_1_5
3772+
recipe: flutter/flutter_drone
3773+
bringup: true
37503774
timeout: 60
37513775
# Flake rate of >2.5% in presubmit
37523776
presubmit: false # https://github.com/flutter/flutter/issues/150642
@@ -3760,12 +3784,13 @@ targets:
37603784
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
37613785
]
37623786
shard: build_tests
3763-
subshard: "1_4"
3787+
subshard: "1_5"
37643788
tags: >
37653789
["framework", "hostonly", "shard", "mac"]
37663790
3767-
- name: Mac_arm64 build_tests_2_4
3791+
- name: Mac_arm64 build_tests_2_5
37683792
recipe: flutter/flutter_drone
3793+
bringup: true
37693794
timeout: 60
37703795
properties:
37713796
add_recipes_cq: "true"
@@ -3777,12 +3802,13 @@ targets:
37773802
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
37783803
]
37793804
shard: build_tests
3780-
subshard: "2_4"
3805+
subshard: "2_5"
37813806
tags: >
37823807
["framework", "hostonly", "shard", "mac"]
37833808
3784-
- name: Mac_arm64 build_tests_3_4
3809+
- name: Mac_arm64 build_tests_3_5
37853810
recipe: flutter/flutter_drone
3811+
bringup: true
37863812
timeout: 60
37873813
properties:
37883814
add_recipes_cq: "true"
@@ -3794,12 +3820,13 @@ targets:
37943820
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
37953821
]
37963822
shard: build_tests
3797-
subshard: "3_4"
3823+
subshard: "3_5"
37983824
tags: >
37993825
["framework", "hostonly", "shard", "mac"]
38003826
3801-
- name: Mac_arm64 build_tests_4_4
3827+
- name: Mac_arm64 build_tests_4_5
38023828
recipe: flutter/flutter_drone
3829+
bringup: true
38033830
timeout: 60
38043831
properties:
38053832
add_recipes_cq: "true"
@@ -3811,7 +3838,25 @@ targets:
38113838
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
38123839
]
38133840
shard: build_tests
3814-
subshard: "4_4"
3841+
subshard: "4_5"
3842+
tags: >
3843+
["framework", "hostonly", "shard", "mac"]
3844+
3845+
- name: Mac_arm64 build_tests_5_5
3846+
recipe: flutter/flutter_drone
3847+
bringup: true
3848+
timeout: 60
3849+
properties:
3850+
add_recipes_cq: "true"
3851+
dependencies: >-
3852+
[
3853+
{"dependency": "android_sdk", "version": "version:36v8unmodified"},
3854+
{"dependency": "open_jdk", "version": "version:21"},
3855+
{"dependency": "ruby", "version": "ruby_3.1-pod_1.13"},
3856+
{"dependency": "goldctl", "version": "git_revision:031e93819017b95c3f2dfe463189c7b8d02f2f83"}
3857+
]
3858+
shard: build_tests
3859+
subshard: "5_5"
38153860
tags: >
38163861
["framework", "hostonly", "shard", "mac"]
38173862

‎dev/bots/analyze.dart‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,23 +2572,30 @@ final String _kWindowsRunnerSubPath = path.join('windows', 'runner');
25722572
const String _kProjectNameKey = '{{projectName}}';
25732573
const String _kTmplExt = '.tmpl';
25742574

2575-
String _getFlutterLicense() {
2576-
return '// Copyright 2014 The Flutter Authors. All rights reserved.\n'
2577-
'// Use of this source code is governed by a BSD-style license that can be\n'
2578-
'// found in the LICENSE file.\n'
2579-
'\n';
2580-
}
2575+
const String _kFlutterLicense =
2576+
'// Copyright 2014 The Flutter Authors. All rights reserved.\n'
2577+
'// Use of this source code is governed by a BSD-style license that can be\n'
2578+
'// found in the LICENSE file.\n'
2579+
'\n';
2580+
2581+
const String _kFlutterLicenseHtml = '''
2582+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
2583+
Use of this source code is governed by a BSD-style license that can be
2584+
found in the LICENSE file. -->
2585+
''';
25812586

2582-
String _removeLicenseIfPresent(String fileContents, String license) {
2583-
if (fileContents.startsWith(license)) {
2584-
return fileContents.substring(license.length);
2587+
String _removeLicenseIfPresent(String fileContents) {
2588+
if (fileContents.startsWith(_kFlutterLicense)) {
2589+
return fileContents.substring(_kFlutterLicense.length);
2590+
}
2591+
if (fileContents.contains(_kFlutterLicenseHtml)) {
2592+
return fileContents.replaceFirst(_kFlutterLicenseHtml, '');
25852593
}
25862594
return fileContents;
25872595
}
25882596

25892597
Future<void> verifyIntegrationTestTemplateFiles(String flutterRoot) async {
25902598
final errors = <String>[];
2591-
final String license = _getFlutterLicense();
25922599
final String integrationTestsPath = path.join(flutterRoot, _kIntegrationTestsRelativePath);
25932600
final String templatePath = path.join(flutterRoot, _kTemplateRelativePath);
25942601
final Iterable<Directory> subDirs = Directory(
@@ -2620,7 +2627,7 @@ Future<void> verifyIntegrationTestTemplateFiles(String flutterRoot) async {
26202627
); // Substitute template project name
26212628
}
26222629
String appFileContents = File(appFilePath).readAsLinesSync().join('\n');
2623-
appFileContents = _removeLicenseIfPresent(appFileContents, license);
2630+
appFileContents = _removeLicenseIfPresent(appFileContents);
26242631
if (appFileContents != templateFileContents) {
26252632
int indexOfDifference;
26262633
for (

‎dev/bots/test.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Future<void> _runIntegrationToolTests() async {
247247

248248
await runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'hook_user_defines'));
249249
await runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'link_hook'));
250+
await runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'data_asset_app'));
250251
}
251252

252253
Future<void> _runWidgetPreviewScaffoldToolTests() async {
@@ -354,6 +355,7 @@ Future<void> _runBuildTests() async {
354355
)
355356
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'android_views')))
356357
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'channels')))
358+
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'data_asset_app')))
357359
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'hybrid_android_views')))
358360
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'flutter_gallery')))
359361
..add(
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins-dependencies
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
/coverage/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "d446c00806d41e8d39a8e9c56cb01e0330c193b5"
8+
channel: "[user-branch]"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
17+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
18+
- platform: linux
19+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
20+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
21+
- platform: macos
22+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
23+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
24+
- platform: web
25+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
26+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
27+
- platform: windows
28+
create_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
29+
base_revision: d446c00806d41e8d39a8e9c56cb01e0330c193b5
30+
31+
# User provided section
32+
33+
# List of Local paths (relative to this file) that should be
34+
# ignored by the migrate tool.
35+
#
36+
# Files that are not part of the templates will be ignored by default.
37+
unmanaged_files:
38+
- 'lib/main.dart'
39+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# data_asset_app
2+
3+
This app demonstrates and tests the use of Dart data assets in a Flutter application.
4+
It includes a local data asset and depends on `data_asset_package` which also provides a data asset.
5+
The app displays the content of these assets and is used for integration testing of the Dart data assets feature.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:data_assets/data_assets.dart';
6+
import 'package:hooks/hooks.dart';
7+
8+
void main(List<String> args) async {
9+
await build(args, (BuildInput input, BuildOutputBuilder output) async {
10+
if (input.config.buildAssetTypes.contains('data_assets/data')) {
11+
final assets = <String>['id1.txt']; // @assets
12+
for (final id in assets) {
13+
output.assets.data.add(
14+
DataAsset(
15+
package: input.packageName,
16+
name: 'data/$id',
17+
file: input.packageRoot.resolve('data/$id'),
18+
),
19+
);
20+
}
21+
}
22+
});
23+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: avoid_print
6+
import 'package:flutter/services.dart' show rootBundle;
7+
8+
// Only run the code once for each version.
9+
String lastVersion = '';
10+
11+
class AssetData {
12+
const AssetData(this.version, this.found, this.notFound);
13+
final String version;
14+
final Map<String, String> found;
15+
final List<String> notFound;
16+
}
17+
18+
Future<AssetData?> loadAppAssets() async {
19+
const version = 'version1'; // @version
20+
if (lastVersion == version) {
21+
return null;
22+
}
23+
lastVersion = version;
24+
25+
final found = <String, String>{};
26+
final notFound = <String>[];
27+
final assets = <String>['packages/data_asset_app/data/id1.txt']; // @assets
28+
for (final assetId in assets) {
29+
try {
30+
found[assetId] = await rootBundle.loadString(assetId);
31+
} catch (e) {
32+
print('EXCEPTION $e');
33+
notFound.add(assetId);
34+
}
35+
}
36+
37+
return AssetData(version, found, notFound);
38+
}

0 commit comments

Comments
 (0)