blob: 965dd292afbc88942e84ec6f165c9248d5454c92 [file] [log] [blame]
Craig Tiller1a718112015-07-03 12:07:06 -07001#!/usr/bin/env python2.7
2
Craig Tiller32d0f142016-01-19 13:50:59 -08003# Copyright 2015-2016, Google Inc.
Craig Tiller1a718112015-07-03 12:07:06 -07004# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10# * Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# * Redistributions in binary form must reproduce the above
13# copyright notice, this list of conditions and the following disclaimer
14# in the documentation and/or other materials provided with the
15# distribution.
16# * Neither the name of Google Inc. nor the names of its
17# contributors may be used to endorse or promote products derived from
18# this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
Craig Tiller0fe5ee72015-12-22 12:50:36 -080032import argparse
Craig Tiller1a718112015-07-03 12:07:06 -070033import glob
34import os
Craig Tiller259e6272015-08-31 16:58:18 -070035import shutil
Craig Tiller1a718112015-07-03 12:07:06 -070036import sys
37import tempfile
David Garcia Quintas985f22e2015-10-04 23:14:37 -070038import multiprocessing
Craig Tiller1a718112015-07-03 12:07:06 -070039sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..', 'run_tests'))
40
41assert sys.argv[1:], 'run generate_projects.sh instead of this directly'
42
43import jobset
44
45os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '..', '..'))
Craig Tiller0fe5ee72015-12-22 12:50:36 -080046
47argp = argparse.ArgumentParser()
48argp.add_argument('json', nargs='+')
49argp.add_argument('--templates', nargs='+', default=[])
Craig Tiller12971702016-01-21 13:38:35 -080050argp.add_argument('--jobs', '-j', default=multiprocessing.cpu_count(), type=int)
Craig Tiller0fe5ee72015-12-22 12:50:36 -080051args = argp.parse_args()
52
53json = args.json
Craig Tiller1a718112015-07-03 12:07:06 -070054
55test = {} if 'TEST' in os.environ else None
56
57plugins = sorted(glob.glob('tools/buildgen/plugins/*.py'))
58
Craig Tiller0fe5ee72015-12-22 12:50:36 -080059templates = args.templates
60if not templates:
61 for root, dirs, files in os.walk('templates'):
62 for f in files:
63 templates.append(os.path.join(root, f))
64
Craig Tiller1a718112015-07-03 12:07:06 -070065jobs = []
Craig Tiller0fe5ee72015-12-22 12:50:36 -080066for template in templates:
67 root, f = os.path.split(template)
68 if os.path.splitext(f)[1] == '.template':
69 out_dir = '.' + root[len('templates'):]
70 out = out_dir + '/' + os.path.splitext(f)[0]
71 if not os.path.exists(out_dir):
72 os.makedirs(out_dir)
73 cmd = ['python2.7', 'tools/buildgen/mako_renderer.py']
74 for plugin in plugins:
75 cmd.append('-p')
76 cmd.append(plugin)
77 for js in json:
78 cmd.append('-d')
79 cmd.append(js)
80 cmd.append('-o')
81 if test is None:
82 cmd.append(out)
83 else:
84 tf = tempfile.mkstemp()
85 test[out] = tf[1]
86 os.close(tf[0])
87 cmd.append(test[out])
88 cmd.append(root + '/' + f)
Craig Tiller590105a2016-01-19 13:03:46 -080089 jobs.append(jobset.JobSpec(cmd, shortname=out, timeout_seconds=None))
Craig Tiller1a718112015-07-03 12:07:06 -070090
Craig Tiller12971702016-01-21 13:38:35 -080091jobset.run(jobs, maxjobs=args.jobs)
Craig Tiller1a718112015-07-03 12:07:06 -070092
93if test is not None:
Nicolas "Pixel" Noble22232ae2015-07-11 22:40:22 +020094 for s, g in test.iteritems():
Craig Tiller259e6272015-08-31 16:58:18 -070095 if os.path.isfile(g):
Nicolas "Pixel" Noble9baaead2015-10-03 02:25:02 +020096 assert 0 == os.system('diff %s %s' % (s, g)), s
Craig Tiller259e6272015-08-31 16:58:18 -070097 os.unlink(g)
98 else:
Nicolas "Pixel" Noble9baaead2015-10-03 02:25:02 +020099 assert 0 == os.system('diff -r %s %s' % (s, g)), s
Craig Tiller259e6272015-08-31 16:58:18 -0700100 shutil.rmtree(g, ignore_errors=True)