Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 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 | |
| 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 | |
| 12 | import json |
| 13 | |
| 14 | |
| 15 | DEPS = [ |
| 16 | 'recipe_engine/context', |
| 17 | 'recipe_engine/file', |
| 18 | 'recipe_engine/path', |
| 19 | 'recipe_engine/properties', |
| 20 | 'recipe_engine/step', |
Eric Boren | 90f0503 | 2018-05-24 09:14:18 -0400 | [diff] [blame] | 21 | 'checkout', |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 22 | 'infra', |
| 23 | 'run', |
| 24 | 'vars', |
| 25 | ] |
| 26 | |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 27 | |
| 28 | def 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 Mistry | 8668438 | 2018-06-20 08:30:29 -0400 | [diff] [blame] | 37 | 'go.skia.org/infra/fiddlek/go/fiddlecli']) |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 38 | |
| 39 | |
| 40 | def RunSteps(api): |
| 41 | api.vars.setup() |
Eric Boren | 90f0503 | 2018-05-24 09:14:18 -0400 | [diff] [blame] | 42 | checkout_root = api.checkout.default_checkout_root |
| 43 | api.checkout.bot_update(checkout_root=checkout_root) |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 44 | api.infra.go_version() |
| 45 | go_get_fiddlecli(api) |
| 46 | |
Eric Boren | 72f6668 | 2018-05-18 07:36:55 -0400 | [diff] [blame] | 47 | skia_dir = checkout_root.join('skia') |
| 48 | with api.context(cwd=skia_dir, env=api.infra.go_env): |
Eric Boren | 322a859 | 2018-06-01 10:08:53 -0400 | [diff] [blame] | 49 | bookmaker_binary = api.vars.build_dir.join('bookmaker') |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 50 | buildername = api.vars.builder_name |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 51 | |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 52 | 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 Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 68 | |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 69 | 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 Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 73 | |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 74 | # 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 Mistry | 5ca9413 | 2017-12-11 16:40:48 -0500 | [diff] [blame] | 80 | |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 81 | # 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 Gregorio | 05f83d9 | 2018-06-27 08:07:55 -0400 | [diff] [blame] | 86 | '--procs', 10, # Number of concurrent requests. |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 87 | '--logtostderr', |
| 88 | '--force', |
| 89 | ] |
| 90 | api.run(api.step, 'Force fiddle to compile all examples', cmd=cmd) |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 91 | |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 92 | # 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 Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 100 | |
Ravi Mistry | bcc00b2 | 2018-03-15 16:55:16 -0400 | [diff] [blame] | 101 | # Output fiddleout.json for easy debugging. |
| 102 | api.run(api.step, 'Output fiddleout.json', |
| 103 | cmd=['cat', fiddlecli_output]) |
| 104 | |
Ravi Mistry | 042b5e9 | 2018-02-08 14:54:52 -0500 | [diff] [blame] | 105 | failing_fiddles_to_errors = {} |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 106 | for fiddle_name in out: |
| 107 | props = out[fiddle_name] |
| 108 | if props['compile_errors'] or props['runtime_error']: |
Ravi Mistry | 042b5e9 | 2018-02-08 14:54:52 -0500 | [diff] [blame] | 109 | # 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 Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 117 | # create an eror message and fail the bot! |
Ravi Mistry | 042b5e9 | 2018-02-08 14:54:52 -0500 | [diff] [blame] | 118 | 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 Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 125 | 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 Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 129 | cmd = ['python', |
Eric Boren | 72f6668 | 2018-05-18 07:36:55 -0400 | [diff] [blame] | 130 | skia_dir.join('infra', 'bots', 'upload_md.py'), |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 131 | '--bookmaker_binary', bookmaker_binary, |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 132 | '--fiddlecli_output', fiddlecli_output] |
Eric Boren | 72f6668 | 2018-05-18 07:36:55 -0400 | [diff] [blame] | 133 | with api.context(cwd=skia_dir, env=api.infra.go_env): |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 134 | api.run(api.step, 'Generate and Upload Markdown files', cmd=cmd) |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 135 | |
| 136 | |
| 137 | def 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 Mistry | 042b5e9 | 2018-02-08 14:54:52 -0500 | [diff] [blame] | 145 | "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 Salomon | 7258e97 | 2018-06-02 11:18:33 -0400 | [diff] [blame] | 172 | "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 Mistry | 042b5e9 | 2018-02-08 14:54:52 -0500 | [diff] [blame] | 173 | "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 Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 253 | """ |
| 254 | yield ( |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 255 | 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 Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 275 | 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 Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 281 | api.path.exists(api.path['start_dir'].join('fiddleout.json')) |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 282 | ) |
| 283 | |
| 284 | yield ( |
Ravi Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 285 | api.test('nightly_failed_fiddles') + |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 286 | 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 Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 296 | api.test('nightly_failed_extract_fiddles') + |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 297 | 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 Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 306 | api.test('nightly_failed_fiddlecli') + |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 307 | 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 Mistry | d4731e9 | 2018-01-02 14:54:43 -0500 | [diff] [blame] | 316 | api.test('nightly_failed_upload') + |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 317 | 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 | ) |