Skip to content

Commit 0c529b0

Browse files
authored
Merge pull request #41714 from lorentey/fix-update-checkout-output
[utils] Make update-checkout output more readable
2 parents bc6a38c + 4f9cf1d commit 0c529b0

File tree

6 files changed

+62
-46
lines changed

6 files changed

+62
-46
lines changed

utils/check-incremental

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def compile_and_stat(compile_args, output_file):
3535
"""
3636
subprocess.check_call(compile_args)
3737

38-
md5 = subprocess.check_output(["md5", "-q", output_file], text=True)
38+
md5 = subprocess.check_output(["md5", "-q", output_file],
39+
universal_newlines=True)
3940
mtime = time.ctime(os.path.getmtime(output_file))
4041

4142
if VERBOSE:

utils/refactor-check-compiles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def run_cmd(cmd, desc):
1111
try:
12-
return subprocess.check_output(cmd)
12+
return subprocess.check_output(cmd, universal_newlines=True)
1313
except subprocess.CalledProcessError:
1414
print('FAILED ' + desc + ':', file=sys.stderr)
1515
print(' '.join(cmd), file=sys.stderr)
@@ -130,7 +130,7 @@ def main():
130130
'-source-filename', args.source_filename,
131131
'-rewritten-output-file', temp_file_path,
132132
'-pos', args.pos
133-
] + extra_refactor_args + extra_both_args, desc='producing edit').decode("utf-8")
133+
] + extra_refactor_args + extra_both_args, desc='producing edit')
134134
sys.stdout.write(dump_text_output)
135135

136136
run_cmd([

utils/swift-darwin-postprocess.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def main(arguments):
3232
# (rdar://78851265)
3333
def unrpathize(filename):
3434
dylibsOutput = subprocess.check_output(
35-
['xcrun', 'dyldinfo', '-dylibs', filename])
35+
['xcrun', 'dyldinfo', '-dylibs', filename],
36+
universal_newlines=True)
3637

3738
# Do not rewrite @rpath-relative load commands for these libraries:
3839
# they are test support libraries that are never installed under
@@ -60,8 +61,7 @@ def unrpathize(filename):
6061

6162
# Build a command to invoke install_name_tool.
6263
command = ['install_name_tool']
63-
for binaryline in dylibsOutput.splitlines():
64-
line = binaryline.decode("utf-8", "strict")
64+
for line in dylibsOutput.splitlines():
6565
match = dylib_regex.match(line)
6666
if match and match.group('filename') not in allow_list:
6767
command.append('-change')

utils/swift-rpathize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def main(arguments):
5555

5656
def rpathize(filename):
5757
dylibsOutput = subprocess.check_output(
58-
['xcrun', 'dyldinfo', '-dylibs', filename])
58+
['xcrun', 'dyldinfo', '-dylibs', filename],
59+
universal_newlines=True)
5960

6061
# The output from dyldinfo -dylibs is a line of header followed by one
6162
# install name per line, indented with spaces.
@@ -64,8 +65,7 @@ def rpathize(filename):
6465

6566
# Build a command to invoke install_name_tool.
6667
command = ['install_name_tool']
67-
for binaryline in dylibsOutput.splitlines():
68-
line = binaryline.decode("utf-8", "strict")
68+
for line in dylibsOutput.splitlines():
6969
match = dylib_regex.match(line)
7070
if match:
7171
command.append('-change')

utils/swift_build_support/swift_build_support/shell.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,11 @@ def capture(command, stderr=None, env=None, dry_run=None, echo=True,
132132
_env = dict(os.environ)
133133
_env.update(env)
134134
try:
135-
out = subprocess.check_output(command, env=_env, stderr=stderr)
136-
# Coerce to `str` hack. not py3 `byte`, not py2 `unicode`.
137-
return str(out.decode())
135+
return subprocess.check_output(command, env=_env, stderr=stderr,
136+
universal_newlines=True)
138137
except subprocess.CalledProcessError as e:
139138
if allow_non_zero_exit:
140-
return str(e.output.decode())
139+
return e.output
141140
if optional:
142141
return None
143142
_fatal_error(
@@ -213,25 +212,29 @@ def run(*args, **kwargs):
213212
echo_output = kwargs.pop('echo', False)
214213
dry_run = kwargs.pop('dry_run', False)
215214
env = kwargs.pop('env', None)
215+
prefix = kwargs.pop('prefix', '')
216216
if dry_run:
217-
_echo_command(dry_run, *args, env=env)
217+
_echo_command(dry_run, *args, env=env, prompt="{0}+ ".format(prefix))
218218
return(None, 0, args)
219219

220220
my_pipe = subprocess.Popen(
221-
*args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
222-
(stdout, stderr) = my_pipe.communicate()
221+
*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
222+
universal_newlines=True,
223+
**kwargs)
224+
(output, _) = my_pipe.communicate()
223225
ret = my_pipe.wait()
224226

225227
if lock:
226228
lock.acquire()
227229
if echo_output:
228-
print(repo_path)
229-
_echo_command(dry_run, *args, env=env)
230-
if stdout:
231-
print(stdout, end="")
232-
if stderr:
233-
print(stderr, end="")
234-
print()
230+
sys.stdout.flush()
231+
sys.stderr.flush()
232+
_echo_command(dry_run, *args, env=env, prompt="{0}+ ".format(prefix))
233+
if output:
234+
for line in output.splitlines():
235+
print("{0}{1}".format(prefix, line))
236+
sys.stdout.flush()
237+
sys.stderr.flush()
235238
if lock:
236239
lock.release()
237240

@@ -240,6 +243,6 @@ def run(*args, **kwargs):
240243
eout.ret = ret
241244
eout.args = args
242245
eout.repo_path = repo_path
243-
eout.stderr = stderr
246+
eout.stderr = output
244247
raise eout
245-
return (stdout, 0, args)
248+
return (output, 0, args)

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def check_parallel_results(results, op):
7070
print("%s failed (ret=%d): %s" % (r.repo_path, r.ret, r))
7171
fail_count += 1
7272
if r.stderr:
73-
print(r.stderr.decode('utf-8'))
73+
print(r.stderr)
7474
return fail_count
7575

7676

@@ -125,7 +125,9 @@ def update_single_repository(pool_args):
125125
return
126126

127127
try:
128-
print("Updating '" + repo_path + "'")
128+
prefix = "[{0}] ".format(os.path.basename(repo_path)).ljust(40)
129+
print(prefix + "Updating '" + repo_path + "'")
130+
129131
with shell.pushd(repo_path, dry_run=False, echo=False):
130132
cross_repo = False
131133
checkout_target = None
@@ -141,15 +143,20 @@ def update_single_repository(pool_args):
141143

142144
# The clean option restores a repository to pristine condition.
143145
if should_clean:
144-
shell.run(['git', 'clean', '-fdx'], echo=True)
145-
shell.run(['git', 'submodule', 'foreach', '--recursive', 'git',
146-
'clean', '-fdx'], echo=True)
147-
shell.run(['git', 'submodule', 'foreach', '--recursive', 'git',
148-
'reset', '--hard', 'HEAD'], echo=True)
149-
shell.run(['git', 'reset', '--hard', 'HEAD'], echo=True)
146+
shell.run(['git', 'clean', '-fdx'],
147+
echo=True, prefix=prefix)
148+
shell.run(['git', 'submodule', 'foreach', '--recursive',
149+
'git', 'clean', '-fdx'],
150+
echo=True, prefix=prefix)
151+
shell.run(['git', 'submodule', 'foreach', '--recursive',
152+
'git', 'reset', '--hard', 'HEAD'],
153+
echo=True, prefix=prefix)
154+
shell.run(['git', 'reset', '--hard', 'HEAD'],
155+
echo=True, prefix=prefix)
150156
# It is possible to reset --hard and still be mid-rebase.
151157
try:
152-
shell.run(['git', 'rebase', '--abort'], echo=True)
158+
shell.run(['git', 'rebase', '--abort'],
159+
echo=True, prefix=prefix)
153160
except Exception:
154161
pass
155162

@@ -166,29 +173,32 @@ def update_single_repository(pool_args):
166173
except Exception:
167174
shell.run(["git", "fetch", "--recurse-submodules=yes",
168175
"--tags"],
169-
echo=True)
176+
echo=True, prefix=prefix)
170177

171178
try:
172-
shell.run(['git', 'checkout', checkout_target], echo=True)
179+
shell.run(['git', 'checkout', checkout_target],
180+
echo=True, prefix=prefix)
173181
except Exception as originalException:
174182
try:
175183
result = shell.run(['git', 'rev-parse', checkout_target])
176184
revision = result[0].strip()
177-
shell.run(['git', 'checkout', revision], echo=True)
185+
shell.run(['git', 'checkout', revision],
186+
echo=True, prefix=prefix)
178187
except Exception:
179188
raise originalException
180189

181190
# It's important that we checkout, fetch, and rebase, in order.
182191
# .git/FETCH_HEAD updates the not-for-merge attributes based on
183192
# which branch was checked out during the fetch.
184193
shell.run(["git", "fetch", "--recurse-submodules=yes", "--tags"],
185-
echo=True)
194+
echo=True, prefix=prefix)
186195

187196
# If we were asked to reset to the specified branch, do the hard
188197
# reset and return.
189198
if checkout_target and reset_to_remote and not cross_repo:
190199
full_target = full_target_name('origin', checkout_target)
191-
shell.run(['git', 'reset', '--hard', full_target], echo=True)
200+
shell.run(['git', 'reset', '--hard', full_target],
201+
echo=True, prefix=prefix)
192202
return
193203

194204
# Query whether we have a "detached HEAD", which will mean that
@@ -215,13 +225,15 @@ def update_single_repository(pool_args):
215225
# --rebase" that respects rebase.autostash. See
216226
# http://stackoverflow.com/a/30209750/125349
217227
if not cross_repo and not detached_head:
218-
shell.run(["git", "rebase", "FETCH_HEAD"], echo=True)
228+
shell.run(["git", "rebase", "FETCH_HEAD"],
229+
echo=True, prefix=prefix)
219230
elif detached_head:
220-
print(repo_path,
221-
"\nDetached HEAD; probably checked out a tag. No need "
222-
"to rebase.\n")
231+
print(prefix +
232+
"Detached HEAD; probably checked out a tag. No need "
233+
"to rebase.")
223234

224-
shell.run(["git", "submodule", "update", "--recursive"], echo=True)
235+
shell.run(["git", "submodule", "update", "--recursive"],
236+
echo=True, prefix=prefix)
225237
except Exception:
226238
(type, value, tb) = sys.exc_info()
227239
print('Error on repo "%s": %s' % (repo_path, traceback.format_exc()))
@@ -431,12 +443,12 @@ def validate_config(config):
431443

432444

433445
def full_target_name(repository, target):
434-
tag = shell.capture(["git", "tag", "-l", target], echo=True).strip()
446+
tag = shell.capture(["git", "tag", "-l", target], echo=False).strip()
435447
if tag == target:
436448
return tag
437449

438450
branch = shell.capture(["git", "branch", "--list", target],
439-
echo=True).strip().replace("* ", "")
451+
echo=False).strip().replace("* ", "")
440452
if branch == target:
441453
name = "%s/%s" % (repository, target)
442454
return name

0 commit comments

Comments
 (0)