Skip to content

Commit 0aeabb1

Browse files
committed
feat(build): look up VM configurations through a repository option
CONFIG_REPO joins CONFIG_SRC in Kconfig, empty meaning the in-tree configs folder, and CONFIG_SRC accepts a configuration name resolved in that repository, a configuration folder, or a config.c path. Seeding records the name as given (plus the repository when explicit) instead of a resolved absolute path, keeping .config files portable; the config pin covers both values. Signed-off-by: Jose Martins <josemartins90@gmail.com>
1 parent 6e9bbce commit 0aeabb1

3 files changed

Lines changed: 77 additions & 27 deletions

File tree

Makefile

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ lib_dir=$(src_dir)/lib
6666
core_dir=$(src_dir)/core
6767
platforms_dir=$(src_dir)/platform
6868
configs_dir=$(cur_dir)/configs
69+
config_repo_arg:=$(filter command environment,$(origin CONFIG_REPO))
6970
CONFIG_REPO?=$(configs_dir)
7071
scripts_dir:=$(cur_dir)/scripts
7172
ci_dir:=$(cur_dir)/ci
@@ -193,15 +194,16 @@ seed_plat_defconfig=$(wildcard $(platform_dir)/defconfig)
193194
seed_config_defconfig=$(strip $(if $(filter-out $(CONFIG_REPO),$(config_dir)), \
194195
$(wildcard $(config_dir)/defconfig)))
195196
seed_defconfigs=$(seed_plat_defconfig) $(seed_config_defconfig)
196-
seed_config_src_arg=$(if $(config_src),--config-src $(abspath $(config_src)))
197+
seed_config_src_arg=$(if $(CONFIG),--config-src $(CONFIG)) \
198+
$(if $(config_repo_arg),--config-repo $(CONFIG_REPO))
197199
seed_defconfig_args=\
198200
$(if $(seed_plat_defconfig),--platform-defconfig $(seed_plat_defconfig)) \
199201
$(if $(seed_config_defconfig),--config-defconfig $(seed_config_defconfig)) \
200202
$(seed_config_src_arg)
201203

202204
$(kconfig_file):
203205
$(if $(PLATFORM),,$(error No configuration in $(build_dir): pass \
204-
PLATFORM= and CONFIG=, or run make \
206+
PLATFORM= and CONFIG= for a classic build, or run make \
205207
$(if $(default_o),,O=$(O) )<platform>_defconfig first))
206208
@echo "Seeding config $(patsubst $(cur_dir)/%,%, $@)"
207209
@mkdir -p $(dir $@)
@@ -247,28 +249,57 @@ endif
247249
ifneq ($(strip $(build_targets) $(filter listconfig,$(targets))),)
248250
-include $(kconfig_auto_conf)
249251

252+
# A missing or out-of-date auto.conf is about to be (re)generated, after
253+
# which make restarts: validation against its values only runs once it is
254+
# current, never against stale ones
255+
kconfig_auto_stale:=$(if $(wildcard $(kconfig_auto_conf)),$(shell \
256+
test $(kconfig_file) -nt $(kconfig_auto_conf) && echo y),y)
257+
250258
ifneq ($(O),)
251-
# In the O= workflow the .config owns the platform and the VM configuration.
252-
# PLATFORM= must then agree with it and CONFIG= overrides the configuration
253-
# source for this invocation only. The checks are skipped while auto.conf is
254-
# still being (re)generated; make restarts with the resolved values
259+
# In the O= workflow the .config owns the platform and the VM configuration
255260
PLATFORM:=$(CONFIG_PLATFORM)
256-
ifneq ($(wildcard $(kconfig_auto_conf)),)
261+
ifeq ($(kconfig_auto_stale),)
257262
ifneq ($(PLATFORM),)
258263
ifeq ($(wildcard $(platform_dir)),)
259264
$(error Target platform $(PLATFORM) is not supported)
260265
endif
261266
endif
262267
ifeq ($(config_src),)
263-
config_src:=$(CONFIG_CONFIG_SRC)
264-
config_dir:=$(patsubst %/,%,$(dir $(config_src)))
265-
ifeq ($(notdir $(config_src)),config.c)
268+
config_spec:=$(CONFIG_CONFIG_SRC)
269+
config_repo:=$(strip $(if $(config_repo_arg),$(CONFIG_REPO), \
270+
$(if $(CONFIG_CONFIG_REPO),$(CONFIG_CONFIG_REPO),$(configs_dir))))
271+
ifneq ($(build_targets),)
272+
ifeq ($(config_spec),)
273+
$(error No VM configuration set in $(kconfig_file): set it via menuconfig)
274+
endif
275+
endif
276+
# The stored configuration is a name looked up in the repository, a
277+
# configuration folder, or a config.c path
278+
ifeq ($(findstring /,$(config_spec)),)
279+
config_src:=$(wildcard $(config_repo)/$(config_spec).c)
280+
ifeq ($(config_src),)
281+
config_dir:=$(config_repo)/$(config_spec)
282+
-include $(config_dir)/config.mk
283+
ifeq ($(config_src),)
284+
config_src:=$(wildcard $(config_dir)/config.c)
285+
endif
286+
else
287+
config_dir:=$(config_repo)
288+
endif
289+
else ifeq ($(filter %.c,$(config_spec)),)
290+
config_dir:=$(patsubst %/,%,$(config_spec))
266291
-include $(config_dir)/config.mk
292+
ifeq ($(config_src),)
293+
config_src:=$(wildcard $(config_dir)/config.c)
294+
endif
295+
else
296+
config_src:=$(config_spec)
297+
config_dir:=$(patsubst %/,%,$(dir $(config_spec)))
267298
endif
268299
endif
269300
ifneq ($(build_targets),)
270-
ifeq ($(config_src),)
271-
$(error No VM configuration: pass CONFIG= or set CONFIG_SRC in menuconfig)
301+
ifeq ($(wildcard $(config_src)),)
302+
$(error VM configuration $(if $(config_spec),$(config_spec),$(CONFIG)) not found)
272303
endif
273304
endif
274305
endif
@@ -584,11 +615,11 @@ endif
584615
# Configuration frontends operating on this build's .config
585616

