From e1a07113291c240d598f018a8086dcef23003961 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 27 Jan 2022 14:11:45 +0100 Subject: topology: fix the command line define merge for new includes The defines from the command line must overwrite the defines from the included configuration files forcefully. Link: https://github.com/alsa-project/alsa-utils/pull/129 Signed-off-by: Jaroslav Kysela --- topology/pre-process-object.c | 1 + topology/pre-processor.c | 33 ++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/topology/pre-process-object.c b/topology/pre-process-object.c index 5ce3beb..2063cca 100644 --- a/topology/pre-process-object.c +++ b/topology/pre-process-object.c @@ -1521,6 +1521,7 @@ static int pre_process_find_variable(snd_config_t **dst, const char *str, snd_co return -EINVAL; } + static int pre_process_object_variables_expand_fcn(snd_config_t **dst, const char *str, void *private_data) { diff --git a/topology/pre-processor.c b/topology/pre-processor.c index 90a1570..2c30758 100644 --- a/topology/pre-processor.c +++ b/topology/pre-processor.c @@ -225,18 +225,25 @@ err: } #if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION -static int pre_process_defines(struct tplg_pre_processor *tplg_pp, const char *pre_processor_defs, - snd_config_t *top) +static int pre_process_defines(struct tplg_pre_processor *tplg_pp, const char *pre_processor_defs) { snd_config_t *conf_defines, *defines; int ret; ret = snd_config_search(tplg_pp->input_cfg, "Define", &conf_defines); + if (ret == -ENOENT) { + ret = snd_config_make_compound(&conf_defines, "Define", 0); + if (ret < 0) + return ret; + ret = snd_config_add(tplg_pp->input_cfg, conf_defines); + } if (ret < 0) - return 0; + return ret; - if (snd_config_get_type(conf_defines) != SND_CONFIG_TYPE_COMPOUND) - return 0; + if (snd_config_get_type(conf_defines) != SND_CONFIG_TYPE_COMPOUND) { + fprintf(stderr, "Define must be a compound!\n"); + return -EINVAL; + } /* * load and merge the command line defines with the variables in the conf file to override @@ -364,13 +371,6 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf goto err; } - /* process any args in the included file */ - ret = pre_process_defines(tplg_pp, pre_processor_defs, *new); - if (ret < 0) { - fprintf(stderr, "Failed to parse arguments in input config\n"); - goto err; - } - /* recursively process any nested includes */ return pre_process_includes(tplg_pp, *new, pre_processor_defs, inc_path); } @@ -426,6 +426,13 @@ static int pre_process_includes(struct tplg_pre_processor *tplg_pp, snd_config_t fprintf(stderr, "Failed to add included conf\n"); return ret; } + + /* forcefully overwrite with defines from the command line */ + ret = pre_process_defines(tplg_pp, pre_processor_defs); + if (ret < 0) { + fprintf(stderr, "Failed to parse arguments in input config\n"); + return ret; + } } /* remove all includes from current top */ @@ -495,7 +502,7 @@ int pre_process(struct tplg_pre_processor *tplg_pp, char *config, size_t config_ #if SND_LIB_VER(1, 2, 5) < SND_LIB_VERSION /* parse command line definitions */ - err = pre_process_defines(tplg_pp, pre_processor_defs, tplg_pp->input_cfg); + err = pre_process_defines(tplg_pp, pre_processor_defs); if (err < 0) { fprintf(stderr, "Failed to parse arguments in input config\n"); goto err; -- cgit v1.2.1