Commit b328f7f7 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

param: Add a %D expansion to cc_command

And slightly polish the cc_command description.
parent 60181878
......@@ -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);
......
......@@ -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"
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment