fixdep: avoid parsing the same file over again
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 7 Jan 2023 09:18:19 +0000 (18:18 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sun, 22 Jan 2023 14:43:33 +0000 (23:43 +0900)
commitfaa91c472be8ffa3121c9db803d3e529d48e246a
tree6caf27d9379f743b9d974896dbe864ba1569c47c
parent871d657385466d380133e457fc86672bedf14cd9
fixdep: avoid parsing the same file over again

The dep files (*.d files) emitted by C compilers usually contain the
deduplicated list of included files.

One exceptional case is when a header is included by the -include
command line option, and also by #include directive.

For example, the top Makefile adds the command line option,
"-include $(srctree)/include/linux/kconfig.h". You do not need to
include <linux/kconfig.h> in every source file.

In fact, include/linux/kconfig.h is listed twice in many .*.cmd files
due to include/linux/xarray.h having "#include <linux/kconfig.h>".
I did not fix that since it is a small redundancy.

However, this is more annoying for rustc. rustc emits the dependency
for each emission type.

For example, cmd_rustc_library emits dep-info, obj, and metadata.
So, the emitted *.d file contains the dependency for those 3 targets,
which makes fixdep parse the same file 3 times.

  $ grep rust/alloc/raw_vec.rs rust/.alloc.o.cmd
    rust/alloc/raw_vec.rs \
    rust/alloc/raw_vec.rs \
    rust/alloc/raw_vec.rs \

To skip the second parsing, this commit adds a hash table for parsed
files, just like we did for CONFIG options.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
scripts/basic/fixdep.c