Skip to content

Commit 92e8949

Browse files
authored
Merge branch 'master' into analytics_inheritSuppression2
2 parents 1b5d4c4 + 66b3ad9 commit 92e8949

8 files changed

Lines changed: 421 additions & 10 deletions

File tree

‎DEPS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vars = {
1515
'skia_git': 'https://skia.googlesource.com',
1616
'llvm_git': 'https://llvm.googlesource.com',
1717
'dart_ai_rev': '9c96bfe5f091c9451eff5b59c9bffeb2e806b875',
18-
'skia_revision': 'f572728c472590e617ade43515b9a8ab48bb3d55',
18+
'skia_revision': '87eb6de3ac825eda202896de2391ea45a5dc1d5d',
1919

2020
# Do not download the Emscripten SDK by default.
2121
# This prevents us from downloading the Emscripten toolchain for builds

‎packages/flutter_tools/lib/src/isolated/resident_web_runner.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ class ResidentWebRunner extends ResidentRunner {
309309
if (debuggingOptions.buildInfo.isDebug && !useWasm) {
310310
await runSourceGenerators();
311311
final UpdateFSReport report = await _updateDevFS(fullRestart: true, resetCompiler: true);
312+
sendDdcCompileAnalytics(
313+
deprecatedJsInterop: debuggingOptions.buildInfo.deprecatedJsInterop,
314+
command: 'run',
315+
succeeded: report.success,
316+
analytics: analytics,
317+
);
312318
if (!report.success) {
313319
logger.printError('Failed to compile application.');
314320
appFailedToStart();

‎packages/flutter_tools/lib/src/test/web_test_compiler.dart‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ class WebTestCompiler {
150150
fs: fs,
151151
projectRootPath: projectDirectory.absolute.path,
152152
);
153-
if (output == null || output.errorCount > 0) {
153+
final bool compileFailed = output == null || output.errorCount > 0;
154+
sendDdcCompileAnalytics(
155+
deprecatedJsInterop: buildInfo.deprecatedJsInterop,
156+
command: 'test',
157+
succeeded: !compileFailed,
158+
);
159+
if (compileFailed) {
154160
throwToolExit('Failed to compile');
155161
}
156162
// Cache the output kernel file to speed up subsequent compiles.

‎packages/flutter_tools/lib/src/web/compile.dart‎

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import '../cache.dart';
2020
import '../compile.dart' show kDdcCanaryFeatures;
2121
import '../context/tool_context.dart';
2222
import '../flutter_plugins.dart';
23+
import '../globals.dart' as globals;
2324
import '../platform_plugins.dart';
2425
import '../plugins.dart';
2526
import '../project.dart';
@@ -109,6 +110,7 @@ class WebBuilder {
109110
final migration = ProjectMigration(migrators);
110111
await migration.run();
111112

113+
final String buildSettingsString = _buildEventAnalyticsSettings(configs: compilerConfigs);
112114
final Status status = logger.startProgress('Compiling $target for the Web...');
113115
final sw = Stopwatch()..start();
114116
try {
@@ -160,6 +162,11 @@ class WebBuilder {
160162
: null,
161163
);
162164
}
165+
_sendFailedBuildAnalytics(
166+
compilerConfigs: compilerConfigs,
167+
exceptions: result.exceptions,
168+
settings: buildSettingsString,
169+
);
163170
throwToolExit('Failed to compile application for the Web.');
164171
}
165172
} on Exception catch (err) {
@@ -176,8 +183,6 @@ class WebBuilder {
176183
color: TerminalColor.green,
177184
);
178185

179-
final String buildSettingsString = _buildEventAnalyticsSettings(configs: compilerConfigs);
180-
181186
_analytics.send(
182187
Event.flutterBuildInfo(label: 'web-compile', buildType: 'web', settings: buildSettingsString),
183188
);
@@ -192,6 +197,35 @@ class WebBuilder {
192197
),
193198
);
194199
}
200+
201+
void _sendFailedBuildAnalytics({
202+
required List<WebCompilerConfig> compilerConfigs,
203+
required Map<String, ExceptionMeasurement> exceptions,
204+
required String settings,
205+
}) {
206+
final bool hasDeprecatedJsInteropFlag = compilerConfigs.any(
207+
(WebCompilerConfig config) =>
208+
config is JsCompilerConfig && config.deprecatedJsInterop != null,
209+
);
210+
if (!hasDeprecatedJsInteropFlag) {
211+
return;
212+
}
213+
final List<String> failedTargets = <String>{
214+
for (final ExceptionMeasurement measurement in exceptions.values) measurement.target,
215+
}.toList()..sort();
216+
final rawError = failedTargets.isEmpty
217+
? 'web-compile-failure'
218+
: '${failedTargets.join(',')}-failure';
219+
final error = rawError.length > 100 ? '${rawError.substring(0, 92)}...-fail' : rawError;
220+
_analytics.send(
221+
Event.flutterBuildInfo(
222+
label: 'web-compile',
223+
buildType: 'web',
224+
settings: settings,
225+
error: error,
226+
),
227+
);
228+
}
195229
}
196230

197231
/// Web rendering backend mode.
@@ -287,8 +321,41 @@ String _buildEventAnalyticsSettings({required List<WebCompilerConfig> configs})
287321
values['web-renderer'] = renderers.join(',');
288322
values['web-target'] = targets.join(',');
289323

290-
final List<String> sortedList =
291-
values.entries.map((MapEntry<String, Object> e) => '${e.key}: ${e.value};').toList()..sort();
324+
String formatValues(Map<String, Object> entries) {
325+
final List<String> sortedList =
326+
entries.entries.map((MapEntry<String, Object> e) => '${e.key}: ${e.value};').toList()
327+
..sort();
328+
return sortedList.join(' ');
329+
}
330+
331+
final String result = formatValues(values);
332+
// GA4 / package:unified_analytics enforces a 100-character limit on event
333+
// parameter values. Drop `optimizationLevel` if the combined settings
334+
// exceed the limit.
335+
if (result.length > 100 && values.remove('optimizationLevel') != null) {
336+
return formatValues(values);
337+
}
338+
return result;
339+
}
292340

293-
return sortedList.join(' ');
341+
/// Sends an [Event.flutterBuildInfo] event for a DDC web compilation when
342+
/// `--[no-]deprecated-js-interop` (`[deprecatedJsInterop]`) was explicitly set.
343+
void sendDdcCompileAnalytics({
344+
required bool? deprecatedJsInterop,
345+
required String command,
346+
required bool succeeded,
347+
Analytics? analytics,
348+
}) {
349+
if (deprecatedJsInterop == null) {
350+
return;
351+
}
352+
(analytics ?? globals.analytics).send(
353+
Event.flutterBuildInfo(
354+
label: 'web-compile',
355+
buildType: 'web',
356+
command: command,
357+
settings: 'deprecatedJsInterop: $deprecatedJsInterop; web-compiler: ddc;',
358+
error: succeeded ? null : 'ddc-compile-failure',
359+
),
360+
);
294361
}

‎packages/flutter_tools/lib/src/web/compiler_config.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ class JsCompilerConfig extends WebCompilerConfig {
159159
};
160160
return jsonEncode(settings);
161161
}
162+
163+
@override
164+
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{
165+
...super.buildEventAnalyticsValues,
166+
'deprecatedJsInterop': ?deprecatedJsInterop?.toString(),
167+
};
162168
}
163169

