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;
|
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.
|
// Run pub.
|
||||||
ProcessWrapper process = ProcessWrapper(await Process.start(
|
ProcessWrapper process = ProcessWrapper(await runPubProcess(
|
||||||
pubExecutable,
|
dartBinaryPath: dartExecutable,
|
||||||
<String>['get'],
|
arguments: <String>['get'],
|
||||||
workingDirectory: kDocsRoot,
|
workingDirectory: kDocsRoot,
|
||||||
environment: pubEnvironment,
|
environment: pubEnvironment,
|
||||||
));
|
));
|
||||||
@ -120,8 +120,9 @@ Future<void> main(List<String> arguments) async {
|
|||||||
|
|
||||||
// Verify which version of snippets and dartdoc we're using.
|
// Verify which version of snippets and dartdoc we're using.
|
||||||
final ProcessResult snippetsResult = Process.runSync(
|
final ProcessResult snippetsResult = Process.runSync(
|
||||||
pubExecutable,
|
dartExecutable,
|
||||||
<String>[
|
<String>[
|
||||||
|
'pub',
|
||||||
'global',
|
'global',
|
||||||
'list',
|
'list',
|
||||||
],
|
],
|
||||||
@ -216,11 +217,11 @@ Future<void> main(List<String> arguments) async {
|
|||||||
];
|
];
|
||||||
|
|
||||||
String quote(String arg) => arg.contains(' ') ? "'$arg'" : arg;
|
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(
|
process = ProcessWrapper(await runPubProcess(
|
||||||
pubExecutable,
|
dartBinaryPath: dartExecutable,
|
||||||
dartdocArgs,
|
arguments: dartdocArgs,
|
||||||
workingDirectory: kDocsRoot,
|
workingDirectory: kDocsRoot,
|
||||||
environment: pubEnvironment,
|
environment: pubEnvironment,
|
||||||
));
|
));
|
||||||
@ -464,7 +465,6 @@ void putRedirectInOldIndexLocation() {
|
|||||||
File('$kPublishRoot/flutter/index.html').writeAsStringSync(metaTag);
|
File('$kPublishRoot/flutter/index.html').writeAsStringSync(metaTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void writeSnippetsIndexFile() {
|
void writeSnippetsIndexFile() {
|
||||||
final Directory snippetsDir = Directory(path.join(kPublishRoot, 'snippets'));
|
final Directory snippetsDir = Directory(path.join(kPublishRoot, 'snippets'));
|
||||||
if (snippetsDir.existsSync()) {
|
if (snippetsDir.existsSync()) {
|
||||||
@ -531,3 +531,18 @@ void printStream(Stream<List<int>> stream, { String prefix = '', List<Pattern> f
|
|||||||
print('$prefix$line'.trim());
|
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 'package:test/test.dart';
|
||||||
|
|
||||||
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
|
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
|
||||||
import '../dartdoc.dart' show getBranchName;
|
import '../dartdoc.dart' show getBranchName, runPubProcess;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const String branchName = 'stable';
|
const String branchName = 'stable';
|
||||||
@ -77,4 +77,22 @@ void main() {
|
|||||||
);
|
);
|
||||||
expect(processManager, hasNoRemainingExpectations);
|
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…
x
Reference in New Issue
Block a user