Split --raw-logs into --no-pretty and --no-log options.

--no-log: don't capture logs or run redo-log (same as pre-redo-log redo)
  --no-pretty: don't pretty-print logs, print @@REDO lines.

The latter is an option to both redo and redo-log.
This commit is contained in:
Avery Pennarun 2018-11-19 10:55:56 -05:00
commit bc632982fc
6 changed files with 25 additions and 18 deletions

View file

@ -22,8 +22,8 @@ def _try_stat(filename):
log_reader_pid = None
def start_stdin_log_reader(status, details, debug_locks, debug_pids):
if vars.RAW_LOGS: return
def start_stdin_log_reader(status, details, pretty, debug_locks, debug_pids):
if not vars.LOG: return
global log_reader_pid
r, w = os.pipe() # main pipe to redo-log
ar, aw = os.pipe() # ack pipe from redo-log --ack-fd
@ -61,6 +61,7 @@ def start_stdin_log_reader(status, details, debug_locks, debug_pids):
'--ack-fd', str(aw),
('--status' if status and os.isatty(2) else '--no-status'),
('--details' if details else '--no-details'),
('--pretty' if pretty else '--no-pretty'),
('--debug-locks' if debug_locks else '--no-debug-locks'),
('--debug-pids' if debug_pids else '--no-debug-pids'),
'-'
@ -73,7 +74,7 @@ def start_stdin_log_reader(status, details, debug_locks, debug_pids):
def await_log_reader():
if vars.RAW_LOGS: return
if not vars.LOG: return
global log_reader_pid
if log_reader_pid > 0:
# never actually close fd#1 or fd#2; insanity awaits.
@ -189,7 +190,7 @@ class BuildJob:
argv[0:2] = firstline[2:].split(' ')
# make sure to create the logfile *before* writing the log about it.
# that way redo-log won't trace into an obsolete logfile.
if not vars.RAW_LOGS: open(state.logname(self.sf.id), 'w')
if vars.LOG: open(state.logname(self.sf.id), 'w')
meta('do', _nice(t))
self.dodir = dodir
self.basename = basename
@ -246,7 +247,7 @@ class BuildJob:
os.dup2(self.f.fileno(), 1)
os.close(self.f.fileno())
close_on_exec(1, False)
if not vars.RAW_LOGS:
if vars.LOG:
logf = open(state.logname(self.sf.id), 'w')
os.dup2(logf.fileno(), 2)
close_on_exec(2, False)

View file

@ -100,7 +100,7 @@ _log = None
def setup(file, pretty):
global _log
if pretty:
if pretty or vars.PRETTY:
check_tty(file)
_log = PrettyLog(file=file)
else:

View file

@ -21,7 +21,7 @@ rv = 202
try:
if vars_init.is_toplevel:
builder.start_stdin_log_reader(status=True, details=True,
debug_locks=False, debug_pids=False)
pretty=True, debug_locks=False, debug_pids=False)
if vars.TARGET and not vars.UNLOCKED:
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))

View file

@ -11,7 +11,7 @@ f,follow keep watching for more lines to be appended (like tail -f)
no-details only show 'redo' recursion trace, not build output
no-colorize don't colorize 'redo' log messages
no-status don't display build summary line in --follow
raw-logs don't format logs, just send raw output straight to stdout
no-pretty don't pretty-print logs, show raw @@REDO output instead
debug-locks print messages about file locking (useful for debugging)
debug-pids print process ids in log messages (useful for debugging)
ack-fd= (internal use only) print REDO-OK to this fd upon starting
@ -209,10 +209,7 @@ try:
sys.exit(1)
if opt.status < 2 and not os.isatty(2):
opt.status = False
if opt.raw_logs:
logs.setup(file=sys.stdout, pretty=False)
else:
logs.setup(file=sys.stdout, pretty=True)
logs.setup(file=sys.stdout, pretty=opt.pretty)
if opt.debug_locks:
vars.DEBUG_LOCKS = 1
if opt.debug_pids:

17
redo.py
View file

@ -14,7 +14,8 @@ k,keep-going keep going as long as possible even if some targets fail
shuffle randomize the build order to find dependency bugs
no-details only show 'redo' recursion trace (to see more later, use redo-log)
no-status don't display build summary line at the bottom of the screen
raw-logs don't use redo-log, just send all output straight to stderr
no-log don't capture error output, just let it flow straight to stderr
no-pretty don't pretty-print logs, show raw @@REDO output instead
debug-locks print messages about file locking (useful for debugging)
debug-pids print process ids as part of log messages (useful for debugging)
version print the current version and exit
@ -38,14 +39,19 @@ if opt.keep_going:
os.environ['REDO_KEEP_GOING'] = '1'
if opt.shuffle:
os.environ['REDO_SHUFFLE'] = '1'
if opt.raw_logs:
os.environ['REDO_RAW_LOGS'] = '1'
if opt.debug_locks or not os.environ.get('REDO_RAW_LOGS'):
# FIXME: force-enabled for redo-log, for now
if opt.debug_locks:
os.environ['REDO_DEBUG_LOCKS'] = '1'
if opt.debug_pids:
os.environ['REDO_DEBUG_PIDS'] = '1'
# This is slightly tricky: the log and pretty options default to true. We
# want to inherit that 'true' value from parent processes *unless* someone
# explicitly specifies the reverse.
if opt.no_log:
os.environ['REDO_LOG'] = '0'
if opt.no_pretty:
os.environ['REDO_PRETTY'] = '0'
import vars_init
vars_init.init(targets)
@ -55,6 +61,7 @@ from logs import warn, err
try:
if vars_init.is_toplevel:
builder.start_stdin_log_reader(status=opt.status, details=opt.details,
pretty=opt.pretty,
debug_locks=opt.debug_locks, debug_pids=opt.debug_pids)
for t in targets:
if os.path.exists(t):

View file

@ -16,7 +16,9 @@ DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0
VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0
XTRACE = os.environ.get('REDO_XTRACE', '') and 1 or 0
KEEP_GOING = os.environ.get('REDO_KEEP_GOING', '') and 1 or 0
RAW_LOGS = os.environ.get('REDO_RAW_LOGS', '') and 1 or 0
LOG = atoi(os.environ.get('REDO_LOG', '1')) # defaults on
# subprocesses mustn't pretty-print if a parent is running redo-log
PRETTY = (not LOG) and atoi(os.environ.get('REDO_PRETTY', '1'))
SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0
STARTDIR = os.environ.get('REDO_STARTDIR', '')
RUNID = atoi(os.environ.get('REDO_RUNID')) or None