From 1350900246e0462b584331be0df24e177e7b25be Mon Sep 17 00:00:00 2001 From: Chao Song Date: Tue, 17 Jan 2023 20:52:18 +0800 Subject: [PATCH] topology: pre-processor: support to include conf block with IncludeByKey Currently, The IncludeByKey mechanism only supports conditionally including a topology conf file. Even if we only want to conditionally include a small conf block, we have to use a conf file and in the end we will have a lot of trivial conf files that only contain a single conf blocks. This patch extends the use of IncludeByKey ito support including conf blocks conditionally. For example, the block below will include the route conditionally based on the variable definition COPIER_ROUTE. Define { COPIER_ROUTE 1 } IncludeByKey.COPIER_ROUTE { "1" { Object.Base.route.11 { source copier.module.8.2 sink copier.module.17.2 } } } Fixes: https://github.com/alsa-project/alsa-utils/pull/187 Signed-off-by: Chao Song Co-authored-by: Jaroslav Kysela Signed-off-by: Ranjani Sridharan Signed-off-by: Jaroslav Kysela --- topology/pre-processor.c | 53 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/topology/pre-processor.c b/topology/pre-processor.c index dfe3ad6..38bb87b 100644 --- a/topology/pre-processor.c +++ b/topology/pre-processor.c @@ -504,30 +504,39 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf if (ret) continue; - /* regex matched. now include the conf file */ - ret = snd_config_get_string(n, &filename); - if (ret < 0) - goto err; + /* regex matched. now include or use the configuration */ + if (snd_config_get_type(n) == SND_CONFIG_TYPE_COMPOUND) { + /* configuration block */ + ret = snd_config_merge(*new, n, 0); + if (ret < 0) { + fprintf(stderr, "Unable to merge key '%s'\n", value); + goto err; + } + } else { + ret = snd_config_get_string(n, &filename); + if (ret < 0) + goto err; - if (filename && filename[0] != '/') - full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, filename); - else - full_path = tplg_snprintf("%s", filename); + if (filename && filename[0] != '/') + full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, filename); + else + full_path = tplg_snprintf("%s", filename); - ret = snd_input_stdio_open(&in, full_path, "r"); - if (ret < 0) { - fprintf(stderr, "Unable to open included conf file %s\n", full_path); + ret = snd_input_stdio_open(&in, full_path, "r"); + if (ret < 0) { + fprintf(stderr, "Unable to open included conf file %s\n", full_path); + free(full_path); + goto err; + } free(full_path); - goto err; - } - free(full_path); - /* load config */ - ret = snd_config_load(*new, in); - snd_input_close(in); - if (ret < 0) { - fprintf(stderr, "Unable to load included configuration\n"); - goto err; + /* load config */ + ret = snd_config_load(*new, in); + snd_input_close(in); + if (ret < 0) { + fprintf(stderr, "Unable to load included configuration\n"); + goto err; + } } /* forcefully overwrite with defines from the command line */ @@ -538,7 +547,9 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf } /* recursively process any nested includes */ - return pre_process_includes(tplg_pp, *new); + ret = pre_process_includes(tplg_pp, *new); + if (ret < 0) + goto err; } err: