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) ...@@ -128,7 +128,7 @@ run_vcc(void *priv)
* Expand the cc_command argument * Expand the cc_command argument
*/ */
static void static const char *
cc_expand(struct vsb *sb, const char *cc_cmd, char exp) cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
{ {
const char *p; const char *p;
...@@ -136,7 +136,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) ...@@ -136,7 +136,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
AN(sb); AN(sb);
AN(cc_cmd); AN(cc_cmd);
(void)exp;
for (p = cc_cmd, pct = 0; *p; ++p) { for (p = cc_cmd, pct = 0; *p; ++p) {
if (pct) { if (pct) {
switch (*p) { switch (*p) {
...@@ -152,6 +152,11 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) ...@@ -152,6 +152,11 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
case 'd': case 'd':
VSB_cat(sb, mgt_cc_cmd_def); VSB_cat(sb, mgt_cc_cmd_def);
break; break;
case 'D':
if (exp == pct)
return ("recursive expansion");
cc_expand(sb, mgt_cc_cmd_def, pct);
break;
case '%': case '%':
VSB_putc(sb, '%'); VSB_putc(sb, '%');
break; break;
...@@ -169,6 +174,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) ...@@ -169,6 +174,7 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
} }
if (pct) if (pct)
VSB_putc(sb, '%'); VSB_putc(sb, '%');
return (NULL);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -180,6 +186,7 @@ run_cc(void *priv) ...@@ -180,6 +186,7 @@ run_cc(void *priv)
{ {
struct vcc_priv *vp; struct vcc_priv *vp;
struct vsb *sb; struct vsb *sb;
const char *err;
VJ_subproc(JAIL_SUBPROC_CC); VJ_subproc(JAIL_SUBPROC_CC);
CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC); CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC);
...@@ -188,7 +195,12 @@ run_cc(void *priv) ...@@ -188,7 +195,12 @@ run_cc(void *priv)
sb = VSB_new_auto(); sb = VSB_new_auto();
AN(sb); 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)); AZ(VSB_finish(sb));
(void)umask(027); (void)umask(027);
......
...@@ -3,9 +3,9 @@ varnishtest "cc_command and cc_warnings" ...@@ -3,9 +3,9 @@ varnishtest "cc_command and cc_warnings"
varnish v1 -cliok {param.set debug +vcl_keep} varnish v1 -cliok {param.set debug +vcl_keep}
varnish v1 -cliok {param.set cc_warnings hello} varnish v1 -cliok {param.set cc_warnings hello}
varnish v1 -cliok {param.set cc_command << EOF 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} EOF}
varnish v1 -errvcl "VCL compilation failed" "backend be none;" 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( ...@@ -1530,12 +1530,22 @@ PARAM_STRING(
/* priv */ &mgt_cc_cmd, /* priv */ &mgt_cc_cmd,
/* def */ VCC_CC, /* def */ VCC_CC,
/* descr */ /* descr */
"Command used for compiling the C source code to a " "The command used for compiling the C source code to a "
"dlopen(3) loadable object. Any occurrence of %s in " "dlopen(3) loadable object. The following expansions can "
"the string will be replaced with the source file name, " "be used:\n\n"
"%o will be replaced with the output file name, and %w " "- %s: the source file name\n"
"will be replaced by the cc_warnings parameter. The %d " "- %o: the output file name\n"
"sequence expands to the default value for cc_command.", "- %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, /* flags */ MUST_RELOAD | BUILD_OPTIONS,
/* dyn_min_reason */ NULL, /* dyn_min_reason */ NULL,
/* dyn_max_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