summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@perex.cz>2022-01-27 14:11:45 +0100
committerJaroslav Kysela <perex@perex.cz>2022-01-27 14:16:38 +0100
commite1a07113291c240d598f018a8086dcef23003961 (patch)
treeb7ed0d01f7ccc0837556edcb8618876d84b51917
parentd05ac4a0785c8b6c91ec6037d26c918cfaa2e482 (diff)
downloadalsa-utils-e1a07113291c240d598f018a8086dcef23003961.tar.gz
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 <perex@perex.cz>
-rw-r--r--topology/pre-process-object.c1
-rw-r--r--topology/pre-processor.c33
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;