blob: 5f3af7738b26246e1961f9fc0ef3fa68ace3d740 [file] [log] [blame]
Craig Tiller1a718112015-07-03 12:07:06 -07001#!/usr/bin/env python2.7
2
Craig Tiller6169d5f2016-03-31 07:46:18 -07003# Copyright 2015, 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()
Craig Tiller560c9012016-02-24 16:34:38 -080048argp.add_argument('build_files', nargs='+', default=[])
Craig Tiller0fe5ee72015-12-22 12:50:36 -080049argp.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
Craig Tiller560c9012016-02-24 16:34:38 -080053json = args.build_files
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 Tiller560c9012016-02-24 16:34:38 -080065pre_jobs = []
66base_cmd = ['python2.7', 'tools/buildgen/mako_renderer.py']
67cmd = base_cmd[:]
68for plugin in plugins:
69 cmd.append('-p')
70 cmd.append(plugin)
71for js in json:
72 cmd.append('-d')
73 cmd.append(js)
74cmd.append('-w')
75preprocessed_build = '.preprocessed_build'
76cmd.append(preprocessed_build)
77pre_jobs.append(jobset.JobSpec(cmd, shortname='preprocess', timeout_seconds=None))
78
Craig Tiller1a718112015-07-03 12:07:06 -070079jobs = []
Craig Tiller560c9012016-02-24 16:34:38 -080080for template in reversed(sorted(templates)):
Craig Tiller0fe5ee72015-12-22 12:50:36 -080081 root, f = os.path.split(template)
82 if os.path.splitext(f)[1] == '.template':
83 out_dir = '.' + root[len('templates'):]
84 out = out_dir + '/' + os.path.splitext(f)[0]
85 if not os.path.exists(out_dir):
86 os.makedirs(out_dir)
Craig Tiller560c9012016-02-24 16:34:38 -080087 cmd = base_cmd[:]
88 cmd.append('-P')
89 cmd.append(preprocessed_build)
Craig Tiller0fe5ee72015-12-22 12:50:36 -080090 cmd.append('-o')
91 if test is None:
92 cmd.append(out)
93 else:
94 tf = tempfile.mkstemp()
95 test[out] = tf[1]
96 os.close(tf[0])
97 cmd.append(test[out])
98 cmd.append(root + '/' + f)
Craig Tiller590105a2016-01-19 13:03:46 -080099 jobs.append(jobset.JobSpec(cmd, shortname=out, timeout_seconds=None))
Craig Tiller1a718112015-07-03 12:07:06 -0700100
Craig Tiller560c9012016-02-24 16:34:38 -0800101jobset.run(pre_jobs, maxjobs=args.jobs)
Craig Tiller12971702016-01-21 13:38:35 -0800102jobset.run(jobs, maxjobs=args.jobs)
Craig Tiller1a718112015-07-03 12:07:06 -0700103
104if test is not None:
Nicolas "Pixel" Noble22232ae2015-07-11 22:40:22 +0200105 for s, g in test.iteritems():
Craig Tiller259e6272015-08-31 16:58:18 -0700106 if os.path.isfile(g):
Nicolas "Pixel" Noble9baaead2015-10-03 02:25:02 +0200107 assert 0 == os.system('diff %s %s' % (s, g)), s
Craig Tiller259e6272015-08-31 16:58:18 -0700108 os.unlink(g)
109 else:
Nicolas "Pixel" Noble9baaead2015-10-03 02:25:02 +0200110 assert 0 == os.system('diff -r %s %s' % (s, g)), s
Craig Tiller259e6272015-08-31 16:58:18 -0700111 shutil.rmtree(g, ignore_errors=True)