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