Migrated from Make to CMake.
This commit is contained in:
parent
cda05294f5
commit
b6ba093000
52 changed files with 1276 additions and 1210 deletions
|
|
@ -27,20 +27,39 @@ def main():
|
|||
sentinel = root / 'lib/keep-unrelated.txt'
|
||||
sentinel.parent.mkdir(parents=True)
|
||||
sentinel.write_text('keep\n')
|
||||
make = shlex.split(os.environ.get('MAKE', 'make'))
|
||||
# MAKEFLAGS jobserver descriptors do not cross Python subprocesses.
|
||||
env = dict(os.environ, MAKEFLAGS='', MFLAGS='')
|
||||
variables = [f'BUILD_DIR={args.build_dir}', f'PREFIX={prefix}', f'DESTDIR={stage}']
|
||||
# Generate the real CMake install driver against the already-built inputs.
|
||||
# The temporary cache keeps the caller's build configuration untouched.
|
||||
installer = stage / 'cmake-driver'
|
||||
cache = (args.build_dir / 'CMakeCache.txt').read_text()
|
||||
generator = next(line.partition('=')[2] for line in cache.splitlines()
|
||||
if line.startswith('CMAKE_GENERATOR:INTERNAL='))
|
||||
jack = 'OFF' if 'XTC_WITH_JACK:BOOL=OFF' in cache else 'ON'
|
||||
env = dict(os.environ)
|
||||
variables = ['-DBUILD_TESTING=OFF', f'-DXTC_BUILD_GUI={"ON" if args.gui else "OFF"}',
|
||||
f'-DCMAKE_INSTALL_PREFIX={prefix}',
|
||||
f'-DXTC_INSTALL_BUILD_DIR={args.build_dir.resolve()}',
|
||||
f'-DXTC_WITH_JACK={jack}', '-DXTC_INSTALL_GUI=OFF', '-DCMAKE_INSTALL_DOCDIR=share/doc/xtc']
|
||||
if args.custom_layout:
|
||||
variables += [f'exec_prefix={prefix}/runtime', f'libdir={prefix}/lib64',
|
||||
f'includedir={prefix}/headers', f'datarootdir={prefix}/resources',
|
||||
f'docdir={prefix}/manual', f'pkgconfigdir={prefix}/metadata']
|
||||
variables += ['-DCMAKE_INSTALL_BINDIR=runtime/bin', '-DCMAKE_INSTALL_LIBDIR=lib64',
|
||||
'-DCMAKE_INSTALL_INCLUDEDIR=headers', '-DCMAKE_INSTALL_DATAROOTDIR=resources',
|
||||
'-DCMAKE_INSTALL_DOCDIR=manual', '-DXTC_INSTALL_PKGCONFIGDIR=metadata']
|
||||
|
||||
def install_command(operation, options, **kwargs):
|
||||
config = subprocess.run(['cmake', '-G', generator, '-S', str(source), '-B', str(installer),
|
||||
*options], env=env, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, text=True)
|
||||
if config.returncode:
|
||||
raise RuntimeError(config.stdout)
|
||||
command = (['cmake', '--build', str(installer), '--target', 'uninstall']
|
||||
if operation == 'uninstall' else ['cmake', '--install', str(installer)])
|
||||
return subprocess.run(command, env=dict(env, DESTDIR=str(stage)), **kwargs)
|
||||
|
||||
binaries = root / ('runtime/bin' if args.custom_layout else 'bin')
|
||||
headers = root / ('headers' if args.custom_layout else 'include')
|
||||
resources = root / ('resources' if args.custom_layout else 'share')
|
||||
docs = root / ('manual' if args.custom_layout else 'share/doc/xtc')
|
||||
metadata = root / ('metadata' if args.custom_layout else 'lib/pkgconfig')
|
||||
run(make + ['install'] + variables, env=env)
|
||||
install_command('install', variables, check=True)
|
||||
assert not (binaries / 'xtc').exists()
|
||||
assert (resources / 'licenses/xtc/LICENSE').read_bytes() == (source / 'LICENSE').read_bytes()
|
||||
assert (docs / 'PROJECT_FORMAT.md').is_file()
|
||||
|
|
@ -64,7 +83,7 @@ def main():
|
|||
(binaries / 'xtc-check').symlink_to(protected)
|
||||
# Upgrade/repair repeats the same owned-file install and keeps unrelated data.
|
||||
(headers / 'xtc/xtc.h').write_text('old installation marker\n')
|
||||
run(make + ['install'] + variables, env=env)
|
||||
install_command('install', variables, check=True)
|
||||
assert (headers / 'xtc/xtc.h').read_bytes() == (source / 'include/xtc/xtc.h').read_bytes()
|
||||
assert sentinel.read_text() == 'keep\n'
|
||||
assert protected.read_text() == 'keep unrelated target\n'
|
||||
|
|
@ -79,8 +98,7 @@ def main():
|
|||
pkg_env = dict(env, PKG_CONFIG_PATH=str(metadata) + ':' + env.get('PKG_CONFIG_PATH', ''),
|
||||
PKG_CONFIG_SYSROOT_DIR=str(stage))
|
||||
pkg = shlex.split(os.environ.get('PKG_CONFIG', 'pkg-config'))
|
||||
# A no-JACK test can be invoked with PKG_CONFIG=false; package consumer
|
||||
# discovery itself still uses the installed pkg-config tool.
|
||||
# The build may disable JACK; consumer discovery still uses pkg-config.
|
||||
if pkg == ['false']:
|
||||
pkg = ['pkg-config']
|
||||
flags = shlex.split(subprocess.check_output(pkg + ['--cflags', '--libs', '--static', 'xtc'], env=pkg_env, text=True))
|
||||
|
|
@ -110,7 +128,7 @@ int main(int argc, char **argv) {
|
|||
run(command + [f'-std={standard}', '-Wall', '-Wextra', '-Werror', str(consumer)] + flags + ['-o', str(output)])
|
||||
run([str(output), str(stage / ("installed-" + compiler + ".xtc"))])
|
||||
if args.gui:
|
||||
run(make + ['install-gui'] + variables, env=env)
|
||||
install_command('install', variables + ['-DXTC_INSTALL_GUI=ON'], check=True)
|
||||
gui_env = dict(env, DISPLAY='', WAYLAND_DISPLAY='')
|
||||
assert subprocess.check_output([str(binaries / 'xtc'), '--version'], env=gui_env, text=True) == version
|
||||
run([str(binaries / 'xtc'), '--help'], env=gui_env)
|
||||
|
|
@ -120,9 +138,9 @@ int main(int argc, char **argv) {
|
|||
with tempfile.TemporaryDirectory(prefix='xtc-install-outside-') as outside:
|
||||
escape = root / 'escape'
|
||||
escape.symlink_to(outside, target_is_directory=True)
|
||||
redirected = variables + [f'docdir={prefix}/escape/docs']
|
||||
redirected = variables + [f'-DCMAKE_INSTALL_DOCDIR={prefix}/escape/docs']
|
||||
for operation in ('install', 'uninstall'):
|
||||
refusal = subprocess.run(make + [operation] + redirected, env=env,
|
||||
refusal = install_command(operation, redirected,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
assert refusal.returncode != 0 and not list(Path(outside).iterdir())
|
||||
assert (headers / 'xtc/xtc.h').is_file()
|
||||
|
|
@ -131,13 +149,13 @@ int main(int argc, char **argv) {
|
|||
saved_binary = stage / 'saved-check'
|
||||
(binaries / 'xtc-check').rename(saved_binary)
|
||||
(binaries / 'xtc-check').mkdir()
|
||||
refusal = subprocess.run(make + ['uninstall'] + variables, env=env,
|
||||
refusal = install_command('uninstall', variables + ['-DCMAKE_INSTALL_DOCDIR=manual' if args.custom_layout else '-DCMAKE_INSTALL_DOCDIR=share/doc/xtc'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
assert refusal.returncode != 0 and (headers / 'xtc/xtc.h').is_file()
|
||||
(binaries / 'xtc-check').rmdir()
|
||||
saved_binary.rename(binaries / 'xtc-check')
|
||||
run(make + ['uninstall'] + variables, env=env)
|
||||
run(make + ['uninstall'] + variables, env=env)
|
||||
install_command('uninstall', variables, check=True)
|
||||
install_command('uninstall', variables, check=True)
|
||||
remaining = sorted(p.relative_to(root).as_posix() for p in root.rglob('*') if p.is_file() or p.is_symlink())
|
||||
assert remaining == ['lib/keep-unrelated.txt'], remaining
|
||||
assert sentinel.read_text() == 'keep\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue