• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4"""//build/android implementations of //testing/skia_gold_common.
5
6Used for interacting with the Skia Gold image diffing service.
7"""
8
9import os
10import shutil
11
12from devil.utils import cmd_helper
13from pylib.base.output_manager import Datatype
14from pylib.constants import host_paths
15from pylib.utils import repo_utils
16
17with host_paths.SysPath(host_paths.BUILD_PATH):
18  from skia_gold_common import skia_gold_session
19  from skia_gold_common import skia_gold_session_manager
20  from skia_gold_common import skia_gold_properties
21
22
23class AndroidSkiaGoldSession(skia_gold_session.SkiaGoldSession):
24  def _StoreDiffLinks(self, image_name, output_manager, output_dir):
25    """See SkiaGoldSession._StoreDiffLinks for general documentation.
26
27    |output_manager| must be a build.android.pylib.base.OutputManager instance.
28    """
29    given_path = closest_path = diff_path = None
30    # The directory should contain "input-<hash>.png", "closest-<hash>.png",
31    # and "diff.png".
32    for f in os.listdir(output_dir):
33      filepath = os.path.join(output_dir, f)
34      if f.startswith('input-'):
35        given_path = filepath
36      elif f.startswith('closest-'):
37        closest_path = filepath
38      elif f == 'diff.png':
39        diff_path = filepath
40    results = self._comparison_results.setdefault(image_name,
41                                                  self.ComparisonResults())
42    if given_path:
43      with output_manager.ArchivedTempfile('given_%s.png' % image_name,
44                                           'gold_local_diffs',
45                                           Datatype.PNG) as given_file:
46        shutil.move(given_path, given_file.name)
47      results.local_diff_given_image = given_file.Link()
48    if closest_path:
49      with output_manager.ArchivedTempfile('closest_%s.png' % image_name,
50                                           'gold_local_diffs',
51                                           Datatype.PNG) as closest_file:
52        shutil.move(closest_path, closest_file.name)
53      results.local_diff_closest_image = closest_file.Link()
54    if diff_path:
55      with output_manager.ArchivedTempfile('diff_%s.png' % image_name,
56                                           'gold_local_diffs',
57                                           Datatype.PNG) as diff_file:
58        shutil.move(diff_path, diff_file.name)
59      results.local_diff_diff_image = diff_file.Link()
60
61  @staticmethod
62  def _RunCmdForRcAndOutput(cmd):
63    rc, stdout, _ = cmd_helper.GetCmdStatusOutputAndError(cmd,
64                                                          merge_stderr=True)
65    return rc, stdout
66
67
68class AndroidSkiaGoldSessionManager(
69    skia_gold_session_manager.SkiaGoldSessionManager):
70  @staticmethod
71  def GetSessionClass():
72    return AndroidSkiaGoldSession
73
74
75class AndroidSkiaGoldProperties(skia_gold_properties.SkiaGoldProperties):
76  @staticmethod
77  def _GetGitOriginMainHeadSha1():
78    return repo_utils.GetGitOriginMainHeadSHA1(host_paths.DIR_SOURCE_ROOT)
79