mirror of
https://github.com/flutter/flutter
synced 2024-09-13 21:32:11 +00:00
use 'dart pub' instead of calling the pub executable directly (#97749)
use 'dart pub' instead of calling the pub executable directly
This commit is contained in:
parent
26d1da4188
commit
45f8c39052
|
@ -91,12 +91,12 @@ Future<void> main(List<String> arguments) async {
|
|||
pubEnvironment['PUB_CACHE'] = pubCachePath;
|
||||
}
|
||||
|
||||
final String pubExecutable = '$flutterRoot/bin/cache/dart-sdk/bin/pub';
|
||||
final String dartExecutable = '$flutterRoot/bin/cache/dart-sdk/bin/dart';
|
||||
|
||||
// Run pub.
|
||||
ProcessWrapper process = ProcessWrapper(await Process.start(
|
||||
pubExecutable,
|
||||
<String>['get'],
|
||||
ProcessWrapper process = ProcessWrapper(await runPubProcess(
|
||||
dartBinaryPath: dartExecutable,
|
||||
arguments: <String>['get'],
|
||||
workingDirectory: kDocsRoot,
|
||||
environment: pubEnvironment,
|
||||
));
|
||||
|
@ -120,8 +120,9 @@ Future<void> main(List<String> arguments) async {
|
|||
|
||||
// Verify which version of snippets and dartdoc we're using.
|
||||
final ProcessResult snippetsResult = Process.runSync(
|
||||
pubExecutable,
|
||||
dartExecutable,
|
||||
<String>[
|
||||
'pub',
|
||||
'global',
|
||||
'list',
|
||||
],
|
||||
|
@ -216,11 +217,11 @@ Future<void> main(List<String> arguments) async {
|
|||
];
|
||||
|
||||
String quote(String arg) => arg.contains(' ') ? "'$arg'" : arg;
|
||||
print('Executing: (cd $kDocsRoot ; $pubExecutable ${dartdocArgs.map<String>(quote).join(' ')})');
|
||||
print('Executing: (cd $kDocsRoot ; $dartExecutable ${dartdocArgs.map<String>(quote).join(' ')})');
|
||||
|
||||
process = ProcessWrapper(await Process.start(
|
||||
pubExecutable,
|
||||
dartdocArgs,
|
||||
process = ProcessWrapper(await runPubProcess(
|
||||
dartBinaryPath: dartExecutable,
|
||||
arguments: dartdocArgs,
|
||||
workingDirectory: kDocsRoot,
|
||||
environment: pubEnvironment,
|
||||
));
|
||||
|
@ -464,7 +465,6 @@ void putRedirectInOldIndexLocation() {
|
|||
File('$kPublishRoot/flutter/index.html').writeAsStringSync(metaTag);
|
||||
}
|
||||
|
||||
|
||||
void writeSnippetsIndexFile() {
|
||||
final Directory snippetsDir = Directory(path.join(kPublishRoot, 'snippets'));
|
||||
if (snippetsDir.existsSync()) {
|
||||
|
@ -531,3 +531,18 @@ void printStream(Stream<List<int>> stream, { String prefix = '', List<Pattern> f
|
|||
print('$prefix$line'.trim());
|
||||
});
|
||||
}
|
||||
|
||||
Future<Process> runPubProcess({
|
||||
required String dartBinaryPath,
|
||||
required List<String> arguments,
|
||||
String? workingDirectory,
|
||||
Map<String, String>? environment,
|
||||
@visibleForTesting
|
||||
ProcessManager processManager = const LocalProcessManager(),
|
||||
}) {
|
||||
return processManager.start(
|
||||
<Object>[dartBinaryPath, 'pub', ...arguments],
|
||||
workingDirectory: workingDirectory,
|
||||
environment: environment,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:platform/platform.dart';
|
|||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
|
||||
import '../dartdoc.dart' show getBranchName;
|
||||
import '../dartdoc.dart' show getBranchName, runPubProcess;
|
||||
|
||||
void main() {
|
||||
const String branchName = 'stable';
|
||||
|
@ -77,4 +77,22 @@ void main() {
|
|||
);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
test("runPubProcess doesn't use the pub binary", () {
|
||||
final ProcessManager processManager = FakeProcessManager.list(
|
||||
<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['dart', 'pub', '--one', '--two'],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
runPubProcess(
|
||||
dartBinaryPath: 'dart',
|
||||
arguments: <String>['--one', '--two'],
|
||||
processManager: processManager,
|
||||
);
|
||||
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue