versioner: compile with `clang -include foo.h -`.
At least one warning only triggers in files that are included, instead
of being passed directly. Switch to compiling with -include, and fix
the resulting warnings.
Bug: https://github.com/android-ndk/ndk/issues/474
Test: mma -j && versioner
Test: python tools/versioner/run_tests.py
Change-Id: I784698c18540c9cc30f372f279a1cec1d75721ea
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
index 735ea04..747c767 100644
--- a/tools/versioner/src/versioner.cpp
+++ b/tools/versioner/src/versioner.cpp
@@ -18,6 +18,7 @@
#include <err.h>
#include <limits.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -190,6 +191,21 @@
}
}
+ // Dup an empty file to stdin, so that we can use `clang -include a.h -` instead of `clang a.h`,
+ // since some warnings don't get generated in files that are compiled directly.
+ FILE* empty_file = tmpfile();
+ if (!empty_file) {
+ err(1, "failed to create temporary file");
+ }
+
+ int empty_file_fd = fileno(empty_file);
+ if (empty_file_fd == -1) {
+ errx(1, "fileno failed on tmpfile");
+ }
+
+ dup2(empty_file_fd, STDIN_FILENO);
+ fclose(empty_file);
+
thread_count = std::min(thread_count, jobs.size());
if (thread_count == 1) {