mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
precompile generate_gradle_lockfile script BEFORE updating pub dependencies (#160059)
Avoid situations like https://github.com/flutter/flutter/issues/160055
This commit is contained in:
parent
82ecbb5cbd
commit
29a6c648ca
@ -85,6 +85,7 @@ This PR was generated by the automated
|
||||
final String orgName;
|
||||
|
||||
Future<void> roll() async {
|
||||
final Directory tempDir = framework.fileSystem.systemTempDirectory.createTempSync();
|
||||
try {
|
||||
await authLogin();
|
||||
final bool openPrAlready = await hasOpenPrs();
|
||||
@ -92,18 +93,26 @@ This PR was generated by the automated
|
||||
// Don't open multiple roll PRs.
|
||||
return;
|
||||
}
|
||||
final Directory frameworkDir = await framework.checkoutDirectory;
|
||||
final String regenerateBinary = await _prebuildRegenerateGradleLockfilesBinary(frameworkDir, tempDir);
|
||||
final bool didUpdate = await updatePackages();
|
||||
if (!didUpdate) {
|
||||
log('Packages are already at latest.');
|
||||
return;
|
||||
}
|
||||
await _regenerateGradleLockfiles(await framework.checkoutDirectory);
|
||||
await _regenerateGradleLockfiles(frameworkDir, regenerateBinary);
|
||||
await pushBranch();
|
||||
await createPr(repository: await framework.checkoutDirectory);
|
||||
await authLogout();
|
||||
} on Exception catch (exception) {
|
||||
final String message = _redactToken(exception.toString());
|
||||
throw Exception('${exception.runtimeType}: $message');
|
||||
} finally {
|
||||
try {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
} on FileSystemException {
|
||||
// Ignore failures
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,12 +148,58 @@ This PR was generated by the automated
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> _regenerateGradleLockfiles(Directory repoRoot) async {
|
||||
Future<String> _prebuildRegenerateGradleLockfilesBinary(Directory repoRoot, Directory tempDir) async {
|
||||
final String entrypoint = '${repoRoot.path}/dev/tools/bin/generate_gradle_lockfiles.dart';
|
||||
final File target = tempDir.childFile('generate_gradle_lockfiles');
|
||||
await framework.streamDart(
|
||||
<String>['pub', 'get'],
|
||||
workingDirectory: '${repoRoot.path}/dev/tools',
|
||||
);
|
||||
await framework.streamDart(<String>[
|
||||
'${repoRoot.path}/dev/tools/bin/generate_gradle_lockfiles.dart',
|
||||
'compile',
|
||||
'exe',
|
||||
entrypoint,
|
||||
'-o',
|
||||
target.path,
|
||||
]);
|
||||
|
||||
assert(
|
||||
target.existsSync(),
|
||||
'expected ${target.path} to exist after compilation, but it did not.',
|
||||
);
|
||||
|
||||
processManager.runSync(<String>['chmod', '+x', target.path]);
|
||||
|
||||
return target.path;
|
||||
}
|
||||
|
||||
Future<void> _regenerateGradleLockfiles(Directory repoRoot, String regenerateBinary) async {
|
||||
final List<String> cmd = <String>[
|
||||
regenerateBinary,
|
||||
'--no-gradle-generation',
|
||||
'--no-exclusion',
|
||||
]);
|
||||
];
|
||||
final io.Process regenerateProcess = await processManager.start(cmd);
|
||||
regenerateProcess
|
||||
.stdout
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) => stdio.printTrace('[stdout] $line'));
|
||||
regenerateProcess
|
||||
.stderr
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) => stdio.printTrace('[stderr] $line'));
|
||||
|
||||
final int exitCode = await regenerateProcess.exitCode;
|
||||
if (exitCode != 0) {
|
||||
throw io.ProcessException(
|
||||
cmd.first,
|
||||
cmd.sublist(1),
|
||||
'Process failed',
|
||||
exitCode,
|
||||
);
|
||||
}
|
||||
switch (CheckoutStatePostGradleRegeneration(await framework.gitStatus(), framework.fileSystem.path)) {
|
||||
// If the git checkout is clean, we did not update any lockfiles and we do
|
||||
// not need an additional commit.
|
||||
|
@ -671,16 +671,23 @@ class FrameworkRepository extends Repository {
|
||||
cmd,
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
process
|
||||
final StreamSubscription<String> stdoutSub = process
|
||||
.stdout
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen(stdoutCallback ?? stdio.printTrace);
|
||||
process
|
||||
final StreamSubscription<String> stderrSub = process
|
||||
.stderr
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.listen(stderrCallback ?? stdio.printError);
|
||||
await Future.wait<void>(<Future<void>>[
|
||||
stdoutSub.asFuture<void>(),
|
||||
stderrSub.asFuture<void>(),
|
||||
]);
|
||||
unawaited(stdoutSub.cancel());
|
||||
unawaited(stderrSub.cancel());
|
||||
|
||||
final int exitCode = await process.exitCode;
|
||||
if (exitCode != 0) {
|
||||
throw io.ProcessException(
|
||||
|
@ -281,6 +281,27 @@ void main() {
|
||||
'rev-parse',
|
||||
'HEAD',
|
||||
], stdout: 'deadbeef'),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
|
||||
'pub',
|
||||
'get',
|
||||
],
|
||||
workingDirectory: '$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools',
|
||||
),
|
||||
FakeCommand(command: const <String>[
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
|
||||
'compile',
|
||||
'exe',
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
|
||||
'-o',
|
||||
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
|
||||
], onRun: (_) => fileSystem.file('/.tmp_rand0/rand0/generate_gradle_lockfiles').createSync()),
|
||||
const FakeCommand(command: <String>[
|
||||
'chmod',
|
||||
'+x',
|
||||
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
|
||||
]),
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'ls-remote',
|
||||
@ -373,6 +394,27 @@ void main() {
|
||||
'rev-parse',
|
||||
'HEAD',
|
||||
], stdout: 'deadbeef'),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
|
||||
'pub',
|
||||
'get',
|
||||
],
|
||||
workingDirectory: '$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools',
|
||||
),
|
||||
FakeCommand(command: const <String>[
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
|
||||
'compile',
|
||||
'exe',
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
|
||||
'-o',
|
||||
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
|
||||
], onRun: (_) => fileSystem.file('/.tmp_rand0/rand0/generate_gradle_lockfiles').createSync()),
|
||||
const FakeCommand(command: <String>[
|
||||
'chmod',
|
||||
'+x',
|
||||
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
|
||||
]),
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'ls-remote',
|
||||
@ -427,8 +469,7 @@ void main() {
|
||||
'HEAD',
|
||||
], stdout: '000deadbeef'),
|
||||
const FakeCommand(command: <String>[
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
|
||||
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
|
||||
'/.tmp_rand0/rand0/generate_gradle_lockfiles',
|
||||
'--no-gradle-generation',
|
||||
'--no-exclusion',
|
||||
]),
|
||||
|
Loading…
Reference in New Issue
Block a user