mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
add profile mode to flutter web applications (#39073)
This commit is contained in:
parent
b2d19d2af5
commit
b3014ff5c0
@ -38,6 +38,8 @@ const String digestsEntrypointExtension = '.digests';
|
||||
const String jsModuleErrorsExtension = '.ddc.js.errors';
|
||||
const String jsModuleExtension = '.ddc.js';
|
||||
const String jsSourceMapExtension = '.ddc.js.map';
|
||||
const String kReleaseFlag = 'release';
|
||||
const String kProfileFlag = 'profile';
|
||||
|
||||
final DartPlatform flutterWebPlatform =
|
||||
DartPlatform.register('flutter_web', <String>[
|
||||
@ -141,7 +143,8 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[
|
||||
'flutter_tools:entrypoint',
|
||||
<BuilderFactory>[
|
||||
(BuilderOptions options) => FlutterWebEntrypointBuilder(
|
||||
options.config['release'] ?? false,
|
||||
options.config[kReleaseFlag] ?? false,
|
||||
options.config[kProfileFlag] ?? false,
|
||||
options.config['flutterWebSdk'],
|
||||
),
|
||||
],
|
||||
@ -201,9 +204,10 @@ class FlutterWebTestEntrypointBuilder implements Builder {
|
||||
|
||||
/// A ddc-only entrypoint builder that respects the Flutter target flag.
|
||||
class FlutterWebEntrypointBuilder implements Builder {
|
||||
const FlutterWebEntrypointBuilder(this.release, this.flutterWebSdk);
|
||||
const FlutterWebEntrypointBuilder(this.release, this.profile, this.flutterWebSdk);
|
||||
|
||||
final bool release;
|
||||
final bool profile;
|
||||
final String flutterWebSdk;
|
||||
|
||||
@override
|
||||
@ -219,8 +223,8 @@ class FlutterWebEntrypointBuilder implements Builder {
|
||||
|
||||
@override
|
||||
Future<void> build(BuildStep buildStep) async {
|
||||
if (release) {
|
||||
await bootstrapDart2Js(buildStep, flutterWebSdk);
|
||||
if (release || profile) {
|
||||
await bootstrapDart2Js(buildStep, flutterWebSdk, profile);
|
||||
} else {
|
||||
await bootstrapDdc(buildStep, platform: flutterWebPlatform);
|
||||
}
|
||||
@ -366,7 +370,7 @@ Future<void> main() async {
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk) async {
|
||||
Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk, bool profile) async {
|
||||
final AssetId dartEntrypointId = buildStep.inputId;
|
||||
final AssetId moduleId = dartEntrypointId.changeExtension(moduleExtension(flutterWebPlatform));
|
||||
final Module module = Module.fromJson(json.decode(await buildStep.readAsString(moduleId)));
|
||||
@ -388,11 +392,17 @@ Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk) async {
|
||||
final String librariesPath = path.join(flutterWebSdkPath, 'libraries.json');
|
||||
final List<String> args = <String>[
|
||||
'--libraries-spec="$librariesPath"',
|
||||
'-O4',
|
||||
if (profile)
|
||||
'-O1'
|
||||
else
|
||||
'-O4',
|
||||
'-o',
|
||||
'$jsOutputPath',
|
||||
'--packages="$packageFile"',
|
||||
'-Ddart.vm.product=true',
|
||||
if (profile)
|
||||
'-Ddart.vm.profile=true'
|
||||
else
|
||||
'-Ddart.vm.product=true',
|
||||
dartPath,
|
||||
];
|
||||
final Dart2JsBatchWorkerPool dart2js = await buildStep.fetchResource(dart2JsWorkerResource);
|
||||
|
||||
@ -140,7 +140,7 @@ class WebFs {
|
||||
}) async {
|
||||
// Start the build daemon and run an initial build.
|
||||
final BuildDaemonClient client = await buildDaemonCreator
|
||||
.startBuildDaemon(fs.currentDirectory.path, release: buildInfo.isRelease);
|
||||
.startBuildDaemon(fs.currentDirectory.path, release: buildInfo.isRelease, profile: buildInfo.isProfile);
|
||||
client.startBuild();
|
||||
// Only provide relevant build results
|
||||
final Stream<BuildResult> filteredBuildResults = client.buildResults
|
||||
@ -266,11 +266,12 @@ class BuildDaemonCreator {
|
||||
const BuildDaemonCreator();
|
||||
|
||||
/// Start a build daemon and register the web targets.
|
||||
Future<BuildDaemonClient> startBuildDaemon(String workingDirectory, {bool release = false}) async {
|
||||
Future<BuildDaemonClient> startBuildDaemon(String workingDirectory, {bool release = false, bool profile = false }) async {
|
||||
try {
|
||||
final BuildDaemonClient client = await _connectClient(
|
||||
workingDirectory,
|
||||
release: release,
|
||||
profile: profile,
|
||||
);
|
||||
_registerBuildTargets(client);
|
||||
return client;
|
||||
@ -297,7 +298,7 @@ class BuildDaemonCreator {
|
||||
|
||||
Future<BuildDaemonClient> _connectClient(
|
||||
String workingDirectory,
|
||||
{ bool release }
|
||||
{ bool release, bool profile }
|
||||
) {
|
||||
final String flutterToolsPackages = fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools', '.packages');
|
||||
final String buildScript = fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'lib', 'src', 'build_runner', 'build_script.dart');
|
||||
@ -316,6 +317,7 @@ class BuildDaemonCreator {
|
||||
'--define', 'flutter_tools:ddc=flutterWebSdk=$flutterWebSdk',
|
||||
'--define', 'flutter_tools:entrypoint=flutterWebSdk=$flutterWebSdk',
|
||||
'--define', 'flutter_tools:entrypoint=release=$release',
|
||||
'--define', 'flutter_tools:entrypoint=profile=$profile',
|
||||
'--define', 'flutter_tools:shell=flutterWebSdk=$flutterWebSdk',
|
||||
],
|
||||
logHandler: (ServerLog serverLog) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user