blob: 9d344001f955aa70189e5ecae9f3fffef607a4c6 [file] [log] [blame]
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001# 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
5# Recipe which:
6# 1) Extracts all fiddles out of markdown files.
7# 2) Forces fiddle.skia.org to compile all those fiddles and get output in JSON.
8# 3) Scans the output and reports any compiletime/runtime errors.
9# 4) Updates markdown in site/user/api/ using the new hashes (if any) from
10# fiddle.skia.org.
11
12import json
13
14
15DEPS = [
16 'recipe_engine/context',
17 'recipe_engine/file',
18 'recipe_engine/path',
19 'recipe_engine/properties',
20 'recipe_engine/step',
Eric Boren90f05032018-05-24 09:14:18 -040021 'checkout',
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050022 'infra',
23 'run',
24 'vars',
25]
26
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050027
28def go_get_fiddlecli(api):
29 env = api.context.env
30 env.update(api.infra.go_env)
31 with api.context(env=env):
32 api.run.with_retry(
33 api.step,
34 'go get fiddlecli',
35 5, # Update attempts.
36 cmd=[api.infra.go_exe, 'get', '-u', '-t',
Ravi Mistry86684382018-06-20 08:30:29 -040037 'go.skia.org/infra/fiddlek/go/fiddlecli'])
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050038
39
40def RunSteps(api):
41 api.vars.setup()
Eric Boren90f05032018-05-24 09:14:18 -040042 checkout_root = api.checkout.default_checkout_root
43 api.checkout.bot_update(checkout_root=checkout_root)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050044 api.infra.go_version()
45 go_get_fiddlecli(api)
46
Eric Boren72f66682018-05-18 07:36:55 -040047 skia_dir = checkout_root.join('skia')
48 with api.context(cwd=skia_dir, env=api.infra.go_env):
Eric Boren322a8592018-06-01 10:08:53 -040049 bookmaker_binary = api.vars.build_dir.join('bookmaker')
Ravi Mistryd4731e92018-01-02 14:54:43 -050050 buildername = api.vars.builder_name
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050051
Ravi Mistryd4731e92018-01-02 14:54:43 -050052 if 'PerCommit' in buildername:
53 # Check to see if docs matches include/core.
54 cmd = [bookmaker_binary,
55 '-a', 'docs/status.json', # File containing status of docs.
56 '-x', # Check bmh against includes.
57 ]
58 try:
59 api.run(api.step, 'Validate docs match include/core/*.h', cmd=cmd)
60 except api.step.StepFailure as e:
61 # Display what needs to be fixed.
62 e.reason += (
63 '\n\nView the output of the "Validate docs match include/core/*.h" '
64 'step to see how to get this bot green.'
65 '\n\nhttps://skia.org/user/api/usingBookmaker details how to build '
66 'and run the bookmaker utility locally if needed.')
67 raise e
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050068
Ravi Mistryd4731e92018-01-02 14:54:43 -050069 elif 'Nightly' in buildername:
70 fiddlecli_binary = api.path.join(api.infra.gopath, 'bin', 'fiddlecli')
71 fiddlecli_input = api.path.join(api.path['start_dir'], 'fiddle.json')
72 fiddlecli_output = api.path.join(api.path['start_dir'], 'fiddleout.json')
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050073
Ravi Mistryd4731e92018-01-02 14:54:43 -050074 # Step 1: Extract all fiddles out of markdown files.
75 cmd = [bookmaker_binary,
76 '-a', 'docs/status.json', # File containing status of docs.
77 '-e', fiddlecli_input, # Fiddle cli input.
78 ]
79 api.run(api.step, 'Extract all fiddles out of md files', cmd=cmd)
Ravi Mistry5ca94132017-12-11 16:40:48 -050080
Ravi Mistryd4731e92018-01-02 14:54:43 -050081 # Step 2: Forces fiddle.skia.org to compile all fiddles extracted out of
82 # markdown files and get output in JSON.
83 cmd = [fiddlecli_binary,
84 '--input', fiddlecli_input,
85 '--output', fiddlecli_output,
Joe Gregorio05f83d92018-06-27 08:07:55 -040086 '--procs', 10, # Number of concurrent requests.
Ravi Mistryd4731e92018-01-02 14:54:43 -050087 '--logtostderr',
88 '--force',
89 ]
90 api.run(api.step, 'Force fiddle to compile all examples', cmd=cmd)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050091
Ravi Mistryd4731e92018-01-02 14:54:43 -050092 # Step 3: Scan the output of fiddlecli for any compiletime/runtime errors.
93 # Fail the recipe is there are any errors and summarize results at
94 # the end.
95 if api.path.exists(fiddlecli_output):
96 test_data = api.properties.get('fiddleout_test_data', '{}')
97 content = api.file.read_text('Read fiddleout.json',
98 fiddlecli_output, test_data=test_data)
99 out = json.loads(content)
Ravi Mistryd4731e92018-01-02 14:54:43 -0500100
Ravi Mistrybcc00b22018-03-15 16:55:16 -0400101 # Output fiddleout.json for easy debugging.
102 api.run(api.step, 'Output fiddleout.json',
103 cmd=['cat', fiddlecli_output])
104
Ravi Mistry042b5e92018-02-08 14:54:52 -0500105 failing_fiddles_to_errors = {}
Ravi Mistryd4731e92018-01-02 14:54:43 -0500106 for fiddle_name in out:
107 props = out[fiddle_name]
108 if props['compile_errors'] or props['runtime_error']:
Ravi Mistry042b5e92018-02-08 14:54:52 -0500109 # Construct the error.
110 error = props['runtime_error']
111 if props['compile_errors']:
112 for e in props['compile_errors']:
113 error += '%s\n' % e['text']
114 failing_fiddles_to_errors[props['fiddleHash']] = error
115
116 if failing_fiddles_to_errors:
Ravi Mistryd4731e92018-01-02 14:54:43 -0500117 # create an eror message and fail the bot!
Ravi Mistry042b5e92018-02-08 14:54:52 -0500118 failure_msg = 'Failed fiddles with their errors:\n\n\n'
119 counter = 0
120 for fiddle_hash, error in failing_fiddles_to_errors.iteritems():
121 counter += 1
122 failure_msg += '%d. https://fiddle.skia.org/c/%s\n\n' % (
123 counter, fiddle_hash)
124 failure_msg += '%s\n\n' % error
Ravi Mistryd4731e92018-01-02 14:54:43 -0500125 raise api.step.StepFailure(failure_msg)
126
127 # Step 4: Update docs in site/user/api/ with the output of fiddlecli.
128 # If there are any new changes then upload and commit the changes.
Ravi Mistryd4731e92018-01-02 14:54:43 -0500129 cmd = ['python',
Eric Boren72f66682018-05-18 07:36:55 -0400130 skia_dir.join('infra', 'bots', 'upload_md.py'),
Ravi Mistryd4731e92018-01-02 14:54:43 -0500131 '--bookmaker_binary', bookmaker_binary,
Eric Boren78179312018-04-23 08:35:45 -0400132 '--fiddlecli_output', fiddlecli_output]
Eric Boren72f66682018-05-18 07:36:55 -0400133 with api.context(cwd=skia_dir, env=api.infra.go_env):
Eric Boren78179312018-04-23 08:35:45 -0400134 api.run(api.step, 'Generate and Upload Markdown files', cmd=cmd)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500135
136
137def GenTests(api):
138 fiddleout_no_errors_test_data = """
139{"fiddle1": {"fiddleHash": "abc",
140 "compile_errors": [],
141 "runtime_error": ""}}
142"""
143 fiddleout_with_errors_test_data = """
144{"fiddle1": {"fiddleHash": "abc",
Ravi Mistry042b5e92018-02-08 14:54:52 -0500145 "compile_errors": [
146 {
147 "text": "ninja: Entering directory `out/Release'",
148 "line": 0,
149 "col": 0
150 },
151 {
152 "text": "[1/7] ACTION //:skia.h(//gn/toolchain:gcc_like)",
153 "line": 0,
154 "col": 0
155 },
156 {
157 "text": "[2/7] stamp obj/skia.h.stamp",
158 "line": 0,
159 "col": 0
160 },
161 {
162 "text": "[3/7] compile ../../tools/fiddle/draw.cpp",
163 "line": 0,
164 "col": 0
165 },
166 {
167 "text": "FAILED: obj/tools/fiddle/fiddle.draw.o ",
168 "line": 0,
169 "col": 0
170 },
171 {
Brian Salomon7258e972018-06-02 11:18:33 -0400172 "text": "c++ -MMD -MF obj/tools/fiddle/fiddle.draw.o.d -DNDEBUG -DSK_HAS_HEIF_LIBRARY -DSK_HAS_JPEG_LIBRARY -DSK_SUPPORT_PDF -DSK_PDF_USE_SFNTLY -DSK_HAS_PNG_LIBRARY -DSK_CODEC_DECODES_RAW -DSK_HAS_WEBP_LIBRARY -DSK_XML -DSK_GAMMA_APPLY_TO_A8 -DSK_ENABLE_DISCRETE_GPU -DGR_TEST_UTILS=1 -DSK_SAMPLES_FOR_X -DSK_SUPPORT_ATLAS_TEXT=1 -I../../tools/flags -I../../include/private -I../../src/c -I../../src/codec -I../../src/core -I../../src/effects -I../../src/fonts -I../../src/image -I../../src/images -I../../src/lazy -I../../src/opts -I../../src/pathops -I../../src/pdf -I../../src/ports -I../../src/sfnt -I../../src/shaders -I../../src/shaders/gradients -I../../src/sksl -I../../src/utils -I../../src/utils/win -I../../src/xml -I../../third_party/gif -I../../src/gpu -I../../tools/gpu -I../../include/android -I../../include/c -I../../include/codec -I../../include/config -I../../include/core -I../../include/effects -I../../include/encode -I../../include/gpu -I../../include/gpu/gl -I../../include/atlastext -I../../include/pathops -I../../include/ports -I../../include/svg -I../../include/utils -I../../include/utils/mac -I../../include/atlastext -Igen -fstrict-aliasing -fPIC -Werror -Wall -Wextra -Winit-self -Wpointer-arith -Wsign-compare -Wvla -Wno-deprecated-declarations -Wno-maybe-uninitialized -Wno-unused-parameter -O3 -fdata-sections -ffunction-sections -g -std=c++14 -fno-exceptions -fno-rtti -Wnon-virtual-dtor -Wno-error -c ../../tools/fiddle/draw.cpp -o obj/tools/fiddle/fiddle.draw.o",
Ravi Mistry042b5e92018-02-08 14:54:52 -0500173 "line": 0,
174 "col": 0
175 },
176 {
177 "text": "../../tools/fiddle/draw.cpp: In function 'void draw(SkCanvas*)':",
178 "line": 0,
179 "col": 0
180 },
181 {
182 "text": "draw.cpp:5:12: error: aggregate 'SkMask mask' has incomplete type and cannot be defined",
183 "line": 5,
184 "col": 12
185 },
186 {
187 "text": " }",
188 "line": 0,
189 "col": 0
190 },
191 {
192 "text": " ^ ",
193 "line": 0,
194 "col": 0
195 },
196 {
197 "text": "draw.cpp:6:28: error: incomplete type 'SkMask' used in nested name specifier",
198 "line": 6,
199 "col": 28
200 },
201 {
202 "text": " ",
203 "line": 0,
204 "col": 0
205 },
206 {
207 "text": " ^ ",
208 "line": 0,
209 "col": 0
210 },
211 {
212 "text": "draw.cpp:14:28: error: incomplete type 'SkMask' used in nested name specifier",
213 "line": 14,
214 "col": 28
215 },
216 {
217 "text": " uint8_t bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7 };",
218 "line": 0,
219 "col": 0
220 },
221 {
222 "text": " ^~~~~~~~~~",
223 "line": 0,
224 "col": 0
225 },
226 {
227 "text": "[4/7] compile ../../tools/fiddle/egl_context.cpp",
228 "line": 0,
229 "col": 0
230 },
231 {
232 "text": "[5/7] compile ../../tools/fiddle/fiddle_main.cpp",
233 "line": 0,
234 "col": 0
235 },
236 {
237 "text": "[6/7] link libskia.a",
238 "line": 0,
239 "col": 0
240 },
241 {
242 "text": "ninja: build stopped: subcommand failed.",
243 "line": 0,
244 "col": 0
245 },
246 {
247 "text": "",
248 "line": 0,
249 "col": 0
250 }
251 ],
252 "runtime_error": ""}}
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500253"""
254 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500255 api.test('percommit_bookmaker') +
256 api.properties(buildername='Housekeeper-PerCommit-Bookmaker',
257 repository='https://skia.googlesource.com/skia.git',
258 revision='abc123',
259 path_config='kitchen',
260 swarm_out_dir='[SWARM_OUT_DIR]')
261 )
262
263 yield (
264 api.test('percommit_failed_validation') +
265 api.properties(buildername='Housekeeper-PerCommit-Bookmaker',
266 repository='https://skia.googlesource.com/skia.git',
267 revision='abc123',
268 path_config='kitchen',
269 swarm_out_dir='[SWARM_OUT_DIR]') +
270 api.step_data('Validate docs match include/core/*.h', retcode=1)
271 )
272
273 yield (
274 api.test('nightly_bookmaker') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500275 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
276 repository='https://skia.googlesource.com/skia.git',
277 revision='abc123',
278 path_config='kitchen',
279 fiddleout_test_data=fiddleout_no_errors_test_data,
280 swarm_out_dir='[SWARM_OUT_DIR]') +
Eric Boren78179312018-04-23 08:35:45 -0400281 api.path.exists(api.path['start_dir'].join('fiddleout.json'))
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500282 )
283
284 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500285 api.test('nightly_failed_fiddles') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500286 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
287 repository='https://skia.googlesource.com/skia.git',
288 revision='abc123',
289 path_config='kitchen',
290 fiddleout_test_data=fiddleout_with_errors_test_data,
291 swarm_out_dir='[SWARM_OUT_DIR]') +
292 api.path.exists(api.path['start_dir'].join('fiddleout.json'))
293 )
294
295 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500296 api.test('nightly_failed_extract_fiddles') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500297 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
298 repository='https://skia.googlesource.com/skia.git',
299 revision='abc123',
300 path_config='kitchen',
301 swarm_out_dir='[SWARM_OUT_DIR]') +
302 api.step_data('Extract all fiddles out of md files', retcode=1)
303 )
304
305 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500306 api.test('nightly_failed_fiddlecli') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500307 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
308 repository='https://skia.googlesource.com/skia.git',
309 revision='abc123',
310 path_config='kitchen',
311 swarm_out_dir='[SWARM_OUT_DIR]') +
312 api.step_data('Force fiddle to compile all examples', retcode=1)
313 )
314
315 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500316 api.test('nightly_failed_upload') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500317 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
318 repository='https://skia.googlesource.com/skia.git',
319 revision='abc123',
320 path_config='kitchen',
321 swarm_out_dir='[SWARM_OUT_DIR]') +
322 api.step_data('Generate and Upload Markdown files', retcode=1)
323 )