[master] b328f7f78 param: Add a %D expansion to cc_command

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jan 3 14:13:06 UTC 2022


commit b328f7f78fc7564377cd48870bd67347549dba91
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Dec 14 08:14:03 2021 +0100

    param: Add a %D expansion to cc_command
    
    And slightly polish the cc_command description.

diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 070e03ac3..d32894b64 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -128,7 +128,7 @@ run_vcc(void *priv)
  * Expand the cc_command argument
  */
 
-static void
+static const char *
 cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
 {
 	const char *p;
@@ -136,7 +136,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
 
 	AN(sb);
 	AN(cc_cmd);
-	(void)exp;
+
 	for (p = cc_cmd, pct = 0; *p; ++p) {
 		if (pct) {
 			switch (*p) {
@@ -152,6 +152,11 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
 			case 'd':
 				VSB_cat(sb, mgt_cc_cmd_def);
 				break;
+			case 'D':
+				if (exp == pct)
+					return ("recursive expansion");
+				cc_expand(sb, mgt_cc_cmd_def, pct);
+				break;
 			case '%':
 				VSB_putc(sb, '%');
 				break;
@@ -169,6 +174,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
 	}
 	if (pct)
 		VSB_putc(sb, '%');
+	return (NULL);
 }
 
 /*--------------------------------------------------------------------
@@ -180,6 +186,7 @@ run_cc(void *priv)
 {
 	struct vcc_priv *vp;
 	struct vsb *sb;
+	const char *err;
 
 	VJ_subproc(JAIL_SUBPROC_CC);
 	CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC);
@@ -188,7 +195,12 @@ run_cc(void *priv)
 
 	sb = VSB_new_auto();
 	AN(sb);
-	cc_expand(sb, mgt_cc_cmd, '\0');
+	err = cc_expand(sb, mgt_cc_cmd, '\0');
+	if (err != NULL) {
+		VSB_destroy(&sb);
+		fprintf(stderr, "cc_command: %s\n", err);
+		exit(1);
+	}
 	AZ(VSB_finish(sb));
 
 	(void)umask(027);
diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc
index 40d451296..5321aa43f 100644
--- a/bin/varnishtest/tests/c00109.vtc
+++ b/bin/varnishtest/tests/c00109.vtc
@@ -3,9 +3,9 @@ varnishtest "cc_command and cc_warnings"
 varnish v1 -cliok {param.set debug +vcl_keep}
 varnish v1 -cliok {param.set cc_warnings hello}
 varnish v1 -cliok {param.set cc_command << EOF
-! printf 'd="%%s" w="%%s"' '%d' '%w' >world
+! printf 'd="%%s" D="%%s" w="%%s"' '%d' '%D' '%w' >world
 EOF}
 
 varnish v1 -errvcl "VCL compilation failed" "backend be none;"
 
-shell -match {d=".+" w="hello"} "cat v1/vcl_*/world"
+shell -match {d=".+" D=".+hello.+" w="hello"} "cat v1/vcl_*/world"
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 1fb9c9423..6ad2cbe4d 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1530,12 +1530,22 @@ PARAM_STRING(
 	/* priv */	&mgt_cc_cmd,
 	/* def */	VCC_CC,
 	/* descr */
-	"Command used for compiling the C source code to a "
-	"dlopen(3) loadable object.  Any occurrence of %s in "
-	"the string will be replaced with the source file name, "
-	"%o will be replaced with the output file name, and %w "
-	"will be replaced by the cc_warnings parameter. The %d "
-	"sequence expands to the default value for cc_command.",
+	"The command used for compiling the C source code to a "
+	"dlopen(3) loadable object. The following expansions can "
+	"be used:\n\n"
+	"- %s: the source file name\n"
+	"- %o: the output file name\n"
+	"- %w: the cc_warnings parameter\n"
+	"- %d: the raw default cc_command\n"
+	"- %D: the expanded default cc_command\n"
+	"- %%: a percent sign\n"
+	"\n"
+	"Unknown percent expansion sequences are ignored, and to "
+	"avoid future incompatibilities percent characters should "
+	"be escaped with a double percent sequence.\n\n"
+	"The %d and %D expansions allow passing the parameter's "
+	"default value to a wrapper script to perform additional "
+	"processing.",
 	/* flags */	MUST_RELOAD | BUILD_OPTIONS,
 	/* dyn_min_reason */	NULL,
 	/* dyn_max_reason */	NULL,


More information about the varnish-commit mailing list