Skip to content

Commit ede575a

Browse files
author
Hans Muller
authored
Refactor sample catalog screenshot production (flutter#10676)
1 parent e5213b8 commit ede575a

7 files changed

Lines changed: 30 additions & 22 deletions

File tree

dev/devicelab/lib/tasks/sample_catalog_generator.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import '../framework/adb.dart';
99
import '../framework/framework.dart';
1010
import '../framework/ios.dart';
1111
import '../framework/utils.dart';
12+
import 'save_catalog_screenshots.dart' show saveCatalogScreenshots;
13+
1214

1315
Future<TaskResult> samplePageCatalogGenerator(String authorizationToken) async {
1416
final Device device = await devices.workingDevice;
@@ -19,7 +21,8 @@ Future<TaskResult> samplePageCatalogGenerator(String authorizationToken) async {
1921
await inDirectory(catalogDirectory, () async {
2022
await flutter('packages', options: <String>['get']);
2123

22-
if (deviceOperatingSystem == DeviceOperatingSystem.ios)
24+
final bool isIosDevice = deviceOperatingSystem == DeviceOperatingSystem.ios;
25+
if (isIosDevice)
2326
await prepareProvisioningCertificates(catalogDirectory.path);
2427

2528
await dart(<String>['bin/sample_page.dart']);
@@ -31,11 +34,12 @@ Future<TaskResult> samplePageCatalogGenerator(String authorizationToken) async {
3134
deviceId,
3235
]);
3336

34-
await dart(<String>[
35-
'bin/save_screenshots.dart',
36-
await getCurrentFlutterRepoCommit(),
37-
authorizationToken,
38-
]);
37+
await saveCatalogScreenshots(
38+
directory: dir('${flutterDirectory.path}/examples/catalog/.generated'),
39+
commit: await getCurrentFlutterRepoCommit(),
40+
token: authorizationToken,
41+
prefix: isIosDevice ? 'ios_' : '',
42+
);
3943
});
4044

4145
return new TaskResult.success(null);

examples/catalog/bin/save_screenshots.dart renamed to dev/devicelab/lib/tasks/save_catalog_screenshots.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
15
import 'dart:async';
26
import 'dart:convert';
37
import 'dart:io';
@@ -56,6 +60,7 @@ class Upload {
5660

5761
final HttpClientResponse response = await request.close().timeout(timeLimit);
5862
if (response.statusCode == HttpStatus.OK) {
63+
logMessage('Saved $name');
5964
await response.drain<Null>();
6065
} else {
6166
// TODO(hansmuller): only retry on 5xx and 429 responses
@@ -96,40 +101,40 @@ Future<Null> saveScreenshots(List<String> fromPaths, List<String> largeNames, Li
96101
for (int index = 0; index < uploads.length; index += 1)
97102
uploads[index] = new Upload(fromPaths[index], largeNames[index], smallNames[index]);
98103

99-
final HttpClient client = new HttpClient();
100104
while(uploads.any(Upload.isNotComplete)) {
105+
final HttpClient client = new HttpClient();
101106
uploads = uploads.where(Upload.isNotComplete).toList();
102107
await Future.wait(uploads.map((Upload upload) => upload.run(client)));
108+
client.close(force: true);
103109
}
104-
client.close();
105110
}
106111

107112

108113
// If path is lib/foo.png then screenshotName is foo.
109114
String screenshotName(String path) => basenameWithoutExtension(path);
110115

111-
Future<Null> main(List<String> args) async {
112-
if (args.length != 2)
113-
throw new UploadError('Usage: dart bin/save_screenshots.dart commit authorization');
114-
115-
final Directory outputDirectory = new Directory('.generated');
116+
Future<Null> saveCatalogScreenshots({
117+
Directory directory, // Where the *.png screenshots are.
118+
String commit, // The commit hash to be used as a cloud storage "directory".
119+
String token, // Cloud storage authorization token.
120+
String prefix, // Prefix for all file names.
121+
}) async {
116122
final List<String> screenshots = <String>[];
117-
outputDirectory.listSync().forEach((FileSystemEntity entity) {
123+
directory.listSync().forEach((FileSystemEntity entity) {
118124
if (entity is File && entity.path.endsWith('.png')) {
119125
final File file = entity;
120126
screenshots.add(file.path);
121127
}
122128
});
123129

124-
final String commit = args[0];
125130
final List<String> largeNames = <String>[]; // Cloud storage names for the full res screenshots.
126131
final List<String> smallNames = <String>[]; // Likewise for the scaled down screenshots.
127132
for (String path in screenshots) {
128133
final String name = screenshotName(path);
129-
largeNames.add('$commit/$name.png');
130-
smallNames.add('$commit/${name}_small.png');
134+
largeNames.add('$commit/$prefix$name.png');
135+
smallNames.add('$commit/$prefix${name}_small.png');
131136
}
132137

133-
authorizationToken = args[1];
138+
authorizationToken = token;
134139
await saveScreenshots(screenshots, largeNames, smallNames);
135140
}

dev/devicelab/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ tasks:
118118
description: >
119119
Builds sample catalog markdown pages and Android screenshots
120120
stage: devicelab
121-
required_agent_capabilities: ["linux/android"]
121+
required_agent_capabilities: ["has-android-device"]
122122
flaky: true
123123

124124
complex_layout_semantics_perf:

dev/devicelab/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ environment:
99

1010
dependencies:
1111
args: ^0.13.4
12+
image: ^1.1.27
1213
meta: ^1.0.5
1314
path: ^1.4.0
1415
process: 2.0.3

examples/catalog/bin/sample_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void generate() {
180180
screenshotDriverTemplate,
181181
<String, String>{
182182
'paths': samples.map((SampleGenerator sample) {
183-
return "'${outputFile('\${prefix}' + sample.sourceName + '.png').path}'";
183+
return "'${outputFile(sample.sourceName + '.png').path}'";
184184
}).toList().join(',\n'),
185185
},
186186
);

examples/catalog/bin/screenshot_test.dart.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:test/test.dart';
88

99
void main() {
1010
group('sample screenshots', () {
11-
final String prefix = Platform.isMacOS ? 'ios_' : "";
1211
FlutterDriver driver;
1312

1413
setUpAll(() async {

examples/catalog/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: A collection of Flutter sample apps
33
dependencies:
44
flutter:
55
sdk: flutter
6-
image:
76
path: ^1.4.0
87

98
dev_dependencies:

0 commit comments

Comments
 (0)