aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-08-08 21:29:19 -0400
committerXavier Claessens <xclaesse@gmail.com>2021-08-20 09:12:20 -0400
commit12e5bfbc1c1c387fc3ea7a1b12bac6ddd068c3f1 (patch)
treea4374eae78abe0c2604a16adf4f0b488a69a6b7b
parente2f4126e415abedf0af90a30332e5e72c98b3d9e (diff)
downloadmeson-12e5bfbc1c1c387fc3ea7a1b12bac6ddd068c3f1.zip
meson-12e5bfbc1c1c387fc3ea7a1b12bac6ddd068c3f1.tar.gz
meson-12e5bfbc1c1c387fc3ea7a1b12bac6ddd068c3f1.tar.bz2
external-project: Add support for WAF build system
Fixes: #7638
-rw-r--r--docs/markdown/External-Project-module.md4
-rw-r--r--docs/markdown/snippets/waf.md5
-rw-r--r--mesonbuild/modules/unstable_external_project.py39
-rw-r--r--mesonbuild/scripts/externalproject.py32
4 files changed, 53 insertions, 27 deletions
diff --git a/docs/markdown/External-Project-module.md b/docs/markdown/External-Project-module.md
index 866564e..640caaf 100644
--- a/docs/markdown/External-Project-module.md
+++ b/docs/markdown/External-Project-module.md
@@ -63,6 +63,10 @@ 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.
+*Since 0.60.0* If the first positional argument is `'waf'`, special treatment
+is done for the [waf](https://waf.io/) build system. The waf executable must be
+found either in the current directory, or in system `PATH`.
+
Keyword arguments:
- `configure_options`: An array of strings to be passed as arguments to the
diff --git a/docs/markdown/snippets/waf.md b/docs/markdown/snippets/waf.md
new file mode 100644
index 0000000..87634a0
--- /dev/null
+++ b/docs/markdown/snippets/waf.md
@@ -0,0 +1,5 @@
+## Waf support in external-project module
+
+If the first argument is `'waf'`, special treatment is done for the
+[waf](https://waf.io/) build system. The waf executable must be
+found either in the current directory, or in system `PATH`.
diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py
index f866e75..32ecdf9 100644
--- a/mesonbuild/modules/unstable_external_project.py
+++ b/mesonbuild/modules/unstable_external_project.py
@@ -19,7 +19,7 @@ import typing as T
from . import ExtensionModule, ModuleReturnValue, ModuleState, NewExtensionModule
from .. import mlog, build
from ..mesonlib import (MesonException, Popen_safe, MachineChoice,
- get_variable_regex, do_replacement, extract_as_list)
+ get_variable_regex, do_replacement, extract_as_list, join_args)
from ..interpreterbase import InterpreterException, FeatureNew
from ..interpreterbase import permittedKwargs, typed_pos_args
from ..compilers.compilers import CFLAGS_MAPPING, CEXE_MAPPING
@@ -67,19 +67,26 @@ class ExternalProject(NewExtensionModule):
# self.prefix is an absolute path, so we cannot append it to another path.
self.rel_prefix = self.prefix.relative_to(self.prefix.root)
- self.make = state.find_program('make')
- self.make = self.make.get_command()[0]
-
self._configure(state)
self.targets = self._create_targets()
def _configure(self, state: ModuleState):
- # Assume it's the name of a script in source dir, like 'configure',
- # 'autogen.sh', etc).
- configure_path = Path(self.src_dir, self.configure_command)
- configure_prog = state.find_program(configure_path.as_posix())
- configure_cmd = configure_prog.get_command()
+ if self.configure_command == 'waf':
+ FeatureNew('Waf external project', '0.60.0').use(self.subproject)
+ waf = state.find_program('waf')
+ configure_cmd = waf.get_command()
+ configure_cmd += ['configure', '-o', str(self.build_dir)]
+ workdir = self.src_dir
+ self.make = waf.get_command() + ['build']
+ else:
+ # Assume it's the name of a script in source dir, like 'configure',
+ # 'autogen.sh', etc).
+ configure_path = Path(self.src_dir, self.configure_command)
+ configure_prog = state.find_program(configure_path.as_posix())
+ configure_cmd = configure_prog.get_command()
+ workdir = self.build_dir
+ self.make = state.find_program('make').get_command()
d = [('PREFIX', '--prefix=@PREFIX@', self.prefix.as_posix()),
('LIBDIR', '--libdir=@PREFIX@/@LIBDIR@', self.libdir.as_posix()),
@@ -122,7 +129,7 @@ class ExternalProject(NewExtensionModule):
Path(self.env.get_build_dir(), 'meson-uninstalled').as_posix())
self.build_dir.mkdir(parents=True, exist_ok=True)
- self._run('configure', configure_cmd)
+ self._run('configure', configure_cmd, workdir)
def _quote_and_join(self, array: T.List[str]) -> str:
return ' '.join([shlex.quote(i) for i in array])
@@ -156,9 +163,9 @@ class ExternalProject(NewExtensionModule):
f"Variables {var_list} in configure options are missing.")
return out
- def _run(self, step: str, command: T.List[str]):
+ def _run(self, step: str, command: T.List[str], workdir: Path):
mlog.log(f'External project {self.name}:', mlog.bold(step))
- m = 'Running command ' + str(command) + ' in directory ' + str(self.build_dir) + '\n'
+ m = 'Running command ' + str(command) + ' in directory ' + str(workdir) + '\n'
log_filename = Path(mlog.log_dir, f'{self.name}-{step}.log')
output = None
if not self.verbose:
@@ -167,9 +174,9 @@ class ExternalProject(NewExtensionModule):
output.flush()
else:
mlog.log(m)
- p, o, e = Popen_safe(command, cwd=str(self.build_dir), env=self.run_env,
- stderr=subprocess.STDOUT,
- stdout=output)
+ p, o, e = Popen_safe(command, cwd=str(workdir), env=self.run_env,
+ stderr=subprocess.STDOUT,
+ stdout=output)
if p.returncode != 0:
m = f'{step} step returned error code {p.returncode}.'
if not self.verbose:
@@ -184,7 +191,7 @@ class ExternalProject(NewExtensionModule):
'--builddir', self.build_dir.as_posix(),
'--installdir', self.install_dir.as_posix(),
'--logdir', mlog.log_dir,
- '--make', self.make,
+ '--make', join_args(self.make),
]
if self.verbose:
cmd.append('--verbose')
diff --git a/mesonbuild/scripts/externalproject.py b/mesonbuild/scripts/externalproject.py
index a8e3bfe..eefa32e 100644
--- a/mesonbuild/scripts/externalproject.py
+++ b/mesonbuild/scripts/externalproject.py
@@ -19,7 +19,7 @@ import subprocess
from pathlib import Path
import typing as T
-from ..mesonlib import Popen_safe
+from ..mesonlib import Popen_safe, split_args
class ExternalProject:
def __init__(self, options: argparse.Namespace):
@@ -31,7 +31,7 @@ class ExternalProject:
self.verbose = options.verbose
self.stampfile = options.stampfile
self.depfile = options.depfile
- self.make = options.make
+ self.make = split_args(options.make)
def write_depfile(self) -> None:
with open(self.depfile, 'w', encoding='utf-8') as f:
@@ -49,22 +49,28 @@ class ExternalProject:
pass
def gnu_make(self) -> bool:
- p, o, e = Popen_safe([self.make, '--version'])
+ p, o, e = Popen_safe(self.make + ['--version'])
if p.returncode == 0 and 'GNU Make' in o:
return True
return False
def build(self) -> int:
- make_cmd = [self.make]
- if self.gnu_make():
- make_cmd.append('-j' + str(multiprocessing.cpu_count()))
-
+ is_make = self.make[0] == 'make'
+ make_cmd = self.make.copy()
+ if is_make and self.gnu_make():
+ make_cmd.append(f'-j{multiprocessing.cpu_count()}')
rc = self._run('build', make_cmd)
if rc != 0:
return rc
- install_cmd = make_cmd + ['DESTDIR= ' + self.install_dir, 'install']
- rc = self._run('install', install_cmd)
+ install_cmd = self.make.copy()
+ install_env = {}
+ if is_make:
+ install_cmd.append(f'DESTDIR={self.install_dir}')
+ else:
+ install_env['DESTDIR'] = self.install_dir
+ install_cmd.append('install')
+ rc = self._run('install', install_cmd, install_env)
if rc != 0:
return rc
@@ -73,7 +79,7 @@ class ExternalProject:
return 0
- def _run(self, step: str, command: T.List[str]) -> int:
+ def _run(self, step: str, command: T.List[str], env: T.Optional[T.Dict[str, str]] = None) -> int:
m = 'Running command ' + str(command) + ' in directory ' + str(self.build_dir) + '\n'
log_filename = Path(self.log_dir, f'{self.name}-{step}.log')
output = None
@@ -83,8 +89,12 @@ class ExternalProject:
output.flush()
else:
print(m)
+ run_env = os.environ.copy()
+ if env:
+ run_env.update(env)
p, o, e = Popen_safe(command, stderr=subprocess.STDOUT, stdout=output,
- cwd=self.build_dir)
+ cwd=self.build_dir,
+ env=run_env)
if p.returncode != 0:
m = f'{step} step returned error code {p.returncode}.'
if not self.verbose: