Skip to content

Commit bd20fa7

Browse files
author
Oto Šťáva
committed
manager: add install config module
This new module allows Manager to use Meson-configured paths (generally inside the install prefix). It will allow us to add functionality to e.g. check for Lua modules during config validation.
1 parent 3c2052f commit bd20fa7

File tree

6 files changed

+72
-10
lines changed

6 files changed

+72
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This generated file is kept outside of the knot_resolver_manager module
2+
# because it may sometimes (when debugging) reside in another Python module
3+
# search path. Since Python does not merge module directories it finds on
4+
# multiple paths, it just uses the first one it finds, we need to keep this
5+
# separate.
6+
7+
lib_dir = "@lib_dir@"
8+
bin_dir = "@bin_dir@"
9+
sbin_dir = "@sbin_dir@"

manager/knot_resolver_manager/constants.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import importlib.util
12
import logging
23
from pathlib import Path
34
from typing import TYPE_CHECKING, Optional
45

5-
from knot_resolver_manager.utils import which
6+
# Install config is semi-optional - only needed to actually run Manager, but not
7+
# for its unit tests.
8+
if importlib.util.find_spec("knot_resolver_install_config"):
9+
import knot_resolver_install_config as install_config
10+
else:
11+
install_config = None
612

713
if TYPE_CHECKING:
814
from knot_resolver_manager.config_store import ConfigStore
@@ -20,11 +26,13 @@
2026

2127

2228
def kresd_executable() -> Path:
23-
return which.which("kresd")
29+
assert install_config is not None
30+
return Path(install_config.sbin_dir) / "kresd"
2431

2532

2633
def kres_gc_executable() -> Path:
27-
return which.which("kres-cache-gc")
34+
assert install_config is not None
35+
return Path(install_config.sbin_dir) / "kres-cache-gc"
2836

2937

3038
def kresd_cache_dir(config: "KresConfig") -> Path:

manager/meson.build

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# SPDX-License-Identifier: GPL-3.0-or-later
22

33
build_manager = false
4+
generate_manager_install_config = false
45

56
if get_option('manager') != 'disabled'
7+
build_manager = true
8+
generate_manager_install_config = true
9+
endif
10+
11+
if get_option('manager_install_config') == 'enabled'
12+
generate_manager_install_config = true
13+
endif
14+
15+
if build_manager or generate_manager_install_config
616
message('--- manager dependencies ---')
717

818
pymod = import('python')
@@ -13,14 +23,30 @@ if get_option('manager') != 'disabled'
1323
error('At least Python 3.6 is required.')
1424
elif py3_deps.returncode() != 0
1525
error(py3_deps.stderr().strip())
16-
else
17-
message('all dependencies found')
18-
build_manager = true
1926
endif
2027

28+
message('all dependencies found')
29+
2130
message('----------------------------')
2231
endif
2332

33+
if generate_manager_install_config
34+
manager_install_config = configuration_data()
35+
manager_install_config.set('lib_dir', lib_dir)
36+
manager_install_config.set('bin_dir', bin_dir)
37+
manager_install_config.set('sbin_dir', sbin_dir)
38+
39+
install_config = configure_file(
40+
input: 'knot_resolver_install_config.py.in',
41+
output: 'knot_resolver_install_config.py',
42+
configuration: manager_install_config,
43+
)
44+
45+
py3.install_sources(
46+
install_config,
47+
)
48+
endif
49+
2450
if build_manager
2551

2652
# shell completion
@@ -34,4 +60,6 @@ if build_manager
3460
sources: 'etc/knot-resolver/config.yaml',
3561
install_dir: etc_dir,
3662
)
37-
endif
63+
64+
endif
65+

manager/scripts/_env.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fi
3030

3131
# update PATH with node_modules
3232
PATH="$PATH:$gitroot/node_modules/.bin"
33+
PYTHONPATH="$PYTHONPATH"
3334

3435
# fail even on unbound variables
3536
set -o nounset
@@ -44,9 +45,13 @@ function build_kresd {
4445
echo
4546
pushd ..
4647
mkdir -p manager/.build_kresd manager/.install_kresd
47-
meson manager/.build_kresd --prefix=$(realpath manager/.install_kresd) --default-library=static --buildtype=debug
48+
meson manager/.build_kresd \
49+
--prefix=$(realpath manager/.install_kresd) \
50+
--default-library=static \
51+
--buildtype=debug \
52+
-Dmanager_install_config=enabled
4853
ninja -C manager/.build_kresd
4954
ninja install -C manager/.build_kresd
50-
export PATH="$(realpath manager/.install_kresd)/sbin:$PATH"
55+
export PYTHONPATH="$(realpath manager/.install_kresd/lib/python*/site-packages):$PYTHONPATH"
5156
popd
5257
}

manager/scripts/run

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ fi
4141

4242
export KRES_MANAGER_CONFIG
4343
export KRES_MANAGER_API_SOCK
44-
python3 -m knot_resolver_manager $@
44+
export PYTHONPATH
45+
python3 -m knot_resolver_manager "$@"

meson_options.txt

+11
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ option(
137137
description: 'build manager and its features',
138138
)
139139

140+
option(
141+
'manager_install_config',
142+
type: 'combo',
143+
choices: [
144+
'enabled',
145+
'disabled',
146+
],
147+
value: 'disabled',
148+
description: 'generate install config for the manager (without building the manager itself)',
149+
)
150+
140151
option(
141152
'utils',
142153
type: 'combo',

0 commit comments

Comments
 (0)