|
| 1 | +project( |
| 2 | + 'cloud-init', |
| 3 | + version: run_command('./tools/read-version', check: true).stdout().strip(), |
| 4 | + meson_version: '>=0.63.0', |
| 5 | + default_options: [ |
| 6 | + # The default can yield broken results. |
| 7 | + 'python.install_env=auto' |
| 8 | + ] |
| 9 | +) |
| 10 | +completions = dependency('bash-completion') |
| 11 | +systemd = dependency('systemd') |
| 12 | +system = host_machine.system() |
| 13 | + |
| 14 | +libdir = get_option('libdir') |
| 15 | +pkgdatadir = get_option('datadir') |
| 16 | +sysconfdir = get_option('sysconfdir') |
| 17 | +INIT_SYSTEM = get_option('init_system') |
| 18 | +VALID_INIT_SYSTEMS = [ |
| 19 | + 'systemd', 'sysvinit', 'sysvinit_deb', 'sysvinit_dragonfly', |
| 20 | + 'sysvinit_freebsd', 'sysvinit_netbsd', 'sysvinit_openbsd' |
| 21 | +] |
| 22 | +if not VALID_INIT_SYSTEMS.contains(INIT_SYSTEM) |
| 23 | + error( |
| 24 | + 'Invalid init_system supplied: "@0@". Must be one of: @1@'.format( |
| 25 | + INIT_SYSTEM, VALID_INIT_SYSTEMS) |
| 26 | + ) |
| 27 | +endif |
| 28 | + |
| 29 | + |
| 30 | +DISTRO = get_option('distro') |
| 31 | +BSD_DISTROS = ['dragonfly', 'freebsd', 'netbsd', 'openbsd'] |
| 32 | +RHEL_DISTROS = [ |
| 33 | + 'almalinux', 'centos', 'cloudlinux', 'eurolinux', 'fedora', 'miraclelinux', |
| 34 | + 'rhel', 'rocky', 'virtuozzo' |
| 35 | +] |
| 36 | +VALID_DISTROS = [ |
| 37 | + 'alpine', 'amazon', 'debian', 'mariner', 'opencloudos', 'openeuler', |
| 38 | + 'photon', 'ubuntu', 'suse', '' |
| 39 | +] + RHEL_DISTROS + BSD_DISTROS |
| 40 | + |
| 41 | +if not VALID_DISTROS.contains(DISTRO) |
| 42 | + error( |
| 43 | + 'Invalid distro supplied: "@0@". Must be one of: @1@'.format( |
| 44 | + DISTRO, VALID_DISTROS) |
| 45 | + ) |
| 46 | +endif |
| 47 | + |
| 48 | + |
| 49 | +if BSD_DISTROS.contains(system) or BSD_DISTROS.contains(DISTRO) |
| 50 | + if INIT_SYSTEM = '' |
| 51 | + if DISTRO == '' |
| 52 | + DISTRO = system |
| 53 | + endif |
| 54 | + INIT_SYSTEM = 'sysvinit_' + DISTRO |
| 55 | + endif |
| 56 | +else |
| 57 | + if INIT_SYSTEM == '' |
| 58 | + INIT_SYSTEM = 'systemd' |
| 59 | + endif |
| 60 | + if DISTRO == '' |
| 61 | + fs = import('fs') |
| 62 | + if fs.is_file('/etc/redhat-release') |
| 63 | + message('Setting distro to rhel because of host /etc/redhat-release') |
| 64 | + DISTRO = 'rhel' |
| 65 | + endif |
| 66 | + endif |
| 67 | +endif |
| 68 | + |
| 69 | +if RHEL_DISTROS.contains(DISTRO) |
| 70 | + lib_exec_dir = join_paths('/usr', get_option('libexecdir'), 'cloud-init') |
| 71 | +else |
| 72 | + lib_exec_dir = join_paths('/usr', 'lib', 'cloud-init') |
| 73 | +endif |
| 74 | +message('LIBEXEC: @0@ @1@'.format(lib_exec_dir, DISTRO)) |
| 75 | + |
| 76 | + |
| 77 | +pymod = import('python') |
| 78 | +python = pymod.find_installation('python3', required: true) |
| 79 | +python.dependency() |
| 80 | + |
| 81 | +find = find_program('find') |
| 82 | + |
| 83 | +# TODO(When RHEL support meson >= 1.0.0 use install_sources 'preserve_path: true') |
| 84 | +py_sources = run_command(find, 'cloudinit', '-maxdepth', '1', '-name', '*.py', check: true).stdout().strip().split('\n') |
| 85 | +py_sources_files = files(py_sources) |
| 86 | +python.install_sources(py_sources, subdir: 'cloudinit') |
| 87 | + |
| 88 | +py_source_dirs = run_command(find, 'cloudinit', '-type', 'd', '-not', '-name', '*pycache*', check: true).stdout().strip().split('\n') |
| 89 | +foreach source_subdir: py_source_dirs |
| 90 | + py_sources = run_command(find, source_subdir, '-maxdepth', '1', '-name', '*.py', check: true).stdout().strip().split('\n') |
| 91 | + python.install_sources(py_sources, subdir: source_subdir) |
| 92 | +endforeach |
| 93 | + |
| 94 | +bash_completions_dir = completions.get_variable( |
| 95 | + pkgconfig: 'completionsdir', default_value: '/etc/bash_completion.d') |
| 96 | +install_data( |
| 97 | + 'bash_completion/cloud-init', install_dir: bash_completions_dir, install_tag: 'scripts') |
| 98 | + |
| 99 | +foreach script: ['tools/ds-identify', 'tools/hook-hotplug','tools/uncloud-init', 'tools/write-ssh-key-fingerprints' ] |
| 100 | + install_data( |
| 101 | + script, install_dir: lib_exec_dir, install_tag: 'scripts') |
| 102 | +endforeach |
| 103 | + |
| 104 | + |
| 105 | +# Scripts |
| 106 | +foreach script: files( |
| 107 | + ['tools/cloud-init-per', 'tools/cloud-id', 'tools/cloud-init']) |
| 108 | + install_data( |
| 109 | + script, |
| 110 | + install_mode: 'rwxr-xr-x', |
| 111 | + install_dir: get_option('bindir'), |
| 112 | + ) |
| 113 | +endforeach |
| 114 | + |
| 115 | +# Schemas |
| 116 | + |
| 117 | +# Required Config and Templates |
| 118 | +render_tmpl = './tools/render-template' |
| 119 | +subdir('config/cloud.cfg.d') |
| 120 | +subdir('templates') |
| 121 | + |
| 122 | +if INIT_SYSTEM == 'systemd' |
| 123 | + udev = dependency('udev') |
| 124 | + systemd_unit_dir = systemd.get_variable( |
| 125 | + pkgconfig: 'systemdsystemunitdir' |
| 126 | + ) |
| 127 | + systemd_generator_dir = systemd.get_variable( |
| 128 | + pkgconfig: 'systemdsystemgeneratordir' |
| 129 | + ) |
| 130 | + subdir('systemd') |
| 131 | + udev_dir = udev.get_variable( |
| 132 | + pkgconfig: 'udevdir', default_value: '/usr/lib/udev' |
| 133 | + ) |
| 134 | + install_data( |
| 135 | + 'udev/66-azure-ephemeral.rules', |
| 136 | + install_dir: join_paths(udev_dir, 'rules.d'), |
| 137 | + install_tag: 'systemd' |
| 138 | + ) |
| 139 | + |
| 140 | + # Must generate systemd templates in root mesonbuild, because nested |
| 141 | + # systemd/meson.build results in builddir @OUTPUT@ macro being doubly-nested |
| 142 | + # paths |
| 143 | + systemd_generators = run_command(find, 'systemd', '-name', '*generator*.tmpl', check: true).stdout().strip().split('\n') |
| 144 | + foreach template: systemd_generators |
| 145 | + custom_target( |
| 146 | + input: template, |
| 147 | + output: '@BASENAME@', |
| 148 | + command: [render_tmpl, '@INPUT@', join_paths(meson.current_build_dir(), '@OUTPUT@')], |
| 149 | + install: true, |
| 150 | + install_dir: systemd_generator_dir, |
| 151 | + install_tag: 'systemd' |
| 152 | + ) |
| 153 | + endforeach |
| 154 | + |
| 155 | + systemd_templates = run_command(find, 'systemd', '-not', '-name', '*generator*', '-name', '*.tmpl', check: true).stdout().strip().split('\n') |
| 156 | + foreach template: systemd_templates |
| 157 | + custom_target( |
| 158 | + input: template, |
| 159 | + output: '@BASENAME@', |
| 160 | + command: [render_tmpl, '@INPUT@', join_paths(meson.current_build_dir(), '@OUTPUT@')], |
| 161 | + install: true, |
| 162 | + install_dir: systemd_unit_dir, |
| 163 | + install_tag: 'systemd' |
| 164 | + ) |
| 165 | + endforeach |
| 166 | +endif |
| 167 | + |
| 168 | +# Schema files |
| 169 | +json_schemas = run_command(find, 'cloudinit', '-name', '*.json', check: true).stdout().strip().split('\n') |
| 170 | +python.install_sources(json_schemas, subdir: join_paths('cloudinit', 'config', 'schemas')) |
| 171 | + |
| 172 | +custom_target( |
| 173 | + input: 'config/cloud.cfg.tmpl', |
| 174 | + output: 'cloud.cfg', |
| 175 | + command: [render_tmpl, '--is-yaml', '@INPUT@', join_paths(meson.current_build_dir(), '@OUTPUT@')], |
| 176 | + install: true, |
| 177 | + install_dir: join_paths(sysconfdir, 'cloud'), |
| 178 | + install_tag: 'config' |
| 179 | +) |
| 180 | + |
| 181 | + |
| 182 | +# Docs and Examples: |
| 183 | +subdir('doc/examples') |
| 184 | +subdir('doc/examples/seed') |
| 185 | +mandir = get_option('mandir') |
| 186 | +foreach man_page : ['cloud-init.1', 'cloud-id.1', 'cloud-init-per.1'] |
| 187 | + install_data( |
| 188 | + 'doc/man/' + man_page, |
| 189 | + install_dir: join_paths(mandir, 'man1'), |
| 190 | + install_tag: 'docs' |
| 191 | + ) |
| 192 | +endforeach |
| 193 | + |
| 194 | +# Prerequisite for using install_deps or install_test_deps: |
| 195 | +# python3 -m venv ../.venv |
| 196 | +# source ../.venv/bin/activate |
| 197 | +# meson setup ../builddir -Dinit_system=systemd -Ddistro=ubuntu |
| 198 | +# meson compile -C ../builddir install_deps |
| 199 | +# meson compile -C ../builddir install_test_deps |
| 200 | +run_target( |
| 201 | + 'install_deps', |
| 202 | + command: [python, '-m', 'pip', 'install', '-r', meson.project_source_root() / 'requirements.txt'], |
| 203 | +) |
| 204 | +run_target( |
| 205 | + 'install_test_deps', |
| 206 | + command: [python, '-m', 'pip', 'install', '-r', meson.project_source_root() / 'test-requirements.txt'], |
| 207 | +) |
| 208 | + |
| 209 | +# CLI: meson test -C ../builddir py3 -v |
| 210 | +test( |
| 211 | + 'py3', |
| 212 | + python, |
| 213 | + args: ['-m', 'pytest', meson.project_source_root() / 'tests' / 'unittests'], |
| 214 | + timeout: 180, |
| 215 | + is_parallel: true |
| 216 | +) |
0 commit comments