diff --git a/dev/devicelab/lib/tasks/sample_catalog_generator.dart b/dev/devicelab/lib/tasks/sample_catalog_generator.dart index 8b005d1179..c3a73d698c 100644 --- a/dev/devicelab/lib/tasks/sample_catalog_generator.dart +++ b/dev/devicelab/lib/tasks/sample_catalog_generator.dart @@ -9,6 +9,8 @@ import '../framework/adb.dart'; import '../framework/framework.dart'; import '../framework/ios.dart'; import '../framework/utils.dart'; +import 'save_catalog_screenshots.dart' show saveCatalogScreenshots; + Future samplePageCatalogGenerator(String authorizationToken) async { final Device device = await devices.workingDevice; @@ -19,7 +21,8 @@ Future samplePageCatalogGenerator(String authorizationToken) async { await inDirectory(catalogDirectory, () async { await flutter('packages', options: ['get']); - if (deviceOperatingSystem == DeviceOperatingSystem.ios) + final bool isIosDevice = deviceOperatingSystem == DeviceOperatingSystem.ios; + if (isIosDevice) await prepareProvisioningCertificates(catalogDirectory.path); await dart(['bin/sample_page.dart']); @@ -31,11 +34,12 @@ Future samplePageCatalogGenerator(String authorizationToken) async { deviceId, ]); - await dart([ - 'bin/save_screenshots.dart', - await getCurrentFlutterRepoCommit(), - authorizationToken, - ]); + await saveCatalogScreenshots( + directory: dir('${flutterDirectory.path}/examples/catalog/.generated'), + commit: await getCurrentFlutterRepoCommit(), + token: authorizationToken, + prefix: isIosDevice ? 'ios_' : '', + ); }); return new TaskResult.success(null); diff --git a/examples/catalog/bin/save_screenshots.dart b/dev/devicelab/lib/tasks/save_catalog_screenshots.dart similarity index 84% rename from examples/catalog/bin/save_screenshots.dart rename to dev/devicelab/lib/tasks/save_catalog_screenshots.dart index fd78f02c07..661266699f 100644 --- a/examples/catalog/bin/save_screenshots.dart +++ b/dev/devicelab/lib/tasks/save_catalog_screenshots.dart @@ -1,3 +1,7 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -56,6 +60,7 @@ class Upload { final HttpClientResponse response = await request.close().timeout(timeLimit); if (response.statusCode == HttpStatus.OK) { + logMessage('Saved $name'); await response.drain(); } else { // TODO(hansmuller): only retry on 5xx and 429 responses @@ -96,40 +101,40 @@ Future saveScreenshots(List fromPaths, List largeNames, Li for (int index = 0; index < uploads.length; index += 1) uploads[index] = new Upload(fromPaths[index], largeNames[index], smallNames[index]); - final HttpClient client = new HttpClient(); while(uploads.any(Upload.isNotComplete)) { + final HttpClient client = new HttpClient(); uploads = uploads.where(Upload.isNotComplete).toList(); await Future.wait(uploads.map((Upload upload) => upload.run(client))); + client.close(force: true); } - client.close(); } // If path is lib/foo.png then screenshotName is foo. String screenshotName(String path) => basenameWithoutExtension(path); -Future main(List args) async { - if (args.length != 2) - throw new UploadError('Usage: dart bin/save_screenshots.dart commit authorization'); - - final Directory outputDirectory = new Directory('.generated'); +Future saveCatalogScreenshots({ + Directory directory, // Where the *.png screenshots are. + String commit, // The commit hash to be used as a cloud storage "directory". + String token, // Cloud storage authorization token. + String prefix, // Prefix for all file names. + }) async { final List screenshots = []; - outputDirectory.listSync().forEach((FileSystemEntity entity) { + directory.listSync().forEach((FileSystemEntity entity) { if (entity is File && entity.path.endsWith('.png')) { final File file = entity; screenshots.add(file.path); } }); - final String commit = args[0]; final List largeNames = []; // Cloud storage names for the full res screenshots. final List smallNames = []; // Likewise for the scaled down screenshots. for (String path in screenshots) { final String name = screenshotName(path); - largeNames.add('$commit/$name.png'); - smallNames.add('$commit/${name}_small.png'); + largeNames.add('$commit/$prefix$name.png'); + smallNames.add('$commit/$prefix${name}_small.png'); } - authorizationToken = args[1]; + authorizationToken = token; await saveScreenshots(screenshots, largeNames, smallNames); } diff --git a/dev/devicelab/manifest.yaml b/dev/devicelab/manifest.yaml index a8fab3f439..c455fc220f 100644 --- a/dev/devicelab/manifest.yaml +++ b/dev/devicelab/manifest.yaml @@ -118,7 +118,7 @@ tasks: description: > Builds sample catalog markdown pages and Android screenshots stage: devicelab - required_agent_capabilities: ["linux/android"] + required_agent_capabilities: ["has-android-device"] flaky: true complex_layout_semantics_perf: diff --git a/dev/devicelab/pubspec.yaml b/dev/devicelab/pubspec.yaml index 141f8eeee7..d2a2397605 100644 --- a/dev/devicelab/pubspec.yaml +++ b/dev/devicelab/pubspec.yaml @@ -9,6 +9,7 @@ environment: dependencies: args: ^0.13.4 + image: ^1.1.27 meta: ^1.0.5 path: ^1.4.0 process: 2.0.3 diff --git a/examples/catalog/bin/sample_page.dart b/examples/catalog/bin/sample_page.dart index c9f1ac14cd..b790330737 100644 --- a/examples/catalog/bin/sample_page.dart +++ b/examples/catalog/bin/sample_page.dart @@ -180,7 +180,7 @@ void generate() { screenshotDriverTemplate, { 'paths': samples.map((SampleGenerator sample) { - return "'${outputFile('\${prefix}' + sample.sourceName + '.png').path}'"; + return "'${outputFile(sample.sourceName + '.png').path}'"; }).toList().join(',\n'), }, ); diff --git a/examples/catalog/bin/screenshot_test.dart.template b/examples/catalog/bin/screenshot_test.dart.template index 4457b0617e..2b283773d3 100644 --- a/examples/catalog/bin/screenshot_test.dart.template +++ b/examples/catalog/bin/screenshot_test.dart.template @@ -8,7 +8,6 @@ import 'package:test/test.dart'; void main() { group('sample screenshots', () { - final String prefix = Platform.isMacOS ? 'ios_' : ""; FlutterDriver driver; setUpAll(() async { diff --git a/examples/catalog/pubspec.yaml b/examples/catalog/pubspec.yaml index 3c2aec5e80..bca57f4a43 100644 --- a/examples/catalog/pubspec.yaml +++ b/examples/catalog/pubspec.yaml @@ -3,7 +3,6 @@ description: A collection of Flutter sample apps dependencies: flutter: sdk: flutter - image: path: ^1.4.0 dev_dependencies: