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 | |
David Pursehouse | f46902a | 2017-10-31 12:27:17 +0900 | [diff] [blame] | 107 | Example: to list projects: |
| 108 | |
| 109 | %prog% forall -c 'echo $REPO_PROJECT' |
| 110 | |
| 111 | Notice that $REPO_PROJECT is quoted to ensure it is expanded in |
| 112 | the context of running <command> instead of in the calling shell. |
| 113 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 114 | Unless -p is used, stdin, stdout, stderr are inherited from the |
| 115 | terminal and are not redirected. |
Victor Boivie | 88b8672 | 2011-09-07 09:43:28 +0200 | [diff] [blame] | 116 | |
| 117 | If -e is used, when a command exits unsuccessfully, '%prog' will abort |
| 118 | without iterating through the remaining projects. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 119 | """ |
| 120 | |
| 121 | def _Options(self, p): |
| 122 | def cmd(option, opt_str, value, parser): |
| 123 | setattr(parser.values, option.dest, list(parser.rargs)) |
| 124 | while parser.rargs: |
| 125 | del parser.rargs[0] |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 126 | p.add_option('-r', '--regex', |
| 127 | dest='regex', action='store_true', |
| 128 | help="Execute the command only on projects matching regex or wildcard expression") |
Takeshi Kanemoto | 1f05644 | 2016-01-26 14:11:35 +0900 | [diff] [blame] | 129 | p.add_option('-i', '--inverse-regex', |
| 130 | dest='inverse_regex', action='store_true', |
| 131 | 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] | 132 | p.add_option('-g', '--groups', |
| 133 | dest='groups', |
| 134 | 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] | 135 | p.add_option('-c', '--command', |
| 136 | help='Command (and arguments) to execute', |
| 137 | dest='command', |
| 138 | action='callback', |
| 139 | callback=cmd) |
Victor Boivie | 88b8672 | 2011-09-07 09:43:28 +0200 | [diff] [blame] | 140 | p.add_option('-e', '--abort-on-errors', |
| 141 | dest='abort_on_errors', action='store_true', |
| 142 | help='Abort if a command exits unsuccessfully') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 143 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 144 | g = p.add_option_group('Output') |
| 145 | g.add_option('-p', |
| 146 | dest='project_header', action='store_true', |
| 147 | help='Show project headers before output') |
| 148 | g.add_option('-v', '--verbose', |
| 149 | dest='verbose', action='store_true', |
| 150 | help='Show command error messages') |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 151 | g.add_option('-j', '--jobs', |
| 152 | dest='jobs', action='store', type='int', default=1, |
| 153 | help='number of commands to execute simultaneously') |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 154 | |
| 155 | def WantPager(self, opt): |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 156 | return opt.project_header and opt.jobs == 1 |
| 157 | |
| 158 | def _SerializeProject(self, project): |
| 159 | """ Serialize a project._GitGetByExec instance. |
| 160 | |
| 161 | project._GitGetByExec is not pickle-able. Instead of trying to pass it |
| 162 | around between processes, make a dict ourselves containing only the |
| 163 | attributes that we need. |
| 164 | |
| 165 | """ |
David Pursehouse | 30d13ee | 2015-05-07 15:01:15 +0900 | [diff] [blame] | 166 | if not self.manifest.IsMirror: |
| 167 | lrev = project.GetRevisionId() |
| 168 | else: |
| 169 | lrev = None |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 170 | return { |
| 171 | 'name': project.name, |
| 172 | 'relpath': project.relpath, |
| 173 | 'remote_name': project.remote.name, |
David Pursehouse | 30d13ee | 2015-05-07 15:01:15 +0900 | [diff] [blame] | 174 | 'lrev': lrev, |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 175 | 'rrev': project.revisionExpr, |
| 176 | 'annotations': dict((a.name, a.value) for a in project.annotations), |
| 177 | 'gitdir': project.gitdir, |
| 178 | 'worktree': project.worktree, |
| 179 | } |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 180 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 181 | def Execute(self, opt, args): |
| 182 | if not opt.command: |
| 183 | self.Usage() |
| 184 | |
| 185 | cmd = [opt.command[0]] |
| 186 | |
| 187 | shell = True |
| 188 | if re.compile(r'^[a-z0-9A-Z_/\.-]+$').match(cmd[0]): |
| 189 | shell = False |
| 190 | |
| 191 | if shell: |
| 192 | cmd.append(cmd[0]) |
| 193 | cmd.extend(opt.command[1:]) |
| 194 | |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 195 | if opt.project_header \ |
| 196 | and not shell \ |
| 197 | and cmd[0] == 'git': |
| 198 | # If this is a direct git command that can enable colorized |
| 199 | # output and the user prefers coloring, add --color into the |
| 200 | # command line because we are going to wrap the command into |
| 201 | # a pipe and git won't know coloring should activate. |
| 202 | # |
| 203 | for cn in cmd[1:]: |
| 204 | if not cn.startswith('-'): |
| 205 | break |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 206 | else: |
| 207 | cn = None |
David Pursehouse | 4f7bdea | 2012-10-22 12:50:15 +0900 | [diff] [blame] | 208 | # pylint: disable=W0631 |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 209 | if cn and cn in _CAN_COLOR: |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 210 | class ColorCmd(Coloring): |
| 211 | def __init__(self, config, cmd): |
| 212 | Coloring.__init__(self, config, cmd) |
| 213 | if ColorCmd(self.manifest.manifestProject.config, cn).is_on: |
| 214 | cmd.insert(cmd.index(cn) + 1, '--color') |
David Pursehouse | 4f7bdea | 2012-10-22 12:50:15 +0900 | [diff] [blame] | 215 | # pylint: enable=W0631 |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 216 | |
Shawn O. Pearce | 4446946 | 2009-03-03 17:51:01 -0800 | [diff] [blame] | 217 | mirror = self.manifest.IsMirror |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 218 | rc = 0 |
Shawn O. Pearce | db45da1 | 2009-04-18 13:49:13 -0700 | [diff] [blame] | 219 | |
David Pursehouse | 6944cdb | 2015-05-07 14:39:44 +0900 | [diff] [blame] | 220 | smart_sync_manifest_name = "smart_sync_override.xml" |
| 221 | smart_sync_manifest_path = os.path.join( |
| 222 | self.manifest.manifestProject.worktree, smart_sync_manifest_name) |
| 223 | |
| 224 | if os.path.isfile(smart_sync_manifest_path): |
| 225 | self.manifest.Override(smart_sync_manifest_path) |
| 226 | |
Takeshi Kanemoto | 1f05644 | 2016-01-26 14:11:35 +0900 | [diff] [blame] | 227 | if opt.regex: |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 228 | projects = self.FindProjects(args) |
Takeshi Kanemoto | 1f05644 | 2016-01-26 14:11:35 +0900 | [diff] [blame] | 229 | elif opt.inverse_regex: |
| 230 | projects = self.FindProjects(args, inverse=True) |
| 231 | else: |
| 232 | projects = self.GetProjects(args, groups=opt.groups) |
Zhiguang Li | a8864fb | 2013-03-15 10:32:10 +0800 | [diff] [blame] | 233 | |
Mitchel Humpherys | e81bc03 | 2014-03-31 11:36:56 -0700 | [diff] [blame] | 234 | os.environ['REPO_COUNT'] = str(len(projects)) |
| 235 | |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 236 | pool = multiprocessing.Pool(opt.jobs, InitWorker) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 237 | try: |
| 238 | config = self.manifest.manifestProject.config |
| 239 | results_it = pool.imap( |
| 240 | DoWorkWrapper, |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 241 | self.ProjectArgs(projects, mirror, opt, cmd, shell, config)) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 242 | pool.close() |
| 243 | for r in results_it: |
| 244 | rc = rc or r |
| 245 | if r != 0 and opt.abort_on_errors: |
| 246 | raise Exception('Aborting due to previous error') |
| 247 | except (KeyboardInterrupt, WorkerKeyboardInterrupt): |
| 248 | # Catch KeyboardInterrupt raised inside and outside of workers |
| 249 | print('Interrupted - terminating the pool') |
| 250 | pool.terminate() |
| 251 | rc = rc or errno.EINTR |
| 252 | except Exception as e: |
| 253 | # Catch any other exceptions raised |
Alexandre Garnier | 4cfb6d7 | 2015-09-09 15:51:31 +0200 | [diff] [blame] | 254 | print('Got an error, terminating the pool: %s: %s' % |
| 255 | (type(e).__name__, e), |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 256 | file=sys.stderr) |
| 257 | pool.terminate() |
| 258 | rc = rc or getattr(e, 'errno', 1) |
| 259 | finally: |
| 260 | pool.join() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 261 | if rc != 0: |
| 262 | sys.exit(rc) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 263 | |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 264 | def ProjectArgs(self, projects, mirror, opt, cmd, shell, config): |
| 265 | for cnt, p in enumerate(projects): |
| 266 | try: |
| 267 | project = self._SerializeProject(p) |
| 268 | except Exception as e: |
Alexandre Garnier | 4cfb6d7 | 2015-09-09 15:51:31 +0200 | [diff] [blame] | 269 | print('Project list error on project %s: %s: %s' % |
| 270 | (p.name, type(e).__name__, e), |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 271 | file=sys.stderr) |
| 272 | return |
| 273 | except KeyboardInterrupt: |
| 274 | print('Project list interrupted', |
| 275 | file=sys.stderr) |
| 276 | return |
| 277 | yield [mirror, opt, cmd, shell, cnt, config, project] |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 278 | |
| 279 | class WorkerKeyboardInterrupt(Exception): |
| 280 | """ Keyboard interrupt exception for worker processes. """ |
| 281 | pass |
| 282 | |
| 283 | |
Colin Cross | 31a7be5 | 2015-05-13 00:04:36 -0700 | [diff] [blame] | 284 | def InitWorker(): |
| 285 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
| 286 | |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 287 | def DoWorkWrapper(args): |
| 288 | """ A wrapper around the DoWork() method. |
| 289 | |
| 290 | Catch the KeyboardInterrupt exceptions here and re-raise them as a different, |
| 291 | ``Exception``-based exception to stop it flooding the console with stacktraces |
| 292 | and making the parent hang indefinitely. |
| 293 | |
| 294 | """ |
| 295 | project = args.pop() |
| 296 | try: |
| 297 | return DoWork(project, *args) |
| 298 | except KeyboardInterrupt: |
| 299 | print('%s: Worker interrupted' % project['name']) |
| 300 | raise WorkerKeyboardInterrupt() |
| 301 | |
| 302 | |
| 303 | def DoWork(project, mirror, opt, cmd, shell, cnt, config): |
| 304 | env = os.environ.copy() |
| 305 | def setenv(name, val): |
| 306 | if val is None: |
| 307 | val = '' |
Anthony King | c116f94 | 2015-06-03 17:29:29 +0100 | [diff] [blame] | 308 | if hasattr(val, 'encode'): |
| 309 | val = val.encode() |
| 310 | env[name] = val |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 311 | |
| 312 | setenv('REPO_PROJECT', project['name']) |
| 313 | setenv('REPO_PATH', project['relpath']) |
| 314 | setenv('REPO_REMOTE', project['remote_name']) |
| 315 | setenv('REPO_LREV', project['lrev']) |
| 316 | setenv('REPO_RREV', project['rrev']) |
| 317 | setenv('REPO_I', str(cnt + 1)) |
| 318 | for name in project['annotations']: |
| 319 | setenv("REPO__%s" % (name), project['annotations'][name]) |
| 320 | |
| 321 | if mirror: |
| 322 | setenv('GIT_DIR', project['gitdir']) |
| 323 | cwd = project['gitdir'] |
| 324 | else: |
| 325 | cwd = project['worktree'] |
| 326 | |
| 327 | if not os.path.exists(cwd): |
| 328 | if (opt.project_header and opt.verbose) \ |
| 329 | or not opt.project_header: |
| 330 | print('skipping %s/' % project['relpath'], file=sys.stderr) |
| 331 | return |
| 332 | |
| 333 | if opt.project_header: |
| 334 | stdin = subprocess.PIPE |
| 335 | stdout = subprocess.PIPE |
| 336 | stderr = subprocess.PIPE |
| 337 | else: |
| 338 | stdin = None |
| 339 | stdout = None |
| 340 | stderr = None |
| 341 | |
| 342 | p = subprocess.Popen(cmd, |
| 343 | cwd=cwd, |
| 344 | shell=shell, |
| 345 | env=env, |
| 346 | stdin=stdin, |
| 347 | stdout=stdout, |
| 348 | stderr=stderr) |
| 349 | |
| 350 | if opt.project_header: |
| 351 | out = ForallColoring(config) |
| 352 | out.redirect(sys.stdout) |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 353 | empty = True |
| 354 | errbuf = '' |
| 355 | |
| 356 | p.stdin.close() |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 357 | s_in = platform_utils.FileDescriptorStreams.create() |
| 358 | s_in.add(p.stdout, sys.stdout, 'stdout') |
| 359 | s_in.add(p.stderr, sys.stderr, 'stderr') |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 360 | |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 361 | while not s_in.is_done: |
| 362 | in_ready = s_in.select() |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 363 | for s in in_ready: |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 364 | buf = s.read() |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 365 | if not buf: |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 366 | s.close() |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 367 | s_in.remove(s) |
| 368 | continue |
| 369 | |
| 370 | if not opt.verbose: |
Renaud Paquay | 2e70291 | 2016-11-01 11:23:38 -0700 | [diff] [blame] | 371 | if s.std_name == 'stderr': |
Takeshi Kanemoto | a769498 | 2014-04-14 17:36:57 +0900 | [diff] [blame] | 372 | errbuf += buf |
| 373 | continue |
| 374 | |
| 375 | if empty and out: |
| 376 | if not cnt == 0: |
| 377 | out.nl() |
| 378 | |
| 379 | if mirror: |
| 380 | project_header_path = project['name'] |
| 381 | else: |
| 382 | project_header_path = project['relpath'] |
| 383 | out.project('project %s/', project_header_path) |
| 384 | out.nl() |
| 385 | out.flush() |
| 386 | if errbuf: |
| 387 | sys.stderr.write(errbuf) |
| 388 | sys.stderr.flush() |
| 389 | errbuf = '' |
| 390 | empty = False |
| 391 | |
| 392 | s.dest.write(buf) |
| 393 | s.dest.flush() |
| 394 | |
| 395 | r = p.wait() |
| 396 | return r |