diff --git a/engine/src/flutter/ci/bin/format.dart b/engine/src/flutter/ci/bin/format.dart index b606729045..093900067f 100644 --- a/engine/src/flutter/ci/bin/format.dart +++ b/engine/src/flutter/ci/bin/format.dart @@ -6,8 +6,10 @@ // // Run with --help for usage. +// TODO(gspencergoog): Support clang formatting on Windows. +// TODO(gspencergoog): Support Java formatting on Windows. + import 'dart:io'; -import 'dart:math'; import 'package:args/args.dart'; import 'package:meta/meta.dart'; @@ -82,7 +84,13 @@ String formatCheckToName(FormatCheck check) { } List formatCheckNames() { - return FormatCheck.values + List allowed; + if (!Platform.isWindows) { + allowed = FormatCheck.values; + } else { + allowed = [FormatCheck.gn, FormatCheck.whitespace]; + } + return allowed .map((FormatCheck check) => check.toString().replaceFirst('$FormatCheck.', '')) .toList(); } @@ -206,13 +214,7 @@ abstract class FormatChecker { @protected Stream> codeUnitsAsStream(List? input) async* { if (input != null) { - int pos = 0; - while (input.length > pos) { - // On Windows large pages seem to be truncated - final int len = min(input.length - pos, 512); - yield input.getRange(pos, pos + len).toList(growable: false); - pos += len; - } + yield input; } } @@ -322,8 +324,6 @@ class ClangFormatChecker extends FormatChecker { clangOs = 'linux-x64'; } else if (Platform.isMacOS) { clangOs = 'mac-x64'; - } else if (Platform.isWindows) { - clangOs = 'windows-x64'; } else { throw FormattingException( "Unknown operating system: don't know how to run clang-format here."); @@ -400,25 +400,8 @@ class ClangFormatChecker extends FormatChecker { await for (final WorkerJob completedJob in completedClangFormats) { if (completedJob.result.exitCode == 0) { diffJobs.add( - WorkerJob([ - 'git', - 'diff', - '--no-index', - '-U0', - '--no-color', - '--', - completedJob.command.last, - '-' - ], stdinRaw: codeUnitsAsStream(completedJob.result.stdoutRaw), - failOk: true - ), - ); - } else { - final String formatterCommand = completedJob.command.join(' '); - error( - 'Formatter command \'$formatterCommand\' failed with exit code ' - '${completedJob.result.exitCode}. Command output follows:\n\n' - '${completedJob.result.output}' + WorkerJob(['diff', '-u', completedJob.command.last, '-'], + stdinRaw: codeUnitsAsStream(completedJob.result.stdoutRaw), failOk: true), ); } } @@ -557,33 +540,17 @@ class JavaFormatChecker extends FormatChecker { processRunner: _processRunner, printReport: namedReport('Java format'), ); - final Stream completedJavaFormats = formatPool.startWorkers(formatJobs); + final Stream completedClangFormats = formatPool.startWorkers(formatJobs); final List diffJobs = []; - await for (final WorkerJob completedJob in completedJavaFormats) { + await for (final WorkerJob completedJob in completedClangFormats) { if (completedJob.result.exitCode == 0) { diffJobs.add( WorkerJob( - [ - 'git', - 'diff', - '--no-index', - '-U0', - '--no-color', - '--', - completedJob.command.last, - '-' - ], + ['diff', '-u', completedJob.command.last, '-'], stdinRaw: codeUnitsAsStream(completedJob.result.stdoutRaw), failOk: true, ), ); - } else { - final String formatterCommand = completedJob.command.join(' '); - error( - 'Formatter command \'$formatterCommand\' failed with exit code ' - '${completedJob.result.exitCode}. Command output follows:\n\n' - '${completedJob.result.output}' - ); } } final ProcessPool diffPool = ProcessPool( @@ -670,88 +637,45 @@ class GnFormatChecker extends FormatChecker { final List cmd = [ gnBinary.path, 'format', - if (!fixing) '--stdin', + if (!fixing) '--dry-run', ]; - final List jobs = []; + final List jobs = []; for (final String file in filesToCheck) { - if (!fixing) { - final WorkerJob job = WorkerJob( - cmd, - stdinRaw: codeUnitsAsStream(File(path.join(repoDir.absolute.path, file)).readAsBytesSync()), - failOk: true, - name: [...cmd, file].join(' '), - ); - jobs.add(job); - } else { - jobs.add(WorkerJob([...cmd, file], name: [...cmd, file].join(' '))); - } + jobs.add(WorkerJob([...cmd, file])); } final ProcessPool gnPool = ProcessPool( processRunner: _processRunner, printReport: namedReport('gn format'), ); - final Stream completedJobs = gnPool.startWorkers(jobs); - final List diffJobs = []; - await for (final WorkerJob completedJob in completedJobs) { - if (completedJob.result.exitCode == 0) { - diffJobs.add( - WorkerJob( - [ - 'git', - 'diff', - '--no-index', - '-U0', - '--no-color', - '--', - completedJob.name.split(' ').last, - '-' - ], - stdinRaw: codeUnitsAsStream(completedJob.result.stdoutRaw), - failOk: true, - ), - ); - } else { - final String formatterCommand = completedJob.command.join(' '); - error( - 'Formatter command \'$formatterCommand\' failed with exit code ' - '${completedJob.result.exitCode}. Command output follows:\n\n' - '${completedJob.result.output}' + final List completedJobs = await gnPool.runToCompletion(jobs); + reportDone(); + final List incorrect = []; + for (final WorkerJob job in completedJobs) { + if (job.result.exitCode == 2) { + incorrect.add(' ${job.command.last}'); + } + if (job.result.exitCode == 1) { + // GN has exit code 1 if it had some problem formatting/checking the + // file. + throw FormattingException( + 'Unable to format ${job.command.last}:\n${job.result.output}', ); } } - final ProcessPool diffPool = ProcessPool( - processRunner: _processRunner, - printReport: namedReport('diff'), - ); - final List completedDiffs = await diffPool.runToCompletion(diffJobs); - final Iterable failed = completedDiffs.where((WorkerJob job) { - return job.result.exitCode != 0; - }); - reportDone(); - if (failed.isNotEmpty) { - final bool plural = failed.length > 1; + if (incorrect.isNotEmpty) { + final bool plural = incorrect.length > 1; if (fixing) { - message('Fixed ${failed.length} GN file${plural ? 's' : ''}' + message('Fixed ${incorrect.length} GN file${plural ? 's' : ''}' ' which ${plural ? 'were' : 'was'} formatted incorrectly.'); } else { - error('Found ${failed.length} GN file${plural ? 's' : ''}' - ' which ${plural ? 'were' : 'was'} formatted incorrectly.'); - stdout.writeln('To fix, run:'); - stdout.writeln(); - stdout.writeln('patch -p0 < main(List arguments) async { allowed: formatCheckNames(), defaultsTo: formatCheckNames(), help: 'Specifies which checks will be performed. Defaults to all checks. ' - 'May be specified more than once to perform multiple types of checks. '); + 'May be specified more than once to perform multiple types of checks. ' + 'On Windows, only whitespace and gn checks are currently supported.'); parser.addFlag('verbose', help: 'Print verbose output.', defaultsTo: verbose); late final ArgResults options; diff --git a/engine/src/flutter/ci/format.bat b/engine/src/flutter/ci/format.bat index 35451118bc..d82d64cec0 100644 --- a/engine/src/flutter/ci/format.bat +++ b/engine/src/flutter/ci/format.bat @@ -28,4 +28,5 @@ cd "%ci_dir%" REM Do not use the CALL command in the next line to execute Dart. CALL causes REM Windows to re-read the line from disk after the CALL command has finished REM regardless of the ampersand chain. -"%dart%" --disable-dart-dev bin\format.dart %* & exit /B !ERRORLEVEL! +REM TODO(gspencergoog): Remove --no-sound-null-safety once isolate package is null-safe. +"%dart%" --no-sound-null-safety --disable-dart-dev bin\format.dart %* & exit /B !ERRORLEVEL! diff --git a/engine/src/flutter/ci/format.sh b/engine/src/flutter/ci/format.sh index 0425eb380e..50475df4df 100755 --- a/engine/src/flutter/ci/format.sh +++ b/engine/src/flutter/ci/format.sh @@ -32,8 +32,10 @@ SRC_DIR="$(cd "$SCRIPT_DIR/../.."; pwd -P)" DART_SDK_DIR="${SRC_DIR}/third_party/dart/tools/sdks/dart-sdk" DART="${DART_SDK_DIR}/bin/dart" +# TODO(gspencergoog): Remove --no-sound-null-safety once isolate package is null-safe. cd "$SCRIPT_DIR" "$DART" \ --disable-dart-dev \ + --no-sound-null-safety \ bin/format.dart \ "$@" diff --git a/engine/src/flutter/tools/clang_tidy/lib/src/command.dart b/engine/src/flutter/tools/clang_tidy/lib/src/command.dart index 64100c32f4..1bc87d07be 100644 --- a/engine/src/flutter/tools/clang_tidy/lib/src/command.dart +++ b/engine/src/flutter/tools/clang_tidy/lib/src/command.dart @@ -55,7 +55,6 @@ class Command { static final RegExp _pathRegex = RegExp(r'\S*clang/bin/clang'); static final RegExp _argRegex = RegExp(r'-MF \S*'); - static final RegExp _windowsRspRegex = RegExp(r'@ (\S*)'); String? _tidyArgs; @@ -64,15 +63,6 @@ class Command { return _tidyArgs ??= (() { String result = command; result = result.replaceAll(_pathRegex, ''); - if (io.Platform.isWindows) { - final io.File rsp = io.File(path.join( - directory.path, - _windowsRspRegex.firstMatch(command)?.group(1) ?? '', - )); - if (rsp.existsSync()) { - result = rsp.readAsStringSync().replaceAll('/std:', '-std='); - } - } result = result.replaceAll(_argRegex, ''); return result; })(); @@ -82,20 +72,10 @@ class Command { /// The command but with clang-tidy instead of clang. String get tidyPath { - String clangTidy() { - String clangTidy = _pathRegex.stringMatch(command)?.replaceAll( - 'clang/bin/clang', - 'clang/bin/clang-tidy', - ) ?? ''; - if (io.Platform.isWindows) { - // On Windows [Process].run() sets the working dir after executing the process - clangTidy = path.join(directory.path, clangTidy); - } - - return clangTidy; - } - - return _tidyPath ??= clangTidy(); + return _tidyPath ??= _pathRegex.stringMatch(command)?.replaceAll( + 'clang/bin/clang', + 'clang/bin/clang-tidy', + ) ?? ''; } /// Whether this command operates on any of the files in `queries`. diff --git a/engine/src/flutter/tools/githooks/windows/pre-push b/engine/src/flutter/tools/githooks/windows/pre-push new file mode 100644 index 0000000000..aa363e3cdf --- /dev/null +++ b/engine/src/flutter/tools/githooks/windows/pre-push @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +RED='' +NC='' +BOLD='' +echo "${BOLD}${RED}Warning:${NC} ${BOLD}Pre-push checks not supported on Windows${NC}" +echo "${BOLD}See: https://github.com/flutter/flutter/issues/86506${NC}" diff --git a/engine/src/flutter/tools/yapf.bat b/engine/src/flutter/tools/yapf.bat deleted file mode 100644 index 5ff4ad3ed7..0000000000 --- a/engine/src/flutter/tools/yapf.bat +++ /dev/null @@ -1,16 +0,0 @@ -@ECHO off -REM Copyright 2013 The Flutter Authors. All rights reserved. -REM Use of this source code is governed by a BSD-style license that can be -REM found in the LICENSE file. - -REM ---------------------------------- NOTE ---------------------------------- -REM -REM Please keep the logic in this file consistent with the logic in the -REM `yapf.sh` script in the same directory to ensure that it continues to -REM work across all platforms! -REM -REM -------------------------------------------------------------------------- - -SET yapf_path=%~dp0\..\..\third_party\yapf - -cmd /V /C "SET PYTHONPATH=%yapf_path%&& python3 %yapf_path%\yapf %*" diff --git a/engine/src/flutter/tools/yapf.sh b/engine/src/flutter/tools/yapf.sh index c3cbd5587e..af6e7021dd 100755 --- a/engine/src/flutter/tools/yapf.sh +++ b/engine/src/flutter/tools/yapf.sh @@ -3,14 +3,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# ---------------------------------- NOTE ---------------------------------- -# -# Please keep the logic in this file consistent with the logic in the -# `yapf.bat` script in the same directory to ensure that it continues to -# work across all platforms! -# -# -------------------------------------------------------------------------- - # Generates objc docs for Flutter iOS libraries. set -e