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  'infra',
11  'recipe_engine/context',
12  'recipe_engine/file',
13  'recipe_engine/path',
14  'recipe_engine/properties',
15  'recipe_engine/python',
16  'recipe_engine/raw_io',
17  'recipe_engine/step',
18  'checkout',
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
31  cwd = api.path['checkout']
32
33  with api.context(cwd=cwd):
34    # Get a baseline diff. This should be empty, but we want to be flexible for
35    # cases where we have local diffs on purpose.
36    diff1 = api.run(
37        api.step,
38        'git diff #1',
39        cmd=['git', 'diff', '--no-ext-diff'],
40        stdout=api.m.raw_io.output()).stdout
41
42    with api.context(env=api.infra.go_env):
43      api.step('generate gl interfaces',
44               cmd=['make', '-C', 'tools/gpu/gl/interface', 'generate'])
45
46    # Touch all .fp files so that the generated files are rebuilt.
47    api.run(
48        api.python.inline,
49        'touch fp files',
50        program="""import os
51import subprocess
52
53for r, d, files in os.walk(os.path.join('%s', 'src')):
54  for f in files:
55    if f.endswith('.fp'):
56      path = os.path.join(r, f)
57      print 'touch %%s' %% path
58      subprocess.check_call(['touch', path])
59""" % cwd)
60
61    # Run GN, regenerate the SKSL files, and make sure rewritten #includes work.
62    api.build(checkout_root=checkout_root,
63              out_dir=api.vars.build_dir.join('out', 'Release'))
64
65    # Get a second diff. If this doesn't match the first, then there have been
66    # modifications to the generated files.
67    diff2 = api.run(
68        api.step,
69        'git diff #2',
70        cmd=['git', 'diff', '--no-ext-diff'],
71        stdout=api.m.raw_io.output()).stdout
72
73    api.run(
74        api.python.inline,
75        'compare diffs',
76        program="""
77diff1 = '''%s'''
78
79diff2 = '''%s'''
80
81if diff1 != diff2:
82  print 'Generated files have been edited!'
83  exit(1)
84""" % (diff1, diff2))
85
86
87def GenTests(api):
88  yield (
89      api.test('Housekeeper-PerCommit-CheckGeneratedFiles') +
90      api.properties(buildername='Housekeeper-PerCommit-CheckGeneratedFiles',
91                     repository='https://skia.googlesource.com/skia.git',
92                     revision='abc123',
93                     path_config='kitchen',
94                     swarm_out_dir='[SWARM_OUT_DIR]') +
95      api.path.exists(api.path['start_dir'])
96  )
97