[master] c22c39a8a Get rid of the hardcoded lists of programs and vmods, instead read the actual directories and filter on prefix strings.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Feb 10 12:29:07 UTC 2020
commit c22c39a8a9ec69665ad8d77ced735951ecae2b47
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 10 12:27:42 2020 +0000
Get rid of the hardcoded lists of programs and vmods, instead
read the actual directories and filter on prefix strings.
diff --git a/bin/varnishtest/programs.h b/bin/varnishtest/programs.h
deleted file mode 100644
index 05c4f136d..000000000
--- a/bin/varnishtest/programs.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * Copyright (c) 2013 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-VTC_PROG(haproxy)
-VTC_PROG(varnishadm)
-VTC_PROG(varnishd)
-VTC_PROG(varnishhist)
-VTC_PROG(varnishlog)
-VTC_PROG(varnishncsa)
-VTC_PROG(varnishstat)
-VTC_PROG(varnishtest)
-VTC_PROG(varnishtop)
-#undef VTC_PROG
diff --git a/bin/varnishtest/vmods.h b/bin/varnishtest/vmods.h
deleted file mode 100644
index 2af7644d9..000000000
--- a/bin/varnishtest/vmods.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * Copyright (c) 2013 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-VTC_VMOD(std)
-VTC_VMOD(debug)
-VTC_VMOD(directors)
-VTC_VMOD(purge)
-VTC_VMOD(vtc)
-VTC_VMOD(blob)
-VTC_VMOD(unix)
-VTC_VMOD(proxy)
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index b0cc128b2..6b7ebf0a6 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -35,12 +35,14 @@
#include <sys/wait.h>
#include <ctype.h>
+#include <dirent.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include "vtc.h"
@@ -458,14 +460,44 @@ start_test(void)
* Find the abs path to top of source dir from Makefile, if that
* fails, fall back on "../../"
*
- * Set path to all programs build directories
+ * Set PATH to all programs build directories
+ * Set vmod_path to all vmods build directories
*
*/
+static void
+build_path(const char *topbuilddir, const char *subdir,
+ const char *pfx, const char *sfx, struct vsb *vsb)
+{
+ char buf[PATH_MAX];
+ DIR *dir;
+ struct dirent *de;
+ struct stat st;
+ const char *sep = "";
+
+ bprintf(buf, "%s/%s/", topbuilddir, subdir);
+ dir = opendir(buf);
+ XXXAN(dir);
+ while (1) {
+ de = readdir(dir);
+ if (de == NULL)
+ break;
+ if (strncmp(de->d_name, pfx, strlen(pfx)))
+ continue;
+ bprintf(buf, "%s/%s/%s", topbuilddir, subdir, de->d_name);
+ if (!stat(buf, &st) && S_ISDIR(st.st_mode)) {
+ VSB_cat(vsb, sep);
+ VSB_cat(vsb, buf);
+ VSB_cat(vsb, sfx);
+ sep = ":";
+ }
+ }
+ AZ(closedir(dir));
+}
+
static void
i_mode(void)
{
- const char *sep;
struct vsb *vsb;
char *p, *q;
char *topbuild;
@@ -511,39 +543,27 @@ i_mode(void)
}
AN(topbuild);
extmacro_def("topbuild", "%s", topbuild);
+
/*
* Build $PATH which can find all programs in the build tree
*/
+ VSB_clear(vsb);
VSB_cat(vsb, "PATH=");
- sep = "";
-#define VTC_PROG(l) \
- do { \
- VSB_printf(vsb, "%s%s/bin/" #l, sep, topbuild); \
- sep = ":"; \
- } while (0);
-#include "programs.h"
-
+ build_path(topbuild, "bin", "varnish", "", vsb);
VSB_printf(vsb, ":%s", getenv("PATH"));
AZ(VSB_finish(vsb));
-
AZ(putenv(strdup(VSB_data(vsb))));
/*
* Build vmod_path which can find all VMODs in the build tree
*/
+
VSB_clear(vsb);
- sep = "";
-#define VTC_VMOD(l) \
- do { \
- VSB_printf(vsb, "%s%s/lib/libvmod_" #l "/.libs", \
- sep, topbuild); \
- sep = ":"; \
- } while (0);
-#include "vmods.h"
-#undef VTC_VMOD
+ build_path(topbuild, "lib", "libvmod_", "/.libs", vsb);
AZ(VSB_finish(vsb));
vmod_path = strdup(VSB_data(vsb));
AN(vmod_path);
+
free(topbuild);
VSB_destroy(&vsb);
More information about the varnish-commit
mailing list