Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -26,8 +26,8 @@ const String kPlatformIntegrationPackageName = 'platform_integration';
|
||||
/// Additional package dependencies that we want to have in the docs,
|
||||
/// but not actually depend on them.
|
||||
const Map<String, (String path, String version)> kFakeDependencies = <String, (String, String)>{
|
||||
'flutter_gpu': ('flutter_gpu/gpu.dart', '\n sdk: flutter'),
|
||||
};
|
||||
'flutter_gpu': ('flutter_gpu/gpu.dart', '\n sdk: flutter'),
|
||||
};
|
||||
|
||||
class PlatformDocsSection {
|
||||
const PlatformDocsSection({
|
||||
@@ -102,7 +102,11 @@ Future<void> main(List<String> arguments) async {
|
||||
// The place to find customization files and configuration files for docs
|
||||
// generation.
|
||||
final Directory docsRoot =
|
||||
FlutterInformation.instance.getFlutterRoot().childDirectory('dev').childDirectory('docs').absolute;
|
||||
FlutterInformation.instance
|
||||
.getFlutterRoot()
|
||||
.childDirectory('dev')
|
||||
.childDirectory('docs')
|
||||
.absolute;
|
||||
final ArgParser argParser = _createArgsParser(
|
||||
publishDefault: docsRoot.childDirectory('doc').path,
|
||||
);
|
||||
@@ -133,7 +137,10 @@ Future<void> main(List<String> arguments) async {
|
||||
);
|
||||
configurator.generateConfiguration();
|
||||
|
||||
final PlatformDocGenerator platformGenerator = PlatformDocGenerator(outputDir: publishRoot, filesystem: filesystem);
|
||||
final PlatformDocGenerator platformGenerator = PlatformDocGenerator(
|
||||
outputDir: publishRoot,
|
||||
filesystem: filesystem,
|
||||
);
|
||||
await platformGenerator.generatePlatformDocs();
|
||||
|
||||
final DartdocGenerator dartdocGenerator = DartdocGenerator(
|
||||
@@ -154,14 +161,27 @@ Future<void> main(List<String> arguments) async {
|
||||
ArgParser _createArgsParser({required String publishDefault}) {
|
||||
final ArgParser parser = ArgParser();
|
||||
parser.addFlag('help', abbr: 'h', negatable: false, help: 'Show command help.');
|
||||
parser.addFlag('verbose',
|
||||
defaultsTo: true,
|
||||
help: 'Whether to report all error messages (on) or attempt to '
|
||||
'filter out some known false positives (off). Shut this off '
|
||||
'locally if you want to address Flutter-specific issues.');
|
||||
parser.addFlag('json', help: 'Display json-formatted output from dartdoc and skip stdout/stderr prefixing.');
|
||||
parser.addFlag('validate-links', help: 'Display warnings for broken links generated by dartdoc (slow)');
|
||||
parser.addOption('output-dir', defaultsTo: publishDefault, help: 'Sets the output directory for the documentation.');
|
||||
parser.addFlag(
|
||||
'verbose',
|
||||
defaultsTo: true,
|
||||
help:
|
||||
'Whether to report all error messages (on) or attempt to '
|
||||
'filter out some known false positives (off). Shut this off '
|
||||
'locally if you want to address Flutter-specific issues.',
|
||||
);
|
||||
parser.addFlag(
|
||||
'json',
|
||||
help: 'Display json-formatted output from dartdoc and skip stdout/stderr prefixing.',
|
||||
);
|
||||
parser.addFlag(
|
||||
'validate-links',
|
||||
help: 'Display warnings for broken links generated by dartdoc (slow)',
|
||||
);
|
||||
parser.addOption(
|
||||
'output-dir',
|
||||
defaultsTo: publishDefault,
|
||||
help: 'Sets the output directory for the documentation.',
|
||||
);
|
||||
return parser;
|
||||
}
|
||||
|
||||
@@ -216,13 +236,16 @@ class Configurator {
|
||||
_createPageFooter(packageRoot, version);
|
||||
_copyCustomizations();
|
||||
_createSearchMetadata(
|
||||
docsRoot.childDirectory('lib').childFile('opensearch.xml'), publishRoot.childFile('opensearch.xml'));
|
||||
docsRoot.childDirectory('lib').childFile('opensearch.xml'),
|
||||
publishRoot.childFile('opensearch.xml'),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> generateOfflineAssetsIfNeeded() async {
|
||||
// Only create the offline docs if we're running in a non-presubmit build:
|
||||
// it takes too long otherwise.
|
||||
if (platform.environment.containsKey('LUCI_CI') && (platform.environment['LUCI_PR'] ?? '').isEmpty) {
|
||||
if (platform.environment.containsKey('LUCI_CI') &&
|
||||
(platform.environment['LUCI_PR'] ?? '').isEmpty) {
|
||||
_createOfflineZipFile();
|
||||
await _createDocset();
|
||||
_moveOfflineIntoPlace();
|
||||
@@ -264,8 +287,7 @@ class Configurator {
|
||||
'environment:',
|
||||
" sdk: '>=3.2.0-0 <4.0.0'",
|
||||
'dependencies:',
|
||||
for (final String package in findPackageNames(filesystem))
|
||||
' $package:\n sdk: flutter',
|
||||
for (final String package in findPackageNames(filesystem)) ' $package:\n sdk: flutter',
|
||||
' $kPlatformIntegrationPackageName: 0.0.1',
|
||||
for (final String package in kFakeDependencies.keys)
|
||||
' $package: ${kFakeDependencies[package]!.$2}',
|
||||
@@ -329,12 +351,15 @@ class Configurator {
|
||||
// /foo/../foo/bar/baz won't compare as identical.
|
||||
if (path.canonicalize(source.absolute.path) != path.canonicalize(destination.absolute.path)) {
|
||||
source.copySync(destination.path);
|
||||
print('Copied ${path.canonicalize(source.absolute.path)} to ${path.canonicalize(destination.absolute.path)}');
|
||||
print(
|
||||
'Copied ${path.canonicalize(source.absolute.path)} to ${path.canonicalize(destination.absolute.path)}',
|
||||
);
|
||||
}
|
||||
}
|
||||
final Directory assetsDir = filesystem.directory(publishRoot.childDirectory('assets'));
|
||||
final Directory assetSource = docsRoot.childDirectory('assets');
|
||||
if (path.canonicalize(assetSource.absolute.path) == path.canonicalize(assetsDir.absolute.path)) {
|
||||
if (path.canonicalize(assetSource.absolute.path) ==
|
||||
path.canonicalize(assetsDir.absolute.path)) {
|
||||
// Don't try and copy the directory over itself.
|
||||
return;
|
||||
}
|
||||
@@ -346,7 +371,9 @@ class Configurator {
|
||||
assetSource,
|
||||
assetsDir,
|
||||
onFileCopied: (File src, File dest) {
|
||||
print('Copied ${path.canonicalize(src.absolute.path)} to ${path.canonicalize(dest.absolute.path)}');
|
||||
print(
|
||||
'Copied ${path.canonicalize(src.absolute.path)} to ${path.canonicalize(dest.absolute.path)}',
|
||||
);
|
||||
},
|
||||
filesystem: filesystem,
|
||||
);
|
||||
@@ -378,17 +405,14 @@ class Configurator {
|
||||
// never get to see the logs. Thus, we run it in the background and tail the
|
||||
// logs only if it fails.
|
||||
final ProcessWrapper result = ProcessWrapper(
|
||||
await processManager.start(
|
||||
<String>[
|
||||
'dashing',
|
||||
'build',
|
||||
'--source',
|
||||
publishRoot.path,
|
||||
'--config',
|
||||
docsRoot.childFile('dashing.json').path,
|
||||
],
|
||||
workingDirectory: packageRoot.path,
|
||||
),
|
||||
await processManager.start(<String>[
|
||||
'dashing',
|
||||
'build',
|
||||
'--source',
|
||||
publishRoot.path,
|
||||
'--config',
|
||||
docsRoot.childFile('dashing.json').path,
|
||||
], workingDirectory: packageRoot.path),
|
||||
);
|
||||
final List<int> buffer = <int>[];
|
||||
result.stdout.listen(buffer.addAll);
|
||||
@@ -404,21 +428,28 @@ class Configurator {
|
||||
buffer.clear();
|
||||
|
||||
// Copy the favicon file to the output directory.
|
||||
final File faviconFile =
|
||||
publishRoot.childDirectory('flutter').childDirectory('static-assets').childFile('favicon.png');
|
||||
final File faviconFile = publishRoot
|
||||
.childDirectory('flutter')
|
||||
.childDirectory('static-assets')
|
||||
.childFile('favicon.png');
|
||||
final File iconFile = packageRoot.childDirectory('flutter.docset').childFile('icon.png');
|
||||
faviconFile
|
||||
..createSync(recursive: true)
|
||||
..copySync(iconFile.path);
|
||||
|
||||
// Post-process the dashing output.
|
||||
final File infoPlist =
|
||||
packageRoot.childDirectory('flutter.docset').childDirectory('Contents').childFile('Info.plist');
|
||||
final File infoPlist = packageRoot
|
||||
.childDirectory('flutter.docset')
|
||||
.childDirectory('Contents')
|
||||
.childFile('Info.plist');
|
||||
String contents = infoPlist.readAsStringSync();
|
||||
|
||||
// Since I didn't want to add the XML package as a dependency just for this,
|
||||
// I just used a regular expression to make this simple change.
|
||||
final RegExp findRe = RegExp(r'(\s*<key>DocSetPlatformFamily</key>\s*<string>)[^<]+(</string>)', multiLine: true);
|
||||
final RegExp findRe = RegExp(
|
||||
r'(\s*<key>DocSetPlatformFamily</key>\s*<string>)[^<]+(</string>)',
|
||||
multiLine: true,
|
||||
);
|
||||
contents = contents.replaceAllMapped(findRe, (Match match) {
|
||||
return '${match.group(1)}dartlang${match.group(2)}';
|
||||
});
|
||||
@@ -427,20 +458,32 @@ class Configurator {
|
||||
if (!offlineDir.existsSync()) {
|
||||
offlineDir.createSync(recursive: true);
|
||||
}
|
||||
tarDirectory(packageRoot, offlineDir.childFile('flutter.docset.tar.gz'), processManager: processManager);
|
||||
tarDirectory(
|
||||
packageRoot,
|
||||
offlineDir.childFile('flutter.docset.tar.gz'),
|
||||
processManager: processManager,
|
||||
);
|
||||
|
||||
// Write the Dash/Zeal XML feed file.
|
||||
final bool isStable = platform.environment['LUCI_BRANCH'] == 'stable';
|
||||
offlineDir.childFile('flutter.xml').writeAsStringSync('<entry>\n'
|
||||
' <version>${FlutterInformation.instance.getFlutterVersion()}</version>\n'
|
||||
' <url>https://${isStable ? '' : 'main-'}api.flutter.dev/offline/flutter.docset.tar.gz</url>\n'
|
||||
'</entry>\n');
|
||||
offlineDir
|
||||
.childFile('flutter.xml')
|
||||
.writeAsStringSync(
|
||||
'<entry>\n'
|
||||
' <version>${FlutterInformation.instance.getFlutterVersion()}</version>\n'
|
||||
' <url>https://${isStable ? '' : 'main-'}api.flutter.dev/offline/flutter.docset.tar.gz</url>\n'
|
||||
'</entry>\n',
|
||||
);
|
||||
}
|
||||
|
||||
// Creates the offline ZIP file containing all of the website HTML files.
|
||||
void _createOfflineZipFile() {
|
||||
print('${DateTime.now().toLocal()}: Creating offline docs archive.');
|
||||
zipDirectory(publishRoot, packageRoot.childFile('flutter.docs.zip'), processManager: processManager);
|
||||
zipDirectory(
|
||||
publishRoot,
|
||||
packageRoot.childFile('flutter.docs.zip'),
|
||||
processManager: processManager,
|
||||
);
|
||||
}
|
||||
|
||||
// Moves the generated offline archives into the publish directory so that
|
||||
@@ -448,7 +491,9 @@ class Configurator {
|
||||
void _moveOfflineIntoPlace() {
|
||||
print('${DateTime.now().toUtc()}: Moving offline docs into place.');
|
||||
final Directory offlineDir = publishRoot.childDirectory('offline')..createSync(recursive: true);
|
||||
packageRoot.childFile('flutter.docs.zip').renameSync(offlineDir.childFile('flutter.docs.zip').path);
|
||||
packageRoot
|
||||
.childFile('flutter.docs.zip')
|
||||
.renameSync(offlineDir.childFile('flutter.docs.zip').path);
|
||||
}
|
||||
|
||||
// Creates a robots.txt file that disallows indexing unless the branch is the
|
||||
@@ -522,13 +567,15 @@ class DartdocGenerator {
|
||||
}
|
||||
|
||||
// Run pub.
|
||||
ProcessWrapper process = ProcessWrapper(await runPubProcess(
|
||||
arguments: <String>['get'],
|
||||
workingDirectory: packageRoot,
|
||||
environment: pubEnvironment,
|
||||
filesystem: filesystem,
|
||||
processManager: processManager,
|
||||
));
|
||||
ProcessWrapper process = ProcessWrapper(
|
||||
await runPubProcess(
|
||||
arguments: <String>['get'],
|
||||
workingDirectory: packageRoot,
|
||||
environment: pubEnvironment,
|
||||
filesystem: filesystem,
|
||||
processManager: processManager,
|
||||
),
|
||||
);
|
||||
printStream(process.stdout, prefix: 'pub:stdout: ');
|
||||
printStream(process.stderr, prefix: 'pub:stderr: ');
|
||||
final int code = await process.done;
|
||||
@@ -540,20 +587,16 @@ class DartdocGenerator {
|
||||
|
||||
// Verify which version of the global activated packages we're using.
|
||||
final ProcessResult versionResults = processManager.runSync(
|
||||
<String>[
|
||||
FlutterInformation.instance.getFlutterBinaryPath().path,
|
||||
'pub',
|
||||
'global',
|
||||
'list',
|
||||
],
|
||||
<String>[FlutterInformation.instance.getFlutterBinaryPath().path, 'pub', 'global', 'list'],
|
||||
workingDirectory: packageRoot.path,
|
||||
environment: pubEnvironment,
|
||||
stdoutEncoding: utf8,
|
||||
);
|
||||
print('');
|
||||
final Iterable<RegExpMatch> versionMatches =
|
||||
RegExp(r'^(?<name>dartdoc) (?<version>[^\s]+)', multiLine: true)
|
||||
.allMatches(versionResults.stdout as String);
|
||||
final Iterable<RegExpMatch> versionMatches = RegExp(
|
||||
r'^(?<name>dartdoc) (?<version>[^\s]+)',
|
||||
multiLine: true,
|
||||
).allMatches(versionResults.stdout as String);
|
||||
for (final RegExpMatch match in versionMatches) {
|
||||
print('${match.namedGroup('name')} version: ${match.namedGroup('version')}');
|
||||
}
|
||||
@@ -658,17 +701,21 @@ class DartdocGenerator {
|
||||
];
|
||||
|
||||
String quote(String arg) => arg.contains(' ') ? "'$arg'" : arg;
|
||||
print('Executing: (cd "${packageRoot.path}" ; '
|
||||
'${FlutterInformation.instance.getFlutterBinaryPath().path} '
|
||||
'pub '
|
||||
'${dartdocArgs.map<String>(quote).join(' ')})');
|
||||
print(
|
||||
'Executing: (cd "${packageRoot.path}" ; '
|
||||
'${FlutterInformation.instance.getFlutterBinaryPath().path} '
|
||||
'pub '
|
||||
'${dartdocArgs.map<String>(quote).join(' ')})',
|
||||
);
|
||||
|
||||
process = ProcessWrapper(await runPubProcess(
|
||||
arguments: dartdocArgs,
|
||||
workingDirectory: packageRoot,
|
||||
environment: pubEnvironment,
|
||||
processManager: processManager,
|
||||
));
|
||||
process = ProcessWrapper(
|
||||
await runPubProcess(
|
||||
arguments: dartdocArgs,
|
||||
workingDirectory: packageRoot,
|
||||
environment: pubEnvironment,
|
||||
processManager: processManager,
|
||||
),
|
||||
);
|
||||
printStream(
|
||||
process.stdout,
|
||||
prefix: useJson ? '' : 'dartdoc:stdout: ',
|
||||
@@ -711,7 +758,8 @@ class DartdocGenerator {
|
||||
}
|
||||
} else {
|
||||
throw Exception(
|
||||
"Missing example code sanity test file ${file.path}. Either it didn't get published, or you might have to update the test to look at a different file.");
|
||||
"Missing example code sanity test file ${file.path}. Either it didn't get published, or you might have to update the test to look at a different file.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,15 +773,19 @@ class DartdocGenerator {
|
||||
publishRoot.childDirectory('assets').childFile('overrides.css'),
|
||||
flutterDirectory.childDirectory('dart-io').childFile('File-class.html'),
|
||||
flutterDirectory.childDirectory('dart-ui').childFile('Canvas-class.html'),
|
||||
flutterDirectory.childDirectory('dart-ui').childDirectory('Canvas').childFile('drawRect.html'),
|
||||
flutterDirectory
|
||||
.childDirectory('dart-ui')
|
||||
.childDirectory('Canvas')
|
||||
.childFile('drawRect.html'),
|
||||
flutterDirectory
|
||||
.childDirectory('flutter_driver')
|
||||
.childDirectory('FlutterDriver')
|
||||
.childFile('FlutterDriver.connectedTo.html'),
|
||||
flutterDirectory.childDirectory('flutter_gpu').childFile('flutter_gpu-library.html'),
|
||||
flutterDirectory
|
||||
.childDirectory('flutter_gpu')
|
||||
.childFile('flutter_gpu-library.html'),
|
||||
flutterDirectory.childDirectory('flutter_test').childDirectory('WidgetTester').childFile('pumpWidget.html'),
|
||||
.childDirectory('flutter_test')
|
||||
.childDirectory('WidgetTester')
|
||||
.childFile('pumpWidget.html'),
|
||||
flutterDirectory.childDirectory('material').childFile('Material-class.html'),
|
||||
flutterDirectory.childDirectory('material').childFile('Tooltip-class.html'),
|
||||
widgetsDirectory.childFile('Widget-class.html'),
|
||||
@@ -745,7 +797,9 @@ class DartdocGenerator {
|
||||
void _sanityCheckDocs([Platform platform = const LocalPlatform()]) {
|
||||
for (final File canary in canaries) {
|
||||
if (!canary.existsSync()) {
|
||||
throw Exception('Missing "${canary.path}", which probably means the documentation failed to build correctly.');
|
||||
throw Exception(
|
||||
'Missing "${canary.path}", which probably means the documentation failed to build correctly.',
|
||||
);
|
||||
}
|
||||
}
|
||||
// Make sure at least one example of each kind includes source code.
|
||||
@@ -801,7 +855,10 @@ class DartdocGenerator {
|
||||
}
|
||||
|
||||
void _copyIndexToRootOfDocs() {
|
||||
publishRoot.childDirectory('flutter').childFile('index.html').copySync(publishRoot.childFile('index.html').path);
|
||||
publishRoot
|
||||
.childDirectory('flutter')
|
||||
.childFile('index.html')
|
||||
.copySync(publishRoot.childFile('index.html').path);
|
||||
}
|
||||
|
||||
void _changePackageToSdkInTitlebar() {
|
||||
@@ -844,8 +901,9 @@ class DartdocGenerator {
|
||||
final Directory snippetsDir = publishRoot.childDirectory('snippets');
|
||||
if (snippetsDir.existsSync()) {
|
||||
const JsonEncoder jsonEncoder = JsonEncoder.withIndent(' ');
|
||||
final Iterable<File> files =
|
||||
snippetsDir.listSync().whereType<File>().where((File file) => path.extension(file.path) == '.json');
|
||||
final Iterable<File> files = snippetsDir.listSync().whereType<File>().where(
|
||||
(File file) => path.extension(file.path) == '.json',
|
||||
);
|
||||
// Combine all the metadata into a single JSON array.
|
||||
final Iterable<String> fileContents = files.map((File file) => file.readAsStringSync());
|
||||
final List<dynamic> metadataObjects = fileContents.map<dynamic>(json.decode).toList();
|
||||
@@ -896,13 +954,20 @@ class PlatformDocGenerator {
|
||||
|
||||
// On failure print a short snipped from the body in case it's helpful.
|
||||
final int bodyLength = math.min(1024, response.body.length);
|
||||
stderr.writeln('Response status code ${response.statusCode}. Body: ${response.body.substring(0, bodyLength)}');
|
||||
stderr.writeln(
|
||||
'Response status code ${response.statusCode}. Body: ${response.body.substring(0, bodyLength)}',
|
||||
);
|
||||
sleep(const Duration(seconds: 1));
|
||||
}
|
||||
return responseBytes == null ? null : ZipDecoder().decodeBytes(responseBytes);
|
||||
}
|
||||
|
||||
Future<void> _extractDocs(String url, String name, PlatformDocsSection platform, Directory outputDir) async {
|
||||
Future<void> _extractDocs(
|
||||
String url,
|
||||
String name,
|
||||
PlatformDocsSection platform,
|
||||
Directory outputDir,
|
||||
) async {
|
||||
const int maxTries = 5;
|
||||
final Archive? archive = await _fetchArchive(url, maxTries);
|
||||
if (archive == null) {
|
||||
@@ -935,8 +1000,12 @@ class PlatformDocGenerator {
|
||||
/// specified, for each source/destination file pair.
|
||||
///
|
||||
/// Creates `destDir` if needed.
|
||||
void copyDirectorySync(Directory srcDir, Directory destDir,
|
||||
{void Function(File srcFile, File destFile)? onFileCopied, required FileSystem filesystem}) {
|
||||
void copyDirectorySync(
|
||||
Directory srcDir,
|
||||
Directory destDir, {
|
||||
void Function(File srcFile, File destFile)? onFileCopied,
|
||||
required FileSystem filesystem,
|
||||
}) {
|
||||
if (!srcDir.existsSync()) {
|
||||
throw Exception('Source directory "${srcDir.path}" does not exist, nothing to copy');
|
||||
}
|
||||
@@ -959,8 +1028,14 @@ void copyDirectorySync(Directory srcDir, Directory destDir,
|
||||
}
|
||||
}
|
||||
|
||||
void printStream(Stream<List<int>> stream, {String prefix = '', List<Pattern> filter = const <Pattern>[]}) {
|
||||
stream.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen((String line) {
|
||||
void printStream(
|
||||
Stream<List<int>> stream, {
|
||||
String prefix = '',
|
||||
List<Pattern> filter = const <Pattern>[],
|
||||
}) {
|
||||
stream.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen((
|
||||
String line,
|
||||
) {
|
||||
if (!filter.any((Pattern pattern) => line.contains(pattern))) {
|
||||
print('$prefix$line'.trim());
|
||||
}
|
||||
@@ -970,17 +1045,14 @@ void printStream(Stream<List<int>> stream, {String prefix = '', List<Pattern> fi
|
||||
void zipDirectory(Directory src, File output, {required ProcessManager processManager}) {
|
||||
// We would use the archive package to do this in one line, but it
|
||||
// is a lot slower, and doesn't do compression nearly as well.
|
||||
final ProcessResult zipProcess = processManager.runSync(
|
||||
<String>[
|
||||
'zip',
|
||||
'-r',
|
||||
'-9',
|
||||
'-q',
|
||||
output.path,
|
||||
'.',
|
||||
],
|
||||
workingDirectory: src.path,
|
||||
);
|
||||
final ProcessResult zipProcess = processManager.runSync(<String>[
|
||||
'zip',
|
||||
'-r',
|
||||
'-9',
|
||||
'-q',
|
||||
output.path,
|
||||
'.',
|
||||
], workingDirectory: src.path);
|
||||
|
||||
if (zipProcess.exitCode != 0) {
|
||||
print('Creating offline ZIP archive ${output.path} failed:');
|
||||
@@ -992,17 +1064,14 @@ void zipDirectory(Directory src, File output, {required ProcessManager processMa
|
||||
void tarDirectory(Directory src, File output, {required ProcessManager processManager}) {
|
||||
// We would use the archive package to do this in one line, but it
|
||||
// is a lot slower, and doesn't do compression nearly as well.
|
||||
final ProcessResult tarProcess = processManager.runSync(
|
||||
<String>[
|
||||
'tar',
|
||||
'cf',
|
||||
output.path,
|
||||
'--use-compress-program',
|
||||
'gzip --best',
|
||||
'flutter.docset',
|
||||
],
|
||||
workingDirectory: src.path,
|
||||
);
|
||||
final ProcessResult tarProcess = processManager.runSync(<String>[
|
||||
'tar',
|
||||
'cf',
|
||||
output.path,
|
||||
'--use-compress-program',
|
||||
'gzip --best',
|
||||
'flutter.docset',
|
||||
], workingDirectory: src.path);
|
||||
|
||||
if (tarProcess.exitCode != 0) {
|
||||
print('Creating a tarball ${output.path} failed:');
|
||||
@@ -1026,7 +1095,9 @@ Future<Process> runPubProcess({
|
||||
}
|
||||
|
||||
List<String> findPackageNames(FileSystem filesystem) {
|
||||
return findPackages(filesystem).map<String>((FileSystemEntity file) => path.basename(file.path)).toList();
|
||||
return findPackages(
|
||||
filesystem,
|
||||
).map<String>((FileSystemEntity file) => path.basename(file.path)).toList();
|
||||
}
|
||||
|
||||
/// Finds all packages in the Flutter SDK
|
||||
@@ -1141,42 +1212,50 @@ class FlutterInformation {
|
||||
// that flutter command, otherwise use the first one in the PATH.
|
||||
String flutterCommand;
|
||||
if (platform.environment['FLUTTER_ROOT'] != null) {
|
||||
flutterCommand = filesystem
|
||||
.directory(platform.environment['FLUTTER_ROOT'])
|
||||
.childDirectory('bin')
|
||||
.childFile('flutter')
|
||||
.absolute
|
||||
.path;
|
||||
flutterCommand =
|
||||
filesystem
|
||||
.directory(platform.environment['FLUTTER_ROOT'])
|
||||
.childDirectory('bin')
|
||||
.childFile('flutter')
|
||||
.absolute
|
||||
.path;
|
||||
} else {
|
||||
flutterCommand = 'flutter';
|
||||
}
|
||||
ProcessResult result;
|
||||
try {
|
||||
result = processManager.runSync(
|
||||
<String>[flutterCommand, '--version', '--machine'],
|
||||
stdoutEncoding: utf8,
|
||||
);
|
||||
result = processManager.runSync(<String>[
|
||||
flutterCommand,
|
||||
'--version',
|
||||
'--machine',
|
||||
], stdoutEncoding: utf8);
|
||||
} on ProcessException catch (e) {
|
||||
throw FlutterInformationException(
|
||||
'Unable to determine Flutter information. Either set FLUTTER_ROOT, or place the '
|
||||
'flutter command in your PATH.\n$e');
|
||||
'Unable to determine Flutter information. Either set FLUTTER_ROOT, or place the '
|
||||
'flutter command in your PATH.\n$e',
|
||||
);
|
||||
}
|
||||
if (result.exitCode != 0) {
|
||||
throw FlutterInformationException(
|
||||
'Unable to determine Flutter information, because of abnormal exit of flutter command.');
|
||||
'Unable to determine Flutter information, because of abnormal exit of flutter command.',
|
||||
);
|
||||
}
|
||||
// Strip out any non-JSON that might be printed along with the command
|
||||
// output.
|
||||
flutterVersionJson = (result.stdout as String)
|
||||
.replaceAll('Waiting for another flutter command to release the startup lock...', '');
|
||||
flutterVersionJson = (result.stdout as String).replaceAll(
|
||||
'Waiting for another flutter command to release the startup lock...',
|
||||
'',
|
||||
);
|
||||
}
|
||||
|
||||
final Map<String, dynamic> flutterVersion = json.decode(flutterVersionJson) as Map<String, dynamic>;
|
||||
final Map<String, dynamic> flutterVersion =
|
||||
json.decode(flutterVersionJson) as Map<String, dynamic>;
|
||||
if (flutterVersion['flutterRoot'] == null ||
|
||||
flutterVersion['frameworkVersion'] == null ||
|
||||
flutterVersion['dartSdkVersion'] == null) {
|
||||
throw FlutterInformationException(
|
||||
'Flutter command output has unexpected format, unable to determine flutter root location.');
|
||||
'Flutter command output has unexpected format, unable to determine flutter root location.',
|
||||
);
|
||||
}
|
||||
|
||||
final Map<String, Object> info = <String, Object>{};
|
||||
@@ -1184,17 +1263,23 @@ class FlutterInformation {
|
||||
info['flutterRoot'] = flutterRoot;
|
||||
info['frameworkVersion'] = Version.parse(flutterVersion['frameworkVersion'] as String);
|
||||
info['engineRevision'] = flutterVersion['engineRevision'] as String;
|
||||
final File engineRealm = flutterRoot.childDirectory('bin').childDirectory('internal').childFile('engine.realm');
|
||||
final File engineRealm = flutterRoot
|
||||
.childDirectory('bin')
|
||||
.childDirectory('internal')
|
||||
.childFile('engine.realm');
|
||||
info['engineRealm'] = engineRealm.existsSync() ? engineRealm.readAsStringSync().trim() : '';
|
||||
|
||||
final RegExpMatch? dartVersionRegex = RegExp(r'(?<base>[\d.]+)(?:\s+\(build (?<detail>[-.\w]+)\))?')
|
||||
.firstMatch(flutterVersion['dartSdkVersion'] as String);
|
||||
final RegExpMatch? dartVersionRegex = RegExp(
|
||||
r'(?<base>[\d.]+)(?:\s+\(build (?<detail>[-.\w]+)\))?',
|
||||
).firstMatch(flutterVersion['dartSdkVersion'] as String);
|
||||
if (dartVersionRegex == null) {
|
||||
throw FlutterInformationException(
|
||||
'Flutter command output has unexpected format, unable to parse dart SDK version ${flutterVersion['dartSdkVersion']}.');
|
||||
'Flutter command output has unexpected format, unable to parse dart SDK version ${flutterVersion['dartSdkVersion']}.',
|
||||
);
|
||||
}
|
||||
info['dartSdkVersion'] =
|
||||
Version.parse(dartVersionRegex.namedGroup('detail') ?? dartVersionRegex.namedGroup('base')!);
|
||||
info['dartSdkVersion'] = Version.parse(
|
||||
dartVersionRegex.namedGroup('detail') ?? dartVersionRegex.namedGroup('base')!,
|
||||
);
|
||||
|
||||
info['branchName'] = _getBranchName();
|
||||
info['flutterGitRevision'] = _getFlutterGitRevision();
|
||||
@@ -1212,13 +1297,19 @@ class FlutterInformation {
|
||||
if (luciBranch != null && luciBranch.trim().isNotEmpty) {
|
||||
return luciBranch.trim();
|
||||
}
|
||||
final ProcessResult gitResult = processManager.runSync(<String>['git', 'status', '-b', '--porcelain']);
|
||||
final ProcessResult gitResult = processManager.runSync(<String>[
|
||||
'git',
|
||||
'status',
|
||||
'-b',
|
||||
'--porcelain',
|
||||
]);
|
||||
if (gitResult.exitCode != 0) {
|
||||
throw 'git status exit with non-zero exit code: ${gitResult.exitCode}';
|
||||
}
|
||||
final RegExp gitBranchRegexp = RegExp(r'^## (.*)');
|
||||
final RegExpMatch? gitBranchMatch =
|
||||
gitBranchRegexp.firstMatch((gitResult.stdout as String).trim().split('\n').first);
|
||||
final RegExpMatch? gitBranchMatch = gitBranchRegexp.firstMatch(
|
||||
(gitResult.stdout as String).trim().split('\n').first,
|
||||
);
|
||||
return gitBranchMatch == null ? '' : gitBranchMatch.group(1)!.split('...').first;
|
||||
}
|
||||
|
||||
@@ -1232,6 +1323,8 @@ class FlutterInformation {
|
||||
}
|
||||
final String gitRevision = (gitResult.stdout as String).trim();
|
||||
|
||||
return gitRevision.length > kGitRevisionLength ? gitRevision.substring(0, kGitRevisionLength) : gitRevision;
|
||||
return gitRevision.length > kGitRevisionLength
|
||||
? gitRevision.substring(0, kGitRevisionLength)
|
||||
: gitRevision;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user