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