Skip to content

Commit

Permalink
build.py: add verbose option
Browse files Browse the repository at this point in the history
This can be used to observe the entire build, or for things
like Travis that like to kill builds if they remain quiet for
too long.

Note: we allow both V=1 in the environment (because we want to
pass that in to kmod builds), or a --verbose flag (because
arguments are convenient and easy in argparse).
  • Loading branch information
chris3torek committed Jul 19, 2017
1 parent 554e1ad commit 64c9ddb
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,44 @@
ld_flags = []


def cmd(cmd):
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
def cmd(cmd, quiet=False):
"""
Run a command. If quiet is True, or if V is not set in the
environment, eat its stdout and stderr by default (we'll print
both to stderr on any failure though).
If V is set and we're not forced to be quiet, just let stdout
and stderr flow through as usual. The name V is from the
standard Linux kernel build ("V=1 make" => print everything).
(We use quiet=True for build environment test cleanup steps;
the tests themselves use use cmd_success() to check for failures.)
"""
if not quiet:
quiet = os.getenv('V') is None
if quiet:
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
else:
proc = subprocess.Popen(cmd, shell=True)

# err should be None
out, err = proc.communicate()
# There is never any stderr output here - either it went straight
# to os.STDERR_FILENO, or it went to the pipe for stdout.
out, _ = proc.communicate()

if proc.returncode:
print('Log:\n', out, file=sys.stderr)
# We only have output if we ran in quiet mode.
if quiet:
print('Log:\n', out, file=sys.stderr)
print('Error has occured running command: %s' % cmd, file=sys.stderr)
sys.exit(proc.returncode)


def cmd_success(cmd):
try:
# This is a little sloppy - the pipes swallow up output,
# but if the output exceeds PIPE_MAX, the pipes will
# constipate and check_call may never return.
subprocess.check_call(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
return True
Expand Down Expand Up @@ -82,7 +105,7 @@ def check_header(header_file, compiler):
test_o_file))

finally:
cmd('rm -f %s %s' % (test_c_file, test_o_file))
cmd('rm -f %s %s' % (test_c_file, test_o_file), quiet=True)


def check_c_lib(lib):
Expand All @@ -104,7 +127,7 @@ def check_c_lib(lib):
(test_c_file, lib, ' '.join(cxx_flags),
' '.join(ld_flags), test_e_file))
finally:
cmd('rm -f %s %s' % (test_c_file, test_e_file))
cmd('rm -f %s %s' % (test_c_file, test_e_file), quiet=True)


def required(header_file, lib_name, compiler):
Expand Down Expand Up @@ -349,8 +372,13 @@ def main():
dest='benchmark_path',
nargs=1,
help='Location of benchmark library')
parser.add_argument('-v', '--verbose', action='store_true',
help='enable verbose builds (same as env V=1)')
args = parser.parse_args()

if args.verbose:
os.environ['V'] = '1'

if args.benchmark_path:
update_benchmark_path(args.benchmark_path[0])

Expand Down

0 comments on commit 64c9ddb

Please sign in to comment.