From 0a5e69ae6f31291f1eba516b23ea9388327808ae Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 9 Jul 2020 22:14:48 +0000 Subject: [PATCH] Fix for no inputs in build mode. R=brianwilkerson@google.com Bug: https://buganizer.corp.google.com/issues/160854685 Change-Id: I9dd7f6e6c8293432c39d2d0cdd28bcd06880bf8e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153940 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- pkg/analyzer_cli/lib/src/build_mode.dart | 4 ++ pkg/analyzer_cli/test/driver_test.dart | 55 ++++++++++++++++-------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/pkg/analyzer_cli/lib/src/build_mode.dart b/pkg/analyzer_cli/lib/src/build_mode.dart index f2c6d79b82ad..57b4ef2475fa 100644 --- a/pkg/analyzer_cli/lib/src/build_mode.dart +++ b/pkg/analyzer_cli/lib/src/build_mode.dart @@ -547,6 +547,10 @@ class BuildMode with HasContextMixin { } void _setAnalysisDriverAnalysisContext(String rootPath) { + if (rootPath == null) { + return; + } + var apiContextRoots = api.ContextLocator( resourceProvider: resourceProvider, ).locateRoots( diff --git a/pkg/analyzer_cli/test/driver_test.dart b/pkg/analyzer_cli/test/driver_test.dart index f78dc97061b2..bcb5cec9af86 100644 --- a/pkg/analyzer_cli/test/driver_test.dart +++ b/pkg/analyzer_cli/test/driver_test.dart @@ -38,6 +38,23 @@ void main() { } class AbstractBuildModeTest extends BaseTest { + List get _sdkSummaryArguments { + var sdkPath = path.dirname( + path.dirname( + Platform.resolvedExecutable, + ), + ); + + var dartSdkSummaryPath = path.join( + sdkPath, + 'lib', + '_internal', + 'strong.sum', + ); + + return ['--dart-sdk-summary', dartSdkSummaryPath]; + } + Future _doDrive( String filePath, { String sourceArgument, @@ -54,24 +71,7 @@ class AbstractBuildModeTest extends BaseTest { args.add('--build-mode'); args.add('--format=machine'); - { - var sdkPath = path.dirname( - path.dirname( - Platform.resolvedExecutable, - ), - ); - - var dartSdkSummaryPath = path.join( - sdkPath, - 'lib', - '_internal', - 'strong.sum', - ); - - args.add('--dart-sdk-summary'); - args.add(dartSdkSummaryPath); - } - + args.addAll(_sdkSummaryArguments); args.addAll(additionalArgs); if (sourceArgument == null) { @@ -587,6 +587,25 @@ var b = new B(); expect(exitCode, isNot(0)); } + Future test_noInputs() async { + await withTempDirAsync((tempDir) async { + var outputPath = path.join(tempDir, 'test.sum'); + + await driveMany([], args: [ + '--build-mode', + '--format=machine', + ..._sdkSummaryArguments, + '--build-summary-only', + '--build-summary-output=$outputPath', + ]); + + var output = File(outputPath); + expect(output.existsSync(), isTrue); + + expect(exitCode, 0); + }); + } + Future test_noStatistics() async { await _doDrive(path.join('data', 'test_file.dart')); // Should not print statistics summary.