diff --git a/.cirrus.yml b/.cirrus.yml index 43ee69d5c9516..28ca40e39707d 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -17,6 +17,7 @@ task: # run pub get in all the repo packages ./bin/flutter update-packages + git fetch origin master matrix: - name: docs env: @@ -25,11 +26,15 @@ task: - name: analyze env: SHARD: analyze - test_script: dart ./dev/bots/test.dart + test_script: | + export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD" + dart ./dev/bots/test.dart - name: tests-linux env: SHARD: tests - test_script: dart ./dev/bots/test.dart + test_script: | + export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD" + dart ./dev/bots/test.dart container: cpu: 4 memory: 8G @@ -48,8 +53,10 @@ task: setup_script: - bin\flutter.bat config --no-analytics - bin\flutter.bat update-packages - test_all_script: - - bin\cache\dart-sdk\bin\dart.exe -c dev\bots\test.dart + - git fetch origin master + test_all_script: | + export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD" + bin\cache\dart-sdk\bin\dart.exe -c dev\bots\test.dart task: name: tests-macos @@ -61,6 +68,7 @@ task: setup_script: - bin/flutter config --no-analytics - bin/flutter update-packages - test_all_script: - - ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976 - - bin/cache/dart-sdk/bin/dart -c dev/bots/test.dart + test_all_script: | + ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976 + export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD" + bin/cache/dart-sdk/bin/dart -c dev/bots/test.dart diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 35989af4e3003..e49ba7746279a 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -95,6 +95,41 @@ Future _verifyInternationalizations() async { print('Contents of $localizationsFile matches output of gen_localizations.dart script.'); } +Future _checkForTrailingSpaces() async { + if (!Platform.isWindows) { + final String commitRange = Platform.environment.containsKey('TEST_COMMIT_RANGE') + ? Platform.environment['TEST_COMMIT_RANGE'] + : 'master..HEAD'; + print('Checking for trailing whitespace in source files.'); + final List fileTypes = [ + '*.dart', '*.cxx', '*.cpp', '*.cc', '*.c', '*.C', '*.h', '*.java', '*.mm', '*.m', + ]; + final EvalResult changedFilesResult = await _evalCommand( + 'git', ['diff', '-U0', '--no-color', '--name-only', commitRange, '--'] + fileTypes, + workingDirectory: flutterRoot, + ); + if (changedFilesResult.stdout == null) { + print('No Results for whitespace check.'); + return; + } + final List changedFiles = changedFilesResult.stdout.trim().split('\n') + .where((String item) => item.trim().isNotEmpty).toList(); + if (changedFiles.isNotEmpty) { + await _runCommand('grep', + [ + '--line-number', + '--extended-regexp', + r'[[:space:]]+$', + ] + changedFiles, + workingDirectory: flutterRoot, + printOutput: false, + expectFailure: true, // Just means a non-zero exit code is expected. + expectedExitCode: 1, // Indicates that zero lines were found. + ); + } + } +} + Future _analyzeRepo() async { await _verifyGeneratedPluginRegistrants(flutterRoot); await _verifyNoBadImportsInFlutter(flutterRoot); @@ -123,6 +158,8 @@ Future _analyzeRepo() async { options: ['--flutter-repo', '--watch', '--benchmark'], ); + await _checkForTrailingSpaces(); + // Try an analysis against a big version of the gallery. await _runCommand(dart, ['--preview-dart-2', path.join(flutterRoot, 'dev', 'tools', 'mega_gallery.dart')], @@ -331,6 +368,7 @@ Future _runCommand(String executable, List arguments, { String workingDirectory, Map environment, bool expectFailure = false, + int expectedExitCode, bool printOutput = true, bool skip = false, Duration timeout = _kLongTimeout, @@ -363,7 +401,7 @@ Future _runCommand(String executable, List arguments, { stderr.writeln('Process timed out after $timeout'); return expectFailure ? 0 : 1; }); - if ((exitCode == 0) == expectFailure) { + if ((exitCode == 0) == expectFailure || (expectedExitCode != null && exitCode != expectedExitCode)) { if (!printOutput) { stdout.writeln(utf8.decode((await savedStdout).expand((List ints) => ints).toList())); stderr.writeln(utf8.decode((await savedStderr).expand((List ints) => ints).toList())); diff --git a/dev/bots/travis_script.sh b/dev/bots/travis_script.sh index 355218b10acc3..f85bc3eefc302 100755 --- a/dev/bots/travis_script.sh +++ b/dev/bots/travis_script.sh @@ -59,5 +59,5 @@ elif [ "$SHARD" = "docs" ]; then ./dev/bots/docs.sh fi else - dart ./dev/bots/test.dart + TEST_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE}" dart ./dev/bots/test.dart fi