Skip to content

Commit a79793d

Browse files
authored
Adds analytics to macos impeller opt in/out (flutter#190220)
fixes flutter#190164 This matches the logic that shows up in [`build_ios.dart`](https://github.com/flutter/flutter/blob/e769fffb6c3346381b62693fe6ca16bee5ad2144/packages/flutter_tools/lib/src/commands/build_ios.dart#L1100) ## 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 documentation (doc comments with `///`). - [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. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent b242a05 commit a79793d

2 files changed

Lines changed: 194 additions & 8 deletions

File tree

‎packages/flutter_tools/lib/src/macos/build_macos.dart‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import '../darwin/darwin.dart';
1818
import '../features.dart';
1919
import '../globals.dart' as globals;
2020
import '../ios/migrations/metal_api_validation_migration.dart';
21+
import '../ios/plist_parser.dart';
2122
import '../ios/xcode_build_settings.dart';
2223
import '../ios/xcodeproj.dart';
2324
import '../migrations/swift_package_manager_gitignore_migration.dart';
@@ -283,10 +284,7 @@ Future<void> buildMacOS({
283284
<String>[
284285
'/usr/bin/env',
285286
...xcodebuildCommandArgs,
286-
if (xcodeWorkspace != null) ...<String>[
287-
'-workspace',
288-
xcodeWorkspace.path,
289-
] else ...<String>[
287+
if (xcodeWorkspace != null) ...<String>['-workspace', xcodeWorkspace.path] else ...<String>[
290288
'-project',
291289
xcodeProject.path,
292290
],
@@ -356,6 +354,22 @@ Future<void> buildMacOS({
356354
'Built ${globals.fs.path.relative(outputDirectory.path)}$appSize',
357355
color: TerminalColor.green,
358356
);
357+
358+
final File builtInfoPlist = globals.fs.file(
359+
globals.fs.path.join(outputDirectory.path, 'Contents', 'Info.plist'),
360+
);
361+
final String plistPath = builtInfoPlist.existsSync()
362+
? builtInfoPlist.path
363+
: flutterProject.macos.defaultHostInfoPlist.path;
364+
final bool? impellerEnabled = globals.plistParser.getValueFromFile<bool>(
365+
plistPath,
366+
PlistParser.kFLTEnableImpellerKey,
367+
);
368+
369+
final buildLabel = impellerEnabled == false
370+
? 'plist-impeller-disabled'
371+
: 'plist-impeller-enabled';
372+
globals.analytics.send(Event.flutterBuildInfo(label: buildLabel, buildType: 'macos'));
359373
}
360374
await _writeCodeSizeAnalysis(buildInfo, sizeAnalyzer);
361375
final Duration elapsedDuration = sw.elapsed;

‎packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart‎

Lines changed: 176 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:flutter_tools/src/commands/build.dart';
2020
import 'package:flutter_tools/src/commands/build_macos.dart';
2121
import 'package:flutter_tools/src/dart/pub.dart';
2222
import 'package:flutter_tools/src/features.dart';
23+
import 'package:flutter_tools/src/ios/plist_parser.dart';
2324
import 'package:flutter_tools/src/ios/xcodeproj.dart';
2425
import 'package:flutter_tools/src/project.dart';
2526
import 'package:unified_analytics/unified_analytics.dart';
@@ -166,10 +167,7 @@ void main() {
166167
if (hasWorkspace) ...<String>[
167168
'-workspace',
168169
flutterProject.macos.xcodeWorkspace!.path,
169-
] else ...<String>[
170-
'-project',
171-
flutterProject.macos.xcodeProject.path,
172-
],
170+
] else ...<String>['-project', flutterProject.macos.xcodeProject.path],
173171
'-configuration',
174172
configuration,
175173
'-scheme',
@@ -1629,4 +1627,178 @@ STDERR STUFF
16291627
OperatingSystemUtils: () => FakeOperatingSystemUtils(hostPlatform: HostPlatform.darwin_x64),
16301628
},
16311629
);
1630+
1631+
group('Analytics for impeller plist setting', () {
1632+
const plistContents = '''
1633+
<?xml version="1.0" encoding="UTF-8"?>
1634+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
1635+
<plist version="1.0">
1636+
<dict>
1637+
<key>FLTEnableImpeller</key>
1638+
<false/>
1639+
</dict>
1640+
</plist>
1641+
''';
1642+
1643+
testUsingContext(
1644+
'Sends an analytics event when Impeller is enabled',
1645+
() async {
1646+
final command = BuildCommand(
1647+
androidSdk: FakeAndroidSdk(),
1648+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
1649+
fileSystem: fileSystem,
1650+
logger: BufferLogger.test(),
1651+
osUtils: FakeOperatingSystemUtils(),
1652+
config: FakeConfig(),
1653+
platform: FakePlatform(),
1654+
fileSystemUtils: FakeFileSystemUtils(),
1655+
terminal: FakeTerminal(),
1656+
plistParser: FakePlistParser(),
1657+
processUtils: FakeProcessUtils(),
1658+
processManager: FakeProcessManager.any(),
1659+
templateRenderer: FakeTemplateRenderer(),
1660+
xcode: FakeXcode(),
1661+
artifacts: FakeArtifacts(),
1662+
cache: FakeCache(),
1663+
flutterVersion: FakeFlutterVersion(),
1664+
);
1665+
createMinimalMockProjectFiles();
1666+
1667+
await createTestCommandRunner(command).run(const <String>['build', 'macos', '--no-pub']);
1668+
1669+
expect(
1670+
fakeAnalytics.sentEvents,
1671+
contains(Event.flutterBuildInfo(label: 'plist-impeller-enabled', buildType: 'macos')),
1672+
);
1673+
},
1674+
overrides: <Type, Generator>{
1675+
FileSystem: () => fileSystem,
1676+
ProcessManager: () =>
1677+
FakeProcessManager.list(<FakeCommand>[setUpFakeXcodeBuildHandler('Release')]),
1678+
Platform: () => macosPlatform,
1679+
OperatingSystemUtils: () => FakeOperatingSystemUtils(hostPlatform: HostPlatform.darwin_x64),
1680+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
1681+
Pub: ThrowingPub.new,
1682+
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
1683+
Analytics: () => fakeAnalytics,
1684+
},
1685+
);
1686+
1687+
testUsingContext(
1688+
'Sends an analytics event when Impeller is disabled',
1689+
() async {
1690+
final command = BuildCommand(
1691+
androidSdk: FakeAndroidSdk(),
1692+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
1693+
fileSystem: fileSystem,
1694+
logger: BufferLogger.test(),
1695+
osUtils: FakeOperatingSystemUtils(),
1696+
config: FakeConfig(),
1697+
platform: FakePlatform(),
1698+
fileSystemUtils: FakeFileSystemUtils(),
1699+
terminal: FakeTerminal(),
1700+
plistParser: FakePlistParser(),
1701+
processUtils: FakeProcessUtils(),
1702+
processManager: FakeProcessManager.any(),
1703+
templateRenderer: FakeTemplateRenderer(),
1704+
xcode: FakeXcode(),
1705+
artifacts: FakeArtifacts(),
1706+
cache: FakeCache(),
1707+
flutterVersion: FakeFlutterVersion(),
1708+
);
1709+
createMinimalMockProjectFiles();
1710+
1711+
fileSystem.file(fileSystem.path.join('usr', 'bin', 'plutil')).createSync(recursive: true);
1712+
1713+
final File infoPlist = fileSystem.file(
1714+
fileSystem.path.join('macos', 'Runner', 'Info.plist'),
1715+
)..createSync(recursive: true);
1716+
1717+
infoPlist.writeAsStringSync(plistContents);
1718+
1719+
await createTestCommandRunner(command).run(const <String>['build', 'macos', '--no-pub']);
1720+
1721+
expect(
1722+
fakeAnalytics.sentEvents,
1723+
contains(Event.flutterBuildInfo(label: 'plist-impeller-disabled', buildType: 'macos')),
1724+
);
1725+
},
1726+
overrides: <Type, Generator>{
1727+
FileSystem: () => fileSystem,
1728+
ProcessManager: () =>
1729+
FakeProcessManager.list(<FakeCommand>[setUpFakeXcodeBuildHandler('Release')]),
1730+
Platform: () => macosPlatform,
1731+
OperatingSystemUtils: () => FakeOperatingSystemUtils(hostPlatform: HostPlatform.darwin_x64),
1732+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
1733+
Pub: ThrowingPub.new,
1734+
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
1735+
Analytics: () => fakeAnalytics,
1736+
PlistParser: () => FakePlistParser(<String, Object>{'FLTEnableImpeller': false}),
1737+
},
1738+
);
1739+
1740+
testUsingContext(
1741+
'Reads built app bundle Contents/Info.plist when present',
1742+
() async {
1743+
final command = BuildCommand(
1744+
androidSdk: FakeAndroidSdk(),
1745+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
1746+
fileSystem: fileSystem,
1747+
logger: BufferLogger.test(),
1748+
osUtils: FakeOperatingSystemUtils(),
1749+
config: FakeConfig(),
1750+
platform: FakePlatform(),
1751+
fileSystemUtils: FakeFileSystemUtils(),
1752+
terminal: FakeTerminal(),
1753+
plistParser: FakePlistParser(),
1754+
processUtils: FakeProcessUtils(),
1755+
processManager: FakeProcessManager.any(),
1756+
templateRenderer: FakeTemplateRenderer(),
1757+
xcode: FakeXcode(),
1758+
artifacts: FakeArtifacts(),
1759+
cache: FakeCache(),
1760+
flutterVersion: FakeFlutterVersion(),
1761+
);
1762+
createMinimalMockProjectFiles();
1763+
1764+
await createTestCommandRunner(command).run(const <String>['build', 'macos', '--no-pub']);
1765+
1766+
expect(
1767+
fakeAnalytics.sentEvents,
1768+
contains(Event.flutterBuildInfo(label: 'plist-impeller-disabled', buildType: 'macos')),
1769+
);
1770+
},
1771+
overrides: <Type, Generator>{
1772+
FileSystem: () => fileSystem,
1773+
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
1774+
setUpFakeXcodeBuildHandler(
1775+
'Release',
1776+
onRun: (_) {
1777+
fileSystem
1778+
.file(
1779+
fileSystem.path.join(
1780+
'build',
1781+
'macos',
1782+
'Build',
1783+
'Products',
1784+
'Release',
1785+
'Runner.app',
1786+
'Contents',
1787+
'Info.plist',
1788+
),
1789+
)
1790+
.createSync(recursive: true);
1791+
},
1792+
),
1793+
]),
1794+
Platform: () => macosPlatform,
1795+
OperatingSystemUtils: () => FakeOperatingSystemUtils(hostPlatform: HostPlatform.darwin_x64),
1796+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
1797+
Pub: ThrowingPub.new,
1798+
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
1799+
Analytics: () => fakeAnalytics,
1800+
PlistParser: () => FakePlistParser(<String, Object>{'FLTEnableImpeller': false}),
1801+
},
1802+
);
1803+
});
16321804
}

0 commit comments

Comments
 (0)