From 94a30ddcbb4f28dc2143509b6f8eb9ee99779b69 Mon Sep 17 00:00:00 2001 From: Kenzie Schmoll <43759233+kenzieschmoll@users.noreply.github.com> Date: Tue, 15 Dec 2020 11:06:10 -0800 Subject: [PATCH] Add text to --analyze-size command output to launch DevTools with size data (#72295) * Add text to --analyze-size command output to launch DevTools with size data. --- .../flutter_tools/lib/src/android/gradle.dart | 8 +++++ .../lib/src/commands/build_ios.dart | 8 +++++ .../lib/src/linux/build_linux.dart | 8 +++++ .../lib/src/macos/build_macos.dart | 8 +++++ .../lib/src/windows/build_windows.dart | 8 +++++ .../hermetic/build_ipa_test.dart | 1 + .../hermetic/build_linux_test.dart | 1 + .../hermetic/build_macos_test.dart | 1 + .../hermetic/build_windows_test.dart | 1 + .../integration.shard/analyze_size_test.dart | 29 +++++++++++++++---- 10 files changed, 67 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index c5f2ed4754..e5ae962065 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -540,6 +540,14 @@ Future _performCodeSizeAnalysis( globals.printStatus( 'A summary of your ${kind.toUpperCase()} analysis can be found at: ${outputFile.path}', ); + + // DevTools expects a file path relative to the .flutter-devtools/ dir. + final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim(); + globals.printStatus( + '\nTo analyze your app size in Dart DevTools, run the following command:\n' + 'flutter pub global activate devtools; flutter pub global run devtools ' + '--appSizeBase=$relativeAppSizePath' + ); } /// Builds AAR and POM files. diff --git a/packages/flutter_tools/lib/src/commands/build_ios.dart b/packages/flutter_tools/lib/src/commands/build_ios.dart index de5905c619..b36e23914f 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios.dart @@ -294,6 +294,14 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { globals.printStatus( 'A summary of your iOS bundle analysis can be found at: ${outputFile.path}', ); + + // DevTools expects a file path relative to the .flutter-devtools/ dir. + final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim(); + globals.printStatus( + '\nTo analyze your app size in Dart DevTools, run the following command:\n' + 'flutter pub global activate devtools; flutter pub global run devtools ' + '--appSizeBase=$relativeAppSizePath' + ); } if (result.output != null) { diff --git a/packages/flutter_tools/lib/src/linux/build_linux.dart b/packages/flutter_tools/lib/src/linux/build_linux.dart index 4dede1fe80..81d77d228c 100644 --- a/packages/flutter_tools/lib/src/linux/build_linux.dart +++ b/packages/flutter_tools/lib/src/linux/build_linux.dart @@ -84,6 +84,14 @@ Future buildLinux( globals.printStatus( 'A summary of your Linux bundle analysis can be found at: ${outputFile.path}', ); + + // DevTools expects a file path relative to the .flutter-devtools/ dir. + final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim(); + globals.printStatus( + '\nTo analyze your app size in Dart DevTools, run the following command:\n' + 'flutter pub global activate devtools; flutter pub global run devtools ' + '--appSizeBase=$relativeAppSizePath' + ); } } diff --git a/packages/flutter_tools/lib/src/macos/build_macos.dart b/packages/flutter_tools/lib/src/macos/build_macos.dart index caecf2b4dd..c9416e9bea 100644 --- a/packages/flutter_tools/lib/src/macos/build_macos.dart +++ b/packages/flutter_tools/lib/src/macos/build_macos.dart @@ -140,6 +140,14 @@ Future buildMacOS({ globals.printStatus( 'A summary of your macOS bundle analysis can be found at: ${outputFile.path}', ); + + // DevTools expects a file path relative to the .flutter-devtools/ dir. + final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim(); + globals.printStatus( + '\nTo analyze your app size in Dart DevTools, run the following command:\n' + 'flutter pub global activate devtools; flutter pub global run devtools ' + '--appSizeBase=$relativeAppSizePath' + ); } globals.flutterUsage.sendTiming('build', 'xcode-macos', Duration(milliseconds: sw.elapsedMilliseconds)); } diff --git a/packages/flutter_tools/lib/src/windows/build_windows.dart b/packages/flutter_tools/lib/src/windows/build_windows.dart index c893f93ab0..da27a71df8 100644 --- a/packages/flutter_tools/lib/src/windows/build_windows.dart +++ b/packages/flutter_tools/lib/src/windows/build_windows.dart @@ -86,6 +86,14 @@ Future buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, { globals.printStatus( 'A summary of your Windows bundle analysis can be found at: ${outputFile.path}', ); + + // DevTools expects a file path relative to the .flutter-devtools/ dir. + final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim(); + globals.printStatus( + '\nTo analyze your app size in Dart DevTools, run the following command:\n' + 'flutter pub global activate devtools; flutter pub global run devtools ' + '--appSizeBase=$relativeAppSizePath' + ); } } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart index ae1cea0fc9..4bc25fb174 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart @@ -249,6 +249,7 @@ void main() { ); expect(testLogger.statusText, contains('A summary of your iOS bundle analysis can be found at')); + expect(testLogger.statusText, contains('flutter pub global activate devtools; flutter pub global run devtools --appSizeBase=')); expect(buffer.toString(), contains('event {category: code-size-analysis, action: ios, label: null, value: null, cd33: ')); }, overrides: { FileSystem: () => fileSystem, diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart index 288a8638fe..0f74289c06 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart @@ -459,6 +459,7 @@ set(BINARY_NAME "fizz_bar") ); expect(testLogger.statusText, contains('A summary of your Linux bundle analysis can be found at')); + expect(testLogger.statusText, contains('flutter pub global activate devtools; flutter pub global run devtools --appSizeBase=')); expect(buffer.toString(), contains('event {category: code-size-analysis, action: linux, label: null, value: null, cd33:')); }, overrides: { FileSystem: () => fileSystem, diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart index 1743d7e6d8..5d9a6042f7 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart @@ -345,6 +345,7 @@ void main() { ); expect(testLogger.statusText, contains('A summary of your macOS bundle analysis can be found at')); + expect(testLogger.statusText, contains('flutter pub global activate devtools; flutter pub global run devtools --appSizeBase=')); expect(buffer.toString(), contains('event {category: code-size-analysis, action: macos, label: null, value: null, cd33:')); }, overrides: { FileSystem: () => fileSystem, diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart index 54a881b2ce..afd694c826 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart @@ -407,6 +407,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier ); expect(testLogger.statusText, contains('A summary of your Windows bundle analysis can be found at')); + expect(testLogger.statusText, contains('flutter pub global activate devtools; flutter pub global run devtools --appSizeBase=')); expect(buffer.toString(), contains('event {category: code-size-analysis, action: windows, label: null, value: null, cd33:')); }, overrides: { FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true), diff --git a/packages/flutter_tools/test/integration.shard/analyze_size_test.dart b/packages/flutter_tools/test/integration.shard/analyze_size_test.dart index d92b4c3d3e..cb52599f72 100644 --- a/packages/flutter_tools/test/integration.shard/analyze_size_test.dart +++ b/packages/flutter_tools/test/integration.shard/analyze_size_test.dart @@ -10,10 +10,11 @@ import 'test_utils.dart'; const String apkDebugMessage = 'A summary of your APK analysis can be found at: '; const String iosDebugMessage = 'A summary of your iOS bundle analysis can be found at: '; +const String runDevToolsMessage = 'flutter pub global activate devtools; flutter pub global run devtools '; void main() { testWithoutContext('--analyze-size flag produces expected output on hello_world for Android', () async { - final String woringDirectory = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world'); + final String workingDirectory = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world'); final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter'); final ProcessResult result = await processManager.run([ flutterBin, @@ -22,7 +23,7 @@ void main() { 'apk', '--analyze-size', '--target-platform=android-arm64' - ], workingDirectory: fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world')); + ], workingDirectory: workingDirectory); print(result.stdout); print(result.stderr); @@ -33,13 +34,21 @@ void main() { .firstWhere((String line) => line.contains(apkDebugMessage)); final String outputFilePath = line.split(apkDebugMessage).last.trim(); - expect(fileSystem.file(fileSystem.path.join(woringDirectory, outputFilePath)), exists); + expect(fileSystem.file(fileSystem.path.join(workingDirectory, outputFilePath)), exists); expect(outputFilePath, contains('.flutter-devtools')); + + final String devToolsCommand = result.stdout.toString() + .split('\n') + .firstWhere((String line) => line.contains(runDevToolsMessage)); + final String commandArguments = devToolsCommand.split(runDevToolsMessage).last.trim(); + final String relativeAppSizePath = outputFilePath.split('.flutter-devtools/').last.trim(); + expect(commandArguments.contains('--appSizeBase=$relativeAppSizePath'), isTrue); + expect(result.exitCode, 0); }); testWithoutContext('--analyze-size flag produces expected output on hello_world for iOS', () async { - final String woringDirectory = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world'); + final String workingDirectory = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world'); final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter'); final ProcessResult result = await processManager.run([ flutterBin, @@ -48,7 +57,7 @@ void main() { 'ios', '--analyze-size', '--no-codesign', - ], workingDirectory: woringDirectory); + ], workingDirectory: workingDirectory); print(result.stdout); print(result.stderr); @@ -59,7 +68,15 @@ void main() { .firstWhere((String line) => line.contains(iosDebugMessage)); final String outputFilePath = line.split(iosDebugMessage).last.trim(); - expect(fileSystem.file(fileSystem.path.join(woringDirectory, outputFilePath)), exists); + expect(fileSystem.file(fileSystem.path.join(workingDirectory, outputFilePath)), exists); + + final String devToolsCommand = result.stdout.toString() + .split('\n') + .firstWhere((String line) => line.contains(runDevToolsMessage)); + final String commandArguments = devToolsCommand.split(runDevToolsMessage).last.trim(); + final String relativeAppSizePath = outputFilePath.split('.flutter-devtools/').last.trim(); + expect(commandArguments.contains('--appSizeBase=$relativeAppSizePath'), isTrue); + expect(result.exitCode, 0); }, skip: true); // Extremely flaky due to https://github.com/flutter/flutter/issues/68144