Skip to content

Commit

Permalink
build: Call 'systemd-tmpfiles --create' when installing
Browse files Browse the repository at this point in the history
It's only necessary to call 'systemd-tmpfiles --create' when building
and installing from source on the host operating system.

It's not needed when using a pre-built binary downstream package,
because:

  * When 'meson install' is called as part of building the package,
    that's not when the temporary files need to be created. They need
    to be created when the binary package is later downloaded and
    installed by the user.

  * Downstream tools can sometimes handle it automatically. eg., on
    Fedora, the systemd RPM installs a trigger that tells RPM to call
    'systemd-tmpfiles --create' automatically when a tmpfiles.d snippet
    is installed.

It's also not needed when installing inside a toolbox container because
the files that 'systemd-tmpfiles --create' is supposed to create are
meant to be on the host.

Downstream distributors set the DESTDIR environment variable when
building their packages. Therefore, it's used to detect when a
downstream package is being built.

Unfortunately, environment variables are messy and, generally, Meson
doesn't support accessing them inside its scripts [1]. Therefore, this
adds a spurious build-time dependency on systemd for downstream
distributors. However, that's probably not a big problem because all
supported downstream operating systems are already expected to use
systemd for the tmpfiles.d(5) snippets to work.

[1] mesonbuild/meson#9

#955
  • Loading branch information
debarshiray committed Jan 10, 2022
1 parent 5d61a74 commit be2ba6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ project(
meson_version: '>= 0.58.0',
)

fs = import('fs')

cc = meson.get_compiler('c')
if not cc.has_argument('-print-file-name=libc.so')
error('C compiler does not support the -print-file-name argument.')
Expand All @@ -22,9 +24,12 @@ migration_path_for_coreos_toolbox = get_option('migration_path_for_coreos_toolbo
profiledir = get_option('profile_dir')

tmpfilesdir = get_option('tmpfiles_dir')
if tmpfilesdir == ''
if tmpfilesdir == '' or not fs.exists('/run/.containerenv')
systemd_dep = dependency('systemd')
tmpfilesdir = systemd_dep.get_variable(pkgconfig: 'tmpfilesdir')

if tmpfilesdir == ''
tmpfilesdir = systemd_dep.get_variable(pkgconfig: 'tmpfilesdir')
endif
endif

if bash_completion.found()
Expand Down Expand Up @@ -65,3 +70,5 @@ subdir('data')
subdir('doc')
subdir('profile.d')
subdir('src')

meson.add_install_script('meson_post_install.py')
18 changes: 18 additions & 0 deletions meson_post_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

import os
import subprocess
import sys

destdir = os.environ.get('DESTDIR', '')

if not destdir and not os.path.exists('/run/.containerenv'):
print('Calling systemd-tmpfiles --create ...')

try:
subprocess.run(['systemd-tmpfiles', '--create'], check=True)
except subprocess.CalledProcessError as e:
print('Returned non-zero exit status', e.returncode)
sys.exit(e.returncode)

sys.exit(0)
7 changes: 0 additions & 7 deletions playbooks/setup-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,3 @@
args:
chdir: '{{ zuul.project.src_dir }}'
creates: /usr/local/bin/toolbox

- name: Setup environment
become: yes
command:
cmd: systemd-tmpfiles --create
creates: /run/media
creates: /run/host

0 comments on commit be2ba6d

Please sign in to comment.