Skip to content

Commit 45f8c39

Browse files
authored
use 'dart pub' instead of calling the pub executable directly (#97749)
use 'dart pub' instead of calling the pub executable directly
1 parent 26d1da4 commit 45f8c39

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

dev/tools/dartdoc.dart

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ Future<void> main(List<String> arguments) async {
9191
pubEnvironment['PUB_CACHE'] = pubCachePath;
9292
}
9393

94-
final String pubExecutable = '$flutterRoot/bin/cache/dart-sdk/bin/pub';
94+
final String dartExecutable = '$flutterRoot/bin/cache/dart-sdk/bin/dart';
9595

9696
// Run pub.
97-
ProcessWrapper process = ProcessWrapper(await Process.start(
98-
pubExecutable,
99-
<String>['get'],
97+
ProcessWrapper process = ProcessWrapper(await runPubProcess(
98+
dartBinaryPath: dartExecutable,
99+
arguments: <String>['get'],
100100
workingDirectory: kDocsRoot,
101101
environment: pubEnvironment,
102102
));
@@ -120,8 +120,9 @@ Future<void> main(List<String> arguments) async {
120120

121121
// Verify which version of snippets and dartdoc we're using.
122122
final ProcessResult snippetsResult = Process.runSync(
123-
pubExecutable,
123+
dartExecutable,
124124
<String>[
125+
'pub',
125126
'global',
126127
'list',
127128
],
@@ -216,11 +217,11 @@ Future<void> main(List<String> arguments) async {
216217
];
217218

218219
String quote(String arg) => arg.contains(' ') ? "'$arg'" : arg;
219-
print('Executing: (cd $kDocsRoot ; $pubExecutable ${dartdocArgs.map<String>(quote).join(' ')})');
220+
print('Executing: (cd $kDocsRoot ; $dartExecutable ${dartdocArgs.map<String>(quote).join(' ')})');
220221

221-
process = ProcessWrapper(await Process.start(
222-
pubExecutable,
223-
dartdocArgs,
222+
process = ProcessWrapper(await runPubProcess(
223+
dartBinaryPath: dartExecutable,
224+
arguments: dartdocArgs,
224225
workingDirectory: kDocsRoot,
225226
environment: pubEnvironment,
226227
));
@@ -464,7 +465,6 @@ void putRedirectInOldIndexLocation() {
464465
File('$kPublishRoot/flutter/index.html').writeAsStringSync(metaTag);
465466
}
466467

467-
468468
void writeSnippetsIndexFile() {
469469
final Directory snippetsDir = Directory(path.join(kPublishRoot, 'snippets'));
470470
if (snippetsDir.existsSync()) {
@@ -531,3 +531,18 @@ void printStream(Stream<List<int>> stream, { String prefix = '', List<Pattern> f
531531
print('$prefix$line'.trim());
532532
});
533533
}
534+
535+
Future<Process> runPubProcess({
536+
required String dartBinaryPath,
537+
required List<String> arguments,
538+
String? workingDirectory,
539+
Map<String, String>? environment,
540+
@visibleForTesting
541+
ProcessManager processManager = const LocalProcessManager(),
542+
}) {
543+
return processManager.start(
544+
<Object>[dartBinaryPath, 'pub', ...arguments],
545+
workingDirectory: workingDirectory,
546+
environment: environment,
547+
);
548+
}

dev/tools/test/dartdoc_test.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:platform/platform.dart';
66
import 'package:test/test.dart';
77

88
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
9-
import '../dartdoc.dart' show getBranchName;
9+
import '../dartdoc.dart' show getBranchName, runPubProcess;
1010

1111
void main() {
1212
const String branchName = 'stable';
@@ -77,4 +77,22 @@ void main() {
7777
);
7878
expect(processManager, hasNoRemainingExpectations);
7979
});
80+
81+
test("runPubProcess doesn't use the pub binary", () {
82+
final ProcessManager processManager = FakeProcessManager.list(
83+
<FakeCommand>[
84+
const FakeCommand(
85+
command: <String>['dart', 'pub', '--one', '--two'],
86+
),
87+
],
88+
);
89+
90+
runPubProcess(
91+
dartBinaryPath: 'dart',
92+
arguments: <String>['--one', '--two'],
93+
processManager: processManager,
94+
);
95+
96+
expect(processManager, hasNoRemainingExpectations);
97+
});
8098
}

0 commit comments

Comments
 (0)