OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python2.7 |
| 2 # Copyright 2016, Google Inc. |
| 3 # All rights reserved. |
| 4 # |
| 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are |
| 7 # met: |
| 8 # |
| 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. |
| 11 # * Redistributions in binary form must reproduce the above |
| 12 # copyright notice, this list of conditions and the following disclaimer |
| 13 # in the documentation and/or other materials provided with the |
| 14 # distribution. |
| 15 # * Neither the name of Google Inc. nor the names of its |
| 16 # contributors may be used to endorse or promote products derived from |
| 17 # this software without specific prior written permission. |
| 18 # |
| 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
| 31 """Runs selected gRPC test/build tasks.""" |
| 32 |
| 33 import argparse |
| 34 import atexit |
| 35 import jobset |
| 36 import multiprocessing |
| 37 import sys |
| 38 |
| 39 import artifact_targets |
| 40 import distribtest_targets |
| 41 import package_targets |
| 42 |
| 43 _TARGETS = [] |
| 44 _TARGETS += artifact_targets.targets() |
| 45 _TARGETS += distribtest_targets.targets() |
| 46 _TARGETS += package_targets.targets() |
| 47 |
| 48 def _create_build_map(): |
| 49 """Maps task names and labels to list of tasks to be built.""" |
| 50 target_build_map = dict([(target.name, [target]) |
| 51 for target in _TARGETS]) |
| 52 if len(_TARGETS) > len(target_build_map.keys()): |
| 53 raise Exception('Target names need to be unique') |
| 54 |
| 55 label_build_map = {} |
| 56 label_build_map['all'] = [t for t in _TARGETS] # to build all targets |
| 57 for target in _TARGETS: |
| 58 for label in target.labels: |
| 59 if label in label_build_map: |
| 60 label_build_map[label].append(target) |
| 61 else: |
| 62 label_build_map[label] = [target] |
| 63 |
| 64 if set(target_build_map.keys()).intersection(label_build_map.keys()): |
| 65 raise Exception('Target names need to be distinct from label names') |
| 66 return dict( target_build_map.items() + label_build_map.items()) |
| 67 |
| 68 |
| 69 _BUILD_MAP = _create_build_map() |
| 70 |
| 71 argp = argparse.ArgumentParser(description='Runs build/test targets.') |
| 72 argp.add_argument('-b', '--build', |
| 73 choices=sorted(_BUILD_MAP.keys()), |
| 74 nargs='+', |
| 75 default=['all'], |
| 76 help='Target name or target label to build.') |
| 77 argp.add_argument('-f', '--filter', |
| 78 choices=sorted(_BUILD_MAP.keys()), |
| 79 nargs='+', |
| 80 default=[], |
| 81 help='Filter targets to build with AND semantics.') |
| 82 argp.add_argument('-j', '--jobs', default=multiprocessing.cpu_count(), type=int) |
| 83 argp.add_argument('-t', '--travis', |
| 84 default=False, |
| 85 action='store_const', |
| 86 const=True) |
| 87 |
| 88 args = argp.parse_args() |
| 89 |
| 90 # Figure out which targets to build |
| 91 targets = [] |
| 92 for label in args.build: |
| 93 targets += _BUILD_MAP[label] |
| 94 |
| 95 # Among targets selected by -b, filter out those that don't match the filter |
| 96 targets = [t for t in targets if all(f in t.labels for f in args.filter)] |
| 97 targets = sorted(set(targets)) |
| 98 |
| 99 # Execute pre-build phase |
| 100 prebuild_jobs = [] |
| 101 for target in targets: |
| 102 prebuild_jobs += target.pre_build_jobspecs() |
| 103 if prebuild_jobs: |
| 104 num_failures, _ = jobset.run( |
| 105 prebuild_jobs, newline_on_success=True, maxjobs=args.jobs) |
| 106 if num_failures != 0: |
| 107 jobset.message('FAILED', 'Pre-build phase failed.', do_newline=True) |
| 108 sys.exit(1) |
| 109 |
| 110 build_jobs = [] |
| 111 for target in targets: |
| 112 build_jobs.append(target.build_jobspec()) |
| 113 if not build_jobs: |
| 114 print 'Nothing to build.' |
| 115 sys.exit(1) |
| 116 |
| 117 jobset.message('START', 'Building targets.', do_newline=True) |
| 118 num_failures, _ = jobset.run( |
| 119 build_jobs, newline_on_success=True, maxjobs=args.jobs) |
| 120 if num_failures == 0: |
| 121 jobset.message('SUCCESS', 'All targets built successfully.', |
| 122 do_newline=True) |
| 123 else: |
| 124 jobset.message('FAILED', 'Failed to build targets.', |
| 125 do_newline=True) |
| 126 sys.exit(1) |
OLD | NEW |