Skip to contentSkip to conversation

configurator: Support for Windows and MSVC

PATCH Superseded Kevin Locke 4 participants 78 messages Sep 19, 2016 – Dec 2, 2016 Kbuild

lore
Share & tools
lore
#1 lore raw

PATCH 1/9 configurator: Replace unlink with remove

In reply to Kevin Locke

Although Windows provides unlink, using it adds complication due to the lack of unistd.h which must be included to define the function on POSIX systems. Instead, use remove, which C89 requires to be in stdio.h.

---
 tools/configurator/configurator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/configurator/configurator.c +2 -2
index 67dadc6..e322c76 100644
@@ -639,8 +639,8 @@ int main(int argc, const char *argv[])
 		run_test(cmd, &tests[i]);
 	free(cmd);
 
-	unlink(OUTPUT_FILE);
-	unlink(INPUT_FILE);
+	remove(OUTPUT_FILE);
+	remove(INPUT_FILE);
 
 	printf("/* Generated by CCAN configurator */\n"
 	       "#ifndef CCAN_CONFIG_H\n"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#3 lore raw

PATCH 2/9 configurator: Reimplement run using popen

In reply to Kevin Locke

Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

---
 tools/configurator/configurator.c | 77 +++++++++++++++------------------------
 1 file changed, 29 insertions(+), 48 deletions(-)
tools/configurator/configurator.c +29 -48
index e322c76..9817fcd 100644
@@ -24,14 +24,14 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <err.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
+
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 
@@ -367,20 +367,19 @@ static struct test tests[] = {
 	},
 };
 
-static char *grab_fd(int fd)
+static char *grab_stream(FILE *file)
 {
-	int ret;
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
 
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread(buffer+size, 1, max - size, file)) == max - size) {
 		size += ret;
-		if (size == max)
-			buffer = realloc(buffer, max *= 2);
+		buffer = realloc(buffer, max *= 2);
 	}
-	if (ret < 0)
+	size += ret;
+	if (ferror(file))
 		err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
@@ -388,43 +387,25 @@ static char *grab_fd(int fd)
 
 static char *run(const char *cmd, int *exitstatus)
 {
-	pid_t pid;
-	int p[2];
+	static const char redir[] = " 2>&1";
+	size_t cmdlen;
+	char *cmdredir;
+	FILE *cmdout;
 	char *ret;
-	int status;
 
-	if (pipe(p) != 0)
-		err(1, "creating pipe");
-
-	pid = fork();
-	if (pid == -1)
-		err(1, "forking");
-
-	if (pid == 0) {
-		if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
-		    || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
-		    || close(p[0]) != 0
-		    || close(STDIN_FILENO) != 0
-		    || open("/dev/null", O_RDONLY) != STDIN_FILENO)
-			exit(128);
-
-		status = system(cmd);
-		if (WIFEXITED(status))
-			exit(WEXITSTATUS(status));
-		/* Here's a hint... */
-		exit(128 + WTERMSIG(status));
-	}
+	cmdlen = strlen(cmd);
+	cmdredir = malloc(cmdlen + sizeof(redir));
+	memcpy(cmdredir, cmd, cmdlen);
+	memcpy(cmdredir + cmdlen, redir, sizeof(redir));
+
+	cmdout = popen(cmdredir, "r");
+	if (!cmdout)
+		err(1, "popen \"%s\"", cmdredir);
+
+	free(cmdredir);
 
-	close(p[1]);
-	ret = grab_fd(p[0]);
-	/* This shouldn't fail... */
-	if (waitpid(pid, &status, 0) != pid)
-		err(1, "Failed to wait for child");
-	close(p[0]);
-	if (WIFEXITED(status))
-		*exitstatus = WEXITSTATUS(status);
-	else
-		*exitstatus = -WTERMSIG(status);
+	ret = grab_stream(cmdout);
+	*exitstatus = pclose(cmdout);
 	return ret;
 }
 
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#12 lore raw

PATCH 5/9 configurator: Mark non-Windows tests MAY_NOT_COMPILE

In reply to Kevin Locke

Several of the EXECUTABLE tests depend on headers not available on Windows. Mark these tests MAY_NOT_COMPILE to handle this.

---
 tools/configurator/configurator.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/configurator/configurator.c +6 -6
index e95fd70..0307635 100644
@@ -72,7 +72,7 @@ struct test {
 };
 
 static struct test tests[] = {
-	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "int main(void) {\n"
 	  "	return sizeof(off_t) == 4 ? 0 : 1;\n"
@@ -177,7 +177,7 @@ static struct test tests[] = {
 	{ "HAVE_COMPOUND_LITERALS", INSIDE_MAIN, NULL, NULL,
 	  "int *foo = (int[]) { 1, 2, 3, 4 };\n"
 	  "return foo[0] ? 0 : 1;" },
-	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -198,7 +198,7 @@ static struct test tests[] = {
 	  "	if (arg == 4)\n"
 	  "		warnx(\"warn %u\", arg);\n"
 	  "}\n" },
-	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_32BIT_OFF_T", NULL,
 	  "#define _FILE_OFFSET_BITS 64\n"
 	  "#include <sys/types.h>\n"
@@ -244,7 +244,7 @@ static struct test tests[] = {
 	  "static void *func(int fd) {\n"
 	  "	return mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);\n"
 	  "}" },
-	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -329,7 +329,7 @@ static struct test tests[] = {
 	  "-Werror -fopenmp" },
 	{ "HAVE_VALGRIND_MEMCHECK_H", OUTSIDE_MAIN, NULL, NULL,
 	  "#include <valgrind/memcheck.h>\n" },
-	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  NULL, NULL,
 	  "#include <ucontext.h>\n"
 	  "static int x = 0;\n"
@@ -350,7 +350,7 @@ static struct test tests[] = {
 	  "	return (x == 3) ? 0 : 1;\n"
 	  "}\n"
 	},
-	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_UCONTEXT", NULL,
 	  "#include <stddef.h>\n"
 	  "#include <ucontext.h>\n"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#14 lore raw

PATCH 6/9 configurator: Print test source without cat

In reply to Kevin Locke

Windows does not provide cat. Instead, copy the test source to stdout using the file stream to which it was written.

---
 tools/configurator/configurator.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
tools/configurator/configurator.c +23 -5
index 0307635..0386930 100644
@@ -422,6 +422,22 @@ static void errx(int status, const char *fmt, ...)
 	va_end(ap);
 }
 
+static size_t fcopy(FILE *fsrc, FILE *fdst)
+{
+	char buffer[BUFSIZ];
+	size_t rsize, wsize;
+	size_t copied = 0;
+
+	while ((rsize = fread(buffer, 1, BUFSIZ, fsrc)) > 0) {
+		wsize = fwrite(buffer, 1, rsize, fdst);
+		copied += wsize;
+		if (wsize != rsize)
+			break;
+	}
+
+	return copied;
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -545,7 +561,7 @@ static bool run_test(const char *cmd, struct test *test)
 		}
 	}
 
-	outf = fopen(INPUT_FILE, "w");
+	outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w");
 	if (!outf)
 		err(1, "creating %s", INPUT_FILE);
 
@@ -576,11 +592,13 @@ static bool run_test(const char *cmd, struct test *test)
 		abort();
 
 	}
-	fclose(outf);
 
-	if (verbose > 1)
-		if (system("cat " INPUT_FILE) == -1)
-			;
+	if (verbose > 1) {
+		fseek(outf, 0, SEEK_SET);
+		fcopy(outf, stdout);
+	}
+
+	fclose(outf);
 
 	newcmd = strdup(cmd);
 
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#16 lore raw

PATCH 7/9 configurator: Fix compiler warning with compare

In reply to Kevin Locke

Visual Studio prints warning C4706 "assignment within conditional expression" when there is an assignment without a comparison in a conditional expression. Therefore, to silence the warning, add an explicit comparison.

---
 tools/configurator/configurator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/configurator/configurator.c +1 -1
index 0386930..0c30aff 100644
@@ -535,7 +535,7 @@ static bool run_test(const char *cmd, struct test *test)
 		char *dep;
 
 		/* Space-separated dependencies, could be ! for inverse. */
-		while ((len = strcspn(deps, " "))) {
+		while ((len = strcspn(deps, " ")) != 0) {
 			bool positive = true;
 			if (deps[len]) {
 				dep = strdup(deps);
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#0 lore raw

cover configurator: Support for Windows and MSVC

Hi all,

This patch series adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle. For me, this patch series is sufficient, so I don't have any further plans for changes to other files or the build system at the moment.

The two patches that are particularly likely to raise objections are patch 3 and 8:

Patch 3 adds a copy of the err.h functions used by configurator to work around the lack of err.h on Windows. If this is too much code to lump into configurator.c, I can split it out (and copy err.{c,h} verbatim from musl) or call fprintf+exit directly.

Patch 8 adds the output cflag (-o) to DEFAULT_CFLAGS and the expected configurator cflags argument. This changes both the configurator API and the config.h API and will break existing code which depend on these. If that is unacceptable, I'd be open to implementing a backwards-compatible alternative. One idea would be to add an --output-cflag option to configurator, although it will require quite a bit of argument parsing code. I'm open to other alternatives as well.

Thanks for considering,
Kevin

Kevin Locke (9):
configurator: Replace unlink with remove
configurator: Reimplement run using popen
configurator: Inline err.h functions from musl libc
configurator: Use native directory separator
configurator: Mark non-Windows tests MAY_NOT_COMPILE
configurator: Print test source without cat
configurator: Fix compiler warning with compare
configurator: Pass output cflag to configurator
configurator: DEFAULT_{COMPILER,FLAGS} for MSVC

 Makefile                          |   2 +-
 tools/configurator/configurator.c | 197 +++++++++++++++++++++++++-------------
 2 files changed, 131 insertions(+), 68 deletions(-)
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#10 lore raw

PATCH 4/9 configurator: Use native directory separator

Although Windows APIs generally permit "/" or "\\" for directory separators in paths, cmd.exe does not recognize "./" when invoking executables using a relative path and prints the following error:

'.' is not recognized as an internal or external command, operable program or batch file.

Therefore, use "\\" when invoking tests on Windows.

---
 tools/configurator/configurator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +7 -1
index 9dcf307..e95fd70 100644
@@ -41,6 +41,12 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+#ifdef _WIN32
+#define DIR_SEP   "\\"
+#else
+#define DIR_SEP   "/"
+#endif
+
 static const char *progname = "";
 static int verbose;
 
@@ -615,7 +621,7 @@ static bool run_test(const char *cmd, struct test *test)
 		free(output);
 		/* We run INSIDE_MAIN tests for sanity checking. */
 		if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
-			output = run("./" OUTPUT_FILE, &status);
+			output = run("." DIR_SEP OUTPUT_FILE, &status);
 			if (!(test->style & EXECUTE) && status != 0)
 				errx(1, "Test for %s failed with %i:\n%s",
 				     test->name, status, output);
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#22 lore raw

PATCH 9/9 configurator: DEFAULT_{COMPILER, FLAGS} for MSVC

In reply to Kevin Locke

When compiling with Visual Studio, use default compiler name and flags which are likely to work with the known-available compiler.

This is also a convenience for users who may not know what arguments cl.exe may need to compile the tests.

---
 tools/configurator/configurator.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/configurator/configurator.c +6 -0
index 820ccf7..4f08701 100644
@@ -35,8 +35,14 @@
 #define pclose _pclose
 #endif
 
+#ifdef _MSC_VER
+#define DEFAULT_COMPILER "cl"
+#define DEFAULT_FLAGS "/nologo /Zi /W4 " \
+	"/D_CRT_NONSTDC_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /Fe:"
+#else
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -o"
+#endif
 
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#7 lore raw

PATCH 3/9 configurator: Inline err.h functions from musl libc

In reply to Kevin Locke

Since we can't use HAVE_ERR_H in configurator, provide a definition for the err.h functions used. The version provided is the one from musl libc, since it is concise and shares the MIT License with configurator.

---
 tools/configurator/configurator.c | 54 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +53 -1
index 9817fcd..9dcf307 100644
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Rusty Russell <[email protected]>.  MIT license.
  *
+ * err, errx, verr, verrx, vwarn, vwarnx functions from musl libc
+ * Copyright 2005-2013 Rich Felker.  MIT license.
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -22,9 +25,9 @@
  * THE SOFTWARE.
  */
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <err.h>
 #include <string.h>
 
 #ifdef _MSC_VER
@@ -38,6 +41,7 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+static const char *progname = "";
 static int verbose;
 
 enum test_style {
@@ -367,6 +371,51 @@ static struct test tests[] = {
 	},
 };
 
+static void vwarn(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) {
+		vfprintf(stderr, fmt, ap);
+		fputs (": ", stderr);
+	}
+	perror(0);
+}
+
+static void vwarnx(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) vfprintf(stderr, fmt, ap);
+	putc('\n', stderr);
+}
+
+static void verr(int status, const char *fmt, va_list ap)
+{
+	vwarn(fmt, ap);
+	exit(status);
+}
+
+static void verrx(int status, const char *fmt, va_list ap)
+{
+	vwarnx(fmt, ap);
+	exit(status);
+}
+
+static void err(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verr(status, fmt, ap);
+	va_end(ap);
+}
+
+static void errx(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verrx(status, fmt, ap);
+	va_end(ap);
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -593,6 +642,9 @@ int main(int argc, const char *argv[])
 	const char *default_args[]
 		= { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
 
+	if (argc > 0)
+		progname = argv[0];
+
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#18 lore raw

PATCH 8/9 configurator: Pass output cflag to configurator

In reply to Kevin Locke

Unfortunately, not all compilers support -o as a command-line option for specifying the output file. Visual Studio cl.exe issues warning D9035 when -o is given, which is detected as a compile warning by the configurator.

To support such compilers, pass the output flag as the last flag to the configurator.

This is a breaking change. Existing scripts which pass flags to the compiler must be modified to add "-o" as the last flag. As noted in the cover letter for this patch series, I'm open to considering alternatives if this is unacceptable.

---
 Makefile                          | 2 +-
 tools/configurator/configurator.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Makefile +1 -1
index 127b875..f36ccb5 100644
@@ -89,7 +89,7 @@ FORCE:
 
 # Ensure we don't end up with empty file if configurator fails!
 config.h: tools/configurator/configurator Makefile Makefile-ccan
-	tools/configurator/configurator $(CC) $(CCAN_CFLAGS) > [email protected] && mv [email protected] $@
+	tools/configurator/configurator $(CC) $(CCAN_CFLAGS) -o > [email protected] && mv [email protected] $@
 
 include tools/Makefile
 -include inter-depends
tools/configurator/configurator.c +3 -3
index 0c30aff..820ccf7 100644
@@ -36,7 +36,7 @@
 #endif
 
 #define DEFAULT_COMPILER "cc"
-#define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
+#define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -o"
 
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
@@ -672,7 +672,7 @@ int main(int argc, const char *argv[])
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
-			       "  <compiler> <flags> will have \"-o <outfile> <infile.c>\" appended\n"
+			       "  <compiler> <flags> will have \"<outfile> <infile.c>\" appended\n"
 			       "Default: %s %s\n",
 			       DEFAULT_COMPILER, DEFAULT_FLAGS);
 			exit(0);
@@ -691,7 +691,7 @@ int main(int argc, const char *argv[])
 	if (argc == 1)
 		argv = default_args;
 
-	cmd = connect_args(argv, " -o " OUTPUT_FILE " " INPUT_FILE);
+	cmd = connect_args(argv, OUTPUT_FILE " " INPUT_FILE);
 	for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
 		run_test(cmd, &tests[i]);
 	free(cmd);
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] configurator: Replace unlink with remove

In reply to Kevin Locke
Quoted 5 lines · Kevin Locke

Although Windows provides unlink, using it adds complication due to the lack of unistd.h which must be included to define the function on POSIX systems. Instead, use remove, which C89 requires to be in stdio.h.

Quoted 19 lines
---
 tools/configurator/configurator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/configurator/configurator.c +2 -2
index 67dadc6..e322c76 100644
@@ -639,8 +639,8 @@ int main(int argc, const char *argv[])
 		run_test(cmd, &tests[i]);
 	free(cmd);
 
-	unlink(OUTPUT_FILE);
-	unlink(INPUT_FILE);
+	remove(OUTPUT_FILE);
+	remove(INPUT_FILE);
 
 	printf("/* Generated by CCAN configurator */\n"
 	       "#ifndef CCAN_CONFIG_H\n"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#4 lore raw

Re: [PATCH 2/9] configurator: Reimplement run using popen

In reply to Kevin Locke
Quoted 3 lines · Kevin Locke

Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

Concept looks good, one little wart.

Quoted 38 lines
---
 tools/configurator/configurator.c | 77 +++++++++++++++------------------------
 1 file changed, 29 insertions(+), 48 deletions(-)
tools/configurator/configurator.c +6 -7
index e322c76..9817fcd 100644
@@ -24,14 +24,14 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <err.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
+
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 
@@ -367,20 +367,19 @@ static struct test tests[] = {
 	},
 };
 
-static char *grab_fd(int fd)
+static char *grab_stream(FILE *file)
 {
-	int ret;

tools/configurator/configurator.c static struct test tests[] = { · line 377

Quoted 10 lines
tools/configurator/configurator.c +4 -4
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
 
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread(buffer+size, 1, max - size, file)) == max - size) {

This assumes that fread() will never return a short read except on EOF or error. I expect that will be true in practice for regular files, but I'm not sure if it's a good idea to rely on it.

Quoted 71 lines
tools/configurator/configurator.c +19 -37
 		size += ret;
-		if (size == max)
-			buffer = realloc(buffer, max *= 2);
+		buffer = realloc(buffer, max *= 2);
 	}
-	if (ret < 0)
+	size += ret;
+	if (ferror(file))
 		err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
@@ -388,43 +387,25 @@ static char *grab_fd(int fd)
 
 static char *run(const char *cmd, int *exitstatus)
 {
-	pid_t pid;
-	int p[2];
+	static const char redir[] = " 2>&1";
+	size_t cmdlen;
+	char *cmdredir;
+	FILE *cmdout;
 	char *ret;
-	int status;
 
-	if (pipe(p) != 0)
-		err(1, "creating pipe");
-
-	pid = fork();
-	if (pid == -1)
-		err(1, "forking");
-
-	if (pid == 0) {
-		if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
-		    || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
-		    || close(p[0]) != 0
-		    || close(STDIN_FILENO) != 0
-		    || open("/dev/null", O_RDONLY) != STDIN_FILENO)
-			exit(128);
-
-		status = system(cmd);
-		if (WIFEXITED(status))
-			exit(WEXITSTATUS(status));
-		/* Here's a hint... */
-		exit(128 + WTERMSIG(status));
-	}
+	cmdlen = strlen(cmd);
+	cmdredir = malloc(cmdlen + sizeof(redir));
+	memcpy(cmdredir, cmd, cmdlen);
+	memcpy(cmdredir + cmdlen, redir, sizeof(redir));
+
+	cmdout = popen(cmdredir, "r");
+	if (!cmdout)
+		err(1, "popen \"%s\"", cmdredir);
+
+	free(cmdredir);
 
-	close(p[1]);
-	ret = grab_fd(p[0]);
-	/* This shouldn't fail... */
-	if (waitpid(pid, &status, 0) != pid)
-		err(1, "Failed to wait for child");
-	close(p[0]);
-	if (WIFEXITED(status))
-		*exitstatus = WEXITSTATUS(status);
-	else
-		*exitstatus = -WTERMSIG(status);
+	ret = grab_stream(cmdout);
+	*exitstatus = pclose(cmdout);
 	return ret;
 }
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#8 lore raw

