From 25ea9a3d9866845687fbdef0a8ceecc683e3e23a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 9 Jul 2015 14:34:56 +0930 Subject: [PATCH] tools/modfiles: list files in a module. Signed-off-by: Rusty Russell --- .gitignore | 1 + tools/Makefile | 10 +++++- tools/modfiles.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tools/modfiles.c diff --git a/.gitignore b/.gitignore index 60886efd..680d1296 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ tools/namespacize tools/run_tests tools/ccanlint/ccanlint tools/ccanlint/generated-testlist +tools/modfiles inter-depends test-depends lib-depends diff --git a/tools/Makefile b/tools/Makefile index ddd6545f..338befc4 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,9 +1,15 @@ -ALL_TOOLS = tools/configurator/configurator tools/ccan_depends tools/doc_extract tools/namespacize tools/ccanlint/ccanlint +ALL_TOOLS = tools/configurator/configurator tools/ccan_depends tools/doc_extract tools/namespacize tools/ccanlint/ccanlint tools/modfiles LDLIBS = -lrt DEP_OBJS = ccan/err/err.o \ ccan/foreach/foreach.o \ + ccan/hash/hash.o \ + ccan/htable/htable.o \ ccan/list/list.o \ ccan/noerr/noerr.o \ + ccan/opt/opt.o \ + ccan/opt/helpers.o \ + ccan/opt/parse.o \ + ccan/opt/usage.o \ ccan/rbuf/rbuf.o \ ccan/read_write_all/read_write_all.o \ ccan/str/debug.o \ @@ -36,6 +42,8 @@ tools/namespacize.o tools/depends.o: tools/tools.h tools/configurator/configurator: tools/configurator/configurator.c +tools/modfiles: tools/modfiles.o tools/manifest.o $(DEP_OBJS) + tools-clean: ccanlint-clean $(RM) $(ALL_TOOLS) diff --git a/tools/modfiles.c b/tools/modfiles.c new file mode 100644 index 00000000..b7092cde --- /dev/null +++ b/tools/modfiles.c @@ -0,0 +1,87 @@ +/* List files in a module, or modules. */ +#include +#include +#include +#include "manifest.h" +#include + +static void add_file(const struct ccan_file *f, + bool fullpath, bool nul_term, bool gitonly) +{ + /* Hacky way of seeing if git knows about this. */ + if (gitonly) { + char *cmd = tal_fmt(f, "git status --porcelain --ignored %s | grep -q '^ *[!?]'", f->fullname); + if (system(cmd) == 0) + return; + } + printf("%s%c", fullpath ? f->fullname : f->name, + nul_term ? '\0' : '\n'); +} + +int main(int argc, char *argv[]) +{ + bool code = true; + bool license = true; + bool tests = true; + bool other = true; + bool gitonly = false; + bool nul_term = false; + bool fullpath = false; + int i; + + opt_register_noarg("--no-code", opt_set_invbool, &code, + "Don't list .c and .h files"); + opt_register_noarg("--no-license", opt_set_invbool, &license, + "Don't list license file"); + opt_register_noarg("--no-tests", opt_set_invbool, &tests, + "Don't list test files"); + opt_register_noarg("--no-other", opt_set_invbool, &other, + "Don't list other files"); + opt_register_noarg("--git-only", opt_set_bool, &gitonly, + "Only include files in git"); + opt_register_noarg("--fullpath", opt_set_bool, &fullpath, + "Print full path names instead of module-relative ones"); + opt_register_noarg("--null|-0", opt_set_bool, &nul_term, + "Separate files with nul character instead of \\n"); + opt_register_noarg("-h|--help", opt_usage_and_exit, + "...", + "Show usage"); + + opt_parse(&argc, argv, opt_log_stderr_exit); + if (argc < 2) + opt_usage_exit_fail("Expected one or more module directories"); + + for (i = 1; i < argc; i++) { + struct manifest *m = get_manifest(NULL, argv[i]); + struct list_head *list; + struct ccan_file *f; + if (code) { + foreach_ptr(list, &m->c_files, &m->h_files) { + list_for_each(list, f, list) + add_file(f, fullpath, nul_term, gitonly); + } + } + if (license) { + list_for_each(&m->other_files, f, list) { + if (streq(f->name, "LICENSE")) + add_file(f, fullpath, nul_term, gitonly); + } + } + if (tests) { + foreach_ptr(list, &m->run_tests, &m->api_tests, + &m->compile_ok_tests, &m->compile_fail_tests, + &m->other_test_c_files, + &m->other_test_files) { + list_for_each(list, f, list) + add_file(f, fullpath, nul_term, gitonly); + } + } + if (other) { + list_for_each(&m->other_files, f, list) { + if (!streq(f->name, "LICENSE")) + add_file(f, fullpath, nul_term, gitonly); + } + } + } + return 0; +} -- 2.39.2