r1349 - in branches/1.0: . bin/varnishd lib/libvcl
des at projects.linpro.no
des at projects.linpro.no
Thu Apr 19 16:51:14 CEST 2007
Author: des
Date: 2007-04-19 16:51:14 +0200 (Thu, 19 Apr 2007)
New Revision: 1349
Modified:
branches/1.0/
branches/1.0/bin/varnishd/mgt_vcc.c
branches/1.0/lib/libvcl/vcc_compile.c
Log:
r37082 at cat (orig r1306): phk | 2007-04-09 22:28:08 +0200
Move the function that pushes the compiled VCL programs C source through
the systems cc(1) from the VCL compiler library to the varnishd process.
This reduces the VCL-compiler library to a text-procesing functionality
and makes it easier to build other tools, including test-suites,
around the VCL-compiler.
It also moves the actual compiler invocation string into the varnishd
sources, where it can be handled appropriately, possibly as a paramter.
Property changes on: branches/1.0
___________________________________________________________________
Name: svk:merge
- d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1305
+ d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1306
Modified: branches/1.0/bin/varnishd/mgt_vcc.c
===================================================================
--- branches/1.0/bin/varnishd/mgt_vcc.c 2007-04-19 14:51:12 UTC (rev 1348)
+++ branches/1.0/bin/varnishd/mgt_vcc.c 2007-04-19 14:51:14 UTC (rev 1349)
@@ -118,8 +118,127 @@
" discard;\n"
"}\n";
+/*--------------------------------------------------------------------
+ * Invoke system C compiler on source and return resulting dlfile.
+ * Errors goes in sb;
+ */
+
+static char *
+mgt_CallCc(const char *source, struct vsb *sb)
+{
+ FILE *fo, *fs;
+ char *of, *sf, buf[BUFSIZ];
+ int i, j, sfd;
+
+ /* Create temporary C source file */
+ sf = strdup("/tmp/vcl.XXXXXXXX");
+ assert(sf != NULL);
+ sfd = mkstemp(sf);
+ if (sfd < 0) {
+ vsb_printf(sb,
+ "Cannot open temporary source file \"%s\": %s\n",
+ sf, strerror(errno));
+ free(sf);
+ return (NULL);
+ }
+ fs = fdopen(sfd, "r+");
+ assert(fs != NULL);
+
+ if (fputs(source, fs) || fflush(fs)) {
+ vsb_printf(sb,
+ "Write error to C source file: %s\n",
+ strerror(errno));
+ unlink(sf);
+ fclose(fs);
+ return (NULL);
+ }
+ rewind(fs);
+
+ /* Name the output shared library */
+ of = strdup("/tmp/vcl.XXXXXXXX");
+ assert(of != NULL);
+ of = mktemp(of);
+ assert(of != NULL);
+
+ /* Attempt to open a pipe to the system C-compiler */
+ sprintf(buf,
+ "ln -f %s /tmp/_.c ;" /* XXX: for debugging */
+ "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1",
+ sf, of, sf);
+
+ fo = popen(buf, "r");
+ if (fo == NULL) {
+ vsb_printf(sb,
+ "Internal error: Cannot execute cc(1): %s\n",
+ strerror(errno));
+ free(of);
+ unlink(sf);
+ fclose(fs);
+ return (NULL);
+ }
+
+ /* If we get any output, it's bad */
+ j = 0;
+ while (1) {
+ if (fgets(buf, sizeof buf, fo) == NULL)
+ break;
+ if (!j) {
+ vsb_printf(sb, "Internal error: cc(1) complained:\n");
+ j++;
+ }
+ vsb_cat(sb, buf);
+ }
+
+ i = pclose(fo);
+ if (j == 0 && i != 0)
+ vsb_printf(sb,
+ "Internal error: cc(1) exit status 0x%04x\n", i);
+
+ /* If the compiler complained, or exited non-zero, fail */
+ if (i || j) {
+ unlink(of);
+ free(of);
+ of = NULL;
+ }
+
+ /* clean up and return */
+ unlink(sf);
+ free(sf);
+ fclose(fs);
+ return (of);
+}
+
/*--------------------------------------------------------------------*/
+static char *
+mgt_VccCompile(struct vsb *sb, const char *b, const char *e)
+{
+ char *csrc, *vf;
+
+ csrc = VCC_Compile(sb, b, e);
+ if (csrc != NULL) {
+ vf = mgt_CallCc(csrc, sb);
+ free(csrc);
+ }
+ return (vf);
+}
+
+static char *
+mgt_VccCompileFile(struct vsb *sb, const char *fn)
+{
+ char *csrc, *vf;
+
+ csrc = VCC_CompileFile(sb, fn);
+ if (csrc != NULL) {
+ vf = mgt_CallCc(csrc, sb);
+ free(csrc);
+ }
+ return (vf);
+}
+
+
+/*--------------------------------------------------------------------*/
+
static struct vclprog *
mgt_vcc_add(const char *name, char *file)
{
@@ -193,10 +312,10 @@
free(addr);
free(port);
AN(buf);
- vf = VCC_Compile(sb, buf, NULL);
+ vf = mgt_VccCompile(sb, buf, NULL);
free(buf);
} else {
- vf = VCC_CompileFile(sb, f_arg);
+ vf = mgt_VccCompileFile(sb, f_arg);
}
vsb_finish(sb);
if (vsb_len(sb) > 0) {
@@ -275,7 +394,7 @@
sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
XXXAN(sb);
- vf = VCC_Compile(sb, av[3], NULL);
+ vf = mgt_VccCompile(sb, av[3], NULL);
vsb_finish(sb);
if (vsb_len(sb) > 0) {
cli_out(cli, "%s", vsb_data(sb));
@@ -306,7 +425,7 @@
sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
XXXAN(sb);
- vf = VCC_CompileFile(sb, av[3]);
+ vf = mgt_VccCompileFile(sb, av[3]);
vsb_finish(sb);
if (vsb_len(sb) > 0) {
cli_out(cli, "%s", vsb_data(sb));
Modified: branches/1.0/lib/libvcl/vcc_compile.c
===================================================================
--- branches/1.0/lib/libvcl/vcc_compile.c 2007-04-19 14:51:12 UTC (rev 1348)
+++ branches/1.0/lib/libvcl/vcc_compile.c 2007-04-19 14:51:14 UTC (rev 1349)
@@ -577,101 +577,10 @@
}
/*--------------------------------------------------------------------
- * Invoke system C compiler on source and return resulting dlfile.
- * Errors goes in sb;
+ * Compile the VCL code from the given source and return the C-source
*/
static char *
-vcc_CallCc(const char *source, struct vsb *sb)
-{
- FILE *fo, *fs;
- char *of, *sf, buf[BUFSIZ];
- int i, j, sfd;
-
- /* Create temporary C source file */
- sf = strdup("/tmp/vcl.XXXXXXXX");
- assert(sf != NULL);
- sfd = mkstemp(sf);
- if (sfd < 0) {
- vsb_printf(sb,
- "Cannot open temporary source file \"%s\": %s\n",
- sf, strerror(errno));
- free(sf);
- return (NULL);
- }
- fs = fdopen(sfd, "r+");
- assert(fs != NULL);
-
- if (fputs(source, fs) || fflush(fs)) {
- vsb_printf(sb,
- "Write error to C source file: %s\n",
- strerror(errno));
- unlink(sf);
- fclose(fs);
- return (NULL);
- }
- rewind(fs);
-
- /* Name the output shared library */
- of = strdup("/tmp/vcl.XXXXXXXX");
- assert(of != NULL);
- of = mktemp(of);
- assert(of != NULL);
-
- /* Attempt to open a pipe to the system C-compiler */
- sprintf(buf,
- "ln -f %s /tmp/_.c ;" /* XXX: for debugging */
- "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1",
- sf, of, sf);
-
- fo = popen(buf, "r");
- if (fo == NULL) {
- vsb_printf(sb,
- "Internal error: Cannot execute cc(1): %s\n",
- strerror(errno));
- free(of);
- unlink(sf);
- fclose(fs);
- return (NULL);
- }
-
- /* If we get any output, it's bad */
- j = 0;
- while (1) {
- if (fgets(buf, sizeof buf, fo) == NULL)
- break;
- if (!j) {
- vsb_printf(sb, "Internal error: cc(1) complained:\n");
- j++;
- }
- vsb_cat(sb, buf);
- }
-
- i = pclose(fo);
- if (j == 0 && i != 0)
- vsb_printf(sb,
- "Internal error: cc(1) exit status 0x%04x\n", i);
-
- /* If the compiler complained, or exited non-zero, fail */
- if (i || j) {
- unlink(of);
- free(of);
- of = NULL;
- }
-
- /* clean up and return */
- unlink(sf);
- free(sf);
- fclose(fs);
- return (of);
-}
-
-/*--------------------------------------------------------------------
- * Compile the VCL code from the given source and return the filename
- * of the resulting shared library.
- */
-
-static char *
vcc_CompileSource(struct vsb *sb, struct source *sp)
{
struct tokenlist *tl;
@@ -755,8 +664,8 @@
vsb_cat(tl->fh, vsb_data(tl->fc));
vsb_finish(tl->fh);
- /* Grind it through cc(1) */
- of = vcc_CallCc(vsb_data(tl->fh), sb);
+ of = strdup(vsb_data(tl->fh));
+ AN(of);
/* done */
return (vcc_DestroyTokenList(tl, of));
More information about the varnish-commit
mailing list