Re: [systemd-devel] Removing unnecessary includes
On Sun, 22.02.15 14:56, Thomas H.P. Andersen (pho...@gmail.com) wrote: For info I am attaching a diff with the changes so far: 1309 includes removed out of the current 7707. It is only compile and make check-tested. I am only looking for comments (and perhaps compile testing on an AppArmor system as I do not have a system with that). The patch bitrots quickly. I have updated it and also dropped a few removals of architecture.h and endian.h. It passes make check and I have not seen any issues with using it on my own system. Still not tested with AppArmor though. If you are reasonably sure that the patch is OK, go ahead and push. We are still at the beginning of the cycle, and can fix any fallout in time. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Mon, Feb 23, 2015 at 2:02 PM, Lennart Poettering mzerq...@0pointer.de wrote: On Sun, 22.02.15 14:56, Thomas H.P. Andersen (pho...@gmail.com) wrote: For info I am attaching a diff with the changes so far: 1309 includes removed out of the current 7707. It is only compile and make check-tested. I am only looking for comments (and perhaps compile testing on an AppArmor system as I do not have a system with that). The patch bitrots quickly. I have updated it and also dropped a few removals of architecture.h and endian.h. It passes make check and I have not seen any issues with using it on my own system. Still not tested with AppArmor though. If you are reasonably sure that the patch is OK, go ahead and push. We are still at the beginning of the cycle, and can fix any fallout in time. Ok. I pushed the patch now. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Sun, Feb 15, 2015 at 11:53 PM, Thomas H.P. Andersen pho...@gmail.com wrote: On Tue, Feb 10, 2015 at 10:05 PM, Lennart Poettering lenn...@poettering.net wrote: On Sat, 07.02.15 10:29, Thomas H.P. Andersen (pho...@gmail.com) wrote: Hi, I am looking at ways to automatically trim the unnecessary includes. One way to do it is a script[1] which simply tests if the compile still works after removing each include one at a time. It does this in reverse order for all includes in the .c files. Using -Werror we catch any new warnings too. I think this is quite useful, but I'd also be really careful with this. glibc versions sometimes require different headers to be included to get some functionality, thus automatic removal of headers that are unnecessary on one system doesn't mean this is universally the case... Moreover depdending on compile-time options you might different headers... I have used IWYU to only drop headers that we do not use any symbols from. There are no automatically added headers nor includes replaced by forward declarations.I have manually checked all removals from files that contain a #ifdef or #if defined() to catch issues from various compile-time option combinations. No includes of missing.h were removed and I tried to be careful with endianness. Are there specific headers I should be extra careful with or ignore completely? For info I am attaching a diff with the changes so far: 1309 includes removed out of the current 7707. It is only compile and make check-tested. I am only looking for comments (and perhaps compile testing on an AppArmor system as I do not have a system with that). The patch bitrots quickly. I have updated it and also dropped a few removals of architecture.h and endian.h. It passes make check and I have not seen any issues with using it on my own system. Still not tested with AppArmor though. I moved the patch to github: https://github.com/phomes/systemd-1/commit/cf3c313747ebae18b63effb251f801ac4c370f05 Here is a list the headers removed and number of times removed: 74 sys/types.h 69 unistd.h 65 string.h 63 assert.h 53 util.h 45 fcntl.h 42 stdlib.h 38 inttypes.h 29 errno.h 28 sys/stat.h 21 strv.h 19 label.h 17 sys/socket.h 16 path-util.h 16 fileio.h 16 def.h 15 stdio.h 15 dirent.h 15 arpa/inet.h 14 unit.h 14 mkdir.h 14 log.h 14 ctype.h 13 sys/un.h 13 dbus-unit.h 12 stdarg.h 12 set.h 12 poll.h 12 netinet/ether.h 11 limits.h 11 bus-message.h 10 stdbool.h 10 signal.h 9 time.h 9 sys/wait.h 9 socket-util.h 9 sd-bus.h 9 pwd.h 9 network-internal.h 9 list.h 8 sys/ioctl.h 8 sd-id128.h 8 net/if.h 8 load-fragment.h 8 getopt.h 7 sys/param.h 7 macro.h 7 hashmap.h 7 event-util.h 7 bus-error.h 6 utf8.h 6 sys/time.h 6 sys/prctl.h 6 grp.h 6 conf-parser.h 6 capability.h 6 bus-util.h 6 build.h 5 udev-util.h 5 sys/timex.h 5 sys/timerfd.h 5 sys/syscall.h 5 sys/epoll.h 5 load-dropin.h 4 virt.h 4 termios.h 4 sys/signalfd.h 4 sys/mount.h 4 stddef.h 4 sd-messages.h 4 resolved-manager.h 4 netinet/in.h 4 manager.h 4 logind-seat.h 4 linux/vt.h 4 libudev.h 4 exit-status.h 4 execute.h 4 conf-files.h 4 cgroup-util.h 4 byteswap.h 4 bus-control.h 4 bus-common-errors.h 4 audit.h 3 time-util.h 3 sys/utsname.h 3 sys/resource.h 3 stdint.h 3 special.h 3 smack-util.h 3 resolved-dns-scope.h 3 net/ethernet.h 3 logind-session.h 3 logind.h 3 libudev.h 3 in-addr-util.h 3 endian.h 2 wchar.h 2 unit-name.h 2 sys/xattr.h 2 systemd/sd-login.h 2 systemd/sd-journal.h 2 sys/statvfs.h 2 sys/mman.h 2 synthesize.h 2 siphash24.h 2 sd-rtnl.h 2 sd-event.h 2 sd-dhcp-client.h 2 sd-bus-protocol.h 2 rtnl-util.h 2 rtnl-internal.h 2 resolved-dns-stream.h 2 resolved-dns-server.h 2 resolved-dns-rr.h 2 network-util.h 2 netinet/if_ether.h 2 mount-setup.h 2 mount.h 2 logind-device.h 2 linux/types.h 2 linux/limits.h 2 linux/ioctl.h 2 linux/fs.h 2 libudev-private.h 2 journal-authenticate.h 2 install.h 2 fsprg.h 2 fnmatch.h 2 failure-action.h 2 driver.h 2 dhcp-lease-internal.h 2 dbus-kill.h 2 clock-util.h 2 cgroup.h 2 bus-label.h 2 asm/types.h 2 arpa/nameser.h 1 xml.h 1 xkbcommon/xkbcommon.h 1 unaligned.h 1 target.h 1 sys/vfs.h 1 sys/uio.h 1 sys/swap.h 1 sys/select.h 1 sys/inotify.h 1 sys/file.h 1 sys/eventfd.h 1 strxcpyx.h 1 specifier.h 1 service.h 1 sd-lldp.h 1 sd-dhcp-lease.h 1 sd-daemon.h 1 resolved-dns-transaction.h 1 resolved-dns-query.h 1 resolved-dns-domain.h 1 pthread.h 1 path-lookup.h 1 networkd-netdev.h 1 networkd-link.h 1 mntent.h 1 machine.h 1 logind-user.h 1 logind-session-device.h 1 logind-inhibit.h 1 locale.h 1 linux/veth.h 1 linux/sched.h 1 linux/ppp_defs.h 1 linux/oom.h 1 linux/netlink.h 1 linux/input.h 1 linux/in6.h 1 linux/if_link.h 1 linux/if.h 1 linux/if_ether.h
Re: [systemd-devel] Removing unnecessary includes
On Wed, 11.02.15 23:46, Thomas H.P. Andersen (pho...@gmail.com) wrote: On Wed, Feb 11, 2015 at 12:39 PM, Lennart Poettering lenn...@poettering.net wrote: On Wed, 11.02.15 01:40, Thomas H.P. Andersen (pho...@gmail.com) wrote: Yep. Makes sense. Here is a status on what I have done so far. include-what-you-want does the following: 1) sorts the includes 2) adds missing headers for any symbols used 3) adds forward declarations 4) removes any unused headers (after step 2+3) 5) changes some headers. (only saw sys/poll.h to poll.h for now) The diff we get out of that is too big a mess to locate what we want: the currently unused headers. To break it up I first did the sorting in separate step. (I have a patch to commit after 219 for some minor issues that came up from that). I then started to look at all the removals and one by one see if they make sense today, or was due to step 2/3/5, or was something we want to keep like missing.h. It is slow manual work but I will get there. It would be helpful to know if we might want 2, 3, and 5 done? What precisely do you mean by 3? E.g. for src/journal/mmap-cache.h it replaces #include sys/stat.h by struct stat; since we only use the struct but none of the functions. Saves time including that header and anything it brings in with it. Oh, no, that sounds like an awful idea... We want readable, minimal sources, but certainly don't want to fine-tune compilation times with concepts like this... Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Wed, Feb 11, 2015 at 12:39 PM, Lennart Poettering lenn...@poettering.net wrote: On Wed, 11.02.15 01:40, Thomas H.P. Andersen (pho...@gmail.com) wrote: Yep. Makes sense. Here is a status on what I have done so far. include-what-you-want does the following: 1) sorts the includes 2) adds missing headers for any symbols used 3) adds forward declarations 4) removes any unused headers (after step 2+3) 5) changes some headers. (only saw sys/poll.h to poll.h for now) The diff we get out of that is too big a mess to locate what we want: the currently unused headers. To break it up I first did the sorting in separate step. (I have a patch to commit after 219 for some minor issues that came up from that). I then started to look at all the removals and one by one see if they make sense today, or was due to step 2/3/5, or was something we want to keep like missing.h. It is slow manual work but I will get there. It would be helpful to know if we might want 2, 3, and 5 done? What precisely do you mean by 3? E.g. for src/journal/mmap-cache.h it replaces #include sys/stat.h by struct stat; since we only use the struct but none of the functions. Saves time including that header and anything it brings in with it. Don't care too much about 2 either way. 5 sounds useful. Will include 5. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Wed, 11.02.15 01:40, Thomas H.P. Andersen (pho...@gmail.com) wrote: Yep. Makes sense. Here is a status on what I have done so far. include-what-you-want does the following: 1) sorts the includes 2) adds missing headers for any symbols used 3) adds forward declarations 4) removes any unused headers (after step 2+3) 5) changes some headers. (only saw sys/poll.h to poll.h for now) The diff we get out of that is too big a mess to locate what we want: the currently unused headers. To break it up I first did the sorting in separate step. (I have a patch to commit after 219 for some minor issues that came up from that). I then started to look at all the removals and one by one see if they make sense today, or was due to step 2/3/5, or was something we want to keep like missing.h. It is slow manual work but I will get there. It would be helpful to know if we might want 2, 3, and 5 done? What precisely do you mean by 3? Don't care too much about 2 either way. 5 sounds useful. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Mon, 09.02.15 10:19, Thomas H.P. Andersen (pho...@gmail.com) wrote: include-what-you-use is actually pretty nice. It is also a little bit crazy. It wants to include everything directly and we would add a lot includes for errno.h, string.h, stdlib.h, stdbool.h, stddef.h, etc etc everywhere. It also wants to use forward declares when possible. The coding style does not say anything specific about this. Any preferences? I will use the tool to trim the unnecessary includes first and leave its other advise for later. It will be interesting to see how each step affects the build time. A feature is that I find interesting is that it can comment each include with the reason that it was included. Not something to commit, but useful to get an overview of why each include is there. Hmm, I find this unnecessary noise I must say... #include stdbool.h// for false, true, bool #include stddef.h // for offsetof, size_t #include stdint.h // for uint64_t #include string.h // for strdup, strlen #include config.h // for PACKAGE_STRING, #VERSION This one we get though -include config.h on the gcc command line. #include src/shared/macro.h // for assert, assert_cc, etc #include src/shared/path-lookup.h #include src/shared/time-util.h // for format_timespan, usec_t, etc #include src/systemd/sd-bus-protocol.h // for ::SD_BUS_TYPE_ARRAY Nah, please no absolute includes... Any chance this can turned off? The full include-list for src/analyze/analyze.c: #include errno.h // for EIO, ENOMEM, E2BIG, EINVAL, etc #include fnmatch.h// for fnmatch #include getopt.h // for optind, no_argument, optarg, etc #include locale.h // for NULL, setlocale, LC_ALL, etc #include stdbool.h// for false, true, bool #include stddef.h // for offsetof, size_t #include stdint.h // for uint64_t #include stdio.h // for printf, puts, fputs, stdout #include stdlib.h // for free, qsort, EXIT_FAILURE, etc #include string.h // for strdup, strlen #include analyze-verify.h // for verify_units #include build.h // for SYSTEMD_FEATURES #include bus-error.h // for bus_error_message #include bus-util.h // for UnitInfo, etc #include config.h // for PACKAGE_STRING, VERSION #include hashmap.h// for hashmap_get, Hashmap, etc #include log.h// for log_error, log_oom, etc #include pager.h // for pager_close, pager_open #include sd-bus.h // for sd_bus, SD_BUS_ERROR_NULL, etc #include special.h// for SPECIAL_DEFAULT_TARGET #include src/shared/macro.h // for assert, assert_cc, etc #include src/shared/path-lookup.h #include src/shared/time-util.h // for format_timespan, usec_t, etc #include src/systemd/sd-bus-protocol.h // for ::SD_BUS_TYPE_ARRAY #include strv.h // for strv_isempty, STRV_FOREACH, etc #include strxcpyx.h // for strpcpyf #include unit-name.h // for unit_dbus_path_from_name #include util.h // for isempty, streq, etc Note that I actually try to roughly maintain an order when including things: For the headers of other projects i try to put system headers first, 3rd party headers second. For our own stuff I try to put external API stuff first (i.e. sd-*.h), followed by internal API-like stuff form src/shared, and finally the other headers that are prviate to the specific module the code is in. I'd really like to avoid a scheme where this is reordered randomly... The order kinda is relevant, since more local, specific definitions should never influence more public, generic interfaces, if you follow what I mean? A lot of header files use #ifndef, and only conditionally define things then. They should not get confused by our own definitions Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Sat, 07.02.15 10:29, Thomas H.P. Andersen (pho...@gmail.com) wrote: Hi, I am looking at ways to automatically trim the unnecessary includes. One way to do it is a script[1] which simply tests if the compile still works after removing each include one at a time. It does this in reverse order for all includes in the .c files. Using -Werror we catch any new warnings too. I think this is quite useful, but I'd also be really careful with this. glibc versions sometimes require different headers to be included to get some functionality, thus automatic removal of headers that are unnecessary on one system doesn't mean this is universally the case... Moreover depdending on compile-time options you might different headers... Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Tue, Feb 10, 2015 at 10:13 PM, Lennart Poettering lenn...@poettering.net wrote: On Mon, 09.02.15 10:19, Thomas H.P. Andersen (pho...@gmail.com) wrote: include-what-you-use is actually pretty nice. It is also a little bit crazy. It wants to include everything directly and we would add a lot includes for errno.h, string.h, stdlib.h, stdbool.h, stddef.h, etc etc everywhere. It also wants to use forward declares when possible. The coding style does not say anything specific about this. Any preferences? I will use the tool to trim the unnecessary includes first and leave its other advise for later. It will be interesting to see how each step affects the build time. A feature is that I find interesting is that it can comment each include with the reason that it was included. Not something to commit, but useful to get an overview of why each include is there. Hmm, I find this unnecessary noise I must say... Well, for someone who is still learning it can be useful :) Getting that list of symbols actually used from each header adds some context and makes the includes feel less magic. Anyway, something to use on the fly but not to commit of course. There is an option to turn it off so that is not a problem. #include stdbool.h// for false, true, bool #include stddef.h // for offsetof, size_t #include stdint.h // for uint64_t #include string.h // for strdup, strlen #include config.h // for PACKAGE_STRING, #VERSION This one we get though -include config.h on the gcc command line. We can configure it to understand that. #include src/shared/macro.h // for assert, assert_cc, etc #include src/shared/path-lookup.h #include src/shared/time-util.h // for format_timespan, usec_t, etc #include src/systemd/sd-bus-protocol.h // for ::SD_BUS_TYPE_ARRAY Nah, please no absolute includes... Any chance this can turned off? I did not find any option for that but it is something to look into. The full include-list for src/analyze/analyze.c: #include errno.h // for EIO, ENOMEM, E2BIG, EINVAL, etc #include fnmatch.h// for fnmatch #include getopt.h // for optind, no_argument, optarg, etc #include locale.h // for NULL, setlocale, LC_ALL, etc #include stdbool.h// for false, true, bool #include stddef.h // for offsetof, size_t #include stdint.h // for uint64_t #include stdio.h // for printf, puts, fputs, stdout #include stdlib.h // for free, qsort, EXIT_FAILURE, etc #include string.h // for strdup, strlen #include analyze-verify.h // for verify_units #include build.h // for SYSTEMD_FEATURES #include bus-error.h // for bus_error_message #include bus-util.h // for UnitInfo, etc #include config.h // for PACKAGE_STRING, VERSION #include hashmap.h// for hashmap_get, Hashmap, etc #include log.h// for log_error, log_oom, etc #include pager.h // for pager_close, pager_open #include sd-bus.h // for sd_bus, SD_BUS_ERROR_NULL, etc #include special.h// for SPECIAL_DEFAULT_TARGET #include src/shared/macro.h // for assert, assert_cc, etc #include src/shared/path-lookup.h #include src/shared/time-util.h // for format_timespan, usec_t, etc #include src/systemd/sd-bus-protocol.h // for ::SD_BUS_TYPE_ARRAY #include strv.h // for strv_isempty, STRV_FOREACH, etc #include strxcpyx.h // for strpcpyf #include unit-name.h // for unit_dbus_path_from_name #include util.h // for isempty, streq, etc Note that I actually try to roughly maintain an order when including things: For the headers of other projects i try to put system headers first, 3rd party headers second. For our own stuff I try to put external API stuff first (i.e. sd-*.h), followed by internal API-like stuff form src/shared, and finally the other headers that are prviate to the specific module the code is in. I'd really like to avoid a scheme where this is reordered randomly... Understood. The include-what-you-use tool consists of two separate parts. The first is a program to scan the code and create a report of what to add and remove. The second part is a python script that reads the report and patches the source files. Perhaps the latter be extended to do what we need. The order kinda is relevant, since more local, specific definitions should never influence more public, generic interfaces, if you follow what I mean? A lot of header files use #ifndef, and only conditionally define things then. They should not get
Re: [systemd-devel] Removing unnecessary includes
On Sat, Feb 7, 2015 at 3:38 PM, Thomas H.P. Andersen pho...@gmail.com wrote: On Sat, Feb 7, 2015 at 2:37 PM, Ronny Chevalier chevalier.ro...@gmail.com wrote: 2015-02-07 14:05 GMT+01:00 Daniele Nicolodi dani...@grinta.net: On 07/02/15 10:29, Thomas H.P. Andersen wrote: I am looking at ways to automatically trim the unnecessary includes. One way to do it is a script[1] which simply tests if the compile still works after removing each include one at a time. It does this in reverse order for all includes in the .c files. Using -Werror we catch any new warnings too. Hello Thomas, this approach is not correct: in this way each source file would not be required to include the headers included by other files included before. For example, if header file a.h includes shared.h and implementation file requires the definitions of a.h and shared.h, only the first dependency would be detected by this method. However, it is good practice to include all the required header files, whether those are already included by others or not. Hi, I agree with Daniele. If you want to include the proper headers in each file maybe you can use include-what-you-use [0], but this is a rather recent project with lots of issues that will force you to do a lots of manual review. [0] https://code.google.com/p/include-what-you-use/ Looks useful. Will take a look. include-what-you-use is actually pretty nice. It is also a little bit crazy. It wants to include everything directly and we would add a lot includes for errno.h, string.h, stdlib.h, stdbool.h, stddef.h, etc etc everywhere. It also wants to use forward declares when possible. The coding style does not say anything specific about this. Any preferences? I will use the tool to trim the unnecessary includes first and leave its other advise for later. It will be interesting to see how each step affects the build time. A feature is that I find interesting is that it can comment each include with the reason that it was included. Not something to commit, but useful to get an overview of why each include is there. Include-what-you-use is not packaged yet in fedora and you need to edit the cmake files to make it build there. Dave Johansen is working on the packaging though and it looks like it could go in any day now. https://bugzilla.redhat.com/show_bug.cgi?id=1091659 To run it you need something like: ./autogen.sh c make -k CC=include-what-you-use Here is an example of the advise it gives for a single file: src/analyze/analyze.c should add these lines: #include errno.h // for EIO, ENOMEM, E2BIG, EINVAL, etc #include stdbool.h// for false, true, bool #include stddef.h // for offsetof, size_t #include stdint.h // for uint64_t #include string.h // for strdup, strlen #include config.h // for PACKAGE_STRING, VERSION #include src/shared/macro.h // for assert, assert_cc, etc #include src/shared/path-lookup.h #include src/shared/time-util.h // for format_timespan, usec_t, etc #include src/systemd/sd-bus-protocol.h // for ::SD_BUS_TYPE_ARRAY src/analyze/analyze.c should remove these lines: - #include sys/utsname.h // lines 27-27 - #include fileio.h // lines 38-38 - #include install.h // lines 33-33 The full include-list for src/analyze/analyze.c: #include errno.h // for EIO, ENOMEM, E2BIG, EINVAL, etc #include fnmatch.h// for fnmatch #include getopt.h // for optind, no_argument, optarg, etc #include locale.h // for NULL, setlocale, LC_ALL, etc #include stdbool.h// for false, true, bool #include stddef.h // for offsetof, size_t #include stdint.h // for uint64_t #include stdio.h // for printf, puts, fputs, stdout #include stdlib.h // for free, qsort, EXIT_FAILURE, etc #include string.h // for strdup, strlen #include analyze-verify.h // for verify_units #include build.h // for SYSTEMD_FEATURES #include bus-error.h // for bus_error_message #include bus-util.h // for UnitInfo, etc #include config.h // for PACKAGE_STRING, VERSION #include hashmap.h// for hashmap_get, Hashmap, etc #include log.h// for log_error, log_oom, etc #include pager.h // for pager_close, pager_open #include sd-bus.h // for sd_bus, SD_BUS_ERROR_NULL, etc #include special.h// for SPECIAL_DEFAULT_TARGET #include src/shared/macro.h // for assert, assert_cc, etc #include src/shared/path-lookup.h #include src/shared/time-util.h // for format_timespan, usec_t, etc #include src/systemd/sd-bus-protocol.h // for ::SD_BUS_TYPE_ARRAY #include strv.h
Re: [systemd-devel] Removing unnecessary includes
On 07/02/15 10:29, Thomas H.P. Andersen wrote: I am looking at ways to automatically trim the unnecessary includes. One way to do it is a script[1] which simply tests if the compile still works after removing each include one at a time. It does this in reverse order for all includes in the .c files. Using -Werror we catch any new warnings too. Hello Thomas, this approach is not correct: in this way each source file would not be required to include the headers included by other files included before. For example, if header file a.h includes shared.h and implementation file requires the definitions of a.h and shared.h, only the first dependency would be detected by this method. However, it is good practice to include all the required header files, whether those are already included by others or not. Cheers, Daniele ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
2015-02-07 14:05 GMT+01:00 Daniele Nicolodi dani...@grinta.net: On 07/02/15 10:29, Thomas H.P. Andersen wrote: I am looking at ways to automatically trim the unnecessary includes. One way to do it is a script[1] which simply tests if the compile still works after removing each include one at a time. It does this in reverse order for all includes in the .c files. Using -Werror we catch any new warnings too. Hello Thomas, this approach is not correct: in this way each source file would not be required to include the headers included by other files included before. For example, if header file a.h includes shared.h and implementation file requires the definitions of a.h and shared.h, only the first dependency would be detected by this method. However, it is good practice to include all the required header files, whether those are already included by others or not. Hi, I agree with Daniele. If you want to include the proper headers in each file maybe you can use include-what-you-use [0], but this is a rather recent project with lots of issues that will force you to do a lots of manual review. [0] https://code.google.com/p/include-what-you-use/ Cheers, Daniele ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Sat, Feb 7, 2015 at 2:37 PM, Ronny Chevalier chevalier.ro...@gmail.com wrote: 2015-02-07 14:05 GMT+01:00 Daniele Nicolodi dani...@grinta.net: On 07/02/15 10:29, Thomas H.P. Andersen wrote: I am looking at ways to automatically trim the unnecessary includes. One way to do it is a script[1] which simply tests if the compile still works after removing each include one at a time. It does this in reverse order for all includes in the .c files. Using -Werror we catch any new warnings too. Hello Thomas, this approach is not correct: in this way each source file would not be required to include the headers included by other files included before. For example, if header file a.h includes shared.h and implementation file requires the definitions of a.h and shared.h, only the first dependency would be detected by this method. However, it is good practice to include all the required header files, whether those are already included by others or not. Hi, I agree with Daniele. If you want to include the proper headers in each file maybe you can use include-what-you-use [0], but this is a rather recent project with lots of issues that will force you to do a lots of manual review. [0] https://code.google.com/p/include-what-you-use/ Looks useful. Will take a look. Cheers, Daniele ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Removing unnecessary includes
On Sat, Feb 7, 2015 at 2:05 PM, Daniele Nicolodi dani...@grinta.net wrote: On 07/02/15 10:29, Thomas H.P. Andersen wrote: I am looking at ways to automatically trim the unnecessary includes. One way to do it is a script[1] which simply tests if the compile still works after removing each include one at a time. It does this in reverse order for all includes in the .c files. Using -Werror we catch any new warnings too. Hello Thomas, this approach is not correct: in this way each source file would not be required to include the headers included by other files included before. For example, if header file a.h includes shared.h and implementation file requires the definitions of a.h and shared.h, only the first dependency would be detected by this method. However, it is good practice to include all the required header files, whether those are already included by others or not. Oh, I did not mean to use the output of deheader directly. Only as a way to find potential targets for removal. Each removal should be reviewed manually of course. Cheers, Daniele ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel