]> git.ozlabs.org Git - ccan/blob - tools/modfiles.c
Ensure config.h is created before the main travis builds
[ccan] / tools / modfiles.c
1 /* List files in a module, or modules. */
2 #include <ccan/opt/opt.h>
3 #include <ccan/foreach/foreach.h>
4 #include <ccan/tal/str/str.h>
5 #include "manifest.h"
6 #include <stdio.h>
7
8 static void add_file(const struct ccan_file *f,
9                      bool fullpath, bool nul_term, bool gitonly)
10 {
11         /* Hacky way of seeing if git knows about this. */
12         if (gitonly) {
13                 char *cmd = tal_fmt(f, "git status --porcelain --ignored %s | grep -q '^ *[!?]'", f->fullname);
14                 if (system(cmd) == 0)
15                         return;
16         }
17         printf("%s%c", fullpath ? f->fullname : f->name,
18                nul_term ? '\0' : '\n');
19 }
20
21 int main(int argc, char *argv[])
22 {
23         bool code = true;
24         bool license = true;
25         bool tests = true;
26         bool other = true;
27         bool info = true;
28         bool gitonly = false;
29         bool nul_term = false;
30         bool fullpath = false;
31         int i;
32
33         opt_register_noarg("--no-code", opt_set_invbool, &code,
34                            "Don't list .c and .h files");
35         opt_register_noarg("--no-license", opt_set_invbool, &license,
36                            "Don't list license file");
37         opt_register_noarg("--no-info", opt_set_invbool, &info,
38                            "Don't list _info file");
39         opt_register_noarg("--no-tests", opt_set_invbool, &tests,
40                            "Don't list test files");
41         opt_register_noarg("--no-other", opt_set_invbool, &other,
42                            "Don't list other files");
43         opt_register_noarg("--git-only", opt_set_bool, &gitonly,
44                            "Only include files in git");
45         opt_register_noarg("--fullpath", opt_set_bool, &fullpath,
46                            "Print full path names instead of module-relative ones");
47         opt_register_noarg("--null|-0", opt_set_bool, &nul_term,
48                            "Separate files with nul character instead of \\n");
49         opt_register_noarg("-h|--help", opt_usage_and_exit,
50                            "<moduledir>...",
51                            "Show usage");
52
53         opt_parse(&argc, argv, opt_log_stderr_exit);
54         if (argc < 2)
55                 opt_usage_exit_fail("Expected one or more module directories");
56
57         for (i = 1; i < argc; i++) {
58                 struct manifest *m = get_manifest(NULL, argv[i]);
59                 struct list_head *list;
60                 struct ccan_file *f;
61
62                 if (info)
63                         add_file(m->info_file, fullpath, nul_term, gitonly);
64
65                 if (code) {
66                         foreach_ptr(list, &m->c_files, &m->h_files) {
67                                 list_for_each(list, f, list)
68                                         add_file(f, fullpath, nul_term, gitonly);
69                         }
70                 }
71                 if (license) {
72                         list_for_each(&m->other_files, f, list) {
73                                 if (streq(f->name, "LICENSE"))
74                                         add_file(f, fullpath, nul_term, gitonly);
75                         }
76                 }
77                 if (tests) {
78                         foreach_ptr(list, &m->run_tests, &m->api_tests,
79                                     &m->compile_ok_tests, &m->compile_fail_tests,
80                                     &m->other_test_c_files,
81                                     &m->other_test_files) {
82                                 list_for_each(list, f, list)
83                                         add_file(f, fullpath, nul_term, gitonly);
84                         }
85                 }
86                 if (other) {
87                         list_for_each(&m->other_files, f, list) {
88                                 if (!streq(f->name, "LICENSE"))
89                                         add_file(f, fullpath, nul_term, gitonly);
90                         }
91                 }
92         }
93         return 0;
94 }