Re: [PATCH 3/9] configurator: Inline err.h functions from musl libc

In reply to Kevin Locke
Quoted 5 lines · Kevin Locke

Since we can't use HAVE_ERR_H in configurator, provide a definition for the err.h functions used. The version provided is the one from musl libc, since it is concise and shares the MIT License with configurator.

Right, so this is a general problem of how do we make the configurator itself sufficiently portable, since it hasn't yet worked out the portbility macros.

Personally, I think duplicating these here is an acceptable workaround. Rusty, any opinion?

Quoted 99 lines
---
 tools/configurator/configurator.c | 54 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +53 -1
index 9817fcd..9dcf307 100644
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Rusty Russell <[email protected]>.  MIT license.
  *
+ * err, errx, verr, verrx, vwarn, vwarnx functions from musl libc
+ * Copyright 2005-2013 Rich Felker.  MIT license.
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -22,9 +25,9 @@
  * THE SOFTWARE.
  */
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <err.h>
 #include <string.h>
 
 #ifdef _MSC_VER
@@ -38,6 +41,7 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+static const char *progname = "";
 static int verbose;
 
 enum test_style {
@@ -367,6 +371,51 @@ static struct test tests[] = {
 	},
 };
 
+static void vwarn(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) {
+		vfprintf(stderr, fmt, ap);
+		fputs (": ", stderr);
+	}
+	perror(0);
+}
+
+static void vwarnx(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) vfprintf(stderr, fmt, ap);
+	putc('\n', stderr);
+}
+
+static void verr(int status, const char *fmt, va_list ap)
+{
+	vwarn(fmt, ap);
+	exit(status);
+}
+
+static void verrx(int status, const char *fmt, va_list ap)
+{
+	vwarnx(fmt, ap);
+	exit(status);
+}
+
+static void err(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verr(status, fmt, ap);
+	va_end(ap);
+}
+
+static void errx(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verrx(status, fmt, ap);
+	va_end(ap);
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -593,6 +642,9 @@ int main(int argc, const char *argv[])
 	const char *default_args[]
 		= { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
 
+	if (argc > 0)
+		progname = argv[0];
+
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#23 lore raw
In reply to Kevin Locke
Quoted 8 lines · Kevin Locke

Hi all,

This patch series adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle. For me, this patch series is sufficient, so I don't have any further plans for changes to other files or the build system at the moment.

First, thanks for this. ccan isn't supposed to be platform specific, but it kind of is at the moment, simply because most of the contributions have been from Linux developers. I'm really happy to see some work to make it useful on different platforms.

Second, because I'm not and have never been a Windows dev, my ability to review these is limited - so I'm inclined to apply anything that doesn't break builds on Linux / POSIX.

Third, because most of the main ccan contributors are not Windows devs, I'm a bit worried about bitrot. If you can think of any way of making some kind of automated smoke test form builds on Windows, that would be terrific. Otherwise, I guess we'll just hope for the best.

Quoted 34 lines

The two patches that are particularly likely to raise objections are patch 3 and 8:

Patch 3 adds a copy of the err.h functions used by configurator to work around the lack of err.h on Windows. If this is too much code to lump into configurator.c, I can split it out (and copy err.{c,h} verbatim from musl) or call fprintf+exit directly.

Patch 8 adds the output cflag (-o) to DEFAULT_CFLAGS and the expected configurator cflags argument. This changes both the configurator API and the config.h API and will break existing code which depend on these. If that is unacceptable, I'd be open to implementing a backwards-compatible alternative. One idea would be to add an --output-cflag option to configurator, although it will require quite a bit of argument parsing code. I'm open to other alternatives as well.

Thanks for considering,
Kevin

Kevin Locke (9):
configurator: Replace unlink with remove
configurator: Reimplement run using popen
configurator: Inline err.h functions from musl libc
configurator: Use native directory separator
configurator: Mark non-Windows tests MAY_NOT_COMPILE
configurator: Print test source without cat
configurator: Fix compiler warning with compare
configurator: Pass output cflag to configurator
configurator: DEFAULT_{COMPILER,FLAGS} for MSVC

 Makefile                          |   2 +-
 tools/configurator/configurator.c | 197 +++++++++++++++++++++++++-------------
 2 files changed, 131 insertions(+), 68 deletions(-)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

Reviewed-by on v1 4/9
#11 lore raw

Re: [PATCH 4/9] configurator: Use native directory separator

In reply to Kevin Locke
Quoted 10 lines · Kevin Locke

Although Windows APIs generally permit "/" or "\\" for directory separators in paths, cmd.exe does not recognize "./" when invoking executables using a relative path and prints the following error:

'.' is not recognized as an internal or external command, operable program or batch file.

Therefore, use "\\" when invoking tests on Windows.

A bit ugly, but I think necessarily so to accomplish the goal.

Quoted 30 lines
---
 tools/configurator/configurator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +7 -1
index 9dcf307..e95fd70 100644
@@ -41,6 +41,12 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+#ifdef _WIN32
+#define DIR_SEP   "\\"
+#else
+#define DIR_SEP   "/"
+#endif
+
 static const char *progname = "";
 static int verbose;
 
@@ -615,7 +621,7 @@ static bool run_test(const char *cmd, struct test *test)
 		free(output);
 		/* We run INSIDE_MAIN tests for sanity checking. */
 		if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
-			output = run("./" OUTPUT_FILE, &status);
+			output = run("." DIR_SEP OUTPUT_FILE, &status);
 			if (!(test->style & EXECUTE) && status != 0)
 				errx(1, "Test for %s failed with %i:\n%s",
 				     test->name, status, output);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

Reviewed-by on v1 5/9
#13 lore raw

Re: [PATCH 5/9] configurator: Mark non-Windows tests MAY_NOT_COMPILE

In reply to Kevin Locke
Quoted 4 lines · Kevin Locke

Several of the EXECUTABLE tests depend on headers not available on Windows. Mark these tests MAY_NOT_COMPILE to handle this.

Quoted 62 lines
---
 tools/configurator/configurator.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/configurator/configurator.c +6 -6
index e95fd70..0307635 100644
@@ -72,7 +72,7 @@ struct test {
 };
 
 static struct test tests[] = {
-	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "int main(void) {\n"
 	  "	return sizeof(off_t) == 4 ? 0 : 1;\n"
@@ -177,7 +177,7 @@ static struct test tests[] = {
 	{ "HAVE_COMPOUND_LITERALS", INSIDE_MAIN, NULL, NULL,
 	  "int *foo = (int[]) { 1, 2, 3, 4 };\n"
 	  "return foo[0] ? 0 : 1;" },
-	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -198,7 +198,7 @@ static struct test tests[] = {
 	  "	if (arg == 4)\n"
 	  "		warnx(\"warn %u\", arg);\n"
 	  "}\n" },
-	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_32BIT_OFF_T", NULL,
 	  "#define _FILE_OFFSET_BITS 64\n"
 	  "#include <sys/types.h>\n"
@@ -244,7 +244,7 @@ static struct test tests[] = {
 	  "static void *func(int fd) {\n"
 	  "	return mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);\n"
 	  "}" },
-	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -329,7 +329,7 @@ static struct test tests[] = {
 	  "-Werror -fopenmp" },
 	{ "HAVE_VALGRIND_MEMCHECK_H", OUTSIDE_MAIN, NULL, NULL,
 	  "#include <valgrind/memcheck.h>\n" },
-	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  NULL, NULL,
 	  "#include <ucontext.h>\n"
 	  "static int x = 0;\n"
@@ -350,7 +350,7 @@ static struct test tests[] = {
 	  "	return (x == 3) ? 0 : 1;\n"
 	  "}\n"
 	},
-	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_UCONTEXT", NULL,
 	  "#include <stddef.h>\n"
 	  "#include <ucontext.h>\n"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#15 lore raw

Re: [PATCH 6/9] configurator: Print test source without cat

In reply to Kevin Locke
Quoted 17 lines · Kevin Locke

Windows does not provide cat. Instead, copy the test source to stdout using the file stream to which it was written.

---
 tools/configurator/configurator.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
tools/configurator/configurator.c +1 -0
index 0307635..0386930 100644
@@ -422,6 +422,22 @@ static void errx(int status, const char *fmt, ...)
 	va_end(ap);
 }
 
+static size_t fcopy(FILE *fsrc, FILE *fdst)

tools/configurator/configurator.c static void errx(int status, const char *fmt, ...) · line 435

Quoted 10 lines
tools/configurator/configurator.c +10 -0
+{
+	char buffer[BUFSIZ];
+	size_t rsize, wsize;
+	size_t copied = 0;
+
+	while ((rsize = fread(buffer, 1, BUFSIZ, fsrc)) > 0) {
+		wsize = fwrite(buffer, 1, rsize, fdst);
+		copied += wsize;
+		if (wsize != rsize)
+			break;

Similar to 2/9 you're assuming you'll never get a short fwrite() here. Since the output stream is very likely to be a terminal in this case, that seems a lot more likely to break than just assuming no short reads on fread(). I think this one really does need to handle short writes here.

Quoted 35 lines
tools/configurator/configurator.c +12 -5
+	}
+
+	return copied;
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -545,7 +561,7 @@ static bool run_test(const char *cmd, struct test *test)
 		}
 	}
 
-	outf = fopen(INPUT_FILE, "w");
+	outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w");
 	if (!outf)
 		err(1, "creating %s", INPUT_FILE);
 
@@ -576,11 +592,13 @@ static bool run_test(const char *cmd, struct test *test)
 		abort();
 
 	}
-	fclose(outf);
 
-	if (verbose > 1)
-		if (system("cat " INPUT_FILE) == -1)
-			;
+	if (verbose > 1) {
+		fseek(outf, 0, SEEK_SET);
+		fcopy(outf, stdout);
+	}
+
+	fclose(outf);
 
 	newcmd = strdup(cmd);
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#17 lore raw

Re: [PATCH 7/9] configurator: Fix compiler warning with compare

In reply to Kevin Locke
Quoted 6 lines · Kevin Locke

Visual Studio prints warning C4706 "assignment within conditional expression" when there is an assignment without a comparison in a conditional expression. Therefore, to silence the warning, add an explicit comparison.

Quoted 17 lines
---
 tools/configurator/configurator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/configurator/configurator.c +1 -1
index 0386930..0c30aff 100644
@@ -535,7 +535,7 @@ static bool run_test(const char *cmd, struct test *test)
 		char *dep;
 
 		/* Space-separated dependencies, could be ! for inverse. */
-		while ((len = strcspn(deps, " "))) {
+		while ((len = strcspn(deps, " ")) != 0) {
 			bool positive = true;
 			if (deps[len]) {
 				dep = strdup(deps);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#19 lore raw

Re: [PATCH 8/9] configurator: Pass output cflag to configurator

In reply to Kevin Locke
Quoted 8 lines · Kevin Locke

Unfortunately, not all compilers support -o as a command-line option for specifying the output file. Visual Studio cl.exe issues warning D9035 when -o is given, which is detected as a compile warning by the configurator.

To support such compilers, pass the output flag as the last flag to the configurator.

Quoted 6 lines

This is a breaking change. Existing scripts which pass flags to the compiler must be modified to add "-o" as the last flag. As noted in the cover letter for this patch series, I'm open to considering alternatives if this is unacceptable.

So, as it stands, this change completely breaks ccanlint on POSIX, which is not ok. Specifically it looks like the problem is that the DEFAULT_FLAGS from the configurator make it into CCAN_CFLAGS in config.h. ccanlint then tries to add further options and its own -o to the end of that, which isn't going to work.

In short, I think the problem is that ccanlint needs fixes to work with MSVC (and possibly anything much else apart from gcc). I think we need to look at how to fix that and the configurator together with each other.

Not having working ccanlint on Windows seems like a pretty big, since its the main tool for testing ccan, amongst other things.

Quoted 49 lines
---
 Makefile                          | 2 +-
 tools/configurator/configurator.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Makefile +1 -1
index 127b875..f36ccb5 100644
@@ -89,7 +89,7 @@ FORCE:
 
 # Ensure we don't end up with empty file if configurator fails!
 config.h: tools/configurator/configurator Makefile Makefile-ccan
-	tools/configurator/configurator $(CC) $(CCAN_CFLAGS) > [email protected] && mv [email protected] $@
+	tools/configurator/configurator $(CC) $(CCAN_CFLAGS) -o > [email protected] && mv [email protected] $@
 
 include tools/Makefile
 -include inter-depends
tools/configurator/configurator.c +3 -3
index 0c30aff..820ccf7 100644
@@ -36,7 +36,7 @@
 #endif
 
 #define DEFAULT_COMPILER "cc"
-#define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
+#define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -o"
 
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
@@ -672,7 +672,7 @@ int main(int argc, const char *argv[])
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
-			       "  <compiler> <flags> will have \"-o <outfile> <infile.c>\" appended\n"
+			       "  <compiler> <flags> will have \"<outfile> <infile.c>\" appended\n"
 			       "Default: %s %s\n",
 			       DEFAULT_COMPILER, DEFAULT_FLAGS);
 			exit(0);
@@ -691,7 +691,7 @@ int main(int argc, const char *argv[])
 	if (argc == 1)
 		argv = default_args;
 
-	cmd = connect_args(argv, " -o " OUTPUT_FILE " " INPUT_FILE);
+	cmd = connect_args(argv, OUTPUT_FILE " " INPUT_FILE);
 	for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
 		run_test(cmd, &tests[i]);
 	free(cmd);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#24 lore raw
In reply to David Gibson

Hi David,

Thank you for taking the time to review these patches, especially for a platform that you don't have a strong stake in. I really appreciate it.

Quoted 13 lines · David Gibson
Quoted 6 lines · Kevin Locke

This patch series adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle. For me, this patch series is sufficient, so I don't have any further plans for changes to other files or the build system at the moment.

First, thanks for this. ccan isn't supposed to be platform specific, but it kind of is at the moment, simply because most of the contributions have been from Linux developers. I'm really happy to see some work to make it useful on different platforms.

Quoted 8 lines

Second, because I'm not and have never been a Windows dev, my ability to review these is limited - so I'm inclined to apply anything that doesn't break builds on Linux / POSIX.

Third, because most of the main ccan contributors are not Windows devs, I'm a bit worried about bitrot. If you can think of any way of making some kind of automated smoke test form builds on Windows, that would be terrific. Otherwise, I guess we'll just hope for the best.

I think that's a very legitimate concern. I'm not a frequent Windows developer myself, but had a need for a current project. I've tried to minimize the amount of Windows-specific code, with good results I think, but that's obviously not much of a guarantee that it won't rot or subtly break on Windows going forward.

I've seen appveyor.com used quite often for Windows CI, and it is free for FOSS projects. I'd be happy to work up some basic smoke tests if it seems like that might be useful and not too much of a maintenance burden. Let me know what you think.

Thanks again,
Kevin
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#5 lore raw

Re: [PATCH 2/9] configurator: Reimplement run using popen

In reply to David Gibson
Quoted 17 lines · David Gibson
Quoted 3 lines · Kevin Locke

Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

Concept looks good, one little wart.

Quoted 10 lines

[...]

tools/configurator/configurator.c +2 -3
-static char *grab_fd(int fd)
+static char *grab_stream(FILE *file)
 {
-	int ret;
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
Quoted 10 lines

tools/configurator/configurator.c static struct test tests[] = { · line 377

Quoted 6 lines
tools/configurator/configurator.c +3 -3
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread(buffer+size, 1, max - size, file)) == max - size) {

This assumes that fread() will never return a short read except on EOF or error. I expect that will be true in practice for regular files, but I'm not sure if it's a good idea to rely on it.

Interesting. I was under the impression that the fread couldn't short read. POSIX describes the return value as "the number of elements successfully read which is less than nitems only if a read error or end-of-file is encountered."[1] Now that I think about it, I suppose EINTR could be an issue for non-glibc systems. Is that what you had in mind, or are there other issues I'm overlooking? (Also for fwrite in 6/9?)

Kevin

1. http://pubs.opengroup.org/onlinepubs/9699919799/functions/fread.html
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#20 lore raw

Re: [PATCH 8/9] configurator: Pass output cflag to configurator

In reply to David Gibson
Quoted 20 lines · David Gibson
Quoted 5 lines · Kevin Locke

Unfortunately, not all compilers support -o as a command-line option for specifying the output file. Visual Studio cl.exe issues warning D9035 when -o is given, which is detected as a compile warning by the configurator.

Quoted 7 lines

To support such compilers, pass the output flag as the last flag to the configurator.

This is a breaking change. Existing scripts which pass flags to the compiler must be modified to add "-o" as the last flag. As noted in the cover letter for this patch series, I'm open to considering alternatives if this is unacceptable.

So, as it stands, this change completely breaks ccanlint on POSIX, which is not ok. Specifically it looks like the problem is that the DEFAULT_FLAGS from the configurator make it into CCAN_CFLAGS in config.h. ccanlint then tries to add further options and its own -o to the end of that, which isn't going to work.

Quoted 7 lines

In short, I think the problem is that ccanlint needs fixes to work with MSVC (and possibly anything much else apart from gcc). I think we need to look at how to fix that and the configurator together with each other.

Not having working ccanlint on Windows seems like a pretty big, since its the main tool for testing ccan, amongst other things.

Good catch. I hadn't noticed the ccanlint breakage. That was a big oversight on my part.

The breakage likely extends to any other programs which use CCAN_CFLAGS, since none are expecting the output flag at the end. Perhaps a better solution would be to emit the output flag as a separate macro. Something like CCAN_OUTPUT_CFLAG. What do you think?

The command line API for configurator could either expect the output flag to be the last argument as currently in the patch (which is a breaking change for anything which call it). Or a command line option such as --output-cflag could be added to specify the flag and preserve command-line syntax compatibility.

Thoughts?

Kevin
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#25 lore raw
In reply to Kevin Locke
Quoted 34 lines · Kevin Locke

Hi David,

Thank you for taking the time to review these patches, especially for a platform that you don't have a strong stake in. I really appreciate it.

Quoted 13 lines · David Gibson
Quoted 6 lines · Kevin Locke

This patch series adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle. For me, this patch series is sufficient, so I don't have any further plans for changes to other files or the build system at the moment.

First, thanks for this. ccan isn't supposed to be platform specific, but it kind of is at the moment, simply because most of the contributions have been from Linux developers. I'm really happy to see some work to make it useful on different platforms.

Quoted 8 lines

Second, because I'm not and have never been a Windows dev, my ability to review these is limited - so I'm inclined to apply anything that doesn't break builds on Linux / POSIX.

Third, because most of the main ccan contributors are not Windows devs, I'm a bit worried about bitrot. If you can think of any way of making some kind of automated smoke test form builds on Windows, that would be terrific. Otherwise, I guess we'll just hope for the best.

I think that's a very legitimate concern. I'm not a frequent Windows developer myself, but had a need for a current project. I've tried to minimize the amount of Windows-specific code, with good results I think, but that's obviously not much of a guarantee that it won't rot or subtly break on Windows going forward.

Quoted 4 lines

I've seen appveyor.com used quite often for Windows CI, and it is free for FOSS projects. I'd be happy to work up some basic smoke tests if it seems like that might be useful and not too much of a maintenance burden. Let me know what you think.

Sounds good to me.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#26 lore raw

I do have a bit of experience with windows/linux C code interop, and while Visual C++ tends to be somewhat... unpredictable (It's getting much better than it used to be), I can tell you that...

x86_64-w64-mingw32-gcc

will output binaries that will happily run on windows, so long as you're using a version at least as new as is provided with Debian Jessie. (the wheezy version produced broken binaries). Wine can then be used to test them quite reliably. That compiler comes with enough windows libraries and headers to do most reasonable jobs, and quite a few unix headers mangled to work in windows environments.

sudo apt-get install mingw-w64

There's a 32bit version if you're that way inclined (which is also broken on wheezy), although I haven't used it recently enough to recall it.

regards,

dan
--
"The world is full of magical things patiently waiting for our wits to grow sharper." - Bertrand Russell

Quoted 52 lines · David Gibson
Quoted 8 lines · Kevin Locke

Hi David,

Thank you for taking the time to review these patches, especially for a platform that you don't have a strong stake in. I really appreciate it.

Quoted 2 lines · David Gibson
Quoted 1 line · Kevin Locke

This patch series adds support for building configurator with

Microsoft

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines

Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle. For me, this patch series is sufficient, so I don't have any further plans for changes to other files or the build system at the moment.

First, thanks for this. ccan isn't supposed to be platform specific, but it kind of is at the moment, simply because most of the contributions have been from Linux developers. I'm really happy to see some work to make it useful on different platforms.

Second, because I'm not and have never been a Windows dev, my ability to review these is limited - so I'm inclined to apply anything that doesn't break builds on Linux / POSIX.

Quoted 8 lines
Quoted 4 lines

Third, because most of the main ccan contributors are not Windows devs, I'm a bit worried about bitrot. If you can think of any way of making some kind of automated smoke test form builds on Windows, that would be terrific. Otherwise, I guess we'll just hope for the best.

I think that's a very legitimate concern. I'm not a frequent Windows developer myself, but had a need for a current project. I've tried to minimize the amount of Windows-specific code, with good results I think,

but

Quoted 1 line

that's obviously not much of a guarantee that it won't rot or subtly

break

Quoted 3 lines

on Windows going forward.

I've seen appveyor.com used quite often for Windows CI, and it is free

for

Quoted 1 line

FOSS projects. I'd be happy to work up some basic smoke tests if it

seems

Quoted 1 line

like that might be useful and not too much of a maintenance burden. Let

me

Quoted 1 line

know what you think.

Sounds good to me.

--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_

Quoted 9 lines
                                | _way_ _around_!

http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#6 lore raw

Re: [PATCH 2/9] configurator: Reimplement run using popen

In reply to Kevin Locke
Quoted 29 lines · Kevin Locke
Quoted 17 lines · David Gibson
Quoted 3 lines · Kevin Locke

Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

Concept looks good, one little wart.

Quoted 10 lines

[...]

tools/configurator/configurator.c +2 -3
-static char *grab_fd(int fd)
+static char *grab_stream(FILE *file)
 {
-	int ret;
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
Quoted 10 lines

tools/configurator/configurator.c static struct test tests[] = { · line 377

Quoted 6 lines
tools/configurator/configurator.c +3 -3
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread(buffer+size, 1, max - size, file)) == max - size) {

This assumes that fread() will never return a short read except on EOF or error. I expect that will be true in practice for regular files, but I'm not sure if it's a good idea to rely on it.

Quoted 6 lines

Interesting. I was under the impression that the fread couldn't short read. POSIX describes the return value as "the number of elements successfully read which is less than nitems only if a read error or end-of-file is encountered."[1] Now that I think about it, I suppose EINTR could be an issue for non-glibc systems. Is that what you had in mind, or are there other issues I'm overlooking? (Also for fwrite in 6/9?)

Ah..so it does. I'm afraid I just looked at the Linux man page, not the POSIX requirements, and it didn't mention this constraint.

I guess it's ok then. Although.. I do wonder a bit whether we can trust all implementations to actually comply with this requirement.

Quoted 5 lines

Kevin

1. http://pubs.opengroup.org/onlinepubs/9699919799/functions/fread.html

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#21 lore raw

Re: [PATCH 8/9] configurator: Pass output cflag to configurator

In reply to Kevin Locke
Quoted 29 lines · Kevin Locke
Quoted 20 lines · David Gibson
Quoted 5 lines · Kevin Locke

Unfortunately, not all compilers support -o as a command-line option for specifying the output file. Visual Studio cl.exe issues warning D9035 when -o is given, which is detected as a compile warning by the configurator.

Quoted 7 lines

To support such compilers, pass the output flag as the last flag to the configurator.

This is a breaking change. Existing scripts which pass flags to the compiler must be modified to add "-o" as the last flag. As noted in the cover letter for this patch series, I'm open to considering alternatives if this is unacceptable.

So, as it stands, this change completely breaks ccanlint on POSIX, which is not ok. Specifically it looks like the problem is that the DEFAULT_FLAGS from the configurator make it into CCAN_CFLAGS in config.h. ccanlint then tries to add further options and its own -o to the end of that, which isn't going to work.

Quoted 7 lines

In short, I think the problem is that ccanlint needs fixes to work with MSVC (and possibly anything much else apart from gcc). I think we need to look at how to fix that and the configurator together with each other.

Not having working ccanlint on Windows seems like a pretty big, since its the main tool for testing ccan, amongst other things.

Quoted 7 lines

Good catch. I hadn't noticed the ccanlint breakage. That was a big oversight on my part.

The breakage likely extends to any other programs which use CCAN_CFLAGS, since none are expecting the output flag at the end. Perhaps a better solution would be to emit the output flag as a separate macro. Something like CCAN_OUTPUT_CFLAG. What do you think?

I think that's a better option, and maybe the way to go in the short term.

Longer term, I'm wondering if we want some sort of mini-library for shared use by the ccan tools - configurator, ccanlint, etc. Amongst other things that could have an "invoke compiler" function which abstracts this sort of thing in a more general way.

Of course, this borders on the questions about use of err() etc. in the configurator - within the tools themselves, what can we and can't we assume about the system.

Quoted 7 lines

The command line API for configurator could either expect the output flag to be the last argument as currently in the patch (which is a breaking change for anything which call it). Or a command line option such as --output-cflag could be added to specify the flag and preserve command-line syntax compatibility.

Thoughts?

--output-cflag is kind of clunky, but again might be our best bet in the short term.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#27 lore raw
In reply to Daniel Burke
Quoted 13 lines · Daniel Burke

I do have a bit of experience with windows/linux C code interop, and while Visual C++ tends to be somewhat... unpredictable (It's getting much better than it used to be), I can tell you that...

x86_64-w64-mingw32-gcc

will output binaries that will happily run on windows, so long as you're using a version at least as new as is provided with Debian Jessie. (the wheezy version produced broken binaries). Wine can then be used to test them quite reliably. That compiler comes with enough windows libraries and headers to do most reasonable jobs, and quite a few unix headers mangled to work in windows environments.

Quoted 4 lines

sudo apt-get install mingw-w64

There's a 32bit version if you're that way inclined (which is also broken on wheezy), although I haven't used it recently enough to recall it.

Thanks for the info. We should try to get some mingw builds and wine tests into Travis (although at the moment the Travis builds are already broken due to a problem on clang I haven't had a chance to debug :).

However, as noted elsewhere, mingw shouldn't be our only or primary way of building for windows.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#29 lore raw

PATCH v2 1/13 configurator: Replace unlink with remove

In reply to Kevin Locke

Although Windows provides unlink, using it adds complication due to the lack of unistd.h which must be included to define the function on POSIX systems. Instead, use remove, which C89 requires to be in stdio.h.

---
 tools/configurator/configurator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/configurator/configurator.c +2 -2
index 67dadc6..e322c76 100644
@@ -639,8 +639,8 @@ int main(int argc, const char *argv[])
 		run_test(cmd, &tests[i]);
 	free(cmd);
 
-	unlink(OUTPUT_FILE);
-	unlink(INPUT_FILE);
+	remove(OUTPUT_FILE);
+	remove(INPUT_FILE);
 
 	printf("/* Generated by CCAN configurator */\n"
 	       "#ifndef CCAN_CONFIG_H\n"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#31 lore raw

PATCH v2 2/13 configurator: Reimplement run using popen

In reply to Kevin Locke

Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

Changes since v1:
- Create fread_noeintr to avoid EINTR in fread without reading any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.
- Define _POSIX_C_SOURCE for popen/pclose with strict implementations which require it (e.g. gcc with -std=c11).

---
 tools/configurator/configurator.c | 90 +++++++++++++++++++--------------------
 1 file changed, 44 insertions(+), 46 deletions(-)
tools/configurator/configurator.c +44 -46
index e322c76..4eed188 100644
@@ -21,17 +21,20 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#define _POSIX_C_SOURCE 200809L		/* For pclose, popen, strdup */
+
+#include <errno.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <err.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
+
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 
@@ -367,20 +370,33 @@ static struct test tests[] = {
 	},
 };
 
-static char *grab_fd(int fd)
+static size_t fread_noeintr(void *ptr, size_t size, size_t nitems,
+		FILE *stream)
+{
+	size_t ret;
+
+	do {
+		errno = 0;
+		ret = fread(ptr, size, nitems, stream);
+	} while (ret == 0 && errno == EINTR);
+
+	return ret;
+}
+
+static char *grab_stream(FILE *file)
 {
-	int ret;
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
 
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread_noeintr(buffer + size, 1, max - size, file)) > 0) {
 		size += ret;
 		if (size == max)
 			buffer = realloc(buffer, max *= 2);
 	}
-	if (ret < 0)
+	size += ret;
+	if (ferror(file))
 		err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
@@ -388,43 +404,25 @@ static char *grab_fd(int fd)
 
 static char *run(const char *cmd, int *exitstatus)
 {
-	pid_t pid;
-	int p[2];
+	static const char redir[] = " 2>&1";
+	size_t cmdlen;
+	char *cmdredir;
+	FILE *cmdout;
 	char *ret;
-	int status;
 
-	if (pipe(p) != 0)
-		err(1, "creating pipe");
-
-	pid = fork();
-	if (pid == -1)
-		err(1, "forking");
-
-	if (pid == 0) {
-		if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
-		    || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
-		    || close(p[0]) != 0
-		    || close(STDIN_FILENO) != 0
-		    || open("/dev/null", O_RDONLY) != STDIN_FILENO)
-			exit(128);
-
-		status = system(cmd);
-		if (WIFEXITED(status))
-			exit(WEXITSTATUS(status));
-		/* Here's a hint... */
-		exit(128 + WTERMSIG(status));
-	}
+	cmdlen = strlen(cmd);
+	cmdredir = malloc(cmdlen + sizeof(redir));
+	memcpy(cmdredir, cmd, cmdlen);
+	memcpy(cmdredir + cmdlen, redir, sizeof(redir));
+
+	cmdout = popen(cmdredir, "r");
+	if (!cmdout)
+		err(1, "popen \"%s\"", cmdredir);
+
+	free(cmdredir);
 
-	close(p[1]);
-	ret = grab_fd(p[0]);
-	/* This shouldn't fail... */
-	if (waitpid(pid, &status, 0) != pid)
-		err(1, "Failed to wait for child");
-	close(p[0]);
-	if (WIFEXITED(status))
-		*exitstatus = WEXITSTATUS(status);
-	else
-		*exitstatus = -WTERMSIG(status);
+	ret = grab_stream(cmdout);
+	*exitstatus = pclose(cmdout);
 	return ret;
 }
 
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#37 lore raw

PATCH v2 4/13 configurator: Use native directory separator

In reply to Kevin Locke

Although Windows APIs generally permit "/" or "\\" for directory separators in paths, cmd.exe does not recognize "./" when invoking executables using a relative path and prints the following error:

'.' is not recognized as an internal or external command, operable program or batch file.

Therefore, use "\\" when invoking tests on Windows.

---
 tools/configurator/configurator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +7 -1
index 5929355..7c4dd4a 100644
@@ -44,6 +44,12 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+#ifdef _WIN32
+#define DIR_SEP   "\\"
+#else
+#define DIR_SEP   "/"
+#endif
+
 static const char *progname = "";
 static int verbose;
 
@@ -632,7 +638,7 @@ static bool run_test(const char *cmd, struct test *test)
 		free(output);
 		/* We run INSIDE_MAIN tests for sanity checking. */
 		if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
-			output = run("./" OUTPUT_FILE, &status);
+			output = run("." DIR_SEP OUTPUT_FILE, &status);
 			if (!(test->style & EXECUTE) && status != 0)
 				errx(1, "Test for %s failed with %i:\n%s",
 				     test->name, status, output);
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#28 lore raw

v2 cover configurator: Support for Windows and MSVC

In reply to Kevin Locke

Hi all,

This is the second revision of my patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle.

The major change in this revision is the handling of the output cflag, which can now be specified by a command-line option to configurator and is set in a separate config.h macro. This both fixes the ccanlint breakage in the previous series and preserves backwards-compatibility for any code calling configurator or using CCAN_CFLAGS.

Patches which need special attention:

As before, patch 3 adds a copy of the err.h functions used by configurator to work around the lack of err.h on Windows. If this is too much code to lump into configurator.c, I can split it out (and copy err.{c,h} verbatim from musl) or call fprintf+exit directly or consider modifying the ccan/err module for use by configurator.

Patch 8 changes the configurator API by adding a command-line option and config.h macro. The names are different than I had previously suggested, as noted in the commit message.

Patch 13 adds appveyor.yml for AppVeyor CI. This will require (free) account setup on ci.appveyor.com once merged to enable automatic building and GitHub integration (if desired). You may also wish to consider whether to add a README badge or email notification or other mechanism to be notified of build status (beyond the default pull request hooks).

Thanks for considering once again,
Kevin

Kevin Locke (13):
configurator: Replace unlink with remove
configurator: Reimplement run using popen
configurator: Inline err.h functions from musl libc
configurator: Use native directory separator
configurator: Mark non-Windows tests MAY_NOT_COMPILE
configurator: Print test source without cat
configurator: Fix compiler warning with compare
configurator: Add output cflag option and macro
configurator: DEFAULT_{COMPILER,FLAGS} for MSVC
configurator: Fix warning in HAVE_FOR_LOOP_DECLARATION
configurator: Return pointer difference as ptrdiff_t
Makefile: Define CFLAGS_FORCE_C_SOURCE macro Add appveyor.yml

 Makefile                          |   2 +-
 Makefile-ccan                     |   1 +
 appveyor.yml                      |  25 ++++
 tools/compile.c                   |  15 +-
 tools/configurator/configurator.c | 288 +++++++++++++++++++++++++++-----------
 tools/tools.h                     |   6 +-
 6 files changed, 249 insertions(+), 88 deletions(-)
 create mode 100644 appveyor.yml

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#34 lore raw

PATCH v2 3/13 configurator: Inline err.h functions from musl libc

Since we can't use HAVE_ERR_H in configurator, provide a definition for the err.h functions used. The version provided is the one from musl libc, since it is concise and shares the MIT License with configurator.

---
 tools/configurator/configurator.c | 54 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +53 -1
index 4eed188..5929355 100644
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Rusty Russell <[email protected]>.  MIT license.
  *
+ * err, errx, verr, verrx, vwarn, vwarnx functions from musl libc
+ * Copyright 2005-2013 Rich Felker.  MIT license.
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -25,9 +28,9 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <err.h>
 #include <string.h>
 
 #ifdef _MSC_VER
@@ -41,6 +44,7 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+static const char *progname = "";
 static int verbose;
 
 enum test_style {
@@ -370,6 +374,51 @@ static struct test tests[] = {
 	},
 };
 
+static void vwarn(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) {
+		vfprintf(stderr, fmt, ap);
+		fputs (": ", stderr);
+	}
+	perror(0);
+}
+
+static void vwarnx(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) vfprintf(stderr, fmt, ap);
+	putc('\n', stderr);
+}
+
+static void verr(int status, const char *fmt, va_list ap)
+{
+	vwarn(fmt, ap);
+	exit(status);
+}
+
+static void verrx(int status, const char *fmt, va_list ap)
+{
+	vwarnx(fmt, ap);
+	exit(status);
+}
+
+static void err(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verr(status, fmt, ap);
+	va_end(ap);
+}
+
+static void errx(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verrx(status, fmt, ap);
+	va_end(ap);
+}
+
 static size_t fread_noeintr(void *ptr, size_t size, size_t nitems,
 		FILE *stream)
 {
@@ -610,6 +659,9 @@ int main(int argc, const char *argv[])
 	const char *default_args[]
 		= { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
 
+	if (argc > 0)
+		progname = argv[0];
+
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#39 lore raw

PATCH v2 5/13 configurator: Mark non-Windows tests MAY_NOT_COMPILE

In reply to Kevin Locke

Several of the EXECUTABLE tests depend on headers not available on Windows. Mark these tests MAY_NOT_COMPILE to handle this.

---
 tools/configurator/configurator.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/configurator/configurator.c +6 -6
index 7c4dd4a..31e3d11 100644
@@ -75,7 +75,7 @@ struct test {
 };
 
 static struct test tests[] = {
-	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "int main(void) {\n"
 	  "	return sizeof(off_t) == 4 ? 0 : 1;\n"
@@ -180,7 +180,7 @@ static struct test tests[] = {
 	{ "HAVE_COMPOUND_LITERALS", INSIDE_MAIN, NULL, NULL,
 	  "int *foo = (int[]) { 1, 2, 3, 4 };\n"
 	  "return foo[0] ? 0 : 1;" },
-	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -201,7 +201,7 @@ static struct test tests[] = {
 	  "	if (arg == 4)\n"
 	  "		warnx(\"warn %u\", arg);\n"
 	  "}\n" },
-	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_32BIT_OFF_T", NULL,
 	  "#define _FILE_OFFSET_BITS 64\n"
 	  "#include <sys/types.h>\n"
@@ -247,7 +247,7 @@ static struct test tests[] = {
 	  "static void *func(int fd) {\n"
 	  "	return mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);\n"
 	  "}" },
-	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -332,7 +332,7 @@ static struct test tests[] = {
 	  "-Werror -fopenmp" },
 	{ "HAVE_VALGRIND_MEMCHECK_H", OUTSIDE_MAIN, NULL, NULL,
 	  "#include <valgrind/memcheck.h>\n" },
-	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  NULL, NULL,
 	  "#include <ucontext.h>\n"
 	  "static int x = 0;\n"
@@ -353,7 +353,7 @@ static struct test tests[] = {
 	  "	return (x == 3) ? 0 : 1;\n"
 	  "}\n"
 	},
-	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_UCONTEXT", NULL,
 	  "#include <stddef.h>\n"
 	  "#include <ucontext.h>\n"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#41 lore raw

PATCH v2 6/13 configurator: Print test source without cat

In reply to Kevin Locke

Windows does not provide cat. Instead, copy the test source to stdout using the file stream to which it was written.

Changes since v1:
- Create fwrite_noeintr to avoid EINTR in fwrite without writing any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.
- Handle short writes from fwrite. This can happen with non-conformant libc or if EINTR occurs after writing some data.

---
 tools/configurator/configurator.c | 48 +++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 5 deletions(-)
tools/configurator/configurator.c +43 -5
index 31e3d11..51d7ac8 100644
@@ -438,6 +438,42 @@ static size_t fread_noeintr(void *ptr, size_t size, size_t nitems,
 	return ret;
 }
 
+static size_t fwrite_noeintr(const void *ptr, size_t size, size_t nitems,
+		FILE *stream)
+{
+	size_t ret;
+
+	do {
+		errno = 0;
+		ret = fwrite(ptr, size, nitems, stream);
+	} while (ret == 0 && errno == EINTR);
+
+	return ret;
+}
+
+static size_t fcopy(FILE *fsrc, FILE *fdst)
+{
+	char buffer[BUFSIZ];
+	size_t copied = 0, rsize;
+
+	while ((rsize = fread_noeintr(buffer, 1, BUFSIZ, fsrc)) > 0) {
+		size_t wsize, wtotal = 0;
+
+		while (wtotal < rsize &&
+		       ((wsize = fwrite_noeintr(buffer + wtotal, 1,
+						rsize - wtotal, fdst)) > 0)) {
+			wtotal += wsize;
+		}
+
+		if (wtotal < rsize)
+			break;
+
+		copied += wtotal;
+	}
+
+	return copied;
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -562,7 +598,7 @@ static bool run_test(const char *cmd, struct test *test)
 		}
 	}
 
-	outf = fopen(INPUT_FILE, "w");
+	outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w");
 	if (!outf)
 		err(1, "creating %s", INPUT_FILE);
 
@@ -593,11 +629,13 @@ static bool run_test(const char *cmd, struct test *test)
 		abort();
 
 	}
-	fclose(outf);
 
-	if (verbose > 1)
-		if (system("cat " INPUT_FILE) == -1)
-			;
+	if (verbose > 1) {
+		fseek(outf, 0, SEEK_SET);
+		fcopy(outf, stdout);
+	}
+
+	fclose(outf);
 
 	newcmd = strdup(cmd);
 
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#44 lore raw

PATCH v2 7/13 configurator: Fix compiler warning with compare

In reply to Kevin Locke

Visual Studio prints warning C4706 "assignment within conditional expression" when there is an assignment without a comparison in a conditional expression. Therefore, to silence the warning, add an explicit comparison.

---
 tools/configurator/configurator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/configurator/configurator.c +1 -1
index 51d7ac8..acf6cc0 100644
@@ -572,7 +572,7 @@ static bool run_test(const char *cmd, struct test *test)
 		char *dep;
 
 		/* Space-separated dependencies, could be ! for inverse. */
-		while ((len = strcspn(deps, " "))) {
+		while ((len = strcspn(deps, " ")) != 0) {
 			bool positive = true;
 			if (deps[len]) {
 				dep = strdup(deps);
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#46 lore raw

PATCH v2 8/13 configurator: Add output cflag option and macro

In reply to Kevin Locke

Unfortunately, not all compilers support -o as a command-line option for specifying the output file. Visual Studio cl.exe issues warning D9035 when -o is given, which is detected as a compile warning by the configurator.

To support such compilers, add the command-line option -O to configurator which can be used to specify the cflag for setting the output executable file name. Additionally define the macro CCAN_OUTPUT_EXE_CFLAG in config.h and use it when invoking the compiler (e.g. from ccanlint).

For reference, the name CCAN_OUTPUT_EXE_CFLAG was chosen to avoid potential name conflicts in the future due to cl.exe requiring different flags for different types of output[1] (e.g. object files are /Fo:).

1. https://msdn.microsoft.com/en-us/library/f1cb223a.aspx

---
 tools/compile.c                   | 15 ++++++++----
 tools/configurator/configurator.c | 50 +++++++++++++++++++++++++++------------
 tools/tools.h                     |  6 +++--
 3 files changed, 49 insertions(+), 22 deletions(-)
tools/compile.c +10 -5
index b88c1d8..e796e3f 100644
@@ -7,8 +7,12 @@
 #ifndef CCAN_CFLAGS
 #define CCAN_CFLAGS DEFAULT_CCAN_CFLAGS
 #endif
+#ifndef CCAN_OUTPUT_EXE_CFLAG
+#define CCAN_OUTPUT_EXE_CFLAG DEFAULT_CCAN_OUTPUT_EXE_CFLAG
+#endif
 const char *compiler = CCAN_COMPILER;
 const char *cflags = CCAN_CFLAGS;
+const char *outexecflag = CCAN_OUTPUT_EXE_CFLAG;
 
 bool compile_verbose = false;
 
@@ -37,8 +41,9 @@ bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
 	if (compile_verbose)
 		printf("Compiling %s\n", outfile);
 	return run_command(ctx, NULL, output,
-			   "%s %s -I%s -c -o %s %s",
-			   compiler, cflags, ccandir, outfile, cfile);
+			   "%s %s -I%s -c %s%s %s",
+			   compiler, cflags, ccandir,
+			   outexecflag, outfile, cfile);
 }
 
 /* Compile and link single C file, with object files.
@@ -51,7 +56,7 @@ bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
 	if (compile_verbose)
 		printf("Compiling and linking %s\n", outfile);
 	return run_command(ctx, NULL, output,
-			   "%s %s -I%s -o %s %s %s %s",
-			   compiler, cflags,
-			   ccandir, outfile, cfile, objs, libs);
+			   "%s %s -I%s %s%s %s %s %s",
+			   compiler, cflags, ccandir,
+			   outexecflag, outfile, cfile, objs, libs);
 }
tools/configurator/configurator.c +35 -15

103 lines not on this page · raw message

tools/tools.h +4 -2
index 3b5c4be..668c91a 100644
@@ -11,6 +11,7 @@
 /* These are the defaults. */
 #define DEFAULT_CCAN_COMPILER "cc"
 #define DEFAULT_CCAN_CFLAGS "-g"
+#define DEFAULT_CCAN_OUTPUT_EXE_CFLAG "-o"
 
 #define IDENT_CHARS	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
 			"abcdefghijklmnopqrstuvwxyz" \
@@ -20,8 +21,9 @@
 
 #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
 
-/* Actual compiler and cflags (defaults to CCAN_COMPILER and CCAN_CFLAGS). */
-extern const char *compiler, *cflags;
+/* Actual compiler and cflags
+ * (defaults to CCAN_COMPILER, CCAN_CFLAGS, CCAN_OUTPUT_EXE_CFLAG). */
+extern const char *compiler, *cflags, *outexecflag;
 
 /* This compiles up the _info file into a temporary. */
 char *compile_info(const void *ctx, const char *dir);
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#48 lore raw

PATCH v2 9/13 configurator: DEFAULT_{COMPILER, FLAGS} for MSVC

In reply to Kevin Locke

When compiling with Visual Studio, use default compiler name and flags which are likely to work with the known-available compiler.

This is also a convenience for users who may not know what arguments cl.exe may need to compile the tests.

Changes since v1:
- Use "-option" instead of "/option" to avoid issues running under msys.
- Disable C4200 warning for use of flexible array members, which MSVC considers an extension (since it does not fully support C99).

---
 tools/configurator/configurator.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/configurator/configurator.c +12 -0
index d81f878..d3e01cd 100644
@@ -38,9 +38,21 @@
 #define pclose _pclose
 #endif
 
+#ifdef _MSC_VER
+#define DEFAULT_COMPILER "cl"
+/* Note:  Dash options avoid POSIX path conversion when used under msys bash
+ *        and are therefore preferred to slash (e.g. -nologo over /nologo)
+ * Note:  Disable Warning 4200 "nonstandard extension used : zero-sized array
+ *        in struct/union" for flexible array members.
+ */
+#define DEFAULT_FLAGS "-nologo -Zi -W4 -wd4200 " \
+	"-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS"
+#define DEFAULT_OUTPUT_EXE_FLAG "-Fe:"
+#else
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 #define DEFAULT_OUTPUT_EXE_FLAG "-o"
+#endif
 
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#50 lore raw

PATCH v2 10/13 configurator: Fix warning in HAVE_FOR_LOOP_DECLARATION

In reply to Kevin Locke

Visual C++ prints "warning C4702: unreachable code" due to the return statement after the for loop which is never reached. Fix this by setting a variable returned by a single return statement at the end.

---
 tools/configurator/configurator.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/configurator/configurator.c +3 -2
index d3e01cd..a43061b 100644
@@ -222,8 +222,9 @@ static struct test tests[] = {
 	  "	return sizeof(off_t) == 8 ? 0 : 1;\n"
 	  "}\n" },
 	{ "HAVE_FOR_LOOP_DECLARATION", INSIDE_MAIN, NULL, NULL,
-	  "for (int i = 0; i < argc; i++) { return 0; };\n"
-	  "return 1;" },
+	  "int ret = 1;\n"
+	  "for (int i = 0; i < argc; i++) { ret = 0; };\n"
+	  "return ret;" },
 	{ "HAVE_FLEXIBLE_ARRAY_MEMBER", OUTSIDE_MAIN, NULL, NULL,
 	  "struct foo { unsigned int x; int arr[]; };" },
 	{ "HAVE_GETPAGESIZE", DEFINES_FUNC, NULL, NULL,
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#52 lore raw

PATCH v2 11/13 configurator: Return pointer difference as ptrdiff_t

In reply to Kevin Locke

On LLP64 systems (like 64-bit Windows) long is 32 bits while pointers are 64 bits, which results in a warning similar to the following:

warning C4244: 'return': conversion from '__int64' to 'long', possible loss of data

for HAVE_STACK_GROWS_UPWARDS. Fix this by using the ptrdiff_t type introduced by C99 for this purpose.

---
 tools/configurator/configurator.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +2 -1
index a43061b..2acb0b2 100644
@@ -298,7 +298,8 @@ static struct test tests[] = {
 	  "	return __stop_mysec - __start_mysec;\n"
 	  "}\n" },
 	{ "HAVE_STACK_GROWS_UPWARDS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
-	  "static long nest(const void *base, unsigned int i)\n"
+	  "#include <stddef.h>\n"
+	  "static ptrdiff_t nest(const void *base, unsigned int i)\n"
 	  "{\n"
 	  "	if (i == 0)\n"
 	  "		return (const char *)&i - (const char *)base;\n"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#54 lore raw

PATCH v2 12/13 Makefile: Define CFLAGS_FORCE_C_SOURCE macro

In reply to Kevin Locke

This macro holds the C compiler flag(s) to force input files to be recognized as C sources regardless of extension. It is defined to allow overriding on the make command line.

---
 Makefile      | 2 +-
 Makefile-ccan | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Makefile +1 -1
index 127b875..37ff17d 100644
@@ -64,7 +64,7 @@ summary-fastcheck/%: tools/ccanlint/ccanlint $(OBJFILES)
 	$(CCANLINT_FAST) -s ccan/$*
 
 ccan/%/info: ccan/%/_info config.h
-	$(CC) $(CCAN_CFLAGS) -I. -o $@ -x c $<
+	$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $<
 
 all_info: $(MODS:%=ccan/%/info)
 
Makefile-ccan +1 -0
index 5c8dea2..d4a5528 100644
@@ -5,6 +5,7 @@
 #CCAN_CFLAGS=-g -O3 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
 CCAN_CFLAGS=-g3 -ggdb -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
 CFLAGS = $(CCAN_CFLAGS) -I. $(DEPGEN)
+CFLAGS_FORCE_C_SOURCE = -x c
 
 MODS := a_star \
 	aga \
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#59 lore raw

PATCH v2 13/13 Add appveyor.yml

In reply to Kevin Locke

This file defines the AppVeyor CI (appveyor.com) settings.

It builds using make+bash under MSYS2 so that the current build system can be used with minimal changes. It currently only builds configurator and generates config.h.

The build and test commands for more thorough testing are left as comments in appveyor.yml so interested parties can use them as a starting point for future work.

Note that several compiler errors not related to configurator are printed due to make attempting to generate and include test-depends. Although Windows-specific code could be added to Makefile to avoid these, it seemed unwarranted if the compile errors may be fixed soon.

---
 appveyor.yml | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 appveyor.yml
appveyor.yml new file +25 -0
new file mode 100644
index 0000000..822c4bd
@@ -0,0 +1,25 @@
+version: 0.0.{build}
+
+platform:
+- x86
+- amd64
+
+build_script:
+# Reset %PATH% to avoid msys/cygwin DLL conflicts which cause
+# *** fatal error - cygheap base mismatch detected
+- set PATH=C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\msys64\usr\bin
+# Set environment variables for chosen compiler
+- "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" %Platform%"
+# Ensure config.h can be generated.
+# Note: Dash options avoid POSIX path conversion by msys
+- "make config.h CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+# FIXME:  -j%NUMBER_OF_PROCESSORS% won't work without DEPGEN for config.h
+#         It may be possible to generate .d from cl using /showIncludes
+#         See https://stackoverflow.com/q/37685069
+#- "make tools CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+#- "make -k CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+
+test_script:
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+#- "make -k check CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#30 lore raw

Re: [PATCH v2 01/13] configurator: Replace unlink with remove

In reply to Kevin Locke
Quoted 6 lines · Kevin Locke

Although Windows provides unlink, using it adds complication due to the lack of unistd.h which must be included to define the function on POSIX systems. Instead, use remove, which C89 requires to be in stdio.h.

This is sane enough on its own, so I'll apply it to master.

Quoted 19 lines
---
 tools/configurator/configurator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/configurator/configurator.c +2 -2
index 67dadc6..e322c76 100644
@@ -639,8 +639,8 @@ int main(int argc, const char *argv[])
 		run_test(cmd, &tests[i]);
 	free(cmd);
 
-	unlink(OUTPUT_FILE);
-	unlink(INPUT_FILE);
+	remove(OUTPUT_FILE);
+	remove(INPUT_FILE);
 
 	printf("/* Generated by CCAN configurator */\n"
 	       "#ifndef CCAN_CONFIG_H\n"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#32 lore raw

Re: [PATCH v2 02/13] configurator: Reimplement run using popen

In reply to Kevin Locke
Quoted 8 lines · Kevin Locke

Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

Changes since v1:
- Create fread_noeintr to avoid EINTR in fread without reading any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.

Hrm. Have you actually confirmed this problem with EINTR? My previous objections to not handling short read were based entirely on not realizing that fread() wasn't supposed to do that, rather than thinking of some edge case you hadn't.

Unless we have a confirmed case where fread() can give a short read that won't have feof() or ferror() set afterwards, I'm inclined to go back to your initial implementation.

Quoted 139 lines

- Define _POSIX_C_SOURCE for popen/pclose with strict implementations which require it (e.g. gcc with -std=c11).

---
 tools/configurator/configurator.c | 90 +++++++++++++++++++--------------------
 1 file changed, 44 insertions(+), 46 deletions(-)
tools/configurator/configurator.c +44 -46
index e322c76..4eed188 100644
@@ -21,17 +21,20 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#define _POSIX_C_SOURCE 200809L		/* For pclose, popen, strdup */
+
+#include <errno.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <err.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
+
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 
@@ -367,20 +370,33 @@ static struct test tests[] = {
 	},
 };
 
-static char *grab_fd(int fd)
+static size_t fread_noeintr(void *ptr, size_t size, size_t nitems,
+		FILE *stream)
+{
+	size_t ret;
+
+	do {
+		errno = 0;
+		ret = fread(ptr, size, nitems, stream);
+	} while (ret == 0 && errno == EINTR);
+
+	return ret;
+}
+
+static char *grab_stream(FILE *file)
 {
-	int ret;
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
 
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread_noeintr(buffer + size, 1, max - size, file)) > 0) {
 		size += ret;
 		if (size == max)
 			buffer = realloc(buffer, max *= 2);
 	}
-	if (ret < 0)
+	size += ret;
+	if (ferror(file))
 		err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
@@ -388,43 +404,25 @@ static char *grab_fd(int fd)
 
 static char *run(const char *cmd, int *exitstatus)
 {
-	pid_t pid;
-	int p[2];
+	static const char redir[] = " 2>&1";
+	size_t cmdlen;
+	char *cmdredir;
+	FILE *cmdout;
 	char *ret;
-	int status;
 
-	if (pipe(p) != 0)
-		err(1, "creating pipe");
-
-	pid = fork();
-	if (pid == -1)
-		err(1, "forking");
-
-	if (pid == 0) {
-		if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
-		    || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
-		    || close(p[0]) != 0
-		    || close(STDIN_FILENO) != 0
-		    || open("/dev/null", O_RDONLY) != STDIN_FILENO)
-			exit(128);
-
-		status = system(cmd);
-		if (WIFEXITED(status))
-			exit(WEXITSTATUS(status));
-		/* Here's a hint... */
-		exit(128 + WTERMSIG(status));
-	}
+	cmdlen = strlen(cmd);
+	cmdredir = malloc(cmdlen + sizeof(redir));
+	memcpy(cmdredir, cmd, cmdlen);
+	memcpy(cmdredir + cmdlen, redir, sizeof(redir));
+
+	cmdout = popen(cmdredir, "r");
+	if (!cmdout)
+		err(1, "popen \"%s\"", cmdredir);
+
+	free(cmdredir);
 
-	close(p[1]);
-	ret = grab_fd(p[0]);
-	/* This shouldn't fail... */
-	if (waitpid(pid, &status, 0) != pid)
-		err(1, "Failed to wait for child");
-	close(p[0]);
-	if (WIFEXITED(status))
-		*exitstatus = WEXITSTATUS(status);
-	else
-		*exitstatus = -WTERMSIG(status);
+	ret = grab_stream(cmdout);
+	*exitstatus = pclose(cmdout);
 	return ret;
 }
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#35 lore raw

Re: [PATCH v2 03/13] configurator: Inline err.h functions from musl libc

In reply to Kevin Locke
Quoted 5 lines · Kevin Locke

Since we can't use HAVE_ERR_H in configurator, provide a definition for the err.h functions used. The version provided is the one from musl libc, since it is concise and shares the MIT License with configurator.

For me this breaks Linux build, because we get "static declaration follows non-static" on these functions.

I think we instead want to stop using the err() etc. functions and use similar functions with a different name that we always define locally.

Quoted 99 lines
---
 tools/configurator/configurator.c | 54 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +53 -1
index 4eed188..5929355 100644
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Rusty Russell <[email protected]>.  MIT license.
  *
+ * err, errx, verr, verrx, vwarn, vwarnx functions from musl libc
+ * Copyright 2005-2013 Rich Felker.  MIT license.
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -25,9 +28,9 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <err.h>
 #include <string.h>
 
 #ifdef _MSC_VER
@@ -41,6 +44,7 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+static const char *progname = "";
 static int verbose;
 
 enum test_style {
@@ -370,6 +374,51 @@ static struct test tests[] = {
 	},
 };
 
+static void vwarn(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) {
+		vfprintf(stderr, fmt, ap);
+		fputs (": ", stderr);
+	}
+	perror(0);
+}
+
+static void vwarnx(const char *fmt, va_list ap)
+{
+	fprintf (stderr, "%s: ", progname);
+	if (fmt) vfprintf(stderr, fmt, ap);
+	putc('\n', stderr);
+}
+
+static void verr(int status, const char *fmt, va_list ap)
+{
+	vwarn(fmt, ap);
+	exit(status);
+}
+
+static void verrx(int status, const char *fmt, va_list ap)
+{
+	vwarnx(fmt, ap);
+	exit(status);
+}
+
+static void err(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verr(status, fmt, ap);
+	va_end(ap);
+}
+
+static void errx(int status, const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	verrx(status, fmt, ap);
+	va_end(ap);
+}
+
 static size_t fread_noeintr(void *ptr, size_t size, size_t nitems,
 		FILE *stream)
 {
@@ -610,6 +659,9 @@ int main(int argc, const char *argv[])
 	const char *default_args[]
 		= { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
 
+	if (argc > 0)
+		progname = argv[0];
+
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#38 lore raw

Re: [PATCH v2 04/13] configurator: Use native directory separator

In reply to Kevin Locke
Quoted 11 lines · Kevin Locke

Although Windows APIs generally permit "/" or "\\" for directory separators in paths, cmd.exe does not recognize "./" when invoking executables using a relative path and prints the following error:

'.' is not recognized as an internal or external command, operable program or batch file.

Therefore, use "\\" when invoking tests on Windows.

This one also looks fine standalone (apart from a trivial context conflict). Applying.

Quoted 30 lines
---
 tools/configurator/configurator.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +7 -1
index 5929355..7c4dd4a 100644
@@ -44,6 +44,12 @@
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
 
+#ifdef _WIN32
+#define DIR_SEP   "\\"
+#else
+#define DIR_SEP   "/"
+#endif
+
 static const char *progname = "";
 static int verbose;
 
@@ -632,7 +638,7 @@ static bool run_test(const char *cmd, struct test *test)
 		free(output);
 		/* We run INSIDE_MAIN tests for sanity checking. */
 		if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
-			output = run("./" OUTPUT_FILE, &status);
+			output = run("." DIR_SEP OUTPUT_FILE, &status);
 			if (!(test->style & EXECUTE) && status != 0)
 				errx(1, "Test for %s failed with %i:\n%s",
 				     test->name, status, output);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#40 lore raw

Re: [PATCH v2 05/13] configurator: Mark non-Windows tests MAY_NOT_COMPILE

In reply to Kevin Locke
Quoted 5 lines · Kevin Locke

Several of the EXECUTABLE tests depend on headers not available on Windows. Mark these tests MAY_NOT_COMPILE to handle this.

Applying.

Quoted 62 lines
---
 tools/configurator/configurator.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/configurator/configurator.c +6 -6
index 7c4dd4a..31e3d11 100644
@@ -75,7 +75,7 @@ struct test {
 };
 
 static struct test tests[] = {
-	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "int main(void) {\n"
 	  "	return sizeof(off_t) == 4 ? 0 : 1;\n"
@@ -180,7 +180,7 @@ static struct test tests[] = {
 	{ "HAVE_COMPOUND_LITERALS", INSIDE_MAIN, NULL, NULL,
 	  "int *foo = (int[]) { 1, 2, 3, 4 };\n"
 	  "return foo[0] ? 0 : 1;" },
-	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -201,7 +201,7 @@ static struct test tests[] = {
 	  "	if (arg == 4)\n"
 	  "		warnx(\"warn %u\", arg);\n"
 	  "}\n" },
-	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_32BIT_OFF_T", NULL,
 	  "#define _FILE_OFFSET_BITS 64\n"
 	  "#include <sys/types.h>\n"
@@ -247,7 +247,7 @@ static struct test tests[] = {
 	  "static void *func(int fd) {\n"
 	  "	return mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);\n"
 	  "}" },
-	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
+	{ "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
 	  "#include <sys/types.h>\n"
 	  "#include <sys/stat.h>\n"
 	  "#include <fcntl.h>\n"
@@ -332,7 +332,7 @@ static struct test tests[] = {
 	  "-Werror -fopenmp" },
 	{ "HAVE_VALGRIND_MEMCHECK_H", OUTSIDE_MAIN, NULL, NULL,
 	  "#include <valgrind/memcheck.h>\n" },
-	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_UCONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  NULL, NULL,
 	  "#include <ucontext.h>\n"
 	  "static int x = 0;\n"
@@ -353,7 +353,7 @@ static struct test tests[] = {
 	  "	return (x == 3) ? 0 : 1;\n"
 	  "}\n"
 	},
-	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE,
+	{ "HAVE_POINTER_SAFE_MAKECONTEXT", DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE,
 	  "HAVE_UCONTEXT", NULL,
 	  "#include <stddef.h>\n"
 	  "#include <ucontext.h>\n"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#42 lore raw

Re: [PATCH v2 06/13] configurator: Print test source without cat

In reply to Kevin Locke
Quoted 11 lines · Kevin Locke

Windows does not provide cat. Instead, copy the test source to stdout using the file stream to which it was written.

Changes since v1:
- Create fwrite_noeintr to avoid EINTR in fwrite without writing any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.
- Handle short writes from fwrite. This can happen with non-conformant libc or if EINTR occurs after writing some data.

Quoted 1 line

As with patch 2, I'm not sure about the need for fwrite_noeintr().

Quoted 78 lines
---
 tools/configurator/configurator.c | 48 +++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 5 deletions(-)
tools/configurator/configurator.c +43 -5
index 31e3d11..51d7ac8 100644
@@ -438,6 +438,42 @@ static size_t fread_noeintr(void *ptr, size_t size, size_t nitems,
 	return ret;
 }
 
+static size_t fwrite_noeintr(const void *ptr, size_t size, size_t nitems,
+		FILE *stream)
+{
+	size_t ret;
+
+	do {
+		errno = 0;
+		ret = fwrite(ptr, size, nitems, stream);
+	} while (ret == 0 && errno == EINTR);
+
+	return ret;
+}
+
+static size_t fcopy(FILE *fsrc, FILE *fdst)
+{
+	char buffer[BUFSIZ];
+	size_t copied = 0, rsize;
+
+	while ((rsize = fread_noeintr(buffer, 1, BUFSIZ, fsrc)) > 0) {
+		size_t wsize, wtotal = 0;
+
+		while (wtotal < rsize &&
+		       ((wsize = fwrite_noeintr(buffer + wtotal, 1,
+						rsize - wtotal, fdst)) > 0)) {
+			wtotal += wsize;
+		}
+
+		if (wtotal < rsize)
+			break;
+
+		copied += wtotal;
+	}
+
+	return copied;
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -562,7 +598,7 @@ static bool run_test(const char *cmd, struct test *test)
 		}
 	}
 
-	outf = fopen(INPUT_FILE, "w");
+	outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w");
 	if (!outf)
 		err(1, "creating %s", INPUT_FILE);
 
@@ -593,11 +629,13 @@ static bool run_test(const char *cmd, struct test *test)
 		abort();
 
 	}
-	fclose(outf);
 
-	if (verbose > 1)
-		if (system("cat " INPUT_FILE) == -1)
-			;
+	if (verbose > 1) {
+		fseek(outf, 0, SEEK_SET);
+		fcopy(outf, stdout);
+	}
+
+	fclose(outf);
 
 	newcmd = strdup(cmd);
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#45 lore raw

Re: [PATCH v2 07/13] configurator: Fix compiler warning with compare

In reply to Kevin Locke
Quoted 7 lines · Kevin Locke

Visual Studio prints warning C4706 "assignment within conditional expression" when there is an assignment without a comparison in a conditional expression. Therefore, to silence the warning, add an explicit comparison.

Applying.

Quoted 17 lines
---
 tools/configurator/configurator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/configurator/configurator.c +1 -1
index 51d7ac8..acf6cc0 100644
@@ -572,7 +572,7 @@ static bool run_test(const char *cmd, struct test *test)
 		char *dep;
 
 		/* Space-separated dependencies, could be ! for inverse. */
-		while ((len = strcspn(deps, " "))) {
+		while ((len = strcspn(deps, " ")) != 0) {
 			bool positive = true;
 			if (deps[len]) {
 				dep = strdup(deps);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

Reviewed-by on v2 8/13
#47 lore raw

Re: [PATCH v2 08/13] configurator: Add output cflag option and macro

In reply to Kevin Locke
Quoted 11 lines · Kevin Locke

Unfortunately, not all compilers support -o as a command-line option for specifying the output file. Visual Studio cl.exe issues warning D9035 when -o is given, which is detected as a compile warning by the configurator.

To support such compilers, add the command-line option -O to configurator which can be used to specify the cflag for setting the output executable file name. Additionally define the macro CCAN_OUTPUT_EXE_CFLAG in config.h and use it when invoking the compiler (e.g. from ccanlint).

Quoted 7 lines

For reference, the name CCAN_OUTPUT_EXE_CFLAG was chosen to avoid potential name conflicts in the future due to cl.exe requiring different flags for different types of output[1] (e.g. object files are /Fo:).

1. https://msdn.microsoft.com/en-us/library/f1cb223a.aspx

This one has some more complex conflicts if applied without the preceding ones, so I haven't applied it yet.

Quoted 182 lines
---
 tools/compile.c                   | 15 ++++++++----
 tools/configurator/configurator.c | 50 +++++++++++++++++++++++++++------------
 tools/tools.h                     |  6 +++--
 3 files changed, 49 insertions(+), 22 deletions(-)
tools/compile.c +10 -5
index b88c1d8..e796e3f 100644
@@ -7,8 +7,12 @@
 #ifndef CCAN_CFLAGS
 #define CCAN_CFLAGS DEFAULT_CCAN_CFLAGS
 #endif
+#ifndef CCAN_OUTPUT_EXE_CFLAG
+#define CCAN_OUTPUT_EXE_CFLAG DEFAULT_CCAN_OUTPUT_EXE_CFLAG
+#endif
 const char *compiler = CCAN_COMPILER;
 const char *cflags = CCAN_CFLAGS;
+const char *outexecflag = CCAN_OUTPUT_EXE_CFLAG;
 
 bool compile_verbose = false;
 
@@ -37,8 +41,9 @@ bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
 	if (compile_verbose)
 		printf("Compiling %s\n", outfile);
 	return run_command(ctx, NULL, output,
-			   "%s %s -I%s -c -o %s %s",
-			   compiler, cflags, ccandir, outfile, cfile);
+			   "%s %s -I%s -c %s%s %s",
+			   compiler, cflags, ccandir,
+			   outexecflag, outfile, cfile);
 }
 
 /* Compile and link single C file, with object files.
@@ -51,7 +56,7 @@ bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
 	if (compile_verbose)
 		printf("Compiling and linking %s\n", outfile);
 	return run_command(ctx, NULL, output,
-			   "%s %s -I%s -o %s %s %s %s",
-			   compiler, cflags,
-			   ccandir, outfile, cfile, objs, libs);
+			   "%s %s -I%s %s%s %s %s %s",
+			   compiler, cflags, ccandir,
+			   outexecflag, outfile, cfile, objs, libs);
 }
tools/configurator/configurator.c +35 -15
index acf6cc0..d81f878 100644
@@ -40,6 +40,7 @@
 
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
+#define DEFAULT_OUTPUT_EXE_FLAG "-o"
 
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
@@ -517,10 +518,12 @@ static char *run(const char *cmd, int *exitstatus)
 	return ret;
 }
 
-static char *connect_args(const char *argv[], const char *extra)
+static char *connect_args(const char *argv[], const char *outflag,
+		const char *files)
 {
-	unsigned int i, len = strlen(extra) + 1;
+	unsigned int i;
 	char *ret;
+	size_t len = strlen(outflag) + strlen(files) + 1;
 
 	for (i = 1; argv[i]; i++)
 		len += 1 + strlen(argv[i]);
@@ -530,10 +533,12 @@ static char *connect_args(const char *argv[], const char *extra)
 	for (i = 1; argv[i]; i++) {
 		strcpy(ret + len, argv[i]);
 		len += strlen(argv[i]);
-		if (argv[i+1])
+		if (argv[i+1] || *outflag)
 			ret[len++] = ' ';
 	}
-	strcpy(ret + len, extra);
+	strcpy(ret + len, outflag);
+	len += strlen(outflag);
+	strcpy(ret + len, files);
 	return ret;
 }
 
@@ -702,33 +707,47 @@ int main(int argc, const char *argv[])
 	unsigned int i;
 	const char *default_args[]
 		= { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
+	const char *outflag = DEFAULT_OUTPUT_EXE_FLAG;
 
 	if (argc > 0)
 		progname = argv[0];
 
-	if (argc > 1) {
+	while (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
-			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
-			       "  <compiler> <flags> will have \"-o <outfile> <infile.c>\" appended\n"
-			       "Default: %s %s\n",
-			       DEFAULT_COMPILER, DEFAULT_FLAGS);
+			printf("Usage: configurator [-v] [-O<outflag>] [<compiler> <flags>...]\n"
+			       "  <compiler> <flags> will have \"<outflag> <outfile> <infile.c>\" appended\n"
+			       "Default: %s %s %s\n",
+			       DEFAULT_COMPILER, DEFAULT_FLAGS,
+			       DEFAULT_OUTPUT_EXE_FLAG);
 			exit(0);
 		}
-		if (strcmp(argv[1], "-v") == 0) {
+		if (strncmp(argv[1], "-O", 2) == 0) {
 			argc--;
 			argv++;
-			verbose = 1;
+			outflag = argv[1] + 2;
+			if (!*outflag) {
+				fprintf(stderr,
+					"%s: option requires an argument -- O\n",
+					argv[0]);
+				exit(1);
+			}
+		} else if (strcmp(argv[1], "-v") == 0) {
+			argc--;
+			argv++;
+			verbose++;
 		} else if (strcmp(argv[1], "-vv") == 0) {
 			argc--;
 			argv++;
-			verbose = 2;
+			verbose += 2;
+		} else {
+			break;
 		}
 	}
 
 	if (argc == 1)
 		argv = default_args;
 
-	cmd = connect_args(argv, " -o " OUTPUT_FILE " " INPUT_FILE);
+	cmd = connect_args(argv, outflag, OUTPUT_FILE " " INPUT_FILE);
 	for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
 		run_test(cmd, &tests[i]);
 	free(cmd);
@@ -743,9 +762,10 @@ int main(int argc, const char *argv[])
 	printf("#define _GNU_SOURCE /* Always use GNU extensions. */\n");
 	printf("#endif\n");
 	printf("#define CCAN_COMPILER \"%s\"\n", argv[1]);
-	cmd = connect_args(argv+1, "");
-	printf("#define CCAN_CFLAGS \"%s\"\n\n", cmd);
+	cmd = connect_args(argv + 1, "", "");
+	printf("#define CCAN_CFLAGS \"%s\"\n", cmd);
 	free(cmd);
+	printf("#define CCAN_OUTPUT_EXE_CFLAG \"%s\"\n\n", outflag);
 	/* This one implies "#include <ccan/..." works, eg. for tdb2.h */
 	printf("#define HAVE_CCAN 1\n");
 	for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
tools/tools.h +4 -2
index 3b5c4be..668c91a 100644
@@ -11,6 +11,7 @@
 /* These are the defaults. */
 #define DEFAULT_CCAN_COMPILER "cc"
 #define DEFAULT_CCAN_CFLAGS "-g"
+#define DEFAULT_CCAN_OUTPUT_EXE_CFLAG "-o"
 
 #define IDENT_CHARS	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
 			"abcdefghijklmnopqrstuvwxyz" \
@@ -20,8 +21,9 @@
 
 #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
 
-/* Actual compiler and cflags (defaults to CCAN_COMPILER and CCAN_CFLAGS). */
-extern const char *compiler, *cflags;
+/* Actual compiler and cflags
+ * (defaults to CCAN_COMPILER, CCAN_CFLAGS, CCAN_OUTPUT_EXE_CFLAG). */
+extern const char *compiler, *cflags, *outexecflag;
 
 /* This compiles up the _info file into a temporary. */
 char *compile_info(const void *ctx, const char *dir);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

Reviewed-by on v2 9/13
#49 lore raw

Re: [PATCH v2 09/13] configurator: DEFAULT_{COMPILER, FLAGS} for MSVC

In reply to Kevin Locke
Quoted 6 lines · Kevin Locke

When compiling with Visual Studio, use default compiler name and flags which are likely to work with the known-available compiler.

This is also a convenience for users who may not know what arguments cl.exe may need to compile the tests.

Quoted 6 lines

Changes since v1:
- Use "-option" instead of "/option" to avoid issues running under msys.
- Disable C4200 warning for use of flexible array members, which MSVC considers an extension (since it does not fully support C99).

But I won't apply it for now, since it makes no sense without the previous one.

Quoted 30 lines
---
 tools/configurator/configurator.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/configurator/configurator.c +12 -0
index d81f878..d3e01cd 100644
@@ -38,9 +38,21 @@
 #define pclose _pclose
 #endif
 
+#ifdef _MSC_VER
+#define DEFAULT_COMPILER "cl"
+/* Note:  Dash options avoid POSIX path conversion when used under msys bash
+ *        and are therefore preferred to slash (e.g. -nologo over /nologo)
+ * Note:  Disable Warning 4200 "nonstandard extension used : zero-sized array
+ *        in struct/union" for flexible array members.
+ */
+#define DEFAULT_FLAGS "-nologo -Zi -W4 -wd4200 " \
+	"-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS"
+#define DEFAULT_OUTPUT_EXE_FLAG "-Fe:"
+#else
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 #define DEFAULT_OUTPUT_EXE_FLAG "-o"
+#endif
 
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#51 lore raw

Re: [PATCH v2 10/13] configurator: Fix warning in HAVE_FOR_LOOP_DECLARATION

In reply to Kevin Locke
Quoted 5 lines · Kevin Locke

Visual C++ prints "warning C4702: unreachable code" due to the return statement after the for loop which is never reached. Fix this by setting a variable returned by a single return statement at the end.

Applying.

Quoted 20 lines
---
 tools/configurator/configurator.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/configurator/configurator.c +3 -2
index d3e01cd..a43061b 100644
@@ -222,8 +222,9 @@ static struct test tests[] = {
 	  "	return sizeof(off_t) == 8 ? 0 : 1;\n"
 	  "}\n" },
 	{ "HAVE_FOR_LOOP_DECLARATION", INSIDE_MAIN, NULL, NULL,
-	  "for (int i = 0; i < argc; i++) { return 0; };\n"
-	  "return 1;" },
+	  "int ret = 1;\n"
+	  "for (int i = 0; i < argc; i++) { ret = 0; };\n"
+	  "return ret;" },
 	{ "HAVE_FLEXIBLE_ARRAY_MEMBER", OUTSIDE_MAIN, NULL, NULL,
 	  "struct foo { unsigned int x; int arr[]; };" },
 	{ "HAVE_GETPAGESIZE", DEFINES_FUNC, NULL, NULL,
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#53 lore raw

Re: [PATCH v2 11/13] configurator: Return pointer difference as ptrdiff_t

In reply to Kevin Locke
Quoted 9 lines · Kevin Locke

On LLP64 systems (like 64-bit Windows) long is 32 bits while pointers are 64 bits, which results in a warning similar to the following:

warning C4244: 'return': conversion from '__int64' to 'long', possible loss of data

for HAVE_STACK_GROWS_UPWARDS. Fix this by using the ptrdiff_t type introduced by C99 for this purpose.

Applying.

Quoted 18 lines
---
 tools/configurator/configurator.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/configurator/configurator.c +2 -1
index a43061b..2acb0b2 100644
@@ -298,7 +298,8 @@ static struct test tests[] = {
 	  "	return __stop_mysec - __start_mysec;\n"
 	  "}\n" },
 	{ "HAVE_STACK_GROWS_UPWARDS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
-	  "static long nest(const void *base, unsigned int i)\n"
+	  "#include <stddef.h>\n"
+	  "static ptrdiff_t nest(const void *base, unsigned int i)\n"
 	  "{\n"
 	  "	if (i == 0)\n"
 	  "		return (const char *)&i - (const char *)base;\n"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#55 lore raw

Re: [PATCH v2 12/13] Makefile: Define CFLAGS_FORCE_C_SOURCE macro

In reply to Kevin Locke
Quoted 5 lines · Kevin Locke

This macro holds the C compiler flag(s) to force input files to be recognized as C sources regardless of extension. It is defined to allow overriding on the make command line.

So.. this approach works.

But I've been wondering for a while if the weird thing we do of having the _info files not have a .c extension is a good idea.

I think the underscore enough is probably enough to mark those special, so things might be less messy if we just called them _info.c.

Rusty, thoughts?

Quoted 30 lines
---
 Makefile      | 2 +-
 Makefile-ccan | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Makefile +1 -1
index 127b875..37ff17d 100644
@@ -64,7 +64,7 @@ summary-fastcheck/%: tools/ccanlint/ccanlint $(OBJFILES)
 	$(CCANLINT_FAST) -s ccan/$*
 
 ccan/%/info: ccan/%/_info config.h
-	$(CC) $(CCAN_CFLAGS) -I. -o $@ -x c $<
+	$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $<
 
 all_info: $(MODS:%=ccan/%/info)
 
Makefile-ccan +1 -0
index 5c8dea2..d4a5528 100644
@@ -5,6 +5,7 @@
 #CCAN_CFLAGS=-g -O3 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
 CCAN_CFLAGS=-g3 -ggdb -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
 CFLAGS = $(CCAN_CFLAGS) -I. $(DEPGEN)
+CFLAGS_FORCE_C_SOURCE = -x c
 
 MODS := a_star \
 	aga \
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#60 lore raw

Re: [PATCH v2 13/13] Add appveyor.yml

In reply to Kevin Locke
Quoted 10 lines · Kevin Locke

This file defines the AppVeyor CI (appveyor.com) settings.

It builds using make+bash under MSYS2 so that the current build system can be used with minimal changes. It currently only builds configurator and generates config.h.

The build and test commands for more thorough testing are left as comments in appveyor.yml so interested parties can use them as a starting point for future work.

Quoted 5 lines

Note that several compiler errors not related to configurator are printed due to make attempting to generate and include test-depends. Although Windows-specific code could be added to Makefile to avoid these, it seemed unwarranted if the compile errors may be fixed soon.

Nice, though I can't really test it until we've got the rest of the Windows / MSVC fixes applied.

If possible it would be nice to have in the commit message, and maybe as a comment in the yml file too, some instructions on how to view the appveyor results - what page to go to, do you need a login etc.

Quoted 38 lines
---
 appveyor.yml | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 appveyor.yml
appveyor.yml new file +25 -0
new file mode 100644
index 0000000..822c4bd
@@ -0,0 +1,25 @@
+version: 0.0.{build}
+
+platform:
+- x86
+- amd64
+
+build_script:
+# Reset %PATH% to avoid msys/cygwin DLL conflicts which cause
+# *** fatal error - cygheap base mismatch detected
+- set PATH=C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\msys64\usr\bin
+# Set environment variables for chosen compiler
+- "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" %Platform%"
+# Ensure config.h can be generated.
+# Note: Dash options avoid POSIX path conversion by msys
+- "make config.h CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+# FIXME:  -j%NUMBER_OF_PROCESSORS% won't work without DEPGEN for config.h
+#         It may be possible to generate .d from cl using /showIncludes
+#         See https://stackoverflow.com/q/37685069
+#- "make tools CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+#- "make -k CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+
+test_script:
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+#- "make -k check CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#62 lore raw
In reply to Kevin Locke
Quoted 25 lines · Kevin Locke

Hi all,

This is the second revision of my patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle.

The major change in this revision is the handling of the output cflag, which can now be specified by a command-line option to configurator and is set in a separate config.h macro. This both fixes the ccanlint breakage in the previous series and preserves backwards-compatibility for any code calling configurator or using CCAN_CFLAGS.

Patches which need special attention:

As before, patch 3 adds a copy of the err.h functions used by configurator to work around the lack of err.h on Windows. If this is too much code to lump into configurator.c, I can split it out (and copy err.{c,h} verbatim from musl) or call fprintf+exit directly or consider modifying the ccan/err module for use by configurator.

Patch 8 changes the configurator API by adding a command-line option and config.h macro. The names are different than I had previously suggested, as noted in the commit message.

Quoted 8 lines

Patch 13 adds appveyor.yml for AppVeyor CI. This will require (free) account setup on ci.appveyor.com once merged to enable automatic building and GitHub integration (if desired). You may also wish to consider whether to add a README badge or email notification or other mechanism to be notified of build status (beyond the default pull request hooks).

Thanks for considering once again,

Thanks for sending again. I've applied a number of the simpler ones already. The remainder I still have some comments on.

Incidentally you are introducing a new concept here which isn't really comment on. The use of more #ifdefs on system macros into configurator means that the way our default compiler options will be set up is basically going to be dependent on the setup used to compile configurator itself.

That seems like a sensible approach to me; we just need to be a bit careful of interactions with make and/or other build systems when we could have a system with multiple compilation options (e.g. both MSVC and cygwin/gcc installed on a Windows machine).

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#9 lore raw

Re: [PATCH 3/9] configurator: Inline err.h functions from musl libc

In reply to David Gibson
Quoted 5 lines · David Gibson
Quoted 4 lines · Kevin Locke

Since we can't use HAVE_ERR_H in configurator, provide a definition for the err.h functions used. The version provided is the one from musl libc, since it is concise and shares the MIT License with configurator.

Quoted 8 lines
Quoted 1 line

Right, so this is a general problem of how do we make the configurator itself sufficiently portable, since it hasn't yet worked out the portbility macros.

Personally, I think duplicating these here is an acceptable workaround. Rusty, any opinion?

Sorry for the delay, I was away for a week, then laptop death...

Yes, this is the right approach. configurator has to stand alone.

Thanks!
Rusty.
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#56 lore raw

Re: [PATCH v2 12/13] Makefile: Define CFLAGS_FORCE_C_SOURCE macro

In reply to David Gibson
Quoted 9 lines · David Gibson
Quoted 5 lines · Kevin Locke

This macro holds the C compiler flag(s) to force input files to be recognized as C sources regardless of extension. It is defined to allow overriding on the make command line.

So.. this approach works.

Quoted 7 lines

But I've been wondering for a while if the weird thing we do of having the _info files not have a .c extension is a good idea.

I think the underscore enough is probably enough to mark those special, so things might be less messy if we just called them _info.c.

Rusty, thoughts?

_info.c breaks the "compile *.c to get the module" rule, though.

_info is for both machines and humans, so it's a border case, but I think it comes down on "make the machine work harder".

Cheers,
Rusty.
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#63 lore raw
In reply to David Gibson
Quoted 7 lines · David Gibson
Quoted 6 lines · Kevin Locke

Hi all,

This is the second revision of my patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle.

Thanks for working on this! (Both of you!) I know it's a pain being a pioneer, but you'll be owed beers by many future programmers!

Cheers,
Rusty.
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#57 lore raw

Re: [PATCH v2 12/13] Makefile: Define CFLAGS_FORCE_C_SOURCE macro

In reply to Rusty Russell
Quoted 13 lines · Paul 'Rusty' Russell
Quoted 12 lines · David Gibson
Quoted 5 lines · Kevin Locke

This macro holds the C compiler flag(s) to force input files to be recognized as C sources regardless of extension. It is defined to allow overriding on the make command line.

So.. this approach works.

But I've been wondering for a while if the weird thing we do of having the _info files not have a .c extension is a good idea.

Quoted 6 lines
Quoted 4 lines

I think the underscore enough is probably enough to mark those special, so things might be less messy if we just called them _info.c.

Rusty, thoughts?

_info.c breaks the "compile *.c to get the module" rule, though.

Which is already broken by modules which have a non-trivial Makefile fragment (like ntdb).

Quoted 2 lines

_info is for both machines and humans, so it's a border case, but I think it comes down on "make the machine work harder".

Ok, let's keep this patch as is for the time being then.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#33 lore raw

PATCH v3 2/13 configurator: Reimplement run using popen

In reply to David Gibson
Quoted 5 lines · David Gibson
Quoted 3 lines · Kevin Locke

- Create fread_noeintr to avoid EINTR in fread without reading any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.

Quoted 8 lines

Hrm. Have you actually confirmed this problem with EINTR? My previous objections to not handling short read were based entirely on not realizing that fread() wasn't supposed to do that, rather than thinking of some edge case you hadn't.

Unless we have a confirmed case where fread() can give a short read that won't have feof() or ferror() set afterwards, I'm inclined to go back to your initial implementation.

Nope, I was just being overly cautious. Sounds good to me. Below is an updated patch which is the same as v1 but with the addition of the #define for _POSIX_C_SOURCE to get pclose, popen, and strdup.

-8<-------------------------------------------------------------------- Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

Changes since v1:
- Create fread_noeintr to avoid EINTR in fread without reading any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.
- Define _POSIX_C_SOURCE for popen/pclose with strict implementations which require it (e.g. gcc with -std=c11).

Changes since v2:
- Revert fread_noeintr and short read changes in v1 as unnecessary.

---
 tools/configurator/configurator.c | 79 +++++++++++++++------------------------
 1 file changed, 31 insertions(+), 48 deletions(-)
tools/configurator/configurator.c +31 -48
index c7577c0..2ad3fff 100644
@@ -21,17 +21,19 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#define _POSIX_C_SOURCE 200809L                /* For pclose, popen, strdup */
+
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <err.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
+
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 
@@ -375,20 +377,19 @@ static struct test tests[] = {
 	},
 };
 
-static char *grab_fd(int fd)
+static char *grab_stream(FILE *file)
 {
-	int ret;
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
 
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread(buffer+size, 1, max - size, file)) == max - size) {
 		size += ret;
-		if (size == max)
-			buffer = realloc(buffer, max *= 2);
+		buffer = realloc(buffer, max *= 2);
 	}
-	if (ret < 0)
+	size += ret;
+	if (ferror(file))
 		err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
@@ -396,43 +397,25 @@ static char *grab_fd(int fd)
 
 static char *run(const char *cmd, int *exitstatus)
 {
-	pid_t pid;
-	int p[2];
+	static const char redir[] = " 2>&1";
+	size_t cmdlen;
+	char *cmdredir;
+	FILE *cmdout;
 	char *ret;
-	int status;
 
-	if (pipe(p) != 0)
-		err(1, "creating pipe");
-
-	pid = fork();
-	if (pid == -1)
-		err(1, "forking");
-
-	if (pid == 0) {
-		if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
-		    || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
-		    || close(p[0]) != 0
-		    || close(STDIN_FILENO) != 0
-		    || open("/dev/null", O_RDONLY) != STDIN_FILENO)
-			exit(128);
-
-		status = system(cmd);
-		if (WIFEXITED(status))
-			exit(WEXITSTATUS(status));
-		/* Here's a hint... */
-		exit(128 + WTERMSIG(status));
-	}
+	cmdlen = strlen(cmd);
+	cmdredir = malloc(cmdlen + sizeof(redir));
+	memcpy(cmdredir, cmd, cmdlen);
+	memcpy(cmdredir + cmdlen, redir, sizeof(redir));
+
+	cmdout = popen(cmdredir, "r");
+	if (!cmdout)
+		err(1, "popen \"%s\"", cmdredir);
+
+	free(cmdredir);
 
-	close(p[1]);
-	ret = grab_fd(p[0]);
-	/* This shouldn't fail... */
-	if (waitpid(pid, &status, 0) != pid)
-		err(1, "Failed to wait for child");
-	close(p[0]);
-	if (WIFEXITED(status))
-		*exitstatus = WEXITSTATUS(status);
-	else
-		*exitstatus = -WTERMSIG(status);
+	ret = grab_stream(cmdout);
+	*exitstatus = pclose(cmdout);
 	return ret;
 }
 

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#36 lore raw

PATCH v3 3/13 configurator: Inline err.h functions

In reply to David Gibson
Quoted 5 lines · David Gibson

For me this breaks Linux build, because we get "static declaration follows non-static" on these functions.

I think we instead want to stop using the err() etc. functions and use similar functions with a different name that we always define locally.

Good catch. On my system the error only appears if I include <err.h> in configurator.c, but it's a good one to fix and may affect many other libcs.

The following patch addresses the issue by prefixing the err functions with "c12r_". It also replaced the musl libc implementation with the one from the err module, since I only recently realized that CCAN already had an err.h implementation and I don't see any need to add a different one to the sources.

-8<-------------------------------------------------------------------- On systems where err.h is not provided (e.g. MSVC) configurator must provide its own definition. The err module can not be used by configurator due to its dependency on config.h, so the relevant source is copied into configurator with the minimum changes necessary.

Changes since v2:
- Use the CCAN err module sources instead of musl libc sources to avoid introducing another implementation of these functions.
- Prefix err.h functions with "c12r_" to avoid name conflicts and "static declaration follows non-static" errors.

---
 tools/configurator/configurator.c | 49 ++++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 8 deletions(-)
tools/configurator/configurator.c +41 -8
index 2ad3fff..a7cbfa5 100644
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Rusty Russell <[email protected]>.  MIT license.
  *
+ * c12r_err, c12r_errx functions copied from ccan/err/err.c
+ * Copyright Rusty Russell <[email protected]>. CC0 (Public domain) License.
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -23,10 +26,11 @@
  */
 #define _POSIX_C_SOURCE 200809L                /* For pclose, popen, strdup */
 
+#include <errno.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <err.h>
 #include <string.h>
 
 #ifdef _MSC_VER
@@ -46,6 +50,7 @@
 #define DIR_SEP   "/"
 #endif
 
+static const char *progname = "";
 static int verbose;
 
 enum test_style {
@@ -377,6 +382,31 @@ static struct test tests[] = {
 	},
 };
 
+static void c12r_err(int eval, const char *fmt, ...)
+{
+	int err_errno = errno;
+	va_list ap;
+
+	fprintf(stderr, "%s: ", progname);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, ": %s\n", strerror(err_errno));
+	exit(eval);
+}
+
+static void c12r_errx(int eval, const char *fmt, ...)
+{
+	va_list ap;
+
+	fprintf(stderr, "%s: ", progname);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, "\n");
+	exit(eval);
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -390,7 +420,7 @@ static char *grab_stream(FILE *file)
 	}
 	size += ret;
 	if (ferror(file))
-		err(1, "reading from command");
+		c12r_err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
 }
@@ -410,7 +440,7 @@ static char *run(const char *cmd, int *exitstatus)
 
 	cmdout = popen(cmdredir, "r");
 	if (!cmdout)
-		err(1, "popen \"%s\"", cmdredir);
+		c12r_err(1, "popen \"%s\"", cmdredir);
 
 	free(cmdredir);
 
@@ -502,7 +532,7 @@ static bool run_test(const char *cmd, struct test *test)
 
 	outf = fopen(INPUT_FILE, "w");
 	if (!outf)
-		err(1, "creating %s", INPUT_FILE);
+		c12r_err(1, "creating %s", INPUT_FILE);
 
 	fprintf(outf, "%s", PRE_BOILERPLATE);
 	switch (test->style & ~(EXECUTE|MAY_NOT_COMPILE)) {
@@ -567,8 +597,8 @@ static bool run_test(const char *cmd, struct test *test)
 			       status ? "fail" : "warning",
 			       test->name, status, output);
 		if ((test->style & EXECUTE) && !(test->style & MAY_NOT_COMPILE))
-			errx(1, "Test for %s did not compile:\n%s",
-			     test->name, output);
+			c12r_errx(1, "Test for %s did not compile:\n%s",
+				  test->name, output);
 		test->answer = false;
 		free(output);
 	} else {
@@ -578,8 +608,8 @@ static bool run_test(const char *cmd, struct test *test)
 		if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
 			output = run("." DIR_SEP OUTPUT_FILE, &status);
 			if (!(test->style & EXECUTE) && status != 0)
-				errx(1, "Test for %s failed with %i:\n%s",
-				     test->name, status, output);
+				c12r_errx(1, "Test for %s failed with %i:\n%s",
+					  test->name, status, output);
 			if (verbose && status)
 				printf("%s exited %i\n", test->name, status);
 			free(output);
@@ -603,6 +633,9 @@ int main(int argc, const char *argv[])
 	const char *default_args[]
 		= { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
 
+	if (argc > 0)
+		progname = argv[0];
+
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"

--
2.9.3
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#43 lore raw

Re: [PATCH v2 06/13] configurator: Print test source without cat

In reply to David Gibson
Quoted 12 lines · David Gibson
Quoted 11 lines · Kevin Locke

Windows does not provide cat. Instead, copy the test source to stdout using the file stream to which it was written.

Changes since v1:
- Create fwrite_noeintr to avoid EINTR in fwrite without writing any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.
- Handle short writes from fwrite. This can happen with non-conformant libc or if EINTR occurs after writing some data.

Quoted 3 lines
Quoted 1 line

As with patch 2, I'm not sure about the need for fwrite_noeintr().

Agreed. The v1 patch should be good as-is with just a few line offsets. If it gives you any problems, I can post an updated one.

Kevin
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#61 lore raw

PATCH v3 13/13 Add appveyor.yml

In reply to David Gibson
Quoted 9 lines · David Gibson
Quoted 1 line · Kevin Locke

This file defines the AppVeyor CI (appveyor.com) settings.

Nice, though I can't really test it until we've got the rest of the Windows / MSVC fixes applied.

If possible it would be nice to have in the commit message, and maybe as a comment in the yml file too, some instructions on how to view the appveyor results - what page to go to, do you need a login etc.

Sure, good idea. This patch includes basic instructions for how to view the current status and how to setup AppVeyor for a copy of the repository.

It makes the assumption that Rusty wouldn't mind setting up AppVeyor for his CCAN GitHub repo (which would also add build checks to pull requests). If you'd prefer not to, I think I can set it up to build from git://git.ozlabs.org/~ccan/ccan on my own account (although I'm not sure how it would handle update checking). Let me know and I'll give it a try to find out.

Also, for reference, you can see the current build results on my repo at https://ci.appveyor.com/project/kevinoid/ccan

-8<-------------------------------------------------------------------- This file defines the AppVeyor CI (appveyor.com) settings.

It builds using make+bash under MSYS2 so that the current build system can be used with minimal changes. It currently only builds configurator and generates config.h.

The build and test commands for more thorough testing are left as comments in appveyor.yml so interested parties can use them as a starting point for future work.

Note that several compiler errors not related to configurator are printed due to make attempting to generate and include test-depends. Although Windows-specific code could be added to Makefile to avoid these, it seemed unwarranted if the compile errors may be fixed soon.

Changes since v2:
- Add reference to AppVeyor results for Rusty's GitHub repo and basic instructions to setup AppVeyor for forks.

---
 appveyor.yml | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 appveyor.yml
appveyor.yml new file +37 -0
new file mode 100644
index 0000000..0a930c6
@@ -0,0 +1,37 @@
+# AppVeyor CI Configuration
+#
+# Current build status can be viewed at
+# https://ci.appveyor.com/project/rustyrussell/ccan
+#
+# To build test a fork of this repository using AppVeyor:
+# 1. Visit appveyor.com and create a free account.
+# 2. On the Projects tab, select "New Project" then the project hosting site.
+# 3. Grant OAuth permissions to your project git host.
+# 4. Select the repository for your project fork.
+# 5. Review build results and push updates until the desired result is reached.
+
+version: 0.0.{build}
+
+platform:
+- x86
+- amd64
+
+build_script:
+# Reset %PATH% to avoid msys/cygwin DLL conflicts which cause
+# *** fatal error - cygheap base mismatch detected
+- set PATH=C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\msys64\usr\bin
+# Set environment variables for chosen compiler
+- "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" %Platform%"
+# Ensure config.h can be generated.
+# Note: Dash options avoid POSIX path conversion by msys
+- "make config.h CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+# FIXME:  -j%NUMBER_OF_PROCESSORS% won't work without DEPGEN for config.h
+#         It may be possible to generate .d from cl using /showIncludes
+#         See https://stackoverflow.com/q/37685069
+#- "make tools CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+#- "make -k CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+
+test_script:
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+#- "make -k check CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
Signature · 6 lines
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
#65 lore raw
In reply to David Gibson
Quoted 8 lines · David Gibson
Quoted 4 lines · Kevin Locke

This is the second revision of my patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle.

Thanks for sending again. I've applied a number of the simpler ones already. The remainder I still have some comments on.

Thanks for reviewing again! I think I've addressed everything, but if there is anything I've overlooked, let me know.

Quoted 10 lines

Incidentally you are introducing a new concept here which isn't really comment on. The use of more #ifdefs on system macros into configurator means that the way our default compiler options will be set up is basically going to be dependent on the setup used to compile configurator itself.

That seems like a sensible approach to me; we just need to be a bit careful of interactions with make and/or other build systems when we could have a system with multiple compilation options (e.g. both MSVC and cygwin/gcc installed on a Windows machine).

That is a good point and probably deserves some more thought and discussion. I've tried to keep most additions configurable at run-time (e.g. the new -O configurator flag) so if the compile-time deduction is wrong it can be overridden. But it still changes the configurator behavior based on how it was compiled without any explicit configuration. That may or may not be desirable. Has there been any discussion of being more explicit about specifying build vs host system at build time? Anything in particular you have in mind?

A good example of something which can not be overridden at runtime is the directory separator passed to popen(3). I don't think there are currently any problems, but the choice of directory separator could easily cause problems between Cygwin and native binaries in other situations. Definitely worth thinking about.

Cheers,
Kevin
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#64 lore raw
In reply to Rusty Russell
Quoted 11 lines · Rusty Russell
Quoted 7 lines · David Gibson
Quoted 6 lines · Kevin Locke

Hi all,

This is the second revision of my patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle.

Thanks for working on this! (Both of you!) I know it's a pain being a pioneer, but you'll be owed beers by many future programmers!

My pleasure. Sounds well worth the reward to me!

Cheers,
Kevin
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#66 lore raw
In reply to Kevin Locke
Quoted 7 lines · Kevin Locke
Quoted 6 lines · David Gibson
Quoted 4 lines · Kevin Locke

This is the second revision of my patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows. The motivation is to add sufficient support for Windows to allow using header-only modules with minimal hassle.

Quoted 5 lines
Quoted 2 lines

Thanks for sending again. I've applied a number of the simpler ones already. The remainder I still have some comments on.

Thanks for reviewing again! I think I've addressed everything, but if there is anything I've overlooked, let me know.

Right. Can you rebase your current patches and post them as a new series. That's makes my life easier compared to updated versions of each patch in various places in the thread.

Quoted 12 lines
Quoted 11 lines

Incidentally you are introducing a new concept here which isn't really comment on. The use of more #ifdefs on system macros into configurator means that the way our default compiler options will be set up is basically going to be dependent on the setup used to compile configurator itself.

That seems like a sensible approach to me; we just need to be a bit careful of interactions with make and/or other build systems when we could have a system with multiple compilation options (e.g. both MSVC and cygwin/gcc installed on a Windows machine).

Quoted 6 lines

That is a good point and probably deserves some more thought and discussion. I've tried to keep most additions configurable at run-time (e.g. the new -O configurator flag) so if the compile-time deduction is wrong it can be overridden. But it still changes the configurator behavior based on how it was compiled without any explicit configuration. That may or may not be desirable.

I think it's desirable, on the whole. But having overrides is generally a good idea too.

Quoted 3 lines

Has there
been any discussion of being more explicit about specifying build vs host system at build time? Anything in particular you have in mind?

No, I'm afraid not.

Quoted 5 lines

A good example of something which can not be overridden at runtime is the directory separator passed to popen(3). I don't think there are currently any problems, but the choice of directory separator could easily cause problems between Cygwin and native binaries in other situations. Definitely worth thinking about.

Yeah.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#67 lore raw

v3 cover configurator: Support for Windows and MSVC

Quoted 3 lines · David Gibson

Right. Can you rebase your current patches and post them as a new series. That's makes my life easier compared to updated versions of each patch in various places in the thread.

Certainly. No problem.

Here is the third revision of the patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows.

Significant changes from v2:
* Removing the unnecessary EINTR and short read/write handling code.
* Switching from the musl libc err.h implementation to the CCAN err module one in hopes of reducing maintenance burden and code proliferation.
* Additional documentation comments for AppVeyor.

Thanks again!
Kevin

Kevin Locke (7):
configurator: Reimplement run using popen
configurator: Inline err.h functions
configurator: Print test source without cat
configurator: Add output cflag option and macro
configurator: DEFAULT_{COMPILER,FLAGS} for MSVC
Makefile: Define CFLAGS_FORCE_C_SOURCE macro
Add appveyor.yml

 Makefile                          |   2 +-
 Makefile-ccan                     |   1 +
 appveyor.yml                      |  37 +++++++
 tools/compile.c                   |  15 ++-
 tools/configurator/configurator.c | 216 +++++++++++++++++++++++++-------------
 tools/tools.h                     |   6 +-
 6 files changed, 194 insertions(+), 83 deletions(-)
 create mode 100644 appveyor.yml

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#68 lore raw

PATCH v3 1/7 configurator: Reimplement run using popen

Rather than using fork+pipe+system+waitpid, most of which are only available on POSIX-like systems, use popen which is also available on Windows (under the name _popen).

Changes since v1:
- Create fread_noeintr to avoid EINTR in fread without reading any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.
- Define _POSIX_C_SOURCE for popen/pclose with strict implementations which require it (e.g. gcc with -std=c11).

Changes since v2:
- Revert fread_noeintr and short read changes in v1 as unnecessary.

---
 tools/configurator/configurator.c | 79 +++++++++++++++------------------------
 1 file changed, 31 insertions(+), 48 deletions(-)
tools/configurator/configurator.c +31 -48
index c7577c0..2ad3fff 100644
@@ -21,17 +21,19 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#define _POSIX_C_SOURCE 200809L                /* For pclose, popen, strdup */
+
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <err.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
+
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 
@@ -375,20 +377,19 @@ static struct test tests[] = {
 	},
 };
 
-static char *grab_fd(int fd)
+static char *grab_stream(FILE *file)
 {
-	int ret;
-	size_t max, size = 0;
+	size_t max, ret, size = 0;
 	char *buffer;
 
-	max = 16384;
-	buffer = malloc(max+1);
-	while ((ret = read(fd, buffer + size, max - size)) > 0) {
+	max = BUFSIZ;
+	buffer = malloc(max);
+	while ((ret = fread(buffer+size, 1, max - size, file)) == max - size) {
 		size += ret;
-		if (size == max)
-			buffer = realloc(buffer, max *= 2);
+		buffer = realloc(buffer, max *= 2);
 	}
-	if (ret < 0)
+	size += ret;
+	if (ferror(file))
 		err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
@@ -396,43 +397,25 @@ static char *grab_fd(int fd)
 
 static char *run(const char *cmd, int *exitstatus)
 {
-	pid_t pid;
-	int p[2];
+	static const char redir[] = " 2>&1";
+	size_t cmdlen;
+	char *cmdredir;
+	FILE *cmdout;
 	char *ret;
-	int status;
 
-	if (pipe(p) != 0)
-		err(1, "creating pipe");
-
-	pid = fork();
-	if (pid == -1)
-		err(1, "forking");
-
-	if (pid == 0) {
-		if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
-		    || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
-		    || close(p[0]) != 0
-		    || close(STDIN_FILENO) != 0
-		    || open("/dev/null", O_RDONLY) != STDIN_FILENO)
-			exit(128);
-
-		status = system(cmd);
-		if (WIFEXITED(status))
-			exit(WEXITSTATUS(status));
-		/* Here's a hint... */
-		exit(128 + WTERMSIG(status));
-	}
+	cmdlen = strlen(cmd);
+	cmdredir = malloc(cmdlen + sizeof(redir));
+	memcpy(cmdredir, cmd, cmdlen);
+	memcpy(cmdredir + cmdlen, redir, sizeof(redir));
+
+	cmdout = popen(cmdredir, "r");
+	if (!cmdout)
+		err(1, "popen \"%s\"", cmdredir);
+
+	free(cmdredir);
 
-	close(p[1]);
-	ret = grab_fd(p[0]);
-	/* This shouldn't fail... */
-	if (waitpid(pid, &status, 0) != pid)
-		err(1, "Failed to wait for child");
-	close(p[0]);
-	if (WIFEXITED(status))
-		*exitstatus = WEXITSTATUS(status);
-	else
-		*exitstatus = -WTERMSIG(status);
+	ret = grab_stream(cmdout);
+	*exitstatus = pclose(cmdout);
 	return ret;
 }
 

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#69 lore raw

PATCH v3 2/7 configurator: Inline err.h functions

In reply to Kevin Locke

On systems where err.h is not provided (e.g. MSVC) configurator must provide its own definition. The err module can not be used by configurator due to its dependency on config.h, so the relevant source is copied into configurator with the minimum changes necessary.

Changes since v2:
- Use the CCAN err module sources instead of musl libc sources to avoid introducing another implementation of these functions.
- Prefix err.h functions with "c12r_" to avoid name conflicts and "static declaration follows non-static" errors.

---
 tools/configurator/configurator.c | 49 ++++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 8 deletions(-)
tools/configurator/configurator.c +41 -8
index 2ad3fff..a7cbfa5 100644
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Rusty Russell <[email protected]>.  MIT license.
  *
+ * c12r_err, c12r_errx functions copied from ccan/err/err.c
+ * Copyright Rusty Russell <[email protected]>. CC0 (Public domain) License.
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -23,10 +26,11 @@
  */
 #define _POSIX_C_SOURCE 200809L                /* For pclose, popen, strdup */
 
+#include <errno.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include <err.h>
 #include <string.h>
 
 #ifdef _MSC_VER
@@ -46,6 +50,7 @@
 #define DIR_SEP   "/"
 #endif
 
+static const char *progname = "";
 static int verbose;
 
 enum test_style {
@@ -377,6 +382,31 @@ static struct test tests[] = {
 	},
 };
 
+static void c12r_err(int eval, const char *fmt, ...)
+{
+	int err_errno = errno;
+	va_list ap;
+
+	fprintf(stderr, "%s: ", progname);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, ": %s\n", strerror(err_errno));
+	exit(eval);
+}
+
+static void c12r_errx(int eval, const char *fmt, ...)
+{
+	va_list ap;
+
+	fprintf(stderr, "%s: ", progname);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, "\n");
+	exit(eval);
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -390,7 +420,7 @@ static char *grab_stream(FILE *file)
 	}
 	size += ret;
 	if (ferror(file))
-		err(1, "reading from command");
+		c12r_err(1, "reading from command");
 	buffer[size] = '\0';
 	return buffer;
 }
@@ -410,7 +440,7 @@ static char *run(const char *cmd, int *exitstatus)
 
 	cmdout = popen(cmdredir, "r");
 	if (!cmdout)
-		err(1, "popen \"%s\"", cmdredir);
+		c12r_err(1, "popen \"%s\"", cmdredir);
 
 	free(cmdredir);
 
@@ -502,7 +532,7 @@ static bool run_test(const char *cmd, struct test *test)
 
 	outf = fopen(INPUT_FILE, "w");
 	if (!outf)
-		err(1, "creating %s", INPUT_FILE);
+		c12r_err(1, "creating %s", INPUT_FILE);
 
 	fprintf(outf, "%s", PRE_BOILERPLATE);
 	switch (test->style & ~(EXECUTE|MAY_NOT_COMPILE)) {
@@ -567,8 +597,8 @@ static bool run_test(const char *cmd, struct test *test)
 			       status ? "fail" : "warning",
 			       test->name, status, output);
 		if ((test->style & EXECUTE) && !(test->style & MAY_NOT_COMPILE))
-			errx(1, "Test for %s did not compile:\n%s",
-			     test->name, output);
+			c12r_errx(1, "Test for %s did not compile:\n%s",
+				  test->name, output);
 		test->answer = false;
 		free(output);
 	} else {
@@ -578,8 +608,8 @@ static bool run_test(const char *cmd, struct test *test)
 		if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
 			output = run("." DIR_SEP OUTPUT_FILE, &status);
 			if (!(test->style & EXECUTE) && status != 0)
-				errx(1, "Test for %s failed with %i:\n%s",
-				     test->name, status, output);
+				c12r_errx(1, "Test for %s failed with %i:\n%s",
+					  test->name, status, output);
 			if (verbose && status)
 				printf("%s exited %i\n", test->name, status);
 			free(output);
@@ -603,6 +633,9 @@ int main(int argc, const char *argv[])
 	const char *default_args[]
 		= { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
 
+	if (argc > 0)
+		progname = argv[0];
+
 	if (argc > 1) {
 		if (strcmp(argv[1], "--help") == 0) {
 			printf("Usage: configurator [-v] [<compiler> <flags>...]\n"

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#70 lore raw

PATCH v3 3/7 configurator: Print test source without cat

In reply to Kevin Locke

Windows does not provide cat. Instead, copy the test source to stdout using the file stream to which it was written.

Changes since v1:
- Create fwrite_noeintr to avoid EINTR in fwrite without writing any data.
- Handle short reads from fread. This can happen with non-conformant libc or if EINTR occurs after reading some data.
- Handle short writes from fwrite. This can happen with non-conformant libc or if EINTR occurs after writing some data.

Changes since v2:
- Revert fwrite_noeintr and short read/write changes.

---
 tools/configurator/configurator.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
tools/configurator/configurator.c +23 -5
index a7cbfa5..73fdc95 100644
@@ -407,6 +407,22 @@ static void c12r_errx(int eval, const char *fmt, ...)
 	exit(eval);
 }
 
+static size_t fcopy(FILE *fsrc, FILE *fdst)
+{
+	char buffer[BUFSIZ];
+	size_t rsize, wsize;
+	size_t copied = 0;
+
+	while ((rsize = fread(buffer, 1, BUFSIZ, fsrc)) > 0) {
+		wsize = fwrite(buffer, 1, rsize, fdst);
+		copied += wsize;
+		if (wsize != rsize)
+			break;
+	}
+
+	return copied;
+}
+
 static char *grab_stream(FILE *file)
 {
 	size_t max, ret, size = 0;
@@ -530,7 +546,7 @@ static bool run_test(const char *cmd, struct test *test)
 		}
 	}
 
-	outf = fopen(INPUT_FILE, "w");
+	outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w");
 	if (!outf)
 		c12r_err(1, "creating %s", INPUT_FILE);
 
@@ -561,11 +577,13 @@ static bool run_test(const char *cmd, struct test *test)
 		abort();
 
 	}
-	fclose(outf);
 
-	if (verbose > 1)
-		if (system("cat " INPUT_FILE) == -1)
-			;
+	if (verbose > 1) {
+		fseek(outf, 0, SEEK_SET);
+		fcopy(outf, stdout);
+	}
+
+	fclose(outf);
 
 	newcmd = strdup(cmd);
 

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#71 lore raw

PATCH v3 4/7 configurator: Add output cflag option and macro

In reply to Kevin Locke

Unfortunately, not all compilers support -o as a command-line option for specifying the output file. Visual Studio cl.exe issues warning D9035 when -o is given, which is detected as a compile warning by the configurator.

To support such compilers, add the command-line option -O to configurator which can be used to specify the cflag for setting the output executable file name. Additionally define the macro CCAN_OUTPUT_EXE_CFLAG in config.h and use it when invoking the compiler (e.g. from ccanlint).

For reference, the name CCAN_OUTPUT_EXE_CFLAG was chosen to avoid potential name conflicts in the future due to cl.exe requiring different flags for different types of output[1] (e.g. object files are /Fo:).

1. https://msdn.microsoft.com/en-us/library/f1cb223a.aspx

---
 tools/compile.c                   | 15 ++++++++----
 tools/configurator/configurator.c | 50 +++++++++++++++++++++++++++------------
 tools/tools.h                     |  6 +++--
 3 files changed, 49 insertions(+), 22 deletions(-)
tools/compile.c +10 -5
index b88c1d8..e796e3f 100644
@@ -7,8 +7,12 @@
 #ifndef CCAN_CFLAGS
 #define CCAN_CFLAGS DEFAULT_CCAN_CFLAGS
 #endif
+#ifndef CCAN_OUTPUT_EXE_CFLAG
+#define CCAN_OUTPUT_EXE_CFLAG DEFAULT_CCAN_OUTPUT_EXE_CFLAG
+#endif
 const char *compiler = CCAN_COMPILER;
 const char *cflags = CCAN_CFLAGS;
+const char *outexecflag = CCAN_OUTPUT_EXE_CFLAG;
 
 bool compile_verbose = false;
 
@@ -37,8 +41,9 @@ bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
 	if (compile_verbose)
 		printf("Compiling %s\n", outfile);
 	return run_command(ctx, NULL, output,
-			   "%s %s -I%s -c -o %s %s",
-			   compiler, cflags, ccandir, outfile, cfile);
+			   "%s %s -I%s -c %s%s %s",
+			   compiler, cflags, ccandir,
+			   outexecflag, outfile, cfile);
 }
 
 /* Compile and link single C file, with object files.
@@ -51,7 +56,7 @@ bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
 	if (compile_verbose)
 		printf("Compiling and linking %s\n", outfile);
 	return run_command(ctx, NULL, output,
-			   "%s %s -I%s -o %s %s %s %s",
-			   compiler, cflags,
-			   ccandir, outfile, cfile, objs, libs);
+			   "%s %s -I%s %s%s %s %s %s",
+			   compiler, cflags, ccandir,
+			   outexecflag, outfile, cfile, objs, libs);
 }
tools/configurator/configurator.c +35 -15

103 lines not on this page · raw message

tools/tools.h +4 -2
index 3b5c4be..668c91a 100644
@@ -11,6 +11,7 @@
 /* These are the defaults. */
 #define DEFAULT_CCAN_COMPILER "cc"
 #define DEFAULT_CCAN_CFLAGS "-g"
+#define DEFAULT_CCAN_OUTPUT_EXE_CFLAG "-o"
 
 #define IDENT_CHARS	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
 			"abcdefghijklmnopqrstuvwxyz" \
@@ -20,8 +21,9 @@
 
 #define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
 
-/* Actual compiler and cflags (defaults to CCAN_COMPILER and CCAN_CFLAGS). */
-extern const char *compiler, *cflags;
+/* Actual compiler and cflags
+ * (defaults to CCAN_COMPILER, CCAN_CFLAGS, CCAN_OUTPUT_EXE_CFLAG). */
+extern const char *compiler, *cflags, *outexecflag;
 
 /* This compiles up the _info file into a temporary. */
 char *compile_info(const void *ctx, const char *dir);

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#72 lore raw

PATCH v3 5/7 configurator: DEFAULT_{COMPILER, FLAGS} for MSVC

In reply to Kevin Locke

When compiling with Visual Studio, use default compiler name and flags which are likely to work with the known-available compiler.

This is also a convenience for users who may not know what arguments cl.exe may need to compile the tests.

Changes since v1:
- Use "-option" instead of "/option" to avoid issues running under msys.
- Disable C4200 warning for use of flexible array members, which MSVC considers an extension (since it does not fully support C99).

---
 tools/configurator/configurator.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/configurator/configurator.c +12 -0
index 4cb84d0..6ec30bd 100644
@@ -38,9 +38,21 @@
 #define pclose _pclose
 #endif
 
+#ifdef _MSC_VER
+#define DEFAULT_COMPILER "cl"
+/* Note:  Dash options avoid POSIX path conversion when used under msys bash
+ *        and are therefore preferred to slash (e.g. -nologo over /nologo)
+ * Note:  Disable Warning 4200 "nonstandard extension used : zero-sized array
+ *        in struct/union" for flexible array members.
+ */
+#define DEFAULT_FLAGS "-nologo -Zi -W4 -wd4200 " \
+	"-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS"
+#define DEFAULT_OUTPUT_EXE_FLAG "-Fe:"
+#else
 #define DEFAULT_COMPILER "cc"
 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
 #define DEFAULT_OUTPUT_EXE_FLAG "-o"
+#endif
 
 #define OUTPUT_FILE "configurator.out"
 #define INPUT_FILE "configuratortest.c"

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#73 lore raw

PATCH v3 6/7 Makefile: Define CFLAGS_FORCE_C_SOURCE macro

In reply to Kevin Locke

This macro holds the C compiler flag(s) to force input files to be recognized as C sources regardless of extension. It is defined to allow overriding on the make command line.

---
 Makefile      | 2 +-
 Makefile-ccan | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Makefile +1 -1
index 127b875..37ff17d 100644
@@ -64,7 +64,7 @@ summary-fastcheck/%: tools/ccanlint/ccanlint $(OBJFILES)
 	$(CCANLINT_FAST) -s ccan/$*
 
 ccan/%/info: ccan/%/_info config.h
-	$(CC) $(CCAN_CFLAGS) -I. -o $@ -x c $<
+	$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $<
 
 all_info: $(MODS:%=ccan/%/info)
 
Makefile-ccan +1 -0
index 5c8dea2..d4a5528 100644
@@ -5,6 +5,7 @@
 #CCAN_CFLAGS=-g -O3 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
 CCAN_CFLAGS=-g3 -ggdb -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
 CFLAGS = $(CCAN_CFLAGS) -I. $(DEPGEN)
+CFLAGS_FORCE_C_SOURCE = -x c
 
 MODS := a_star \
 	aga \

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#74 lore raw

PATCH v3 7/7 Add appveyor.yml

In reply to Kevin Locke

This file defines the AppVeyor CI (appveyor.com) settings.

It builds using make+bash under MSYS2 so that the current build system can be used with minimal changes. It currently only builds configurator and generates config.h.

The build and test commands for more thorough testing are left as comments in appveyor.yml so interested parties can use them as a starting point for future work.

Note that several compiler errors not related to configurator are printed due to make attempting to generate and include test-depends. Although Windows-specific code could be added to Makefile to avoid these, it seemed unwarranted if the compile errors may be fixed soon.

Changes since v2:
- Add reference to AppVeyor results for canonical repo and basic instructions to setup AppVeyor for forks.

---
 appveyor.yml | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 appveyor.yml
appveyor.yml new file +37 -0
new file mode 100644
index 0000000..0a930c6
@@ -0,0 +1,37 @@
+# AppVeyor CI Configuration
+#
+# Current build status can be viewed at
+# https://ci.appveyor.com/project/rustyrussell/ccan
+#
+# To build test a fork of this repository using AppVeyor:
+# 1. Visit appveyor.com and create a free account.
+# 2. On the Projects tab, select "New Project" then the project hosting site.
+# 3. Grant OAuth permissions to your project git host.
+# 4. Select the repository for your project fork.
+# 5. Review build results and push updates until the desired result is reached.
+
+version: 0.0.{build}
+
+platform:
+- x86
+- amd64
+
+build_script:
+# Reset %PATH% to avoid msys/cygwin DLL conflicts which cause
+# *** fatal error - cygheap base mismatch detected
+- set PATH=C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\msys64\usr\bin
+# Set environment variables for chosen compiler
+- "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" %Platform%"
+# Ensure config.h can be generated.
+# Note: Dash options avoid POSIX path conversion by msys
+- "make config.h CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+# FIXME:  -j%NUMBER_OF_PROCESSORS% won't work without DEPGEN for config.h
+#         It may be possible to generate .d from cl using /showIncludes
+#         See https://stackoverflow.com/q/37685069
+#- "make tools CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+#- "make -k CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+
+test_script:
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+#- "make -k check CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"

--
2.9.3

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

Applied
#75 lore raw
In reply to Kevin Locke
Quoted 11 lines · Kevin Locke
Quoted 3 lines · David Gibson

Right. Can you rebase your current patches and post them as a new series. That's makes my life easier compared to updated versions of each patch in various places in the thread.

Certainly. No problem.

Here is the third revision of the patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows.

Quoted 6 lines

Significant changes from v2:
* Removing the unnecessary EINTR and short read/write handling code.
* Switching from the musl libc err.h implementation to the CCAN err module one in hopes of reducing maintenance burden and code proliferation.
* Additional documentation comments for AppVeyor.

I've merged these to master.

Judging by the FIXMEs in appveyor.yml there's still a lot of things broken, but it's a start.

I set myself up an appveyor account and tweaked your comment to point at that instead of the hypothetical one Rusty may or may not set up at some point.

I've actually set up two appveyor projects: one which tracks my github ccan repository at:
https://ci.appveyor.com/project/dgibson/ccan-c44x3

And another which tracks the upstream master git for ccan at:
https://ci.appveyor.com/project/dgibson/ccan

Bizarrely, the github one is working great, whereas the direct git one is giving errors, even though they're showing as building exactly the same commit :/. It kind of looks like the master one is ignoring the appveyor.yml for no apparent reason - it seems to be looking for a vcproj file instead of using the build scripts you've supplied.

Oh well, maybe we'll figure it out in future.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#76 lore raw
Quoted 5 lines · David Gibson
Quoted 4 lines · Kevin Locke

Here is the third revision of the patch series which adds support for building configurator with Microsoft Visual C++ and running it on Windows.

Quoted 8 lines
Quoted 6 lines

Significant changes from v2:
* Removing the unnecessary EINTR and short read/write handling code.
* Switching from the musl libc err.h implementation to the CCAN err module one in hopes of reducing maintenance burden and code proliferation.
* Additional documentation comments for AppVeyor.

I've merged these to master.

Thanks! That's great!

Quoted 2 lines

Judging by the FIXMEs in appveyor.yml there's still a lot of things broken, but it's a start.

Very true. At the moment it only tests configurator, although it generates and ignores compile errors for ccan_depends due to "-include test-depends". Fixing that will require the dgraph/tlist changes previously discussed[1] and possibly other major changes I haven't discovered yet. So it's on hold for now unless anyone is really eager to push it forward.

Quoted 8 lines

I set myself up an appveyor account and tweaked your comment to point at that instead of the hypothetical one Rusty may or may not set up at some point.

I've actually set up two appveyor projects: one which tracks my github ccan repository at:
https://ci.appveyor.com/project/dgibson/ccan-c44x3

Quoted 8 lines

And another which tracks the upstream master git for ccan at:
https://ci.appveyor.com/project/dgibson/ccan

Bizarrely, the github one is working great, whereas the direct git one is giving errors, even though they're showing as building exactly the same commit :/. It kind of looks like the master one is ignoring the appveyor.yml for no apparent reason - it seems to be looking for a vcproj file instead of using the build scripts you've supplied.

Looks great! Thanks for taking the time to set that up!

I it looks like this is a result of AppVeyor not using appveyor.yml for custom Git repositories.[2] I've added a comment to the issue in their GitHub issue tracker to see what can be done. If they don't move on it, it would be possible to copy the settings from appveyor.yml into the project settings web interface, with the caveat that they wouldn't be updated from the repo in the future. I'll follow up when/if I hear back from the AppVeyor folks.

Thanks again for all of your effort on this,
Kevin

1. https://lists.ozlabs.org/pipermail/ccan/2016-September/001248.html
2. https://github.com/appveyor/ci/issues/545
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#58 lore raw

Re: [PATCH v2 12/13] Makefile: Define CFLAGS_FORCE_C_SOURCE macro

In reply to David Gibson
Quoted 17 lines · David Gibson
Quoted 16 lines · Paul 'Rusty' Russell
Quoted 15 lines · David Gibson
Quoted 5 lines · Kevin Locke

This macro holds the C compiler flag(s) to force input files to be recognized as C sources regardless of extension. It is defined to allow overriding on the make command line.

So.. this approach works.

But I've been wondering for a while if the weird thing we do of having the _info files not have a .c extension is a good idea.

I think the underscore enough is probably enough to mark those special, so things might be less messy if we just called them _info.c.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Rusty, thoughts?

_info.c breaks the "compile *.c to get the module" rule, though.

Which is already broken by modules which have a non-trivial Makefile fragment (like ntdb).

Not at all! ntdb's Makefile is a relic from when it was out-of-tree. It builds other things, but the module builds fine.

Cheers,
Rusty.
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#77 lore raw

AppVeyor custom Git URL support (was Re: [PATCH v3 0/7] configurator: Support for Windows and MSVC)

In reply to Kevin Locke
Quoted 18 lines · Kevin Locke
Quoted 8 lines · David Gibson

I set myself up an appveyor account and tweaked your comment to point at that instead of the hypothetical one Rusty may or may not set up at some point.

I've actually set up two appveyor projects: one which tracks my github ccan repository at:
https://ci.appveyor.com/project/dgibson/ccan-c44x3

Quoted 8 lines

And another which tracks the upstream master git for ccan at:
https://ci.appveyor.com/project/dgibson/ccan

Bizarrely, the github one is working great, whereas the direct git one is giving errors, even though they're showing as building exactly the same commit :/. It kind of looks like the master one is ignoring the appveyor.yml for no apparent reason - it seems to be looking for a vcproj file instead of using the build scripts you've supplied.

Quoted 3 lines

I it looks like this is a result of AppVeyor not using appveyor.yml for custom Git repositories.[2] I've added a comment to the issue in their GitHub issue tracker to see what can be done. [...]

To follow up on this, AppVeyor just released an update which includes support for YAML configuration files loaded from a user-specified URL.[1] I tried creating an AppVeyor project with the YAML configuration loaded via gitweb using the following URL:

https://git.ozlabs.org/?p=ccan;a=blob_plain;f=appveyor.yml;hb=HEAD

It built successfully using the project appveyor.yml configuration. You may want to try specifying the above URL as the "Custom configuration .yml file name" in the General Settings of your CCAN AppVeyor project using the git.ozlabs.org Git URL.

1. https://github.com/appveyor/ci/issues/1089#issuecomment-264549196

Signature · 6 lines
Cheers,      |  [email protected]    | XMPP: [email protected]
Kevin        |  https://kevinlocke.name  | IRC:   kevinoid on freenode
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan