Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[tool] Use 'flutter pub get' for Flutter packages
Extracts common logic for running `pub get`, and switches commands to
use it. The common logic always uses `flutter pub get` for Flutter
packages, rather than `dart pub get`, since the latter will fail if
someone has a non-Flutter `dart` in their path before `flutter` (e.g.,
Dart team members contributing PRs).
  • Loading branch information
stuartmorgan-g committed Jul 7, 2023
commit b8e5a7af464a25fb5e038e51731fecf10c4529fe
12 changes: 2 additions & 10 deletions script/tool/lib/src/create_all_packages_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'common/core.dart';
import 'common/file_utils.dart';
import 'common/package_command.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/repository_package.dart';

/// The name of the build-all-packages project, as passed to `flutter create`.
Expand Down Expand Up @@ -96,7 +97,7 @@ class CreateAllPackagesAppCommand extends PackageCommand {
// further and/or implement https://github.com/flutter/flutter/issues/93407,
// and remove the need for this conditional.
if (!platform.isWindows) {
if (!await _genNativeBuildFiles()) {
if (!await runPubGet(app, processRunner, platform)) {
printError(
"Failed to generate native build files via 'flutter pub get'");
throw ToolExit(_exitGenNativeBuildFilesFailed);
Expand Down Expand Up @@ -371,15 +372,6 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
return buffer.toString();
}

Future<bool> _genNativeBuildFiles() async {
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>['pub', 'get'],
workingDir: _appDirectory,
);
return exitCode == 0;
}

Future<void> _updateMacosPodfile() async {
/// Only change the macOS deployment target if the host platform is macOS.
/// The Podfile is not generated on other platforms.
Expand Down
6 changes: 2 additions & 4 deletions script/tool/lib/src/custom_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:platform/platform.dart';

import 'common/package_looping_command.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/repository_package.dart';

const String _scriptName = 'run_tests.dart';
Expand Down Expand Up @@ -47,10 +48,7 @@ class CustomTestCommand extends PackageLoopingCommand {
// Run the custom Dart script if presest.
if (script.existsSync()) {
// Ensure that dependencies are available.
final int pubGetExitCode = await processRunner.runAndStream(
'dart', <String>['pub', 'get'],
workingDir: package.directory);
if (pubGetExitCode != 0) {
if (!await runPubGet(package, processRunner, platform)) {
return PackageResult.fail(
<String>['Unable to get script dependencies']);
}
Expand Down
12 changes: 4 additions & 8 deletions script/tool/lib/src/dart_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'common/core.dart';
import 'common/package_looping_command.dart';
import 'common/plugin_utils.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/repository_package.dart';

/// A command to run Dart unit tests for packages.
Expand Down Expand Up @@ -130,21 +131,16 @@ class DartTestCommand extends PackageLoopingCommand {
/// Runs the Dart tests for a non-Flutter package, returning true on success.
Future<bool> _runDartTests(RepositoryPackage package,
{String? platform}) async {
// Unlike `flutter test`, `pub run test` does not automatically get
// Unlike `flutter test`, `dart run test` does not automatically get
// packages
int exitCode = await processRunner.runAndStream(
'dart',
<String>['pub', 'get'],
workingDir: package.directory,
);
if (exitCode != 0) {
if (!await runPubGet(package, processRunner, super.platform)) {
printError('Unable to fetch dependencies.');
return false;
}

final String experiment = getStringArg(kEnableExperiment);

exitCode = await processRunner.runAndStream(
final int exitCode = await processRunner.runAndStream(
'dart',
<String>[
'run',
Expand Down
7 changes: 2 additions & 5 deletions script/tool/lib/src/publish_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:pub_semver/pub_semver.dart';
import 'common/core.dart';
import 'common/package_looping_command.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/pub_version_finder.dart';
import 'common/repository_package.dart';

Expand Down Expand Up @@ -136,11 +137,7 @@ class PublishCheckCommand extends PackageLoopingCommand {
// Run `dart pub get` on the examples of [package].
Future<void> _fetchExampleDeps(RepositoryPackage package) async {
for (final RepositoryPackage example in package.getExamples()) {
await processRunner.runAndStream(
'dart',
<String>['pub', 'get'],
workingDir: example.directory,
);
await runPubGet(example, processRunner, platform);
}
}

Expand Down
17 changes: 7 additions & 10 deletions script/tool/lib/src/update_dependency_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:yaml_edit/yaml_edit.dart';
import 'common/core.dart';
import 'common/package_looping_command.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/pub_version_finder.dart';
import 'common/repository_package.dart';

Expand Down Expand Up @@ -239,11 +240,9 @@ ${response.httpResponse.body}
}

print('${indentation}Running pub get...');
final io.ProcessResult getResult = await processRunner
.run('dart', <String>['pub', 'get'], workingDir: package.directory);
if (getResult.exitCode != 0) {
printError('dart pub get failed (${getResult.exitCode}):\n'
'${getResult.stdout}\n${getResult.stderr}\n');
if (!await runPubGet(package, processRunner, platform,
streamOutput: false)) {
printError('${indentation}Fetching dependencies failed');
return false;
}

Expand Down Expand Up @@ -273,11 +272,9 @@ ${response.httpResponse.body}
}

print('${indentation}Running pub get...');
final io.ProcessResult getResult = await processRunner
.run('dart', <String>['pub', 'get'], workingDir: package.directory);
if (getResult.exitCode != 0) {
printError('dart pub get failed (${getResult.exitCode}):\n'
'${getResult.stdout}\n${getResult.stderr}\n');
if (!await runPubGet(package, processRunner, platform,
streamOutput: false)) {
printError('${indentation}Fetching dependencies failed');
return false;
}

Expand Down
6 changes: 2 additions & 4 deletions script/tool/lib/src/update_excerpts_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:yaml_edit/yaml_edit.dart';
import 'common/core.dart';
import 'common/package_looping_command.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/repository_package.dart';

/// A command to update .md code excerpts from code files.
Expand Down Expand Up @@ -81,10 +82,7 @@ class UpdateExcerptsCommand extends PackageLoopingCommand {

try {
// Ensure that dependencies are available.
final int pubGetExitCode = await processRunner.runAndStream(
'dart', <String>['pub', 'get'],
workingDir: example.directory);
if (pubGetExitCode != 0) {
if (!await runPubGet(example, processRunner, platform)) {
return PackageResult.fail(
<String>['Unable to get script dependencies']);
}
Expand Down
10 changes: 7 additions & 3 deletions script/tool/test/publish_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void main() {
final Iterable<ProcessCall> pubGetCalls =
plugin1.getExamples().map((RepositoryPackage example) {
return ProcessCall(
'dart',
getFlutterCommand(mockPlatform),
const <String>['pub', 'get'],
example.path,
);
Expand Down Expand Up @@ -117,6 +117,7 @@ void main() {
createFakePlugin('plugin_tools_test_package_a', packagesDir);

processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
FakeProcessInfo(MockProcess(exitCode: 1, stdout: 'Some error from pub'),
<String>['pub', 'publish'])
];
Expand Down Expand Up @@ -205,7 +206,8 @@ void main() {
'Packages with an SDK constraint on a pre-release of the Dart '
'SDK should themselves be published as a pre-release version.');
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
FakeProcessInfo(process, <String>['pub', 'publish'])
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
FakeProcessInfo(process, <String>['pub', 'publish']),
];

expect(
Expand All @@ -223,7 +225,8 @@ void main() {
'Packages with an SDK constraint on a pre-release of the Dart '
'SDK should themselves be published as a pre-release version.');
processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
FakeProcessInfo(process, <String>['pub', 'publish'])
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
FakeProcessInfo(process, <String>['pub', 'publish']),
];

Error? commandError;
Expand All @@ -247,6 +250,7 @@ void main() {
createFakePlugin('d', packagesDir);

processRunner.mockProcessesForExecutable['flutter'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
FakeProcessInfo(MockProcess(stdout: 'Package has 0 warnings.'),
<String>['pub', 'publish']),
];
Expand Down
4 changes: 2 additions & 2 deletions script/tool/test/update_dependency_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ dev_dependencies:
expect(
output,
containsAllInOrder(<Matcher>[
contains('dart pub get failed'),
contains('Fetching dependencies failed'),
contains('Failed to update pigeon files'),
]),
);
Expand Down Expand Up @@ -545,7 +545,7 @@ dev_dependencies:
expect(
output,
containsAllInOrder(<Matcher>[
contains('dart pub get failed'),
contains('Fetching dependencies failed'),
contains('Failed to update mocks'),
]),
);
Expand Down
13 changes: 7 additions & 6 deletions script/tool/test/update_excerpts_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:file/memory.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';
import 'package:flutter_plugin_tools/src/update_excerpts_command.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import 'package:test/test.dart';

import 'common/package_command_test.mocks.dart';
Expand Down Expand Up @@ -48,7 +49,8 @@ void main() {
expect(
processRunner.recordedCalls,
containsAll(<ProcessCall>[
ProcessCall('dart', const <String>['pub', 'get'], example.path),
ProcessCall(getFlutterCommand(const LocalPlatform()),
const <String>['pub', 'get'], example.path),
ProcessCall(
'dart',
const <String>[
Expand Down Expand Up @@ -218,7 +220,8 @@ void main() {
final RepositoryPackage package = createFakePlugin('a_package', packagesDir,
extraFiles: <String>[kReadmeExcerptConfigPath]);

processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
processRunner.mockProcessesForExecutable[
getFlutterCommand(const LocalPlatform())] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(exitCode: 1), <String>['pub', 'get'])
];

Expand Down Expand Up @@ -249,7 +252,8 @@ void main() {
createFakePlugin('a_package', packagesDir,
extraFiles: <String>[kReadmeExcerptConfigPath]);

processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
processRunner.mockProcessesForExecutable[
getFlutterCommand(const LocalPlatform())] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(exitCode: 1), <String>['pub', 'get'])
];

Expand All @@ -274,7 +278,6 @@ void main() {
extraFiles: <String>[kReadmeExcerptConfigPath]);

processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
FakeProcessInfo(MockProcess(exitCode: 1), <String>['run', 'build_runner'])
];

Expand All @@ -299,7 +302,6 @@ void main() {
extraFiles: <String>[kReadmeExcerptConfigPath]);

processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
FakeProcessInfo(MockProcess(), <String>['run', 'build_runner']),
FakeProcessInfo(
MockProcess(exitCode: 1), <String>['run', 'code_excerpt_updater']),
Expand All @@ -326,7 +328,6 @@ void main() {
extraFiles: <String>[kReadmeExcerptConfigPath, 'example/README.md']);

processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
FakeProcessInfo(MockProcess(), <String>['run', 'build_runner']),
FakeProcessInfo(MockProcess(), <String>['run', 'code_excerpt_updater']),
FakeProcessInfo(
Expand Down