OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python2.7 |
| 2 |
| 3 # Copyright 2015-2016, Google Inc. |
| 4 # 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 |
| 32 import argparse |
| 33 import glob |
| 34 import os |
| 35 import shutil |
| 36 import sys |
| 37 import tempfile |
| 38 import multiprocessing |
| 39 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..', 'run_tests')) |
| 40 |
| 41 assert sys.argv[1:], 'run generate_projects.sh instead of this directly' |
| 42 |
| 43 import jobset |
| 44 |
| 45 os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '..', '..')) |
| 46 |
| 47 argp = argparse.ArgumentParser() |
| 48 argp.add_argument('build_files', nargs='+', default=[]) |
| 49 argp.add_argument('--templates', nargs='+', default=[]) |
| 50 argp.add_argument('--jobs', '-j', default=multiprocessing.cpu_count(), type=int) |
| 51 args = argp.parse_args() |
| 52 |
| 53 json = args.build_files |
| 54 |
| 55 test = {} if 'TEST' in os.environ else None |
| 56 |
| 57 plugins = sorted(glob.glob('tools/buildgen/plugins/*.py')) |
| 58 |
| 59 templates = args.templates |
| 60 if 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 |
| 65 pre_jobs = [] |
| 66 base_cmd = ['python2.7', 'tools/buildgen/mako_renderer.py'] |
| 67 cmd = base_cmd[:] |
| 68 for plugin in plugins: |
| 69 cmd.append('-p') |
| 70 cmd.append(plugin) |
| 71 for js in json: |
| 72 cmd.append('-d') |
| 73 cmd.append(js) |
| 74 cmd.append('-w') |
| 75 preprocessed_build = '.preprocessed_build' |
| 76 cmd.append(preprocessed_build) |
| 77 pre_jobs.append(jobset.JobSpec(cmd, shortname='preprocess', timeout_seconds=None
)) |
| 78 |
| 79 jobs = [] |
| 80 for template in reversed(sorted(templates)): |
| 81 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) |
| 87 cmd = base_cmd[:] |
| 88 cmd.append('-P') |
| 89 cmd.append(preprocessed_build) |
| 90 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) |
| 99 jobs.append(jobset.JobSpec(cmd, shortname=out, timeout_seconds=None)) |
| 100 |
| 101 jobset.run(pre_jobs, maxjobs=args.jobs) |
| 102 jobset.run(jobs, maxjobs=args.jobs) |
| 103 |
| 104 if test is not None: |
| 105 for s, g in test.iteritems(): |
| 106 if os.path.isfile(g): |
| 107 assert 0 == os.system('diff %s %s' % (s, g)), s |
| 108 os.unlink(g) |
| 109 else: |
| 110 assert 0 == os.system('diff -r %s %s' % (s, g)), s |
| 111 shutil.rmtree(g, ignore_errors=True) |
OLD | NEW |