The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 16 | from __future__ import print_function |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 17 | import errno |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 18 | import multiprocessing |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | import re |
| 20 | import os |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 21 | import signal |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | import sys |
| 23 | import subprocess |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 24 | |
| 25 | from color import Coloring |
Shawn O. Pearce | 4446946 | 2009-03-03 17:51:01 -0800 | [diff] [blame] | 26 | from command import Command, MirrorSafeCommand |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 27 | import platform_utils |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 28 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 29 | _CAN_COLOR = [ |
| 30 | 'branch', |
| 31 | 'diff', |
| 32 | 'grep', |
| 33 | 'log', |
| 34 | ] |
| 35 | |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 36 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 37 | class ForallColoring(Coloring): |
| 38 | def __init__(self, config): |
| 39 | Coloring.__init__(self, config, 'forall') |
| 40 | self.project = self.printer('project', attr='bold') |
| 41 | |
| 42 | |
Shawn O. Pearce | 4446946 | 2009-03-03 17:51:01 -0800 | [diff] [blame] | 43 | class Forall(Command, MirrorSafeCommand): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | common = False |
| 45 | helpSummary = "Run a shell command in each project" |
| 46 | helpUsage = """ |
| 47 | %prog [<project>...] -c <command> [<arg>...] |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 48 | %prog -r str1 [str2] ... -c <command> [<arg>...]" |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | """ |
| 50 | helpDescription = """ |
| 51 | Executes the same shell command in each project. |
| 52 | |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 53 | The -r option allows running the command only on projects matching |
| 54 | regex or wildcard expression. |
| 55 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 56 | Output Formatting |
| 57 | ----------------- |
| 58 | |
| 59 | The -p option causes '%prog' to bind pipes to the command's stdin, |
| 60 | stdout and stderr streams, and pipe all output into a continuous |
| 61 | stream that is displayed in a single pager session. Project headings |
| 62 | are inserted before the output of each command is displayed. If the |
| 63 | command produces no output in a project, no heading is displayed. |
| 64 | |
| 65 | The formatting convention used by -p is very suitable for some |
| 66 | types of searching, e.g. `repo forall -p -c git log -SFoo` will |
| 67 | print all commits that add or remove references to Foo. |
| 68 | |
| 69 | The -v option causes '%prog' to display stderr messages if a |
| 70 | command produces output only on stderr. Normally the -p option |
| 71 | causes command output to be suppressed until the command produces |
| 72 | at least one byte of output on stdout. |
| 73 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 74 | Environment |
| 75 | ----------- |
Shawn O. Pearce | ff84fea | 2009-04-13 12:11:59 -0700 | [diff] [blame] | 76 | |
Shawn O. Pearce | 4446946 | 2009-03-03 17:51:01 -0800 | [diff] [blame] | 77 | pwd is the project's working directory. If the current client is |
| 78 | a mirror client, then pwd is the Git repository. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 79 | |
| 80 | REPO_PROJECT is set to the unique name of the project. |
| 81 | |
Jeff Bailey | be0e8ac | 2009-01-21 19:05:15 -0500 | [diff] [blame] | 82 | REPO_PATH is the path relative the the root of the client. |
| 83 | |
| 84 | REPO_REMOTE is the name of the remote system from the manifest. |
| 85 | |
| 86 | REPO_LREV is the name of the revision from the manifest, translated |
| 87 | to a local tracking branch. If you need to pass the manifest |
| 88 | revision to a locally executed git command, use REPO_LREV. |
| 89 | |
| 90 | REPO_RREV is the name of the revision from the manifest, exactly |
| 91 | as written in the manifest. |
| 92 | |
Mitchel Humpherys | e81bc03 | 2014-03-31 11:36:56 -0700 | [diff] [blame] | 93 | REPO_COUNT is the total number of projects being iterated. |
| 94 | |
| 95 | REPO_I is the current (1-based) iteration count. Can be used in |
| 96 | conjunction with REPO_COUNT to add a simple progress indicator to your |
| 97 | command. |
| 98 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 99 | REPO__* are any extra environment variables, specified by the |
| 100 | "annotation" element under any project element. This can be useful |
| 101 | for differentiating trees based on user-specific criteria, or simply |
| 102 | annotating tree details. |
| 103 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 104 | shell positional arguments ($1, $2, .., $#) are set to any arguments |
| 105 | following <command>. |
| 106 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 107 | Unless -p is used, stdin, stdout, stderr are inherited from the |
| 108 | terminal and are not redirected. |
Victor Boivie | 88b8672 | 2011-09-07 09:43:28 +0200 | [diff] [blame] | 109 | |
| 110 | If -e is used, when a command exits unsuccessfully, '%prog' will abort |
| 111 | without iterating through the remaining projects. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 112 | """ |
| 113 | |
| 114 | def _Options(self, p): |
| 115 | def cmd(option, opt_str, value, parser): |
| 116 | setattr(parser.values, option.dest, list(parser.rargs)) |
| 117 | while parser.rargs: |
| 118 | del parser.rargs[0] |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 119 | p.add_option('-r', '--regex', |
| 120 | dest='regex', action='store_true', |
| 121 | help="Execute the command only on projects matching regex or wildcard expression") |
Takeshi Kanemoto | 1f05644 | 2016-01-26 14:11:35 +0900 | [diff] [blame] | 122 | p.add_option('-i', '--inverse-regex', |
| 123 | dest='inverse_regex', action='store_true', |
| 124 | help="Execute the command only on projects not matching regex or wildcard expression") |
Graham Christensen | 0369a06 | 2015-07-29 17:02:54 -0500 | [diff] [blame] | 125 | p.add_option('-g', '--groups', |
| 126 | dest='groups', |
| 127 | help="Execute the command only on projects matching the specified groups") |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 128 | p.add_option('-c', '--command', |
| 129 | help='Command (and arguments) to execute', |
| 130 | dest='command', |
| 131 | action='callback', |
| 132 | callback=cmd) |
Victor Boivie | 88b8672 | 2011-09-07 09:43:28 +0200 | [diff] [blame] | 133 | p.add_option('-e', '--abort-on-errors', |
| 134 | dest='abort_on_errors', action='store_true', |
| 135 | help='Abort if a command exits unsuccessfully') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 137 | g = p.add_option_group('Output') |
| 138 | g.add_option('-p', |
| 139 | dest='project_header', action='store_true', |
| 140 | help='Show project headers before output') |
| 141 | g.add_option('-v', '--verbose', |
| 142 | dest='verbose', action='store_true', |
| 143 | help='Show command error messages') |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 144 | g.add_option('-j', '--jobs', |
| 145 | dest='jobs', action='store', type='int', default=1, |
| 146 | help='number of commands to execute simultaneously') |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 147 | |
| 148 | def WantPager(self, opt): |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 149 | return opt.project_header and opt.jobs == 1 |
| 150 | |
| 151 | def _SerializeProject(self, project): |
| 152 | """ Serialize a project._GitGetByExec instance. |
| 153 | |
| 154 | project._GitGetByExec is not pickle-able. Instead of trying to pass it |
| 155 | around between processes, make a dict ourselves containing only the |
| 156 | attributes that we need. |
| 157 | |
| 158 | """ |
David Pursehouse | 30d13ee | 2015-05-07 15:01:15 +0900 | [diff] [blame] | 159 | if not self.manifest.IsMirror: |
| 160 | lrev = project.GetRevisionId() |
| 161 | else: |
| 162 | lrev = None |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 163 | return { |
| 164 | 'name': project.name, |
| 165 | 'relpath': project.relpath, |
| 166 | 'remote_name': project.remote.name, |
David Pursehouse | 30d13ee | 2015-05-07 15:01:15 +0900 | [diff] [blame] | 167 | 'lrev': lrev, |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 168 | 'rrev': project.revisionExpr, |
| 169 | 'annotations': dict((a.name, a.value) for a in project.annotations), |
| 170 | 'gitdir': project.gitdir, |
| 171 | 'worktree': project.worktree, |
| 172 | } |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 174 | def Execute(self, opt, args): |
| 175 | if not opt.command: |
| 176 | self.Usage() |
| 177 | |
| 178 | cmd = [opt.command[0]] |
| 179 | |
| 180 | shell = True |
| 181 | if re.compile(r'^[a-z0-9A-Z_/\.-]+$').match(cmd[0]): |
| 182 | shell = False |
| 183 | |
| 184 | if shell: |
| 185 | cmd.append(cmd[0]) |
| 186 | cmd.extend(opt.command[1:]) |
| 187 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 188 | if opt.project_header \ |
| 189 | and not shell \ |
| 190 | and cmd[0] == 'git': |
| 191 | # If this is a direct git command that can enable colorized |
| 192 | # output and the user prefers coloring, add --color into the |
| 193 | # command line because we are going to wrap the command into |
| 194 | # a pipe and git won't know coloring should activate. |
| 195 | # |
| 196 | for cn in cmd[1:]: |
| 197 | if not cn.startswith('-'): |
| 198 | break |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 199 | else: |
| 200 | cn = None |
David Pursehouse | 4f7bdea | 2012-10-22 12:50:15 +0900 | [diff] [blame] | 201 | # pylint: disable=W0631 |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 202 | if cn and cn in _CAN_COLOR: |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 203 | class ColorCmd(Coloring): |
| 204 | def __init__(self, config, cmd): |
| 205 | Coloring.__init__(self, config, cmd) |
| 206 | if ColorCmd(self.manifest.manifestProject.config, cn).is_on: |
| 207 | cmd.insert(cmd.index(cn) + 1, '--color') |
David Pursehouse | 4f7bdea | 2012-10-22 12:50:15 +0900 | [diff] [blame] | 208 | # pylint: enable=W0631 |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 209 | |
Shawn O. Pearce | 4446946 | 2009-03-03 17:51:01 -0800 | [diff] [blame] | 210 | mirror = self.manifest.IsMirror |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | rc = 0 |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 212 | |
David Pursehouse | 6944cdb | 2015-05-07 14:39:44 +0900 | [diff] [blame] | 213 | smart_sync_manifest_name = "smart_sync_override.xml" |
| 214 | smart_sync_manifest_path = os.path.join( |
| 215 | self.manifest.manifestProject.worktree, smart_sync_manifest_name) |
| 216 | |
| 217 | if os.path.isfile(smart_sync_manifest_path): |
| 218 | self.manifest.Override(smart_sync_manifest_path) |
| 219 | |
Takeshi Kanemoto | 1f05644 | 2016-01-26 14:11:35 +0900 | [diff] [blame] | 220 | if opt.regex: |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 221 | projects = self.FindProjects(args) |
Takeshi Kanemoto | 1f05644 | 2016-01-26 14:11:35 +0900 | [diff] [blame] | 222 | elif opt.inverse_regex: |
| 223 | projects = self.FindProjects(args, inverse=True) |
| 224 | else: |
| 225 | projects = self.GetProjects(args, groups=opt.groups) |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 226 | |
Mitchel Humpherys | e81bc03 | 2014-03-31 11:36:56 -0700 | [diff] [blame] | 227 | os.environ['REPO_COUNT'] = str(len(projects)) |
| 228 | |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 229 | pool = multiprocessing.Pool(opt.jobs, InitWorker) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 230 | try: |
| 231 | config = self.manifest.manifestProject.config |
| 232 | results_it = pool.imap( |
| 233 | DoWorkWrapper, |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 234 | self.ProjectArgs(projects, mirror, opt, cmd, shell, config)) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 235 | pool.close() |
| 236 | for r in results_it: |
| 237 | rc = rc or r |
| 238 | if r != 0 and opt.abort_on_errors: |
| 239 | raise Exception('Aborting due to previous error') |
| 240 | except (KeyboardInterrupt, WorkerKeyboardInterrupt): |
| 241 | # Catch KeyboardInterrupt raised inside and outside of workers |
| 242 | print('Interrupted - terminating the pool') |
| 243 | pool.terminate() |
| 244 | rc = rc or errno.EINTR |
| 245 | except Exception as e: |
| 246 | # Catch any other exceptions raised |
Alexandre Garnier | 4cfb6d7 | 2015-09-09 15:51:31 +0200 | [diff] [blame] | 247 | print('Got an error, terminating the pool: %s: %s' % |
| 248 | (type(e).__name__, e), |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 249 | file=sys.stderr) |
| 250 | pool.terminate() |
| 251 | rc = rc or getattr(e, 'errno', 1) |
| 252 | finally: |
| 253 | pool.join() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 254 | if rc != 0: |
| 255 | sys.exit(rc) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 256 | |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 257 | def ProjectArgs(self, projects, mirror, opt, cmd, shell, config): |
| 258 | for cnt, p in enumerate(projects): |
| 259 | try: |
| 260 | project = self._SerializeProject(p) |
| 261 | except Exception as e: |
Alexandre Garnier | 4cfb6d7 | 2015-09-09 15:51:31 +0200 | [diff] [blame] | 262 | print('Project list error on project %s: %s: %s' % |
| 263 | (p.name, type(e).__name__, e), |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 264 | file=sys.stderr) |
| 265 | return |
| 266 | except KeyboardInterrupt: |
| 267 | print('Project list interrupted', |
| 268 | file=sys.stderr) |
| 269 | return |
| 270 | yield [mirror, opt, cmd, shell, cnt, config, project] |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 271 | |
| 272 | class WorkerKeyboardInterrupt(Exception): |
| 273 | """ Keyboard interrupt exception for worker processes. """ |
| 274 | pass |
| 275 | |
| 276 | |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 277 | def InitWorker(): |
| 278 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
| 279 | |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 280 | def DoWorkWrapper(args): |
| 281 | """ A wrapper around the DoWork() method. |
| 282 | |
| 283 | Catch the KeyboardInterrupt exceptions here and re-raise them as a different, |
| 284 | ``Exception``-based exception to stop it flooding the console with stacktraces |
| 285 | and making the parent hang indefinitely. |
| 286 | |
| 287 | """ |
| 288 | project = args.pop() |
| 289 | try: |
| 290 | return DoWork(project, *args) |
| 291 | except KeyboardInterrupt: |
| 292 | print('%s: Worker interrupted' % project['name']) |
| 293 | raise WorkerKeyboardInterrupt() |
| 294 | |
| 295 | |
| 296 | def DoWork(project, mirror, opt, cmd, shell, cnt, config): |
| 297 | env = os.environ.copy() |
| 298 | def setenv(name, val): |
| 299 | if val is None: |
| 300 | val = '' |
Anthony King | c116f94 | 2015-06-03 17:29:29 +0100 | [diff] [blame] | 301 | if hasattr(val, 'encode'): |
| 302 | val = val.encode() |
| 303 | env[name] = val |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 304 | |
| 305 | setenv('REPO_PROJECT', project['name']) |
| 306 | setenv('REPO_PATH', project['relpath']) |
| 307 | setenv('REPO_REMOTE', project['remote_name']) |
| 308 | setenv('REPO_LREV', project['lrev']) |
| 309 | setenv('REPO_RREV', project['rrev']) |
| 310 | setenv('REPO_I', str(cnt + 1)) |
| 311 | for name in project['annotations']: |
| 312 | setenv("REPO__%s" % (name), project['annotations'][name]) |
| 313 | |
| 314 | if mirror: |
| 315 | setenv('GIT_DIR', project['gitdir']) |
| 316 | cwd = project['gitdir'] |
| 317 | else: |
| 318 | cwd = project['worktree'] |
| 319 | |
| 320 | if not os.path.exists(cwd): |
| 321 | if (opt.project_header and opt.verbose) \ |
| 322 | or not opt.project_header: |
| 323 | print('skipping %s/' % project['relpath'], file=sys.stderr) |
| 324 | return |
| 325 | |
| 326 | if opt.project_header: |
| 327 | stdin = subprocess.PIPE |
| 328 | stdout = subprocess.PIPE |
| 329 | stderr = subprocess.PIPE |
| 330 | else: |
| 331 | stdin = None |
| 332 | stdout = None |
| 333 | stderr = None |
| 334 | |
| 335 | p = subprocess.Popen(cmd, |
| 336 | cwd=cwd, |
| 337 | shell=shell, |
| 338 | env=env, |
| 339 | stdin=stdin, |
| 340 | stdout=stdout, |
| 341 | stderr=stderr) |
| 342 | |
| 343 | if opt.project_header: |
| 344 | out = ForallColoring(config) |
| 345 | out.redirect(sys.stdout) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 346 | empty = True |
| 347 | errbuf = '' |
| 348 | |
| 349 | p.stdin.close() |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 350 | s_in = platform_utils.FileDescriptorStreams.create() |
| 351 | s_in.add(p.stdout, sys.stdout, 'stdout') |
| 352 | s_in.add(p.stderr, sys.stderr, 'stderr') |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 353 | |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 354 | while not s_in.is_done: |
| 355 | in_ready = s_in.select() |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 356 | for s in in_ready: |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 357 | buf = s.read() |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 358 | if not buf: |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 359 | s.close() |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 360 | s_in.remove(s) |
| 361 | continue |
| 362 | |
| 363 | if not opt.verbose: |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 364 | if s.std_name == 'stderr': |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 365 | errbuf += buf |
| 366 | continue |
| 367 | |
| 368 | if empty and out: |
| 369 | if not cnt == 0: |
| 370 | out.nl() |
| 371 | |
| 372 | if mirror: |
| 373 | project_header_path = project['name'] |
| 374 | else: |
| 375 | project_header_path = project['relpath'] |
| 376 | out.project('project %s/', project_header_path) |
| 377 | out.nl() |
| 378 | out.flush() |
| 379 | if errbuf: |
| 380 | sys.stderr.write(errbuf) |
| 381 | sys.stderr.flush() |
| 382 | errbuf = '' |
| 383 | empty = False |
| 384 | |
| 385 | s.dest.write(buf) |
| 386 | s.dest.flush() |
| 387 | |
| 388 | r = p.wait() |
| 389 | return r |