22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- // #############################################################################
6- // This is a script that will let you check golden image diffs locally.
7- //
8- // Usage: compare_goldens.dart <dir path> <dir path>
9- //
10- // The directories are scanned for png files that match in name, then the diff
11- // is written to `diff_<name of file>` in the CWD. This allows you to get
12- // results quicker than having to upload to skia gold. By default it uses fuzzy
13- // RMSE to compare.
14- //
15- // Here's the steps for using this with something like impeller golden tests:
16- // 1) Checkout a base revision
17- // 2) Build impeller_golden_tests
18- // 3) Execute `impeller_golden_tests --working_dir=<path a>
19- // 4) Checkout test revision
20- // 5) Build impeller_golden_tests
21- // 6) Execute `impeller_golden_tests --working_dir=<path b>
22- // 7) Execute `compare_goldens.dart <path a> <path b>
23- //
24- // Requirements: ImageMagick is installed on $PATH
25- // #############################################################################
26-
275import 'dart:io' ;
286
29- bool hasCommandOnPath (String name) {
7+ bool _hasCommandOnPath (String name) {
308 final ProcessResult result = Process .runSync ('which' , < String > [name]);
319 return result.exitCode == 0 ;
3210}
3311
34- List <String > findPairs (Set <String > as , Set <String > bs) {
12+ List <String > _findPairs (Set <String > as , Set <String > bs) {
3513 final List <String > result = < String > [];
3614 for (final String a in as ) {
3715 if (bs.contains (a)) {
@@ -50,19 +28,19 @@ List<String> findPairs(Set<String> as, Set<String> bs) {
5028 return result;
5129}
5230
53- String basename (String path) {
31+ String _basename (String path) {
5432 return path.split (Platform .pathSeparator).last;
5533}
5634
57- Set <String > grabPngFilenames (Directory dir) {
35+ Set <String > _grabPngFilenames (Directory dir) {
5836 return dir.listSync ()
59- .map ((e) => basename (e.path))
37+ .map ((e) => _basename (e.path))
6038 .where ((e) => e.endsWith ('.png' ))
6139 .toSet ();
6240}
6341
64- void main (List <String > args) {
65- if (! hasCommandOnPath ('compare' )) {
42+ void run (List <String > args) {
43+ if (! _hasCommandOnPath ('compare' )) {
6644 throw Exception (r'Could not find `compare` from ImageMagick on $PATH.' );
6745 }
6846 if (args.length != 2 ) {
@@ -78,9 +56,9 @@ void main(List<String> args) {
7856 throw Exception ('Unable to find $dirB ' );
7957 }
8058
81- final Set <String > filesA = grabPngFilenames (dirA);
82- final Set <String > filesB = grabPngFilenames (dirB);
83- final List <String > pairs = findPairs (filesA, filesB);
59+ final Set <String > filesA = _grabPngFilenames (dirA);
60+ final Set <String > filesB = _grabPngFilenames (dirB);
61+ final List <String > pairs = _findPairs (filesA, filesB);
8462
8563 int count = 0 ;
8664 for (final String name in pairs) {
0 commit comments