Skip to content

Commit 06d7288

Browse files
authored
Move analyze and test tasks (dart-lang#3461)
1 parent d716fa3 commit 06d7288

File tree

3 files changed

+184
-123
lines changed

3 files changed

+184
-123
lines changed

tool/grind.dart

Lines changed: 25 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ final String _dartdocDocsPath = createTempSync('dartdoc').path;
5050

5151
final Directory _flutterDir = createTempSync('flutter');
5252

53-
Directory get testPackage => Directory(p.joinAll(['testing', 'test_package']));
54-
55-
Directory get testPackageExperiments =>
56-
Directory(p.joinAll(['testing', 'test_package_experiments']));
57-
5853
Directory get testPackageFlutterPlugin => Directory(
5954
p.joinAll(['testing', 'flutter_packages', 'test_package_flutter_plugin']));
6055

@@ -84,35 +79,13 @@ final Directory flutterDirDevTools =
8479
Directory(p.join(_flutterDir.path, 'dev', 'tools'));
8580

8681
@Task('Analyze dartdoc to ensure there are no errors and warnings')
87-
@Depends(analyzeTestPackages)
8882
void analyze() async {
89-
await SubprocessLauncher('analyze').runStreamed(
90-
Platform.resolvedExecutable,
91-
['analyze', '--fatal-infos', '.'],
92-
);
83+
await task.analyzeTestPackages();
84+
await task.analyzePackage();
9385
}
9486

9587
@Task('Analyze the test packages')
96-
void analyzeTestPackages() async {
97-
var testPackagePaths = [testPackage.path];
98-
if (Platform.version.contains('dev')) {
99-
testPackagePaths.add(testPackageExperiments.path);
100-
}
101-
for (var testPackagePath in testPackagePaths) {
102-
await SubprocessLauncher('pub-get').runStreamed(
103-
Platform.resolvedExecutable,
104-
['pub', 'get'],
105-
workingDirectory: testPackagePath,
106-
);
107-
await SubprocessLauncher('analyze-test-package').runStreamed(
108-
Platform.resolvedExecutable,
109-
// TODO(srawlins): Analyze the whole directory by ignoring the pubspec
110-
// reports.
111-
['analyze', 'lib'],
112-
workingDirectory: testPackagePath,
113-
);
114-
}
115-
}
88+
void analyzeTestPackages() async => task.analyzeTestPackages();
11689

11790
@Task('Check for dart format cleanliness')
11891
void checkFormat() async {
@@ -148,10 +121,11 @@ void checkFormat() async {
148121
analyze,
149122
checkFormat,
150123
checkBuild,
151-
tryPublish,
152-
test,
153124
)
154-
void presubmit() {}
125+
void presubmit() async {
126+
await task.runTryPublish();
127+
await task.runTest();
128+
}
155129

156130
@Task('Run tests, self-test dartdoc, and run the publish test')
157131
@Depends(presubmit, test, testDartdoc)
@@ -268,7 +242,7 @@ Future<Iterable<Map<String, Object?>>> _buildTestPackageDocs(
268242
String label = '',
269243
String? testPackagePath}) async {
270244
if (label != '') label = '-$label';
271-
testPackagePath ??= testPackage.absolute.path;
245+
testPackagePath ??= task.testPackage.absolute.path;
272246
var launcher = SubprocessLauncher('build-test-package-docs$label');
273247
var testPackagePubGet = launcher.runStreamed(
274248
Platform.resolvedExecutable, ['pub', 'get'],
@@ -301,7 +275,7 @@ Future<Iterable<Map<String, Object?>>> _buildTestPackageDocs(
301275
Future<void> buildTestExperimentsPackageDocs() async {
302276
await _buildTestPackageDocs(
303277
_testPackageExperimentsDocsDir.absolute.path, Directory.current.path,
304-
testPackagePath: testPackageExperiments.absolute.path,
278+
testPackagePath: task.testPackageExperiments.absolute.path,
305279
params: [
306280
'--enable-experiment',
307281
'non-nullable,generic-metadata',
@@ -311,10 +285,11 @@ Future<void> buildTestExperimentsPackageDocs() async {
311285

312286
@Task('Serve experimental test package on port 8003.')
313287
@Depends(buildTestExperimentsPackageDocs)
314-
Future<void> serveTestExperimentsPackageDocs() async {
315-
await _serveDocsFrom(_testPackageExperimentsDocsDir.absolute.path, 8003,
316-
'test-package-docs-experiments');
317-
}
288+
Future<void> serveTestExperimentsPackageDocs() async =>
289+
await task.servePackageDocs(
290+
name: Platform.environment['PACKAGE_NAME']!,
291+
version: Platform.environment['PACKAGE_VERSION'],
292+
);
318293

319294
@Task('Build test package docs (HTML) with inherited docs and source code')
320295
@Depends(clean)
@@ -344,45 +319,8 @@ Future<void> startTestPackageDocsServer() async {
344319
]);
345320
}
346321

347-
bool _serveReady = false;
348-
349-
Future<void> _serveDocsFrom(String servePath, int port, String context) async {
350-
log('launching dhttpd on port $port for $context');
351-
var launcher = SubprocessLauncher(context);
352-
if (!_serveReady) {
353-
await launcher.runStreamed(Platform.resolvedExecutable, ['pub', 'get']);
354-
await launcher.runStreamed(
355-
Platform.resolvedExecutable, ['pub', 'global', 'activate', 'dhttpd']);
356-
_serveReady = true;
357-
}
358-
await launcher.runStreamed(Platform.resolvedExecutable, [
359-
'pub',
360-
'global',
361-
'run',
362-
'dhttpd',
363-
'--port',
364-
'$port',
365-
'--path',
366-
servePath
367-
]);
368-
}
369-
370322
@Task('Serve generated SDK docs locally with dhttpd on port 8000')
371-
@Depends(buildSdkDocs)
372-
Future<void> serveSdkDocs() async {
373-
log('launching dhttpd on port 8000 for SDK');
374-
var launcher = SubprocessLauncher('serve-sdk-docs');
375-
await launcher.runStreamed(Platform.resolvedExecutable, [
376-
'pub',
377-
'global',
378-
'run',
379-
'dhttpd',
380-
'--port',
381-
'8000',
382-
'--path',
383-
task.sdkDocsDir.path,
384-
]);
385-
}
323+
Future<void> serveSdkDocs() async => await task.serveSdkDocs();
386324

387325
@Task('Compare warnings in Dartdoc for Flutter')
388326
Future<void> compareFlutterWarnings() async {
@@ -506,26 +444,28 @@ Future<Iterable<Map<String, Object?>>> _buildFlutterDocs(
506444
@Task(
507445
'Build an arbitrary pub package based on PACKAGE_NAME and PACKAGE_VERSION '
508446
'environment variables')
509-
Future<String> buildPubPackage() async => task.docPackage(
447+
Future<String> buildPubPackage() async => await task.docPackage(
510448
name: Platform.environment['PACKAGE_NAME']!,
511449
version: Platform.environment['PACKAGE_VERSION'],
512450
);
513451

514452
@Task(
515-
'Serve an arbitrary pub package based on PACKAGE_NAME and PACKAGE_VERSION environment variables')
516-
Future<void> servePubPackage() async {
517-
await _serveDocsFrom(await buildPubPackage(), 9000, 'serve-pub-package');
518-
}
453+
'Serve an arbitrary pub package based on PACKAGE_NAME and PACKAGE_VERSION '
454+
'environment variables')
455+
Future<void> servePubPackage() async => await task.servePackageDocs(
456+
name: Platform.environment['PACKAGE_NAME']!,
457+
version: Platform.environment['PACKAGE_VERSION'],
458+
);
519459

520460
@Task('Rebuild generated files')
521-
@Depends(clean, buildWeb)
461+
@Depends(clean)
522462
Future<void> build() async {
523463
if (Platform.isWindows) {
524464
// Built files only need to be built on Linux and MacOS, as there are path
525465
// issues with Windows.
526466
return;
527467
}
528-
468+
await task.buildWeb();
529469
await task.buildRenderers();
530470
await task.buildDartdocOptions();
531471
}
@@ -595,11 +535,7 @@ Future<void> checkBuild() async {
595535
Future<void> tryPublish() async => await task.runTryPublish();
596536

597537
@Task('Run all the tests.')
598-
@Depends(analyzeTestPackages)
599-
Future<void> test() async {
600-
await SubprocessLauncher('dart run test').runStreamed(
601-
Platform.resolvedExecutable, <String>['--enable-asserts', 'run', 'test']);
602-
}
538+
Future<void> test() async => await task.runTest();
603539

604540
@Task('Clean up test directories and delete build cache')
605541
Future<void> clean() async {

tool/src/subprocess_launcher.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,19 @@ class SubprocessLauncher {
143143
return jsonObjects;
144144
}
145145

146+
Future<Iterable<Map<String, Object?>>> runStreamedDartCommand(
147+
List<String> arguments, {
148+
String? workingDirectory,
149+
Map<String, String>? environment,
150+
bool includeParentEnvironment = true,
151+
}) async =>
152+
await runStreamed(
153+
Platform.executable,
154+
arguments,
155+
workingDirectory: workingDirectory,
156+
environment: environment,
157+
includeParentEnvironment: includeParentEnvironment,
158+
);
159+
146160
static final _quotables = RegExp(r'[ "\r\n\$]');
147161
}

0 commit comments

Comments
 (0)