• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  'flavor',
20  'run',
21  'vars',
22]
23
24
25def RunSteps(api):
26  # Checkout, compile, etc.
27  api.vars.setup()
28  checkout_root = api.checkout.default_checkout_root
29  api.checkout.bot_update(checkout_root=checkout_root)
30  api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir)
31  api.flavor.setup()
32
33  cwd = api.path['checkout']
34
35  with api.context(cwd=cwd):
36    # Get a baseline diff. This should be empty, but we want to be flexible for
37    # cases where we have local diffs on purpose.
38    diff1 = api.run(
39        api.step,
40        'git diff #1',
41        cmd=['git', 'diff', '--no-ext-diff'],
42        stdout=api.m.raw_io.output()).stdout
43
44    with api.context(env=api.infra.go_env):
45      api.step('generate gl interfaces',
46               cmd=['make', '-C', 'tools/gpu/gl/interface', 'generate'])
47
48    # Reformat all tracked .gn files.
49    api.run(api.python, 'fetch-gn',
50            script='bin/fetch-gn',
51            infra_step=True)
52    files = api.run(api.step, 'list .gn files',
53                    cmd=['git', 'ls-files', '*.gn'],
54                    stdout=api.m.raw_io.output(),
55                    infra_step=True).stdout
56    for f in files.split():
57      api.run(api.step, 'format ' + f,
58              cmd=['bin/gn', 'format', f])
59
60    # Rewrite #includes.
61    api.run(api.python, 'rewrite #includes',
62            script='tools/rewrite_includes.py')
63
64    # Touch all .fp files so that the generated files are rebuilt.
65    api.run(
66        api.python.inline,
67        'touch fp files',
68        program="""import os
69import subprocess
70
71for r, d, files in os.walk('%s'):
72  for f in files:
73    if f.endswith('.fp'):
74      path = os.path.join(r, f)
75      print 'touch %%s' %% path
76      subprocess.check_call(['touch', path])
77""" % cwd)
78
79    # Run GN, regenerate the SKSL files, and make sure rewritten #includes work.
80    api.build(checkout_root=checkout_root,
81              out_dir=api.vars.build_dir.join('out', 'Release'))
82
83    # Get a second diff. If this doesn't match the first, then there have been
84    # modifications to the generated files.
85    diff2 = api.run(
86        api.step,
87        'git diff #2',
88        cmd=['git', 'diff', '--no-ext-diff'],
89        stdout=api.m.raw_io.output()).stdout
90
91    api.run(
92        api.python.inline,
93        'compare diffs',
94        program="""
95diff1 = '''%s'''
96
97diff2 = '''%s'''
98
99if diff1 != diff2:
100  print 'Generated files have been edited!'
101  exit(1)
102""" % (diff1, diff2))
103
104
105def GenTests(api):
106  yield (
107      api.test('Housekeeper-PerCommit-CheckGeneratedFiles') +
108      api.properties(buildername='Housekeeper-PerCommit-CheckGeneratedFiles',
109                     repository='https://skia.googlesource.com/skia.git',
110                     revision='abc123',
111                     path_config='kitchen',
112                     swarm_out_dir='[SWARM_OUT_DIR]') +
113      api.path.exists(api.path['start_dir']) +
114      api.step_data('list .gn files',
115                    stdout=api.raw_io.output('BUILD.gn\ngn/foo.gn\n'))
116  )
117