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 6# Recipe for the Skia PerCommit Housekeeper. 7 8DEPS = [ 9 'build', 10 'recipe_engine/context', 11 'recipe_engine/file', 12 'recipe_engine/path', 13 'recipe_engine/properties', 14 'recipe_engine/python', 15 'recipe_engine/raw_io', 16 'recipe_engine/step', 17 'checkout', 18 'flavor', 19 'run', 20 'vars', 21] 22 23 24def RunSteps(api): 25 # Checkout, compile, etc. 26 api.vars.setup() 27 checkout_root = api.checkout.default_checkout_root 28 api.checkout.bot_update(checkout_root=checkout_root) 29 api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir) 30 api.flavor.setup() 31 32 cwd = api.path['checkout'] 33 34 with api.context(cwd=cwd): 35 # Get a baseline diff. This should be empty, but we want to be flexible for 36 # cases where we have local diffs on purpose. 37 diff1 = api.run( 38 api.step, 39 'git diff #1', 40 cmd=['git', 'diff', '--no-ext-diff'], 41 stdout=api.m.raw_io.output()).stdout 42 43 # Touch all .fp files so that the generated files are rebuilt. 44 api.run( 45 api.python.inline, 46 'touch fp files', 47 program="""import os 48import subprocess 49 50for r, d, files in os.walk('%s'): 51 for f in files: 52 if f.endswith('.fp'): 53 path = os.path.join(r, f) 54 print 'touch %%s' %% path 55 subprocess.check_call(['touch', path]) 56""" % cwd) 57 58 # Regenerate the SKSL files. 59 api.build(checkout_root=checkout_root, 60 out_dir=api.vars.build_dir.join('out', 'Release')) 61 62 # Get a second diff. If this doesn't match the first, then there have been 63 # modifications to the generated files. 64 diff2 = api.run( 65 api.step, 66 'git diff #2', 67 cmd=['git', 'diff', '--no-ext-diff'], 68 stdout=api.m.raw_io.output()).stdout 69 70 api.run( 71 api.python.inline, 72 'compare diffs', 73 program=""" 74diff1 = '''%s''' 75 76diff2 = '''%s''' 77 78if diff1 != diff2: 79 print 'Generated files have been edited!' 80 exit(1) 81""" % (diff1, diff2)) 82 83 84def GenTests(api): 85 yield ( 86 api.test('Housekeeper-PerCommit-CheckGeneratedFiles') + 87 api.properties(buildername='Housekeeper-PerCommit-CheckGeneratedFiles', 88 repository='https://skia.googlesource.com/skia.git', 89 revision='abc123', 90 path_config='kitchen', 91 swarm_out_dir='[SWARM_OUT_DIR]') + 92 api.path.exists(api.path['start_dir']) 93 ) 94