external_project: Improve logging

Write output of 'make' and 'make install' into log files as well when
not verbose.
pull/8264/head
Xavier Claessens 4 years ago
parent 9eb8b6be28
commit 46b68d4c83
  1. 4
      mesonbuild/modules/unstable_external_project.py
  2. 25
      mesonbuild/scripts/externalproject.py

@ -162,12 +162,13 @@ class ExternalProject(InterpreterObject):
def _run(self, step: str, command: T.List[str]):
mlog.log('External project {}:'.format(self.name), mlog.bold(step))
m = 'Running command: ' + str(command)
m = 'Running command ' + str(command) + ' in directory ' + str(self.build_dir) + '\n'
log_filename = Path(mlog.log_dir, '{}-{}.log'.format(self.name, step))
output = None
if not self.verbose:
output = open(log_filename, 'w')
output.write(m + '\n')
output.flush()
else:
mlog.log(m)
p, o, e = Popen_safe(command, cwd=str(self.build_dir), env=self.run_env,
@ -186,6 +187,7 @@ class ExternalProject(InterpreterObject):
'--srcdir', self.src_dir.as_posix(),
'--builddir', self.build_dir.as_posix(),
'--installdir', self.install_dir.as_posix(),
'--logdir', mlog.log_dir,
'--make', self.make,
]
if self.verbose:

@ -27,6 +27,7 @@ class ExternalProject:
self.src_dir = options.srcdir
self.build_dir = options.builddir
self.install_dir = options.installdir
self.log_dir = options.logdir
self.verbose = options.verbose
self.stampfile = options.stampfile
self.depfile = options.depfile
@ -55,17 +56,15 @@ class ExternalProject:
def build(self) -> int:
make_cmd = [self.make]
if not self.verbose:
make_cmd.append('--quiet')
if self.gnu_make():
make_cmd.append('-j' + str(multiprocessing.cpu_count()))
rc = self._run(make_cmd)
rc = self._run('build', make_cmd)
if rc != 0:
return rc
install_cmd = make_cmd + ['DESTDIR= ' + self.install_dir, 'install']
rc = self._run(install_cmd)
rc = self._run('install', install_cmd)
if rc != 0:
return rc
@ -74,10 +73,23 @@ class ExternalProject:
return 0
def _run(self, command: T.List[str]) -> int:
output = None if self.verbose else subprocess.DEVNULL
def _run(self, step: str, command: T.List[str]) -> int:
m = 'Running command ' + str(command) + ' in directory ' + str(self.build_dir) + '\n'
log_filename = Path(self.log_dir, '{}-{}.log'.format(self.name, step))
output = None
if not self.verbose:
output = open(log_filename, 'w')
output.write(m + '\n')
output.flush()
else:
print(m)
p, o, e = Popen_safe(command, stderr=subprocess.STDOUT, stdout=output,
cwd=self.build_dir)
if p.returncode != 0:
m = '{} step returned error code {}.'.format(step, p.returncode)
if not self.verbose:
m += '\nSee logs: ' + str(log_filename)
print(m)
return p.returncode
def run(args: T.List[str]) -> int:
@ -86,6 +98,7 @@ def run(args: T.List[str]) -> int:
parser.add_argument('--srcdir')
parser.add_argument('--builddir')
parser.add_argument('--installdir')
parser.add_argument('--logdir')
parser.add_argument('--make')
parser.add_argument('--verbose', action='store_true')
parser.add_argument('stampfile')

Loading…
Cancel
Save