Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the stats flag when documenting the testing package #4008

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
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
26 changes: 22 additions & 4 deletions tool/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Future<void> runDoc(ArgResults commandResults) async {
'help' => _docHelp(),
'package' => _docPackage(commandResults, withStats: stats),
'sdk' => docSdk(withStats: stats),
'testing-package' => docTestingPackage(),
'testing-package' => docTestingPackage(withStats: stats),
_ => throw UnimplementedError('Unknown doc target: "$target"'),
};
}
Expand Down Expand Up @@ -515,11 +515,15 @@ Map<String, String> createThrowawayPubCache() {
final String _defaultPubCache = Platform.environment['PUB_CACHE'] ??
path.context.resolveTildePath('~/.pub-cache');

Future<String> docTestingPackage() async {
Future<String> docTestingPackage({
bool withStats = false,
}) async {
var testPackagePath = testPackage.absolute.path;
var launcher = SubprocessLauncher('doc-test-package');
await launcher.runStreamedDartCommand(['pub', 'get'],
workingDirectory: testPackagePath);
await launcher.runStreamedDartCommand(
['pub', 'get'],
workingDirectory: testPackagePath,
);
var outputPath = _testingPackageDocsDir.absolute.path;
await launcher.runStreamedDartCommand(
[
Expand All @@ -533,7 +537,21 @@ Future<String> docTestingPackage() async {
'--pretty-index-json',
],
workingDirectory: testPackagePath,
withStats: withStats,
);

if (withStats && (Platform.isLinux || Platform.isMacOS)) {
// Prints all files in `outputPath`, newline-separated.
var findResult = Process.runSync('find', [outputPath, '-type', 'f']);
var fileCount = (findResult.stdout as String).split('\n').length;
var diskUsageResult = Process.runSync('du', ['-sh', outputPath]);
// Output looks like
// 146M /var/folders/72/ltck4q353hsg3bn8kpkg7f84005w15/T/sdkdocsHcquiB
var diskUsageNumber =
(diskUsageResult.stdout as String).trim().split(RegExp('\\s+')).first;
print('Generated $fileCount files amounting to $diskUsageNumber.');
}

return outputPath;
}

Expand Down