Skip to content

Commit eb6acab

Browse files
authored
[record_use] Add experimental flag and test project (flutter#184719)
Bug: * dart-lang/native#2690 **Does _not_ add an implementation**, only: - an experimental flag, - an integration test that should pass when the experiment is implemented, - and the record_use package as an explicit dependency. Landing this PR first because it's a ton of files. It will keep the actual implementation PR more reviewable. Note the test projects go through the usual hoops: * `flutter create`. * Add the things we want to test. * Add copyright headers everywhere. * Drop all the icons, and modify all the native build files to not refer to the icons. (Force pushing 10x in the process to get the bots green.) * The build_tests shards build the test projects for all target OSes (catching things such as misconfigured icons etc.) The integration test loosely follows the data assets integration test, but it only runs release mode (so no hot reload and hot restart). The integration test uses data assets (not code assets) so that we can also test the web backends with record-use. This means the integration test relies on also enabling the data assets experimental flag.
1 parent eb4e55a commit eb6acab

100 files changed

Lines changed: 4903 additions & 1 deletion

File tree

Some content is hidden

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

‎dev/bots/test.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ Future<void> _runBuildTests() async {
365365
Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'ios_app_with_extensions')),
366366
)
367367
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'platform_interaction')))
368+
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'record_use_test_app')))
368369
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'spell_check')))
369370
..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'ui')));
370371

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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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: "83c588dcfe40f23137f4026b3af8adc66677fdd1"
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: 83c588dcfe40f23137f4026b3af8adc66677fdd1
17+
base_revision: 83c588dcfe40f23137f4026b3af8adc66677fdd1
18+
- platform: android
19+
create_revision: 83c588dcfe40f23137f4026b3af8adc66677fdd1
20+
base_revision: 83c588dcfe40f23137f4026b3af8adc66677fdd1
21+
- platform: ios
22+
create_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
23+
base_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
24+
- platform: linux
25+
create_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
26+
base_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
27+
- platform: macos
28+
create_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
29+
base_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
30+
- platform: web
31+
create_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
32+
base_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
33+
- platform: windows
34+
create_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
35+
base_revision: 552fa0da2b0988b97d59963cfb44ca485ac31412
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Record Use Test App
2+
3+
An integration test app for testing the "Record Use" asset tree-shaking feature.
4+
5+
## Overview
6+
7+
This app is used to verify that Flutter can tree-shake assets based on their usage in the source code. It works in conjunction with the `record_use_test_package`.
8+
9+
The feature relies on:
10+
- `@RecordUse()` annotation on functions that use assets.
11+
- Asset hooks (`build.dart` and `link.dart`) that process usage recordings.
12+
13+
## How it works
14+
15+
1. The `record_use_test_package` contains a `translations.json` asset with multiple entries.
16+
2. The package provides a `translate(String key)` function annotated with `@RecordUse()`.
17+
3. This app (`record_use_test_app`) calls `translate('hello')` and `translate('friend')`.
18+
4. During the build, the `link.dart` hook in the package receives a recording of these calls.
19+
5. The hook filters `translations.json` to only include the entries for "hello" and "friend", tree-shaking the unused ones.
20+
21+
## Testing
22+
23+
The integration test for this feature is located at:
24+
`packages/flutter_tools/test/integration.shard/isolated/record_use_test.dart`
25+
26+
To run the test:
27+
```bash
28+
bin/cache/dart-sdk/bin/dart packages/flutter_tools/test/integration.shard/isolated/record_use_test.dart
29+
```
30+
31+
Note: The test requires `--enable-record-use` and `--enable-dart-data-assets` to be enabled in the Flutter config.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
.cxx/
9+
10+
# Remember to never publicly share your keystore.
11+
# See https://flutter.dev/to/reference-keystore
12+
key.properties
13+
**/*.keystore
14+
**/*.jks
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
id("com.android.application")
3+
id("kotlin-android")
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id("dev.flutter.flutter-gradle-plugin")
6+
}
7+
8+
android {
9+
namespace = "com.example.record_use_test_app"
10+
compileSdk = flutter.compileSdkVersion
11+
ndkVersion = flutter.ndkVersion
12+
13+
compileOptions {
14+
sourceCompatibility = JavaVersion.VERSION_17
15+
targetCompatibility = JavaVersion.VERSION_17
16+
}
17+
18+
kotlinOptions {
19+
jvmTarget = JavaVersion.VERSION_17.toString()
20+
}
21+
22+
defaultConfig {
23+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
24+
applicationId = "com.example.record_use_test_app"
25+
// You can update the following values to match your application needs.
26+
// For more information, see: https://flutter.dev/to/review-gradle-config.
27+
minSdk = flutter.minSdkVersion
28+
targetSdk = flutter.targetSdkVersion
29+
versionCode = flutter.versionCode
30+
versionName = flutter.versionName
31+
}
32+
33+
buildTypes {
34+
release {
35+
// TODO: Add your own signing config for the release build.
36+
// Signing with the debug keys for now, so `flutter run --release` works.
37+
signingConfig = signingConfigs.getByName("debug")
38+
}
39+
}
40+
}
41+
42+
flutter {
43+
source = "../.."
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
6+
<!-- The INTERNET permission is required for development. Specifically,
7+
the Flutter tool needs it to communicate with the running application
8+
to allow setting breakpoints, to provide hot reload, etc.
9+
-->
10+
<uses-permission android:name="android.permission.INTERNET"/>
11+
</manifest>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
6+
<application
7+
android:label="record_use_test_app"
8+
android:name="${applicationName}">
9+
<activity
10+
android:name=".MainActivity"
11+
android:exported="true"
12+
android:launchMode="singleTop"
13+
android:taskAffinity=""
14+
android:theme="@style/LaunchTheme"
15+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
16+
android:hardwareAccelerated="true"
17+
android:windowSoftInputMode="adjustResize">
18+
<!-- Specifies an Android theme to apply to this Activity as soon as
19+
the Android process has started. This theme is visible to the user
20+
while the Flutter UI initializes. After that, this theme continues
21+
to determine the Window background behind the Flutter UI. -->
22+
<meta-data
23+
android:name="io.flutter.embedding.android.NormalTheme"
24+
android:resource="@style/NormalTheme"
25+
/>
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN"/>
28+
<category android:name="android.intent.category.LAUNCHER"/>
29+
</intent-filter>
30+
</activity>
31+
<!-- Don't delete the meta-data below.
32+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
33+
<meta-data
34+
android:name="flutterEmbedding"
35+
android:value="2" />
36+
</application>
37+
<!-- Required to query activities that can process text, see:
38+
https://developer.android.com/training/package-visibility and
39+
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
40+
41+
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
42+
<queries>
43+
<intent>
44+
<action android:name="android.intent.action.PROCESS_TEXT"/>
45+
<data android:mimeType="text/plain"/>
46+
</intent>
47+
</queries>
48+
</manifest>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example.recordusetestapp
2+
3+
import io.flutter.embedding.android.FlutterActivity
4+
5+
class MainActivity : FlutterActivity()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
3+
Use of this source code is governed by a BSD-style license that can be
4+
found in the LICENSE file. -->
5+
6+
<!-- Modify this file to customize your launch splash screen -->
7+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
8+
<item android:drawable="?android:colorBackground" />
9+
10+
<!-- You can insert your own image assets here -->
11+
<!-- <item>
12+
<bitmap
13+
android:gravity="center"
14+
android:src="@mipmap/launch_image" />
15+
</item> -->
16+
</layer-list>

0 commit comments

Comments
 (0)