15 """Runs selected gRPC test/build tasks."""
17 from __future__
import print_function
20 import multiprocessing
30 _TARGETS += artifact_targets.targets()
31 _TARGETS += distribtest_targets.targets()
32 _TARGETS += package_targets.targets()
36 """Maps task names and labels to list of tasks to be built."""
37 target_build_map = dict([(target.name, [target])
for target
in _TARGETS])
38 if len(_TARGETS) >
len(list(target_build_map.keys())):
39 raise Exception(
'Target names need to be unique')
42 label_build_map[
'all'] = [t
for t
in _TARGETS]
43 for target
in _TARGETS:
44 for label
in target.labels:
45 if label
in label_build_map:
46 label_build_map[label].append(target)
48 label_build_map[label] = [target]
50 if set(target_build_map.keys()).intersection(list(label_build_map.keys())):
51 raise Exception(
'Target names need to be distinct from label names')
52 return dict(list(target_build_map.items()) + list(label_build_map.items()))
57 argp = argparse.ArgumentParser(description=
'Runs build/test targets.')
58 argp.add_argument(
'-b',
60 choices=sorted(_BUILD_MAP.keys()),
63 help=
'Target name or target label to build.')
64 argp.add_argument(
'-f',
66 choices=sorted(_BUILD_MAP.keys()),
69 help=
'Filter targets to build with AND semantics.')
70 argp.add_argument(
'-j',
'--jobs', default=multiprocessing.cpu_count(), type=int)
71 argp.add_argument(
'-x',
73 default=
'report_taskrunner_sponge_log.xml',
75 help=
'Filename for the JUnit-compatible XML report')
76 argp.add_argument(
'--dry_run',
80 help=
'Only print what would be run.')
86 'Number of parallel jobs to use by each target. Passed as build_jobspec(inner_jobs=N) to each target.'
89 args = argp.parse_args()
93 for label
in args.build:
94 targets += _BUILD_MAP[label]
97 targets = [t
for t
in targets
if all(f
in t.labels
for f
in args.filter)]
99 print(
'Will build %d targets:' %
len(targets))
100 for target
in targets:
101 print(
' %s, labels %s' % (target.name, target.labels))
105 print(
'--dry_run was used, exiting')
110 for target
in targets:
111 prebuild_jobs += target.pre_build_jobspecs()
113 num_failures, _ = jobset.run(prebuild_jobs,
114 newline_on_success=
True,
116 if num_failures != 0:
117 jobset.message(
'FAILED',
'Pre-build phase failed.', do_newline=
True)
121 for target
in targets:
122 build_jobs.append(target.build_jobspec(inner_jobs=args.inner_jobs))
124 print(
'Nothing to build.')
127 jobset.message(
'START',
'Building targets.', do_newline=
True)
128 num_failures, resultset = jobset.run(build_jobs,
129 newline_on_success=
True,
131 report_utils.render_junit_xml_report(resultset,
134 if num_failures == 0:
135 jobset.message(
'SUCCESS',
136 'All targets built successfully.',
139 jobset.message(
'FAILED',
'Failed to build targets.', do_newline=
True)