From 46b68d4c83bba705bb520877c7b0bd04c2f8cd5b Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 29 Jan 2021 09:29:01 -0500 Subject: external_project: Improve logging Write output of 'make' and 'make install' into log files as well when not verbose. --- mesonbuild/modules/unstable_external_project.py | 4 +++- mesonbuild/scripts/externalproject.py | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index aea8366..891ff75 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.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: diff --git a/mesonbuild/scripts/externalproject.py b/mesonbuild/scripts/externalproject.py index 2789dc0..a3ffe73 100644 --- a/mesonbuild/scripts/externalproject.py +++ b/mesonbuild/scripts/externalproject.py @@ -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') -- cgit v1.1 From 6a6323ff096db76b0cd82f13c8f369ac08180ef7 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 29 Jan 2021 10:10:37 -0500 Subject: external_project: Do not set LD in the env This was breaking some autotools projects such as libyaml. --- mesonbuild/modules/unstable_external_project.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index 891ff75..933b064 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.py @@ -119,7 +119,10 @@ class ExternalProject(InterpreterObject): link_exelist = compiler.get_linker_exelist() link_args = self.env.coredata.get_external_link_args(MachineChoice.HOST, lang) if link_exelist: - self.run_env['LD'] = self._quote_and_join(link_exelist) + # FIXME: Do not pass linker because Meson uses CC as linker wrapper, + # but autotools often expects the real linker (e.h. GNU ld). + # self.run_env['LD'] = self._quote_and_join(link_exelist) + pass self.run_env['LDFLAGS'] = self._quote_and_join(link_args) self.run_env = self.user_env.get_env(self.run_env) -- cgit v1.1 From 11cfc258fc2cebe6360322f3338741e1d6694525 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 29 Jan 2021 10:30:28 -0500 Subject: external_project: Add default configure options --- docs/markdown/External-Project-module.md | 12 +++++++++--- mesonbuild/modules/unstable_external_project.py | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/docs/markdown/External-Project-module.md b/docs/markdown/External-Project-module.md index 54b248f..e469024 100644 --- a/docs/markdown/External-Project-module.md +++ b/docs/markdown/External-Project-module.md @@ -54,8 +54,10 @@ build system. Usually in a `meson.build` file placed in the top directory of a subproject, but could be also in any subdir. Its first positional argument is the name of the configure script to be -executed (e.g. `configure` or `autogen.sh`), that file must be in the current -directory and executable. +executed (e.g. `configure`), that file must be in the current directory and +executable. Note that if a bootstrap script is required (e.g. `autogen.sh` when +building from git instead of tarball), it can be done using `run_command()` +before calling `add_project()` method. Keyword arguments: - `configure_options`: An array of strings to be passed as arguments to the @@ -63,7 +65,11 @@ Keyword arguments: them to the configure script: `@PREFIX@`, `@LIBDIR@` and `@INCLUDEDIR@`. Note that `libdir` and `includedir` paths are relative to `prefix` in Meson but some configure scripts requires absolute path, in that case they can be - passed as `'--libdir=@PREFIX@/@LIBDIR@'`. + passed as `'--libdir=@PREFIX@/@LIBDIR@'`. *Since 0.57.0* default arguments are + added in case some tags are not found in `configure_options`: + `'--prefix=@PREFIX@'`, `'--libdir=@PREFIX@/@LIBDIR@'`, and + `'--includedir=@PREFIX@/@INCLUDEDIR@'`. It was previously considered a fatal + error to not specify them. - `cross_configure_options`: Extra options appended to `configure_options` only when cross compiling. special tag `@HOST@` will be replaced by `'{}-{}-{}'.format(host_machine.cpu_family(), build_machine.system(), host_machine.system()`. diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index 933b064..20c1671 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.py @@ -90,11 +90,11 @@ class ExternalProject(InterpreterObject): configure_prog = self.interpreter.find_program_impl(configure_path.as_posix()) configure_cmd = configure_prog.get_command() - d = {'PREFIX': self.prefix.as_posix(), - 'LIBDIR': self.libdir.as_posix(), - 'INCLUDEDIR': self.includedir.as_posix(), - } - self._validate_configure_options(d.keys()) + d = [('PREFIX', '--prefix=@PREFIX@', self.prefix.as_posix()), + ('LIBDIR', '--libdir=@PREFIX@/@LIBDIR@', self.libdir.as_posix()), + ('INCLUDEDIR', '--includedir=@PREFIX@/@INCLUDEDIR@', self.includedir.as_posix()), + ] + self._validate_configure_options(d) configure_cmd += self._format_options(self.configure_options, d) @@ -102,7 +102,7 @@ class ExternalProject(InterpreterObject): host = '{}-{}-{}'.format(self.host_machine.cpu_family, self.build_machine.system, self.host_machine.system) - d = {'HOST': host} + d = [('HOST', None, host)] configure_cmd += self._format_options(self.cross_configure_options, d) # Set common env variables like CFLAGS, CC, etc. @@ -136,23 +136,23 @@ class ExternalProject(InterpreterObject): def _quote_and_join(self, array: T.List[str]) -> str: return ' '.join([shlex.quote(i) for i in array]) - def _validate_configure_options(self, required_keys: T.List[str]): + def _validate_configure_options(self, variables: T.List[T.Tuple[str, str, str]]): # Ensure the user at least try to pass basic info to the build system, # like the prefix, libdir, etc. - for key in required_keys: + for key, default, val in variables: key_format = '@{}@'.format(key) for option in self.configure_options: if key_format in option: break else: - m = 'At least one configure option must contain "{}" key' - raise InterpreterException(m.format(key_format)) + FeatureNew('Default configure_option', '0.57.0').use(self.subproject) + self.configure_options.append(default) - def _format_options(self, options: T.List[str], variables: T.Dict[str, str]) -> T.List[str]: + def _format_options(self, options: T.List[str], variables: T.List[T.Tuple[str, str, str]]) -> T.List[str]: out = [] missing = set() regex = get_variable_regex('meson') - confdata = {k: (v, None) for k, v in variables.items()} + confdata = {k: (v, None) for k, d, v in variables} for o in options: arg, missing_vars = do_replacement(regex, o, 'meson', confdata) missing.update(missing_vars) -- cgit v1.1 From fd572f32d86ff3c1e75c9c5c1efdec2f73eea284 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 29 Jan 2021 11:06:16 -0500 Subject: Popen_safe: Fix stdout/stderr annotation --- mesonbuild/mesonlib/universal.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index dfcec8e..4b913a8 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -1305,8 +1305,8 @@ def partition(pred: T.Callable[[_T], object], iterable: T.Iterator[_T]) -> T.Tup def Popen_safe(args: T.List[str], write: T.Optional[str] = None, - stdout: T.Union[T.BinaryIO, int] = subprocess.PIPE, - stderr: T.Union[T.BinaryIO, int] = subprocess.PIPE, + stdout: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE, + stderr: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE, **kwargs: T.Any) -> T.Tuple[subprocess.Popen, str, str]: import locale encoding = locale.getpreferredencoding() @@ -1328,8 +1328,8 @@ def Popen_safe(args: T.List[str], write: T.Optional[str] = None, def Popen_safe_legacy(args: T.List[str], write: T.Optional[str] = None, - stdout: T.Union[T.BinaryIO, int] = subprocess.PIPE, - stderr: T.Union[T.BinaryIO, int] = subprocess.PIPE, + stdout: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE, + stderr: T.Union[T.TextIO, T.BinaryIO, int] = subprocess.PIPE, **kwargs: T.Any) -> T.Tuple[subprocess.Popen, str, str]: p = subprocess.Popen(args, universal_newlines=False, close_fds=False, stdout=stdout, stderr=stderr, **kwargs) -- cgit v1.1 From ef7dfa97fc6f20d8793609fc086718399c08a85a Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 29 Jan 2021 19:02:48 -0500 Subject: external_project: Add release snippet --- docs/markdown/snippets/external_project.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docs/markdown/snippets/external_project.md diff --git a/docs/markdown/snippets/external_project.md b/docs/markdown/snippets/external_project.md new file mode 100644 index 0000000..b48dc35 --- /dev/null +++ b/docs/markdown/snippets/external_project.md @@ -0,0 +1,11 @@ +## `unstable_external_project` improvements + +- Default arguments are added to `add_project()` in case some tags are not found + in `configure_options`: `'--prefix=@PREFIX@'`, `'--libdir=@PREFIX@/@LIBDIR@'`, + and `'--includedir=@PREFIX@/@INCLUDEDIR@'`. It was previously considered a fatal + error to not specify them. +- When `verbose` keyword argument is not specified, or is false, command outputs + are written on file in `/meson-logs/`. +- `LD` environment variable is not passed any more when running the configure + script. It caused issues because Meson uses CC as linker wrapper but autotools + expects to real linker (e.g. `/usr/bin/ld`). -- cgit v1.1