2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2017-12-15 23:01:30 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-01-10 21:37:36 +00:00
|
|
|
import 'dart:async';
|
2017-12-15 23:01:30 +00:00
|
|
|
import 'dart:convert';
|
2018-02-06 23:32:19 +00:00
|
|
|
import 'dart:io' hide Platform;
|
2018-01-10 21:37:36 +00:00
|
|
|
import 'dart:typed_data';
|
2017-12-15 23:01:30 +00:00
|
|
|
|
|
|
|
import 'package:args/args.dart';
|
2019-02-26 20:02:01 +00:00
|
|
|
import 'package:crypto/crypto.dart';
|
|
|
|
import 'package:crypto/src/digest_sink.dart';
|
2018-01-10 21:37:36 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
2017-12-15 23:01:30 +00:00
|
|
|
import 'package:path/path.dart' as path;
|
2022-07-18 22:04:07 +00:00
|
|
|
import 'package:platform/platform.dart' show LocalPlatform, Platform;
|
2019-02-26 20:02:01 +00:00
|
|
|
import 'package:process/process.dart';
|
2017-12-15 23:01:30 +00:00
|
|
|
|
2022-05-21 05:03:06 +00:00
|
|
|
const String gobMirror =
|
|
|
|
'https://flutter.googlesource.com/mirrors/flutter';
|
2018-02-07 20:21:14 +00:00
|
|
|
const String githubRepo = 'https://github.com/flutter/flutter.git';
|
2021-02-05 01:45:45 +00:00
|
|
|
const String mingitForWindowsUrl = 'https://storage.googleapis.com/flutter_infra_release/mingit/'
|
2018-01-10 21:37:36 +00:00
|
|
|
'603511c649b00bbef0a6122a827ac419b656bc19/mingit.zip';
|
2018-02-07 20:21:14 +00:00
|
|
|
const String releaseFolder = '/releases';
|
2021-05-28 02:04:02 +00:00
|
|
|
const String gsBase = 'gs://flutter_infra_release';
|
|
|
|
const String gsReleaseFolder = '$gsBase$releaseFolder';
|
|
|
|
const String baseUrl = 'https://storage.googleapis.com/flutter_infra_release';
|
2021-03-30 20:15:34 +00:00
|
|
|
const int shortCacheSeconds = 60;
|
2022-01-08 00:30:14 +00:00
|
|
|
const String frameworkVersionTag = 'frameworkVersionFromGit';
|
|
|
|
const String dartVersionTag = 'dartSdkVersion';
|
2022-02-02 17:02:02 +00:00
|
|
|
const String dartTargetArchTag = 'dartTargetArch';
|
2017-12-15 23:01:30 +00:00
|
|
|
|
2018-02-06 23:32:19 +00:00
|
|
|
/// Exception class for when a process fails to run, so we can catch
|
2017-12-15 23:01:30 +00:00
|
|
|
/// it and provide something more readable than a stack trace.
|
2019-03-01 22:38:40 +00:00
|
|
|
class PreparePackageException implements Exception {
|
2020-08-13 15:43:20 +00:00
|
|
|
PreparePackageException(this.message, [this.result]);
|
2017-12-15 23:01:30 +00:00
|
|
|
|
2018-02-06 23:32:19 +00:00
|
|
|
final String message;
|
2021-07-19 20:59:15 +00:00
|
|
|
final ProcessResult? result;
|
2020-08-13 15:43:20 +00:00
|
|
|
int get exitCode => result?.exitCode ?? -1;
|
2017-12-15 23:01:30 +00:00
|
|
|
|
|
|
|
@override
|
2020-08-13 15:43:20 +00:00
|
|
|
String toString() {
|
|
|
|
String output = runtimeType.toString();
|
|
|
|
if (message != null) {
|
|
|
|
output += ': $message';
|
|
|
|
}
|
2021-07-19 20:59:15 +00:00
|
|
|
final String stderr = result?.stderr as String? ?? '';
|
2020-08-13 15:43:20 +00:00
|
|
|
if (stderr.isNotEmpty) {
|
|
|
|
output += ':\n$stderr';
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 13:45:19 +00:00
|
|
|
enum Branch {
|
|
|
|
beta,
|
2022-12-06 19:46:07 +00:00
|
|
|
stable,
|
|
|
|
master,
|
|
|
|
main;
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 15:43:20 +00:00
|
|
|
/// A helper class for classes that want to run a process, optionally have the
|
|
|
|
/// stderr and stdout reported as the process runs, and capture the stdout
|
|
|
|
/// properly without dropping any.
|
|
|
|
class ProcessRunner {
|
|
|
|
ProcessRunner({
|
2021-07-19 20:59:15 +00:00
|
|
|
ProcessManager? processManager,
|
2020-08-13 15:43:20 +00:00
|
|
|
this.subprocessOutput = true,
|
|
|
|
this.defaultWorkingDirectory,
|
|
|
|
this.platform = const LocalPlatform(),
|
|
|
|
}) : processManager = processManager ?? const LocalProcessManager() {
|
|
|
|
environment = Map<String, String>.from(platform.environment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The platform to use for a starting environment.
|
|
|
|
final Platform platform;
|
|
|
|
|
|
|
|
/// Set [subprocessOutput] to show output as processes run. Stdout from the
|
|
|
|
/// process will be printed to stdout, and stderr printed to stderr.
|
|
|
|
final bool subprocessOutput;
|
|
|
|
|
|
|
|
/// Set the [processManager] in order to inject a test instance to perform
|
|
|
|
/// testing.
|
|
|
|
final ProcessManager processManager;
|
|
|
|
|
|
|
|
/// Sets the default directory used when `workingDirectory` is not specified
|
|
|
|
/// to [runProcess].
|
2021-07-19 20:59:15 +00:00
|
|
|
final Directory? defaultWorkingDirectory;
|
2020-08-13 15:43:20 +00:00
|
|
|
|
|
|
|
/// The environment to run processes with.
|
2021-07-19 20:59:15 +00:00
|
|
|
late Map<String, String> environment;
|
2020-08-13 15:43:20 +00:00
|
|
|
|
|
|
|
/// Run the command and arguments in `commandLine` as a sub-process from
|
|
|
|
/// `workingDirectory` if set, or the [defaultWorkingDirectory] if not. Uses
|
|
|
|
/// [Directory.current] if [defaultWorkingDirectory] is not set.
|
|
|
|
///
|
|
|
|
/// Set `failOk` if [runProcess] should not throw an exception when the
|
|
|
|
/// command completes with a non-zero exit code.
|
|
|
|
Future<String> runProcess(
|
|
|
|
List<String> commandLine, {
|
2021-07-19 20:59:15 +00:00
|
|
|
Directory? workingDirectory,
|
2020-08-13 15:43:20 +00:00
|
|
|
bool failOk = false,
|
|
|
|
}) async {
|
|
|
|
workingDirectory ??= defaultWorkingDirectory ?? Directory.current;
|
|
|
|
if (subprocessOutput) {
|
|
|
|
stderr.write('Running "${commandLine.join(' ')}" in ${workingDirectory.path}.\n');
|
|
|
|
}
|
|
|
|
final List<int> output = <int>[];
|
|
|
|
final Completer<void> stdoutComplete = Completer<void>();
|
|
|
|
final Completer<void> stderrComplete = Completer<void>();
|
2021-07-19 20:59:15 +00:00
|
|
|
late Process process;
|
2020-08-13 15:43:20 +00:00
|
|
|
Future<int> allComplete() async {
|
|
|
|
await stderrComplete.future;
|
|
|
|
await stdoutComplete.future;
|
|
|
|
return process.exitCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
process = await processManager.start(
|
|
|
|
commandLine,
|
|
|
|
workingDirectory: workingDirectory.absolute.path,
|
|
|
|
environment: environment,
|
|
|
|
);
|
|
|
|
process.stdout.listen(
|
|
|
|
(List<int> event) {
|
|
|
|
output.addAll(event);
|
|
|
|
if (subprocessOutput) {
|
|
|
|
stdout.add(event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onDone: () async => stdoutComplete.complete(),
|
|
|
|
);
|
|
|
|
if (subprocessOutput) {
|
|
|
|
process.stderr.listen(
|
|
|
|
(List<int> event) {
|
|
|
|
stderr.add(event);
|
|
|
|
},
|
|
|
|
onDone: () async => stderrComplete.complete(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
stderrComplete.complete();
|
|
|
|
}
|
|
|
|
} on ProcessException catch (e) {
|
|
|
|
final String message = 'Running "${commandLine.join(' ')}" in ${workingDirectory.path} '
|
2022-05-06 23:04:13 +00:00
|
|
|
'failed with:\n$e';
|
2020-08-13 15:43:20 +00:00
|
|
|
throw PreparePackageException(message);
|
|
|
|
} on ArgumentError catch (e) {
|
|
|
|
final String message = 'Running "${commandLine.join(' ')}" in ${workingDirectory.path} '
|
2022-05-06 23:04:13 +00:00
|
|
|
'failed with:\n$e';
|
2020-08-13 15:43:20 +00:00
|
|
|
throw PreparePackageException(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
final int exitCode = await allComplete();
|
|
|
|
if (exitCode != 0 && !failOk) {
|
|
|
|
final String message = 'Running "${commandLine.join(' ')}" in ${workingDirectory.path} failed';
|
|
|
|
throw PreparePackageException(
|
|
|
|
message,
|
|
|
|
ProcessResult(0, exitCode, null, 'returned $exitCode'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return utf8.decoder.convert(output).trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-14 19:06:19 +00:00
|
|
|
typedef HttpReader = Future<Uint8List> Function(Uri url, {Map<String, String> headers});
|
2018-02-07 20:21:14 +00:00
|
|
|
|
2017-12-15 23:01:30 +00:00
|
|
|
/// Creates a pre-populated Flutter archive from a git repo.
|
|
|
|
class ArchiveCreator {
|
2022-09-02 04:00:58 +00:00
|
|
|
/// [tempDir] is the directory to use for creating the archive. The script
|
2018-01-10 21:37:36 +00:00
|
|
|
/// will place several GiB of data there, so it should have available space.
|
|
|
|
///
|
|
|
|
/// The processManager argument is used to inject a mock of [ProcessManager] for
|
2017-12-15 23:01:30 +00:00
|
|
|
/// testing purposes.
|
2018-01-10 21:37:36 +00:00
|
|
|
///
|
|
|
|
/// If subprocessOutput is true, then output from processes invoked during
|
|
|
|
/// archive creation is echoed to stderr and stdout.
|
2022-02-02 17:02:02 +00:00
|
|
|
factory ArchiveCreator(
|
|
|
|
Directory tempDir,
|
|
|
|
Directory outputDir,
|
|
|
|
String revision,
|
|
|
|
Branch branch, {
|
|
|
|
bool strict = true,
|
2021-07-19 20:59:15 +00:00
|
|
|
ProcessManager? processManager,
|
2018-06-05 06:50:40 +00:00
|
|
|
bool subprocessOutput = true,
|
2022-02-02 17:02:02 +00:00
|
|
|
Platform platform = const LocalPlatform(),
|
2021-07-19 20:59:15 +00:00
|
|
|
HttpReader? httpReader,
|
2022-02-02 17:02:02 +00:00
|
|
|
}) {
|
|
|
|
final Directory flutterRoot = Directory(path.join(tempDir.path, 'flutter'));
|
|
|
|
final ProcessRunner processRunner = ProcessRunner(
|
|
|
|
processManager: processManager,
|
|
|
|
subprocessOutput: subprocessOutput,
|
|
|
|
platform: platform,
|
|
|
|
)..environment['PUB_CACHE'] = path.join(
|
|
|
|
flutterRoot.absolute.path, '.pub-cache',
|
|
|
|
);
|
|
|
|
final String flutterExecutable = path.join(
|
2018-02-06 23:32:19 +00:00
|
|
|
flutterRoot.absolute.path,
|
2017-12-15 23:01:30 +00:00
|
|
|
'bin',
|
2018-01-10 21:37:36 +00:00
|
|
|
'flutter',
|
2017-12-15 23:01:30 +00:00
|
|
|
);
|
2022-02-02 17:02:02 +00:00
|
|
|
final String dartExecutable = path.join(
|
|
|
|
flutterRoot.absolute.path,
|
|
|
|
'bin',
|
|
|
|
'cache',
|
|
|
|
'dart-sdk',
|
|
|
|
'bin',
|
|
|
|
'dart',
|
|
|
|
);
|
|
|
|
|
|
|
|
return ArchiveCreator._(
|
|
|
|
tempDir: tempDir,
|
|
|
|
platform: platform,
|
|
|
|
flutterRoot: flutterRoot,
|
|
|
|
outputDir: outputDir,
|
|
|
|
revision: revision,
|
|
|
|
branch: branch,
|
|
|
|
strict: strict,
|
|
|
|
processRunner: processRunner,
|
|
|
|
httpReader: httpReader ?? http.readBytes,
|
|
|
|
flutterExecutable: flutterExecutable,
|
|
|
|
dartExecutable: dartExecutable,
|
|
|
|
);
|
2018-01-10 21:37:36 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 17:02:02 +00:00
|
|
|
ArchiveCreator._({
|
|
|
|
required this.tempDir,
|
|
|
|
required this.platform,
|
|
|
|
required this.flutterRoot,
|
|
|
|
required this.outputDir,
|
|
|
|
required this.revision,
|
|
|
|
required this.branch,
|
|
|
|
required this.strict,
|
|
|
|
required ProcessRunner processRunner,
|
|
|
|
required this.httpReader,
|
|
|
|
required String flutterExecutable,
|
|
|
|
required String dartExecutable,
|
|
|
|
}) :
|
|
|
|
assert(revision.length == 40),
|
|
|
|
_processRunner = processRunner,
|
|
|
|
_flutter = flutterExecutable,
|
|
|
|
_dart = dartExecutable;
|
|
|
|
|
2018-02-07 20:21:14 +00:00
|
|
|
/// The platform to use for the environment and determining which
|
|
|
|
/// platform we're running on.
|
2018-02-06 23:32:19 +00:00
|
|
|
final Platform platform;
|
2018-02-07 20:21:14 +00:00
|
|
|
|
2022-09-02 04:00:58 +00:00
|
|
|
/// The branch to build the archive for. The branch must contain [revision].
|
2018-02-06 23:32:19 +00:00
|
|
|
final Branch branch;
|
2018-02-07 20:21:14 +00:00
|
|
|
|
|
|
|
/// The git revision hash to build the archive for. This revision has
|
|
|
|
/// to be available in the [branch], although it doesn't have to be
|
|
|
|
/// at HEAD, since we clone the branch and then reset to this revision
|
|
|
|
/// to create the archive.
|
2018-02-06 23:32:19 +00:00
|
|
|
final String revision;
|
2018-02-07 20:21:14 +00:00
|
|
|
|
|
|
|
/// The flutter root directory in the [tempDir].
|
2018-02-06 23:32:19 +00:00
|
|
|
final Directory flutterRoot;
|
2018-02-07 20:21:14 +00:00
|
|
|
|
|
|
|
/// The temporary directory used to build the archive in.
|
2018-02-06 23:32:19 +00:00
|
|
|
final Directory tempDir;
|
2018-02-07 20:21:14 +00:00
|
|
|
|
|
|
|
/// The directory to write the output file to.
|
2018-02-06 23:32:19 +00:00
|
|
|
final Directory outputDir;
|
2018-02-07 20:21:14 +00:00
|
|
|
|
2019-03-01 22:38:40 +00:00
|
|
|
/// True if the creator should be strict about checking requirements or not.
|
|
|
|
///
|
|
|
|
/// In strict mode, will insist that the [revision] be a tagged revision.
|
|
|
|
final bool strict;
|
|
|
|
|
2018-02-07 20:21:14 +00:00
|
|
|
final Uri _minGitUri = Uri.parse(mingitForWindowsUrl);
|
2018-02-06 23:32:19 +00:00
|
|
|
final ProcessRunner _processRunner;
|
|
|
|
|
2018-02-07 20:21:14 +00:00
|
|
|
/// Used to tell the [ArchiveCreator] which function to use for reading
|
|
|
|
/// bytes from a URL. Used in tests to inject a fake reader. Defaults to
|
|
|
|
/// [http.readBytes].
|
|
|
|
final HttpReader httpReader;
|
|
|
|
|
2022-01-08 00:30:14 +00:00
|
|
|
final Map<String, String> _version = <String, String>{};
|
2021-07-19 20:59:15 +00:00
|
|
|
late String _flutter;
|
2022-02-02 17:02:02 +00:00
|
|
|
late String _dart;
|
|
|
|
|
|
|
|
late final Future<String> _dartArch = (() async {
|
|
|
|
// Parse 'arch' out of a string like '... "os_arch"\n'.
|
|
|
|
return (await _runDart(<String>['--version']))
|
|
|
|
.trim().split(' ').last.replaceAll('"', '').split('_')[1];
|
|
|
|
})();
|
2018-02-06 23:32:19 +00:00
|
|
|
|
2018-01-10 21:37:36 +00:00
|
|
|
/// Returns a default archive name when given a Git revision.
|
|
|
|
/// Used when an output filename is not given.
|
2022-02-02 17:02:02 +00:00
|
|
|
Future<String> get _archiveName async {
|
2018-02-06 23:32:19 +00:00
|
|
|
final String os = platform.operatingSystem.toLowerCase();
|
2022-02-02 17:02:02 +00:00
|
|
|
// Include the intended host archetecture in the file name for non-x64.
|
|
|
|
final String arch = await _dartArch == 'x64' ? '' : '${await _dartArch}_';
|
2018-02-27 21:15:32 +00:00
|
|
|
// We don't use .tar.xz on Mac because although it can unpack them
|
|
|
|
// on the command line (with tar), the "Archive Utility" that runs
|
|
|
|
// when you double-click on them just does some crazy behavior (it
|
|
|
|
// converts it to a compressed cpio archive, and when you double
|
|
|
|
// click on that, it converts it back to .tar.xz, without ever
|
|
|
|
// unpacking it!) So, we use .zip for Mac, and the files are about
|
|
|
|
// 220MB larger than they need to be. :-(
|
|
|
|
final String suffix = platform.isLinux ? 'tar.xz' : 'zip';
|
2022-10-17 13:45:19 +00:00
|
|
|
final String package = '${os}_$arch${_version[frameworkVersionTag]}';
|
|
|
|
return 'flutter_$package-${branch.name}.$suffix';
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Checks out the flutter repo and prepares it for other operations.
|
|
|
|
///
|
2022-01-08 00:30:14 +00:00
|
|
|
/// Returns the version for this release as obtained from the git tags, and
|
|
|
|
/// the dart version as obtained from `flutter --version`.
|
|
|
|
Future<Map<String, String>> initializeRepo() async {
|
2018-02-06 23:32:19 +00:00
|
|
|
await _checkoutFlutter();
|
2022-01-08 00:30:14 +00:00
|
|
|
if (_version.isEmpty) {
|
|
|
|
_version.addAll(await _getVersion());
|
|
|
|
}
|
2018-02-06 23:32:19 +00:00
|
|
|
return _version;
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 21:37:36 +00:00
|
|
|
/// Performs all of the steps needed to create an archive.
|
2018-02-06 23:32:19 +00:00
|
|
|
Future<File> createArchive() async {
|
2022-01-08 00:30:14 +00:00
|
|
|
assert(_version.isNotEmpty, 'Must run initializeRepo before createArchive');
|
2022-02-02 17:02:02 +00:00
|
|
|
final File outputFile = File(path.join(
|
|
|
|
outputDir.absolute.path,
|
|
|
|
await _archiveName,
|
|
|
|
));
|
2018-01-10 21:37:36 +00:00
|
|
|
await _installMinGitIfNeeded();
|
|
|
|
await _populateCaches();
|
2021-05-03 22:14:38 +00:00
|
|
|
await _validate();
|
2022-02-02 17:02:02 +00:00
|
|
|
await _archiveFiles(outputFile);
|
|
|
|
return outputFile;
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 22:14:38 +00:00
|
|
|
/// Validates the integrity of the release package.
|
|
|
|
///
|
|
|
|
/// Currently only checks that macOS binaries are codesigned. Will throw a
|
|
|
|
/// [PreparePackageException] if the test failes.
|
|
|
|
Future<void> _validate() async {
|
|
|
|
// Only validate in strict mode, which means `--publish`
|
|
|
|
if (!strict || !platform.isMacOS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Validate that the dart binary is codesigned
|
|
|
|
try {
|
|
|
|
// TODO(fujino): Use the conductor https://github.com/flutter/flutter/issues/81701
|
|
|
|
await _processRunner.runProcess(
|
|
|
|
<String>[
|
|
|
|
'codesign',
|
|
|
|
'-vvvv',
|
|
|
|
'--check-notarization',
|
2022-02-02 17:02:02 +00:00
|
|
|
_dart,
|
2021-05-03 22:14:38 +00:00
|
|
|
],
|
|
|
|
workingDirectory: flutterRoot,
|
|
|
|
);
|
|
|
|
} on PreparePackageException catch (e) {
|
|
|
|
throw PreparePackageException(
|
2022-02-02 17:02:02 +00:00
|
|
|
'The binary $_dart was not codesigned!\n${e.message}',
|
2021-05-03 22:14:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:30:14 +00:00
|
|
|
/// Returns the version map of this release, according the to tags in the
|
|
|
|
/// repo and the output of `flutter --version --machine`.
|
2019-03-01 22:38:40 +00:00
|
|
|
///
|
|
|
|
/// This looks for the tag attached to [revision] and, if it doesn't find one,
|
|
|
|
/// git will give an error.
|
|
|
|
///
|
|
|
|
/// If [strict] is true, the exact [revision] must be tagged to return the
|
2022-09-02 04:00:58 +00:00
|
|
|
/// version. If [strict] is not true, will look backwards in time starting at
|
2019-03-01 22:38:40 +00:00
|
|
|
/// [revision] to find the most recent version tag.
|
2022-01-08 00:30:14 +00:00
|
|
|
///
|
|
|
|
/// The version found as a git tag is added to the information given by
|
|
|
|
/// `flutter --version --machine` with the `frameworkVersionFromGit` tag, and
|
|
|
|
/// returned.
|
|
|
|
Future<Map<String, String>> _getVersion() async {
|
|
|
|
String gitVersion;
|
2019-03-01 22:38:40 +00:00
|
|
|
if (strict) {
|
|
|
|
try {
|
2022-01-08 00:30:14 +00:00
|
|
|
gitVersion = await _runGit(<String>['describe', '--tags', '--exact-match', revision]);
|
2020-08-13 15:43:20 +00:00
|
|
|
} on PreparePackageException catch (exception) {
|
2019-03-01 22:38:40 +00:00
|
|
|
throw PreparePackageException(
|
2020-08-13 15:43:20 +00:00
|
|
|
'Git error when checking for a version tag attached to revision $revision.\n'
|
|
|
|
'Perhaps there is no tag at that revision?:\n'
|
|
|
|
'$exception'
|
|
|
|
);
|
2019-03-01 22:38:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-01-08 00:30:14 +00:00
|
|
|
gitVersion = await _runGit(<String>['describe', '--tags', '--abbrev=0', revision]);
|
2019-03-01 22:38:40 +00:00
|
|
|
}
|
2022-01-08 00:30:14 +00:00
|
|
|
// Run flutter command twice, once to make sure the flutter command is built
|
|
|
|
// and ready (and thus won't output any junk on stdout the second time), and
|
|
|
|
// once to capture theJSON output. The second run should be fast.
|
|
|
|
await _runFlutter(<String>['--version', '--machine']);
|
|
|
|
final String versionJson = await _runFlutter(<String>['--version', '--machine']);
|
|
|
|
final Map<String, String> versionMap = <String, String>{};
|
|
|
|
final Map<String, dynamic> result = json.decode(versionJson) as Map<String, dynamic>;
|
|
|
|
result.forEach((String key, dynamic value) => versionMap[key] = value.toString());
|
|
|
|
versionMap[frameworkVersionTag] = gitVersion;
|
2022-02-02 17:02:02 +00:00
|
|
|
versionMap[dartTargetArchTag] = await _dartArch;
|
2022-01-08 00:30:14 +00:00
|
|
|
return versionMap;
|
2018-01-10 21:37:36 +00:00
|
|
|
}
|
2017-12-15 23:01:30 +00:00
|
|
|
|
|
|
|
/// Clone the Flutter repo and make sure that the git environment is sane
|
|
|
|
/// for when the user will unpack it.
|
2018-10-04 16:44:23 +00:00
|
|
|
Future<void> _checkoutFlutter() async {
|
2018-02-06 23:32:19 +00:00
|
|
|
// We want the user to start out the in the specified branch instead of a
|
|
|
|
// detached head. To do that, we need to make sure the branch points at the
|
2017-12-15 23:01:30 +00:00
|
|
|
// desired revision.
|
2022-10-17 13:45:19 +00:00
|
|
|
await _runGit(<String>['clone', '-b', branch.name, gobMirror], workingDirectory: tempDir);
|
2018-01-10 21:37:36 +00:00
|
|
|
await _runGit(<String>['reset', '--hard', revision]);
|
2017-12-15 23:01:30 +00:00
|
|
|
|
|
|
|
// Make the origin point to github instead of the chromium mirror.
|
2018-03-14 19:56:44 +00:00
|
|
|
await _runGit(<String>['remote', 'set-url', 'origin', githubRepo]);
|
2022-10-17 15:43:31 +00:00
|
|
|
|
|
|
|
// Minify `.git` footprint (saving about ~100 MB as of Oct 2022)
|
|
|
|
await _runGit(<String>['gc', '--prune=now', '--aggressive']);
|
2018-01-10 21:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Retrieve the MinGit executable from storage and unpack it.
|
2018-10-04 16:44:23 +00:00
|
|
|
Future<void> _installMinGitIfNeeded() async {
|
2018-02-06 23:32:19 +00:00
|
|
|
if (!platform.isWindows) {
|
2018-01-10 21:37:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-07 20:21:14 +00:00
|
|
|
final Uint8List data = await httpReader(_minGitUri);
|
2018-09-12 06:29:29 +00:00
|
|
|
final File gitFile = File(path.join(tempDir.absolute.path, 'mingit.zip'));
|
2018-01-10 21:37:36 +00:00
|
|
|
await gitFile.writeAsBytes(data, flush: true);
|
|
|
|
|
2019-02-26 20:02:01 +00:00
|
|
|
final Directory minGitPath = Directory(path.join(flutterRoot.absolute.path, 'bin', 'mingit'));
|
2018-01-10 21:37:36 +00:00
|
|
|
await minGitPath.create(recursive: true);
|
2018-02-06 23:32:19 +00:00
|
|
|
await _unzipArchive(gitFile, workingDirectory: minGitPath);
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Prepare the archive repo so that it has all of the caches warmed up and
|
2018-01-10 21:37:36 +00:00
|
|
|
/// is configured for the user to begin working.
|
2018-10-04 16:44:23 +00:00
|
|
|
Future<void> _populateCaches() async {
|
2018-01-10 21:37:36 +00:00
|
|
|
await _runFlutter(<String>['doctor']);
|
|
|
|
await _runFlutter(<String>['update-packages']);
|
|
|
|
await _runFlutter(<String>['precache']);
|
|
|
|
await _runFlutter(<String>['ide-config']);
|
|
|
|
|
|
|
|
// Create each of the templates, since they will call 'pub get' on
|
2017-12-15 23:01:30 +00:00
|
|
|
// themselves when created, and this will warm the cache with their
|
|
|
|
// dependencies too.
|
2020-01-07 15:32:04 +00:00
|
|
|
for (final String template in <String>['app', 'package', 'plugin']) {
|
2018-02-06 23:32:19 +00:00
|
|
|
final String createName = path.join(tempDir.path, 'create_$template');
|
2018-01-10 21:37:36 +00:00
|
|
|
await _runFlutter(
|
2017-12-15 23:01:30 +00:00
|
|
|
<String>['create', '--template=$template', createName],
|
2019-01-11 02:04:23 +00:00
|
|
|
// Run it outside the cloned Flutter repo to not nest git repos, since
|
|
|
|
// they'll be git repos themselves too.
|
|
|
|
workingDirectory: tempDir,
|
2017-12-15 23:01:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yes, we could just skip all .packages files when constructing
|
|
|
|
// the archive, but some are checked in, and we don't want to skip
|
|
|
|
// those.
|
2021-02-27 01:10:45 +00:00
|
|
|
await _runGit(<String>[
|
|
|
|
'clean',
|
|
|
|
'-f',
|
|
|
|
// Do not -X as it could lead to entire bin/cache getting cleaned
|
|
|
|
'-x',
|
|
|
|
'--',
|
|
|
|
'**/.packages',
|
|
|
|
]);
|
2020-05-28 19:07:11 +00:00
|
|
|
/// Remove package_config files and any contents in .dart_tool
|
2021-02-27 01:10:45 +00:00
|
|
|
await _runGit(<String>[
|
|
|
|
'clean',
|
|
|
|
'-f',
|
|
|
|
'-x',
|
|
|
|
'--',
|
|
|
|
'**/.dart_tool/',
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Ensure the above commands do not clean out the cache
|
|
|
|
final Directory flutterCache = Directory(path.join(flutterRoot.absolute.path, 'bin', 'cache'));
|
|
|
|
if (!flutterCache.existsSync()) {
|
|
|
|
throw Exception('The flutter cache was not found at ${flutterCache.path}!');
|
|
|
|
}
|
|
|
|
|
2020-07-15 18:56:28 +00:00
|
|
|
/// Remove git subfolder from .pub-cache, this contains the flutter goldens
|
|
|
|
/// and new flutter_gallery.
|
|
|
|
final Directory gitCache = Directory(path.join(flutterRoot.absolute.path, '.pub-cache', 'git'));
|
|
|
|
if (gitCache.existsSync()) {
|
|
|
|
gitCache.deleteSync(recursive: true);
|
|
|
|
}
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 21:37:36 +00:00
|
|
|
/// Write the archive to the given output file.
|
2018-10-04 16:44:23 +00:00
|
|
|
Future<void> _archiveFiles(File outputFile) async {
|
2017-12-15 23:01:30 +00:00
|
|
|
if (outputFile.path.toLowerCase().endsWith('.zip')) {
|
2018-02-06 23:32:19 +00:00
|
|
|
await _createZipArchive(outputFile, flutterRoot);
|
2017-12-16 00:40:49 +00:00
|
|
|
} else if (outputFile.path.toLowerCase().endsWith('.tar.xz')) {
|
2018-02-06 23:32:19 +00:00
|
|
|
await _createTarArchive(outputFile, flutterRoot);
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-02 17:02:02 +00:00
|
|
|
Future<String> _runDart(List<String> args, {Directory? workingDirectory}) {
|
|
|
|
return _processRunner.runProcess(
|
|
|
|
<String>[_dart, ...args],
|
|
|
|
workingDirectory: workingDirectory ?? flutterRoot,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-19 20:59:15 +00:00
|
|
|
Future<String> _runFlutter(List<String> args, {Directory? workingDirectory}) {
|
2020-08-13 15:43:20 +00:00
|
|
|
return _processRunner.runProcess(
|
|
|
|
<String>[_flutter, ...args],
|
2018-03-20 15:14:08 +00:00
|
|
|
workingDirectory: workingDirectory ?? flutterRoot,
|
|
|
|
);
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
2017-12-15 23:01:30 +00:00
|
|
|
|
2021-07-19 20:59:15 +00:00
|
|
|
Future<String> _runGit(List<String> args, {Directory? workingDirectory}) {
|
2020-08-13 15:43:20 +00:00
|
|
|
return _processRunner.runProcess(
|
|
|
|
<String>['git', ...args],
|
|
|
|
workingDirectory: workingDirectory ?? flutterRoot,
|
|
|
|
);
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 21:37:36 +00:00
|
|
|
/// Unpacks the given zip file into the currentDirectory (if set), or the
|
|
|
|
/// same directory as the archive.
|
2021-07-19 20:59:15 +00:00
|
|
|
Future<String> _unzipArchive(File archive, {Directory? workingDirectory}) {
|
2018-09-12 06:29:29 +00:00
|
|
|
workingDirectory ??= Directory(path.dirname(archive.absolute.path));
|
2018-03-14 19:56:44 +00:00
|
|
|
List<String> commandLine;
|
|
|
|
if (platform.isWindows) {
|
|
|
|
commandLine = <String>[
|
|
|
|
'7za',
|
|
|
|
'x',
|
|
|
|
archive.absolute.path,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
commandLine = <String>[
|
|
|
|
'unzip',
|
|
|
|
archive.absolute.path,
|
|
|
|
];
|
|
|
|
}
|
2020-08-13 15:43:20 +00:00
|
|
|
return _processRunner.runProcess(commandLine, workingDirectory: workingDirectory);
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 21:37:36 +00:00
|
|
|
/// Create a zip archive from the directory source.
|
2019-08-28 22:20:47 +00:00
|
|
|
Future<String> _createZipArchive(File output, Directory source) async {
|
2018-02-27 21:15:32 +00:00
|
|
|
List<String> commandLine;
|
|
|
|
if (platform.isWindows) {
|
2019-08-28 22:20:47 +00:00
|
|
|
// Unhide the .git folder, https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/attrib.
|
2020-08-13 15:43:20 +00:00
|
|
|
await _processRunner.runProcess(
|
2019-08-28 22:20:47 +00:00
|
|
|
<String>['attrib', '-h', '.git'],
|
|
|
|
workingDirectory: Directory(source.absolute.path),
|
|
|
|
);
|
2018-02-27 21:15:32 +00:00
|
|
|
commandLine = <String>[
|
|
|
|
'7za',
|
|
|
|
'a',
|
|
|
|
'-tzip',
|
|
|
|
'-mx=9',
|
|
|
|
output.absolute.path,
|
|
|
|
path.basename(source.path),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
commandLine = <String>[
|
|
|
|
'zip',
|
|
|
|
'-r',
|
|
|
|
'-9',
|
2021-03-04 01:21:14 +00:00
|
|
|
'--symlinks',
|
2018-02-27 21:15:32 +00:00
|
|
|
output.absolute.path,
|
|
|
|
path.basename(source.path),
|
|
|
|
];
|
|
|
|
}
|
2020-08-13 15:43:20 +00:00
|
|
|
return _processRunner.runProcess(
|
2018-03-20 15:14:08 +00:00
|
|
|
commandLine,
|
2018-09-12 06:29:29 +00:00
|
|
|
workingDirectory: Directory(path.dirname(source.absolute.path)),
|
2018-03-20 15:14:08 +00:00
|
|
|
);
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 21:37:36 +00:00
|
|
|
/// Create a tar archive from the directory source.
|
2020-08-13 15:43:20 +00:00
|
|
|
Future<String> _createTarArchive(File output, Directory source) {
|
|
|
|
return _processRunner.runProcess(<String>[
|
|
|
|
'tar',
|
|
|
|
'cJf',
|
|
|
|
output.absolute.path,
|
|
|
|
path.basename(source.absolute.path),
|
|
|
|
], workingDirectory: Directory(path.dirname(source.absolute.path)));
|
2018-01-10 21:37:36 +00:00
|
|
|
}
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
2018-01-10 21:37:36 +00:00
|
|
|
|
2018-02-06 23:32:19 +00:00
|
|
|
class ArchivePublisher {
|
|
|
|
ArchivePublisher(
|
|
|
|
this.tempDir,
|
|
|
|
this.revision,
|
|
|
|
this.branch,
|
|
|
|
this.version,
|
2021-02-05 01:45:45 +00:00
|
|
|
this.outputFile,
|
|
|
|
this.dryRun, {
|
2021-07-19 20:59:15 +00:00
|
|
|
ProcessManager? processManager,
|
2018-06-05 06:50:40 +00:00
|
|
|
bool subprocessOutput = true,
|
|
|
|
this.platform = const LocalPlatform(),
|
2019-02-26 20:02:01 +00:00
|
|
|
}) : assert(revision.length == 40),
|
|
|
|
platformName = platform.operatingSystem.toLowerCase(),
|
2021-05-28 02:04:02 +00:00
|
|
|
metadataGsPath = '$gsReleaseFolder/${getMetadataFilename(platform)}',
|
2019-02-26 20:02:01 +00:00
|
|
|
_processRunner = ProcessRunner(
|
|
|
|
processManager: processManager,
|
2020-08-13 15:43:20 +00:00
|
|
|
subprocessOutput: subprocessOutput,
|
2019-02-26 20:02:01 +00:00
|
|
|
);
|
2018-02-06 23:32:19 +00:00
|
|
|
|
|
|
|
final Platform platform;
|
|
|
|
final String platformName;
|
|
|
|
final String metadataGsPath;
|
|
|
|
final Branch branch;
|
|
|
|
final String revision;
|
2022-01-08 00:30:14 +00:00
|
|
|
final Map<String, String> version;
|
2018-02-06 23:32:19 +00:00
|
|
|
final Directory tempDir;
|
|
|
|
final File outputFile;
|
|
|
|
final ProcessRunner _processRunner;
|
2021-02-05 01:45:45 +00:00
|
|
|
final bool dryRun;
|
2022-10-17 13:45:19 +00:00
|
|
|
String get destinationArchivePath => '${branch.name}/$platformName/${path.basename(outputFile.path)}';
|
2018-03-20 15:14:08 +00:00
|
|
|
static String getMetadataFilename(Platform platform) => 'releases_${platform.operatingSystem.toLowerCase()}.json';
|
2018-02-06 23:32:19 +00:00
|
|
|
|
2019-02-26 20:02:01 +00:00
|
|
|
Future<String> _getChecksum(File archiveFile) async {
|
|
|
|
final DigestSink digestSink = DigestSink();
|
|
|
|
final ByteConversionSink sink = sha256.startChunkedConversion(digestSink);
|
|
|
|
|
|
|
|
final Stream<List<int>> stream = archiveFile.openRead();
|
|
|
|
await stream.forEach((List<int> chunk) {
|
|
|
|
sink.add(chunk);
|
|
|
|
});
|
|
|
|
sink.close();
|
|
|
|
return digestSink.value.toString();
|
|
|
|
}
|
|
|
|
|
2018-02-06 23:32:19 +00:00
|
|
|
/// Publish the archive to Google Storage.
|
2020-12-04 01:07:50 +00:00
|
|
|
///
|
|
|
|
/// This method will throw if the target archive already exists on cloud
|
|
|
|
/// storage.
|
|
|
|
Future<void> publishArchive([bool forceUpload = false]) async {
|
2021-05-28 02:04:02 +00:00
|
|
|
final String destGsPath = '$gsReleaseFolder/$destinationArchivePath';
|
|
|
|
if (!forceUpload) {
|
|
|
|
if (await _cloudPathExists(destGsPath) && !dryRun) {
|
|
|
|
throw PreparePackageException(
|
|
|
|
'File $destGsPath already exists on cloud storage!',
|
|
|
|
);
|
2020-12-04 01:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-28 02:04:02 +00:00
|
|
|
await _cloudCopy(
|
|
|
|
src: outputFile.absolute.path,
|
|
|
|
dest: destGsPath,
|
|
|
|
);
|
|
|
|
assert(tempDir.existsSync());
|
2022-11-29 04:14:24 +00:00
|
|
|
final String gcsPath = '$gsReleaseFolder/${getMetadataFilename(platform)}';
|
|
|
|
await _publishMetadata(gcsPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Downloads and updates the metadata file without publishing it.
|
|
|
|
Future<void> generateLocalMetadata() async {
|
2021-05-28 02:04:02 +00:00
|
|
|
await _updateMetadata('$gsReleaseFolder/${getMetadataFilename(platform)}');
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 02:04:02 +00:00
|
|
|
Future<Map<String, dynamic>> _addRelease(Map<String, dynamic> jsonData) async {
|
|
|
|
jsonData['base_url'] = '$baseUrl$releaseFolder';
|
2018-03-22 20:14:31 +00:00
|
|
|
if (!jsonData.containsKey('current_release')) {
|
|
|
|
jsonData['current_release'] = <String, String>{};
|
|
|
|
}
|
2022-10-17 13:45:19 +00:00
|
|
|
(jsonData['current_release'] as Map<String, dynamic>)[branch.name] = revision;
|
2018-03-22 20:14:31 +00:00
|
|
|
if (!jsonData.containsKey('releases')) {
|
|
|
|
jsonData['releases'] = <Map<String, dynamic>>[];
|
|
|
|
}
|
|
|
|
|
|
|
|
final Map<String, dynamic> newEntry = <String, dynamic>{};
|
|
|
|
newEntry['hash'] = revision;
|
2022-10-17 13:45:19 +00:00
|
|
|
newEntry['channel'] = branch.name;
|
2022-01-08 00:30:14 +00:00
|
|
|
newEntry['version'] = version[frameworkVersionTag];
|
|
|
|
newEntry['dart_sdk_version'] = version[dartVersionTag];
|
2022-02-02 17:02:02 +00:00
|
|
|
newEntry['dart_sdk_arch'] = version[dartTargetArchTag];
|
2018-09-12 06:29:29 +00:00
|
|
|
newEntry['release_date'] = DateTime.now().toUtc().toIso8601String();
|
2018-03-22 20:14:31 +00:00
|
|
|
newEntry['archive'] = destinationArchivePath;
|
2019-02-26 20:02:01 +00:00
|
|
|
newEntry['sha256'] = await _getChecksum(outputFile);
|
2018-03-22 20:14:31 +00:00
|
|
|
|
|
|
|
// Search for any entries with the same hash and channel and remove them.
|
2019-12-05 21:34:06 +00:00
|
|
|
final List<dynamic> releases = jsonData['releases'] as List<dynamic>;
|
2019-09-17 14:23:44 +00:00
|
|
|
jsonData['releases'] = <Map<String, dynamic>>[
|
2020-01-07 15:32:04 +00:00
|
|
|
for (final Map<String, dynamic> entry in releases.cast<Map<String, dynamic>>())
|
2022-03-18 04:24:16 +00:00
|
|
|
if (entry['hash'] != newEntry['hash'] ||
|
|
|
|
entry['channel'] != newEntry['channel'] ||
|
|
|
|
entry['dart_sdk_arch'] != newEntry['dart_sdk_arch'])
|
2019-09-17 14:23:44 +00:00
|
|
|
entry,
|
|
|
|
newEntry,
|
|
|
|
]..sort((Map<String, dynamic> a, Map<String, dynamic> b) {
|
2019-12-05 21:34:06 +00:00
|
|
|
final DateTime aDate = DateTime.parse(a['release_date'] as String);
|
|
|
|
final DateTime bDate = DateTime.parse(b['release_date'] as String);
|
2018-03-22 20:14:31 +00:00
|
|
|
return bDate.compareTo(aDate);
|
|
|
|
});
|
|
|
|
return jsonData;
|
|
|
|
}
|
|
|
|
|
2021-05-28 02:04:02 +00:00
|
|
|
Future<void> _updateMetadata(String gsPath) async {
|
2018-03-20 15:14:08 +00:00
|
|
|
// We can't just cat the metadata from the server with 'gsutil cat', because
|
|
|
|
// Windows wants to echo the commands that execute in gsutil.bat to the
|
|
|
|
// stdout when we do that. So, we copy the file locally and then read it
|
|
|
|
// back in.
|
2018-09-12 06:29:29 +00:00
|
|
|
final File metadataFile = File(
|
2018-03-20 15:14:08 +00:00
|
|
|
path.join(tempDir.absolute.path, getMetadataFilename(platform)),
|
|
|
|
);
|
2021-02-05 01:45:45 +00:00
|
|
|
await _runGsUtil(<String>['cp', gsPath, metadataFile.absolute.path]);
|
2022-01-08 00:30:14 +00:00
|
|
|
Map<String, dynamic> jsonData = <String, dynamic>{};
|
2021-02-05 01:45:45 +00:00
|
|
|
if (!dryRun) {
|
|
|
|
final String currentMetadata = metadataFile.readAsStringSync();
|
|
|
|
if (currentMetadata.isEmpty) {
|
|
|
|
throw PreparePackageException('Empty metadata received from server');
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
jsonData = json.decode(currentMetadata) as Map<String, dynamic>;
|
|
|
|
} on FormatException catch (e) {
|
|
|
|
throw PreparePackageException('Unable to parse JSON metadata received from cloud: $e');
|
|
|
|
}
|
|
|
|
}
|
2022-01-08 00:30:14 +00:00
|
|
|
// Run _addRelease, even on a dry run, so we can inspect the metadata on a
|
|
|
|
// dry run. On a dry run, the only thing in the metadata file be the new
|
|
|
|
// release.
|
|
|
|
jsonData = await _addRelease(jsonData);
|
|
|
|
|
|
|
|
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
|
|
|
|
metadataFile.writeAsStringSync(encoder.convert(jsonData));
|
2022-11-29 04:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Publishes the metadata file to GCS.
|
|
|
|
Future<void> _publishMetadata(String gsPath) async {
|
|
|
|
final File metadataFile = File(
|
|
|
|
path.join(tempDir.absolute.path, getMetadataFilename(platform)),
|
|
|
|
);
|
2021-03-30 20:15:34 +00:00
|
|
|
await _cloudCopy(
|
|
|
|
src: metadataFile.absolute.path,
|
|
|
|
dest: gsPath,
|
|
|
|
// This metadata file is used by the website, so we don't want a long
|
|
|
|
// latency between publishing a release and it being available on the
|
|
|
|
// site.
|
|
|
|
cacheSeconds: shortCacheSeconds,
|
|
|
|
);
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 15:14:08 +00:00
|
|
|
Future<String> _runGsUtil(
|
|
|
|
List<String> args, {
|
2021-07-19 20:59:15 +00:00
|
|
|
Directory? workingDirectory,
|
2018-06-05 06:50:40 +00:00
|
|
|
bool failOk = false,
|
2018-03-20 15:14:08 +00:00
|
|
|
}) async {
|
2021-02-05 01:45:45 +00:00
|
|
|
if (dryRun) {
|
|
|
|
print('gsutil.py -- $args');
|
|
|
|
return '';
|
|
|
|
}
|
2019-01-26 02:43:20 +00:00
|
|
|
if (platform.isWindows) {
|
2020-08-13 15:43:20 +00:00
|
|
|
return _processRunner.runProcess(
|
2021-08-06 21:42:08 +00:00
|
|
|
<String>['python3', path.join(platform.environment['DEPOT_TOOLS']!, 'gsutil.py'), '--', ...args],
|
2019-01-26 02:43:20 +00:00
|
|
|
workingDirectory: workingDirectory,
|
|
|
|
failOk: failOk,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-13 15:43:20 +00:00
|
|
|
return _processRunner.runProcess(
|
2019-06-27 19:23:16 +00:00
|
|
|
<String>['gsutil.py', '--', ...args],
|
2018-02-06 23:32:19 +00:00
|
|
|
workingDirectory: workingDirectory,
|
|
|
|
failOk: failOk,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-04 01:07:50 +00:00
|
|
|
/// Determine if a file exists at a given [cloudPath].
|
|
|
|
Future<bool> _cloudPathExists(String cloudPath) async {
|
|
|
|
try {
|
|
|
|
await _runGsUtil(
|
|
|
|
<String>['stat', cloudPath],
|
|
|
|
);
|
|
|
|
} on PreparePackageException {
|
|
|
|
// `gsutil stat gs://path/to/file` will exit with 1 if file does not exist
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-30 20:15:34 +00:00
|
|
|
Future<String> _cloudCopy({
|
2021-07-19 20:59:15 +00:00
|
|
|
required String src,
|
|
|
|
required String dest,
|
|
|
|
int? cacheSeconds,
|
2021-03-30 20:15:34 +00:00
|
|
|
}) async {
|
2018-02-09 23:42:51 +00:00
|
|
|
// We often don't have permission to overwrite, but
|
|
|
|
// we have permission to remove, so that's what we do.
|
2018-02-06 23:32:19 +00:00
|
|
|
await _runGsUtil(<String>['rm', dest], failOk: true);
|
2021-07-19 20:59:15 +00:00
|
|
|
String? mimeType;
|
2018-02-09 23:42:51 +00:00
|
|
|
if (dest.endsWith('.tar.xz')) {
|
|
|
|
mimeType = 'application/x-gtar';
|
|
|
|
}
|
|
|
|
if (dest.endsWith('.zip')) {
|
|
|
|
mimeType = 'application/zip';
|
|
|
|
}
|
|
|
|
if (dest.endsWith('.json')) {
|
|
|
|
mimeType = 'application/json';
|
|
|
|
}
|
2021-03-06 02:38:15 +00:00
|
|
|
return _runGsUtil(<String>[
|
2019-07-02 19:11:56 +00:00
|
|
|
// Use our preferred MIME type for the files we care about
|
|
|
|
// and let gsutil figure it out for anything else.
|
|
|
|
if (mimeType != null) ...<String>['-h', 'Content-Type:$mimeType'],
|
2021-03-30 20:15:34 +00:00
|
|
|
if (cacheSeconds != null) ...<String>['-h', 'Cache-Control:max-age=$cacheSeconds'],
|
2019-07-02 19:11:56 +00:00
|
|
|
'cp',
|
|
|
|
src,
|
|
|
|
dest,
|
|
|
|
]);
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prepares a flutter git repo to be packaged up for distribution.
|
|
|
|
/// It mainly serves to populate the .pub-cache with any appropriate Dart
|
|
|
|
/// packages, and the flutter cache in bin/cache with the appropriate
|
|
|
|
/// dependencies and snapshots.
|
2018-01-10 21:37:36 +00:00
|
|
|
///
|
2018-09-22 09:02:56 +00:00
|
|
|
/// Archives contain the executables and customizations for the platform that
|
|
|
|
/// they are created on.
|
2018-10-30 02:44:00 +00:00
|
|
|
Future<void> main(List<String> rawArguments) async {
|
2018-09-12 06:29:29 +00:00
|
|
|
final ArgParser argParser = ArgParser();
|
2017-12-15 23:01:30 +00:00
|
|
|
argParser.addOption(
|
|
|
|
'temp_dir',
|
|
|
|
help: 'A location where temporary files may be written. Defaults to a '
|
|
|
|
'directory in the system temp folder. Will write a few GiB of data, '
|
2018-02-06 23:32:19 +00:00
|
|
|
'so it should have sufficient free space. If a temp_dir is not '
|
|
|
|
'specified, then the default temp_dir will be created, used, and '
|
|
|
|
'removed automatically.',
|
2017-12-15 23:01:30 +00:00
|
|
|
);
|
2018-02-06 23:32:19 +00:00
|
|
|
argParser.addOption('revision',
|
|
|
|
help: 'The Flutter git repo revision to build the '
|
|
|
|
'archive with. Must be the full 40-character hash. Required.');
|
2017-12-15 23:01:30 +00:00
|
|
|
argParser.addOption(
|
2018-02-06 23:32:19 +00:00
|
|
|
'branch',
|
2022-10-17 13:45:19 +00:00
|
|
|
allowed: Branch.values.map<String>((Branch branch) => branch.name),
|
2018-02-06 23:32:19 +00:00
|
|
|
help: 'The Flutter branch to build the archive with. Required.',
|
2017-12-15 23:01:30 +00:00
|
|
|
);
|
|
|
|
argParser.addOption(
|
|
|
|
'output',
|
2018-02-06 23:32:19 +00:00
|
|
|
help: 'The path to the directory where the output archive should be '
|
|
|
|
'written. If --output is not specified, the archive will be written to '
|
|
|
|
"the current directory. If the output directory doesn't exist, it, and "
|
|
|
|
'the path to it, will be created.',
|
|
|
|
);
|
|
|
|
argParser.addFlag(
|
|
|
|
'publish',
|
2018-02-07 20:21:14 +00:00
|
|
|
help: 'If set, will publish the archive to Google Cloud Storage upon '
|
|
|
|
'successful creation of the archive. Will publish under this '
|
2021-05-28 02:04:02 +00:00
|
|
|
'directory: $baseUrl$releaseFolder',
|
2018-02-07 20:21:14 +00:00
|
|
|
);
|
2020-12-04 01:07:50 +00:00
|
|
|
argParser.addFlag(
|
|
|
|
'force',
|
|
|
|
abbr: 'f',
|
|
|
|
help: 'Overwrite a previously uploaded package.',
|
|
|
|
);
|
2021-02-05 01:45:45 +00:00
|
|
|
argParser.addFlag(
|
|
|
|
'dry_run',
|
|
|
|
negatable: false,
|
|
|
|
help: 'Prints gsutil commands instead of executing them.',
|
|
|
|
);
|
2018-02-07 20:21:14 +00:00
|
|
|
argParser.addFlag(
|
|
|
|
'help',
|
|
|
|
negatable: false,
|
|
|
|
help: 'Print help for this command.',
|
2017-12-15 23:01:30 +00:00
|
|
|
);
|
2018-02-06 23:32:19 +00:00
|
|
|
|
2018-10-30 02:44:00 +00:00
|
|
|
final ArgResults parsedArguments = argParser.parse(rawArguments);
|
2017-12-15 23:01:30 +00:00
|
|
|
|
2019-12-05 21:34:06 +00:00
|
|
|
if (parsedArguments['help'] as bool) {
|
2018-02-07 20:21:14 +00:00
|
|
|
print(argParser.usage);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:01:30 +00:00
|
|
|
void errorExit(String message, {int exitCode = -1}) {
|
|
|
|
stderr.write('Error: $message\n\n');
|
|
|
|
stderr.write('${argParser.usage}\n');
|
|
|
|
exit(exitCode);
|
|
|
|
}
|
|
|
|
|
2020-12-04 01:07:50 +00:00
|
|
|
if (!parsedArguments.wasParsed('revision')) {
|
2017-12-15 23:01:30 +00:00
|
|
|
errorExit('Invalid argument: --revision must be specified.');
|
|
|
|
}
|
2022-10-19 19:13:12 +00:00
|
|
|
final String revision = parsedArguments['revision'] as String;
|
2018-02-06 23:32:19 +00:00
|
|
|
if (revision.length != 40) {
|
|
|
|
errorExit('Invalid argument: --revision must be the entire hash, not just a prefix.');
|
|
|
|
}
|
|
|
|
|
2020-12-04 01:07:50 +00:00
|
|
|
if (!parsedArguments.wasParsed('branch')) {
|
2018-02-06 23:32:19 +00:00
|
|
|
errorExit('Invalid argument: --branch must be specified.');
|
|
|
|
}
|
2017-12-15 23:01:30 +00:00
|
|
|
|
2022-10-19 19:13:12 +00:00
|
|
|
final String? tempDirArg = parsedArguments['temp_dir'] as String?;
|
2018-01-10 21:37:36 +00:00
|
|
|
Directory tempDir;
|
2017-12-15 23:01:30 +00:00
|
|
|
bool removeTempDir = false;
|
2019-12-05 21:34:06 +00:00
|
|
|
if (tempDirArg == null || tempDirArg.isEmpty) {
|
2018-08-17 20:17:23 +00:00
|
|
|
tempDir = Directory.systemTemp.createTempSync('flutter_package.');
|
2017-12-15 23:01:30 +00:00
|
|
|
removeTempDir = true;
|
|
|
|
} else {
|
2019-12-05 21:34:06 +00:00
|
|
|
tempDir = Directory(tempDirArg);
|
2018-01-10 21:37:36 +00:00
|
|
|
if (!tempDir.existsSync()) {
|
2019-12-05 21:34:06 +00:00
|
|
|
errorExit("Temporary directory $tempDirArg doesn't exist.");
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 23:32:19 +00:00
|
|
|
Directory outputDir;
|
2018-10-30 02:44:00 +00:00
|
|
|
if (parsedArguments['output'] == null) {
|
2018-02-06 23:32:19 +00:00
|
|
|
outputDir = tempDir;
|
2018-01-10 21:37:36 +00:00
|
|
|
} else {
|
2019-12-05 21:34:06 +00:00
|
|
|
outputDir = Directory(parsedArguments['output'] as String);
|
2018-02-06 23:32:19 +00:00
|
|
|
if (!outputDir.existsSync()) {
|
|
|
|
outputDir.createSync(recursive: true);
|
2018-01-10 21:37:36 +00:00
|
|
|
}
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 17:02:02 +00:00
|
|
|
final bool publish = parsedArguments['publish'] as bool;
|
|
|
|
final bool dryRun = parsedArguments['dry_run'] as bool;
|
2022-10-19 19:13:12 +00:00
|
|
|
final Branch branch = Branch.values.byName(parsedArguments['branch'] as String);
|
2022-02-02 17:02:02 +00:00
|
|
|
final ArchiveCreator creator = ArchiveCreator(
|
|
|
|
tempDir,
|
|
|
|
outputDir,
|
|
|
|
revision,
|
|
|
|
branch,
|
|
|
|
strict: publish && !dryRun,
|
|
|
|
);
|
2017-12-15 23:01:30 +00:00
|
|
|
int exitCode = 0;
|
2021-07-19 20:59:15 +00:00
|
|
|
late String message;
|
2017-12-15 23:01:30 +00:00
|
|
|
try {
|
2022-01-08 00:30:14 +00:00
|
|
|
final Map<String, String> version = await creator.initializeRepo();
|
2018-02-06 23:32:19 +00:00
|
|
|
final File outputFile = await creator.createArchive();
|
2022-11-29 04:14:24 +00:00
|
|
|
final ArchivePublisher publisher = ArchivePublisher(
|
|
|
|
tempDir,
|
|
|
|
revision,
|
|
|
|
branch,
|
|
|
|
version,
|
|
|
|
outputFile,
|
|
|
|
dryRun,
|
|
|
|
);
|
|
|
|
await publisher.generateLocalMetadata();
|
2019-12-05 21:34:06 +00:00
|
|
|
if (parsedArguments['publish'] as bool) {
|
2020-12-04 01:07:50 +00:00
|
|
|
await publisher.publishArchive(parsedArguments['force'] as bool);
|
2018-02-06 23:32:19 +00:00
|
|
|
}
|
2020-08-13 15:43:20 +00:00
|
|
|
} on PreparePackageException catch (e) {
|
2017-12-15 23:01:30 +00:00
|
|
|
exitCode = e.exitCode;
|
2020-08-13 15:43:20 +00:00
|
|
|
message = e.message;
|
|
|
|
} catch (e) {
|
2018-03-10 02:58:41 +00:00
|
|
|
exitCode = -1;
|
2020-08-13 15:43:20 +00:00
|
|
|
message = e.toString();
|
2017-12-15 23:01:30 +00:00
|
|
|
} finally {
|
|
|
|
if (removeTempDir) {
|
2018-01-10 21:37:36 +00:00
|
|
|
tempDir.deleteSync(recursive: true);
|
2017-12-15 23:01:30 +00:00
|
|
|
}
|
|
|
|
if (exitCode != 0) {
|
|
|
|
errorExit(message, exitCode: exitCode);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|