164170
/// Configuration for the Wasm compiler.

‎packages/flutter_tools/test/general.shard/resident_web_runner_test.dart‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,123 @@ flutter:
24502450
},
24512451
);
24522452
}
2453+
2454+
for (final deprecatedJsInterop in <bool>[true, false]) {
2455+
testUsingContext(
2456+
'ResidentWebRunner sends flutterBuildInfo analytics on debug DDC '
2457+
'compile success when deprecatedJsInterop: $deprecatedJsInterop',
2458+
() async {
2459+
fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
2460+
setupMocks();
2461+
2462+
final ResidentRunner residentWebRunner = setUpResidentRunner(
2463+
flutterDevice,
2464+
debuggingOptions: DebuggingOptions.enabled(
2465+
BuildInfo(
2466+
BuildMode.debug,
2467+
null,
2468+
treeShakeIcons: false,
2469+
packageConfigPath: '.dart_tool/package_config.json',
2470+
deprecatedJsInterop: deprecatedJsInterop,
2471+
),
2472+
),
2473+
);
2474+
residentWebRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
2475+
2476+
final connectionInfoCompleter = Completer<DebugConnectionInfo>();
2477+
unawaited(residentWebRunner.run(connectionInfoCompleter: connectionInfoCompleter));
2478+
await connectionInfoCompleter.future;
2479+
2480+
expect(
2481+
fakeAnalytics.sentEvents,
2482+
contains(
2483+
Event.flutterBuildInfo(
2484+
label: 'web-compile',
2485+
buildType: 'web',
2486+
command: 'run',
2487+
settings: 'deprecatedJsInterop: $deprecatedJsInterop; web-compiler: ddc;',
2488+
),
2489+
),
2490+
);
2491+
},
2492+
overrides: <Type, Generator>{
2493+
Analytics: () => fakeAnalytics,
2494+
FileSystem: () => fileSystem,
2495+
ProcessManager: () => processManager,
2496+
Pub: ThrowingPub.new,
2497+
},
2498+
);
2499+
2500+
testUsingContext(
2501+
'ResidentWebRunner sends flutterBuildInfo analytics with error on debug '
2502+
'DDC compile failure when deprecatedJsInterop: $deprecatedJsInterop',
2503+
() async {
2504+
fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
2505+
setupMocks();
2506+
webDevFS.report = UpdateFSReport();
2507+
2508+
final ResidentRunner residentWebRunner = setUpResidentRunner(
2509+
flutterDevice,
2510+
debuggingOptions: DebuggingOptions.enabled(
2511+
BuildInfo(
2512+
BuildMode.debug,
2513+
null,
2514+
treeShakeIcons: false,
2515+
packageConfigPath: '.dart_tool/package_config.json',
2516+
deprecatedJsInterop: deprecatedJsInterop,
2517+
),
2518+
),
2519+
);
2520+
2521+
expect(await residentWebRunner.run(), 1);
2522+
expect(
2523+
fakeAnalytics.sentEvents,
2524+
contains(
2525+
Event.flutterBuildInfo(
2526+
label: 'web-compile',
2527+
buildType: 'web',
2528+
command: 'run',
2529+
settings: 'deprecatedJsInterop: $deprecatedJsInterop; web-compiler: ddc;',
2530+
error: 'ddc-compile-failure',
2531+
),
2532+
),
2533+
);
2534+
},
2535+
overrides: <Type, Generator>{
2536+
Analytics: () => fakeAnalytics,
2537+
FileSystem: () => fileSystem,
2538+
ProcessManager: () => processManager,
2539+
Pub: ThrowingPub.new,
2540+
},
2541+
);
2542+
}
2543+
2544+
testUsingContext(
2545+
'ResidentWebRunner does not send flutterBuildInfo analytics on debug DDC '
2546+
'compile when deprecatedJsInterop is null',
2547+
() async {
2548+
fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
2549+
setupMocks();
2550+
2551+
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
2552+
residentWebRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
2553+
2554+
final connectionInfoCompleter = Completer<DebugConnectionInfo>();
2555+
unawaited(residentWebRunner.run(connectionInfoCompleter: connectionInfoCompleter));
2556+
await connectionInfoCompleter.future;
2557+
2558+
expect(
2559+
fakeAnalytics.sentEvents.where((Event e) => e.eventData['label'] == 'web-compile'),
2560+
isEmpty,
2561+
);
2562+
},
2563+
overrides: <Type, Generator>{
2564+
Analytics: () => fakeAnalytics,
2565+
FileSystem: () => fileSystem,
2566+
ProcessManager: () => processManager,
2567+
Pub: ThrowingPub.new,
2568+
},
2569+
);
24532570
});
24542571
}
24552572

0 commit comments

Comments
 (0)