Hello, I discovered some cool tools from the Google Laboratories.
One tool is a build system: the positive is that it picks up the few types of dependency issues that conventional make is not good with -- the negative is that it is not usable with existing projects. The second tool is for header files. It is called "include-what-you-use". The name pretty much states what it is intended for. This has always been (not always, but for a long time) the recommended technique. However, without a tool, it is very difficult to do this accurately. For example, if my file.c dereferences struct x, file.c should include x.h if struct x is declared in x.h. But what if y.h #includes x.h, and y.h is #included in file.c? x.h should still be #included in file.c, but the C compiler won't help you much in determining that. You can understand why they call it include-what-you-use rather than include-what-you-need. The C compiler is equivalent to an amalgam of include-what-you-need PLUS include-what-you-do-not-even-use. Although the tool might be difficult to use directly on existing header files, it is a fine choice for new code development. Google advertises it as alpha software. Don't let that fool you -- it is excellent. The only thing is that it will not give you an exact result -- you have to massage the output. The tool was originally written for C++ but much more recently they enabled it for C. Considering that macros and templates give this type of tool the most problems, the fact that it gives a good approximation with VPP heavily macro'd code is amazing. One thing that happens when I use it is that it will want to include <vppinfra/memcpy_avx.h> so I manually change that to <vppinfra/string.h>. And it won't tell you where a file needs to be included if it needs to be included after a #define. To use it, first build it according to the instructions on the web site. You build it against clang, but that is not a problem. The one special detail I recall -- please install it under /usr rather than /usr/local, or it will not find standard header files without extra help. Here is an example where I use it against an existing header file. This example shows why it is more convenient to use it for new code development. $ include-what-you-use -I. -I/home/burts/vpp2/build-root/build-vpp-native/vpp -I/home/burts/vpp2/build-root/install-vpp-native/dpdk/include/dpdk -Iplugins -I/home/burts/vpp2/build-root/build-vpp-native/vpp/plugins -Wno-address-of-packed-member -Wno-constant-conversion -march=native -DWITH_LIBSSL=1 vlibsocket/vl_socket_api_h.h 2>&1 |more In file included from vlibsocket/vl_socket_api_h.h:24: In file included from ./vlibmemory/vl_memory_api_h.h:24: /home/burts/vpp2/build-root/build-vpp-native/vpp/vlibmemory/memclnt.api.h:12:2: warning: no content included from vlibmemory/memclnt.api.h [-W#warnings] #warning no content included from vlibmemory/memclnt.api.h ^ In file included from vlibsocket/vl_socket_api_h.h:25: /home/burts/vpp2/build-root/build-vpp-native/vpp/vlibsocket/sockclnt.api.h:12:2: warning: no content included from vlibsocket/sockclnt.api.h [-W#warnings] #warning no content included from vlibsocket/sockclnt.api.h ^ vlibsocket/vl_socket_api_h.h should add these lines: vlibsocket/vl_socket_api_h.h should remove these lines: - #include <vlibmemory/vl_memory_api_h.h> // lines 24-24 - #include <vlibsocket/sockclnt.api.h> // lines 25-25 The full include-list for vlibsocket/vl_socket_api_h.h: --- Note that on my command line I cancelled a few clang warnings that are not applicable to gcc. I have not attempted to ensure that I am using the correct default -D options, but you can do that. Once you copy and paste changes from the output to your files, just build in the usual manner to see what manual changes you need to make. Note that the example I show might hint that vl_socket_api_h.h can be removed. That would be a huge amount of work. That's why the tool is best used for new code, or in places that do not have wide ranging implications. In case it is not obvious, please do not read this note as a recommendation sanctioned by the project(s). It is just something I found that I figured might not be well known, yet interesting. I almost forgot: https://include-what-you-use.org/ Burt
_______________________________________________ vpp-dev mailing list [email protected] https://lists.fd.io/mailman/listinfo/vpp-dev
