blob: 178cff7918166c194128fa02bcd229f3f59d08eb [file] [log] [blame]
edisonn@google.comc2c49812012-10-10 15:08:12 +00001'''
edisonn@google.comc2c49812012-10-10 15:08:12 +00002Copyright 2012 Google Inc.
3
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
commit-bot@chromium.org11f15622014-01-07 17:03:40 +00006
7Compares the rendererings of serialized SkPictures to expected result.
8
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +00009TODO(epoger): We believe this script is no longer used, so we have disabled it
10and will remove it on 1 Feb 2014 if nobody objects.
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000011See https://code.google.com/p/skia/issues/detail?id=1943#c2
edisonn@google.comc2c49812012-10-10 15:08:12 +000012'''
13# common Python modules
14import os
15import optparse
16import sys
17import shutil
18import tempfile
19
20USAGE_STRING = 'Usage: %s input... expectedDir render_app [reander_app_args]'
21HELP_STRING = '''
22
23Compares the renderings of serialized SkPicture files and directories specified
24by input with the files in expectedDir. Note, files in directoriers are
25expected to end with .skp.
26'''
27
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +000028def _DieBecauseDeprecated():
29 print ('We believe this script is no longer used, so we have disabled it '
30 'and will remove it on 1 Feb 2014 if nobody objects. See '
31 'https://code.google.com/p/skia/issues/detail?id=1943#c2')
32 sys.exit(-1)
33
edisonn@google.comc2c49812012-10-10 15:08:12 +000034def RunCommand(command):
35 """Run a command.
36
37 @param command the command as a single string
38 """
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +000039 _DieBecauseDeprecated()
edisonn@google.comc2c49812012-10-10 15:08:12 +000040 print 'running command [%s]...' % command
41 os.system(command)
42
43
44def FindPathToProgram(program):
45 """Return path to an existing program binary, or raise an exception if we
46 cannot find one.
47
48 @param program the name of the program that is being looked for
49 """
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +000050 _DieBecauseDeprecated()
edisonn@google.comc2c49812012-10-10 15:08:12 +000051 trunk_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
52 os.pardir))
53 possible_paths = [os.path.join(trunk_path, 'out', 'Release', program),
54 os.path.join(trunk_path, 'out', 'Debug', program),
55 os.path.join(trunk_path, 'out', 'Release',
56 program + ".exe"),
57 os.path.join(trunk_path, 'out', 'Debug',
58 program + ".exe")]
59 for try_path in possible_paths:
60 if os.path.isfile(try_path):
61 return try_path
62 raise Exception('cannot find %s in paths %s; maybe you need to '
63 'build %s?' % (program, possible_paths, program))
64
65
66def RenderSkps(inputs, render_dir, render_app, args):
67 """Renders the serialized SkPictures.
68
69 Uses the render_pictures program to do the rendering.
70
71 @param inputs the location(s) to read the serlialized SkPictures
72 @param render_dir the location to write out the rendered images
73 """
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +000074 _DieBecauseDeprecated()
edisonn@google.comc2c49812012-10-10 15:08:12 +000075 renderer_path = FindPathToProgram(render_app)
76 inputs_as_string = " ".join(inputs)
77 command = '%s %s %s' % (renderer_path, inputs_as_string, render_dir)
78
79 command += args
80
81 RunCommand(command)
82
83
84def DiffRenderings(expected_dir, comparison_dir, diff_dir):
85 """Diffs the rendered SkPicture files with the baseline files.
86
87 Uses the skdiff program to do the diffing.
88
89 @param expected_dir the location of the baseline images.
90 @param comparison_dir the location of the images to comapre with the
91 baseline
92 @param diff_dir the location to write out the diff results
93 """
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +000094 _DieBecauseDeprecated()
edisonn@google.comc2c49812012-10-10 15:08:12 +000095 skdiff_path = FindPathToProgram('skdiff')
96 RunCommand('%s %s %s %s %s' %
97 (skdiff_path, expected_dir, comparison_dir, diff_dir,
98 '--noprintdirs'))
99
100
101def Cleanup(render_dir_option, diff_dir_option, render_dir, diff_dir):
102 """Deletes any temporary folders and files created.
103
104 @param foo_option The OptionParser parsed render_dir or diff_dir vars.
105 If these variables are not passed by user we ended up creating
106 temporary directories (render_dir, diff_dir) which we will remove.
107 @param render_dir the directory where the rendered images were written
108 @param diff_dir the directory where the diff results were written
109 """
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +0000110 _DieBecauseDeprecated()
edisonn@google.comc2c49812012-10-10 15:08:12 +0000111 if (not render_dir_option):
112 if (os.path.isdir(render_dir)):
113 shutil.rmtree(render_dir)
114 if (not diff_dir_option):
115 if (os.path.isdir(diff_dir)):
116 shutil.rmtree(diff_dir)
117
118def TestRenderSkps(inputs, expected_dir, render_dir_option, diff_dir_option,
119 render_app, render_args):
commit-bot@chromium.org30d4f832014-01-14 17:01:28 +0000120 _DieBecauseDeprecated()
edisonn@google.comc2c49812012-10-10 15:08:12 +0000121 if (render_dir_option):
122 render_dir = render_dir_option
123 else:
124 render_dir = tempfile.mkdtemp()
125
126 if (diff_dir_option):
127 diff_dir = diff_dir_option
128 else:
129 diff_dir = tempfile.mkdtemp()
130 try:
131 RenderSkps(inputs, render_dir, render_app, render_args)
132 DiffRenderings(expected_dir, render_dir, diff_dir)
133 finally:
134 Cleanup(render_dir_option, diff_dir_option, render_dir, diff_dir)