From 6fb0cb5c80a4b0f229aa91ece02d4ba05d133a84 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 12 Feb 2020 09:39:23 -0500 Subject: [PATCH] repo: add trace support to the launcher Now that we have a central run_command point, we can easily add tracing support to the launcher script. Change-Id: I9e0335c196cafd6263ff501925abfe835f036c5e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254755 Tested-by: Mike Frysinger Reviewed-by: David Pursehouse --- repo | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/repo b/repo index bbcf0d50..ea3df1d5 100755 --- a/repo +++ b/repo @@ -17,8 +17,29 @@ import subprocess import sys +# Keep basic logic in sync with repo_trace.py. +class Trace(object): + """Trace helper logic.""" + + REPO_TRACE = 'REPO_TRACE' + + def __init__(self): + self.set(os.environ.get(self.REPO_TRACE) == '1') + + def set(self, value): + self.enabled = bool(value) + + def print(self, *args, **kwargs): + if self.enabled: + print(*args, **kwargs) + + +trace = Trace() + + def exec_command(cmd): """Execute |cmd| or return None on failure.""" + trace.print(':', ' '.join(cmd)) try: if platform.system() == 'Windows': ret = subprocess.call(cmd) @@ -309,6 +330,7 @@ def run_command(cmd, **kwargs): stdout = stdout.decode('utf-8') if stderr is not None: stderr = stderr.decode('utf-8') + trace.print(':', ' '.join(cmd)) ret = RunResult(proc.returncode, stdout, stderr) # If things failed, print useful debugging output. @@ -810,6 +832,8 @@ def _ParseArguments(args): opt.help = True elif a == '--version': opt.version = True + elif a == '--trace': + trace.set(True) elif not a.startswith('-'): cmd = a arg = args[i + 1:]