Commit faa91c47 authored by Masahiro Yamada's avatar Masahiro Yamada

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: default avatarMasahiro Yamada <masahiroy@kernel.org>
Acked-by: default avatarMiguel Ojeda <ojeda@kernel.org>
Tested-by: default avatarMiguel Ojeda <ojeda@kernel.org>
Reviewed-by: default avatarVincenzo Palazzo <vincenzopalazzodev@gmail.com>
parent 871d6573
......@@ -113,7 +113,7 @@ struct item {
};
#define HASHSZ 256
static struct item *config_hashtab[HASHSZ];
static struct item *config_hashtab[HASHSZ], *file_hashtab[HASHSZ];
static unsigned int strhash(const char *str, unsigned int sz)
{
......@@ -365,6 +365,10 @@ static void parse_dep_file(char *p, const char *target)
* name, which will be the original one, and ignore any
* other source names, which will be intermediate
* temporary files.
*
* rustc emits the same dependency list for each
* emission type. It is enough to list the source name
* just once.
*/
if (!saw_any_target) {
saw_any_target = true;
......@@ -372,7 +376,8 @@ static void parse_dep_file(char *p, const char *target)
printf("deps_%s := \\\n", target);
need_parse = true;
}
} else if (!is_ignored_file(p, q - p)) {
} else if (!is_ignored_file(p, q - p) &&
!in_hashtable(p, q - p, file_hashtab)) {
printf(" %s \\\n", p);
need_parse = true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment