-
Notifications
You must be signed in to change notification settings - Fork 159
Generate, index and display Dart SDK API results in pub search. #1581
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
Changes from all commits
7c34c90
6977b11
56d5713
5737c57
e88a4f8
f31213b
a9d892f
82b37f8
9ca974d
0ec82a7
b53d45c
a7b2cf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import '../job/job.dart'; | |
import '../scorecard/backend.dart'; | ||
import '../scorecard/models.dart'; | ||
import '../shared/analyzer_client.dart'; | ||
import '../shared/configuration.dart' show envConfig; | ||
import '../shared/tool_env.dart'; | ||
import '../shared/urls.dart'; | ||
import '../shared/versions.dart' as versions; | ||
|
@@ -32,7 +33,8 @@ final Uuid _uuid = new Uuid(); | |
const statusFilePath = 'status.json'; | ||
const _archiveFilePath = 'package.tar.gz'; | ||
const _buildLogFilePath = 'log.txt'; | ||
const _dartdocTimeout = const Duration(minutes: 10); | ||
const _packageTimeout = const Duration(minutes: 10); | ||
const _sdkTimeout = const Duration(minutes: 20); | ||
final Duration _twoYears = const Duration(days: 2 * 365); | ||
|
||
final _pkgPubDartdocDir = | ||
|
@@ -42,6 +44,57 @@ class DartdocJobProcessor extends JobProcessor { | |
DartdocJobProcessor({Duration lockDuration}) | ||
: super(service: JobService.dartdoc, lockDuration: lockDuration); | ||
|
||
/// Uses the tool environment's SDK (the one that is used for analysis too) to | ||
/// generate dartdoc documentation and extracted data file for SDK API indexing. | ||
/// Only the extracted data file will be used and uploaded. | ||
Future generateDocsForSdk() async { | ||
if (await dartdocBackend.hasValidDartSdkDartdocData()) return; | ||
final tempDir = | ||
await Directory.systemTemp.createTemp('pub-dartlang-dartdoc'); | ||
try { | ||
final tempDirPath = tempDir.resolveSymbolicLinksSync(); | ||
final outputDir = tempDirPath; | ||
final args = [ | ||
'--sdk-docs', | ||
'--output', | ||
outputDir, | ||
'--hosted-url', | ||
siteRoot, | ||
'--link-to-remote', | ||
'--no-validate-links', | ||
]; | ||
if (envConfig.toolEnvDartSdkDir != null) { | ||
args.addAll(['--sdk-dir', envConfig.toolEnvDartSdkDir]); | ||
} | ||
final pr = await runProc( | ||
'dart', | ||
['bin/pub_dartdoc.dart']..addAll(args), | ||
workingDirectory: _pkgPubDartdocDir, | ||
timeout: _sdkTimeout, | ||
); | ||
|
||
final pubDataFile = new File(p.join(outputDir, 'pub-data.json')); | ||
final hasPubData = await pubDataFile.exists(); | ||
final isOk = pr.exitCode == 0 && hasPubData; | ||
if (!isOk) { | ||
_logger.warning( | ||
'Error while generating SDK docs.\n\n${pr.stdout}\n\n${pr.stderr}'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be an error? Can this be triggered by poor user code? In that case, can we recognize the difference between bad user input and an infrastructure problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is most likely an infrastructure problem, making it a hard error. |
||
throw new Exception( | ||
'Error while generating SDK docs (hasPubData: $hasPubData).'); | ||
} | ||
|
||
// prevent close races updating the same content in close succession | ||
if (await dartdocBackend.hasValidDartSdkDartdocData()) return; | ||
|
||
// upload only the pub dartdoc data file | ||
await dartdocBackend.uploadDartSdkDartdocData(pubDataFile); | ||
} catch (e, st) { | ||
_logger.warning('Error while generating SDK docs.', e, st); | ||
} finally { | ||
await tempDir.delete(recursive: true); | ||
} | ||
} | ||
|
||
@override | ||
Future<bool> shouldProcess( | ||
String package, String version, DateTime updated) async { | ||
|
@@ -231,7 +284,7 @@ class DartdocJobProcessor extends JobProcessor { | |
'dart', | ||
['bin/pub_dartdoc.dart']..addAll(args), | ||
workingDirectory: _pkgPubDartdocDir, | ||
timeout: _dartdocTimeout, | ||
timeout: _packageTimeout, | ||
); | ||
final hasIndexHtml = | ||
await new File(p.join(outputDir, 'index.html')).exists(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const _generatedStaticAssetPaths = const <String>['static-assets']; | |
// Storage contains package data in a form of /package/version/... | ||
// This path contains '-' and is an invalid package name, safe of conflicts. | ||
const _storageSharedAssetPrefix = 'shared-assets'; | ||
const _sdkAssetPrefix = 'sdk-assets'; | ||
|
||
/// Whether the generated file can be moved to the shared assets. | ||
bool isSharedAsset(String relativePath) { | ||
|
@@ -49,3 +50,13 @@ String contentObjectName(String packageName, String packageVersion, String uuid, | |
String relativePath) { | ||
return p.join(contentPrefix(packageName, packageVersion, uuid), relativePath); | ||
} | ||
|
||
/// ObjectName of an SDK asset. | ||
String sdkObjectName(String relativePath) { | ||
return p.join(_sdkAssetPrefix, relativePath); | ||
} | ||
|
||
/// The ObjectName for the Dart SDK's extracted dartdoc content. | ||
String dartSdkDartdocDataName(String runtimeVersion) { | ||
return sdkObjectName('dart/pub-dartdoc-data/$runtimeVersion.json.gz'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does anything garbage collect these old files or do they accumulate indefinitely? Does this mean we have to update the runtime version whenever we update the Dart SDK? Should we decouple the Dart SDK used for the API results and the Dart SDK pub's website itself uses? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No GC yet, but there will be.
We do need to update it right now, but we could decouple the runtime SDK version from it. I'll need to think about it if there is any additional risk with the current stack, and I'll file a separate PR. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we catch a specific exception instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall two distinct kind of error there, but one of them may be related to the outage I have mentioned earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other is
DetailedApiRequestError
, and I'm not sure where it is coming from.