586617
.PHONY: menuconfig
587-
menuconfig: $(if $(O),$(if $(PLATFORM),$(kconfig_file)),$(kconfig_file))
618+
menuconfig: $(if $(O),,$(kconfig_file))
588619
@$(kconfig_env) python3 $(kconfig_tool) menuconfig
589620

590621
.PHONY: listconfig
591-
listconfig: $(kconfig_file)
622+
listconfig: $(if $(O),,$(kconfig_file))
592623
@$(kconfig_env) python3 $(kconfig_tool) list $(seed_defconfig_args)
593624

594625
# Seed the build's .config without building

scripts/kconfig.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ def check_pin(kconf):
4040
'use another directory')
4141

4242

43+
def apply_config_src(kconf, src):
44+
if not kconf.syms['CONFIG_SRC'].visibility and \
45+
kconf.syms['CONFIG_SRC'].str_value != src:
46+
sys.exit('kconfig: the VM configuration is pinned to '
47+
f"{kconf.syms['CONFIG_SRC'].str_value}; reseed with "
48+
'a <platform>_defconfig target to change it')
49+
kconf.syms['CONFIG_SRC'].set_value(src)
50+
51+
4352
def write_build_pin(kconf, pin_platform, pin_config):
4453
path = os.environ.get('BAO_BUILD_PIN')
4554
if not (pin_platform or pin_config) or path == '/dev/null' or \
@@ -57,6 +66,9 @@ def write_build_pin(kconf, pin_platform, pin_config):
5766
if pin_config and src:
5867
f.write('\nconfig CONFIG_PINNED\n\tdefault y\n\n'
5968
f'config CONFIG_SRC\n\tdefault "{src}"\n')
69+
repo = kconf.syms['CONFIG_REPO'].str_value
70+
if repo:
71+
f.write(f'\nconfig CONFIG_REPO\n\tdefault "{repo}"\n')
6072

6173

6274
def check_platform(kconf, platform):
@@ -95,8 +107,9 @@ def write_auto_conf(kconf, path):
95107
def write_auto_conf_header(kconf, path):
96108
with open(path, 'w') as f:
97109
for sym in emitted_syms(kconf):
98-
# CONFIG_SRC is a build input consumed by make, not by code
99-
if sym.name == 'CONFIG_SRC':
110+
# The configuration lookup is a build input consumed by make,
111+
# not by code
112+
if sym.name in ('CONFIG_SRC', 'CONFIG_REPO'):
100113
continue
101114
if sym.orig_type in (kconfiglib.BOOL, kconfiglib.TRISTATE):
102115
if sym.tri_value > 0:
@@ -237,6 +250,7 @@ def main():
237250
parser.add_argument('--platform-defconfig')
238251
parser.add_argument('--config-defconfig')
239252
parser.add_argument('--config-src')
253+
parser.add_argument('--config-repo')
240254
parser.add_argument('--pin-platform', action='store_true')
241255
parser.add_argument('--pin-config', action='store_true')
242256
parser.add_argument('--auto-conf')
@@ -261,12 +275,9 @@ def main():
261275
load_defconfigs(kconf, defconfigs)
262276
platform_symbol(kconf, platform).set_value(2)
263277
if args.config_src:
264-
if not kconf.syms['CONFIG_SRC'].visibility and \
265-
kconf.syms['CONFIG_SRC'].str_value != args.config_src:
266-
sys.exit('kconfig: the VM configuration is pinned to '
267-
f"{kconf.syms['CONFIG_SRC'].str_value}; reseed with "
268-
'a <platform>_defconfig target to change it')
269-
kconf.syms['CONFIG_SRC'].set_value(args.config_src)
278+
apply_config_src(kconf, args.config_src)
279+
if args.config_repo:
280+
kconf.syms['CONFIG_REPO'].set_value(args.config_repo)
270281
check_warnings(kconf)
271282
check_platform(kconf, platform)
272283
check_pin(kconf)

src/Kconfig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
mainmenu "Bao Hypervisor Configuration"
55

66
config CONFIG_SRC
7-
string "VM configuration (config.c path)" if !CONFIG_PINNED
7+
string "VM configuration" if !CONFIG_PINNED
88
help
9-
Fully resolved path of the VM configuration source this build
10-
compiles. Filled in when the configuration is seeded with CONFIG=
11-
on the make command line; passing CONFIG= to a later build
12-
overrides it for that invocation without changing it here.
9+
The VM configuration this build compiles: a configuration name
10+
looked up in the configuration repository, a path to a
11+
configuration folder, or a path to a config.c file. Filled in
12+
when the configuration is seeded with CONFIG= on the make command
13+
line; passing CONFIG= to a later build overrides it for that
14+
invocation without changing it here.
15+
16+
config CONFIG_REPO
17+
string "Configuration repository" if !CONFIG_PINNED
18+
help
19+
Directory where VM configuration names are looked up. Empty
20+
means the in-tree configs/ folder.
1321

1422
comment "VM configuration: @CONFIG_SRC@ (pinned)"
1523
depends on CONFIG_PINNED

0 commit comments

Comments
 (0)