From: Luis Augenstein <luis.augenstein@tngtech.com>
To: nathan@kernel.org, nsc@kernel.org
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, gregkh@linuxfoundation.org,
kstewart@linuxfoundation.org, maximilian.huber@tngtech.com,
Luis Augenstein <luis.augenstein@tngtech.com>
Subject: [PATCH v3 2/7] kbuild: refactor fixdep to collect dependencies before printing
Date: Mon, 12 Oct 2026 23:33:17 +0200 [thread overview]
Message-ID: <20261012213337.2466524-3-luis.augenstein@tngtech.com> (raw)
In-Reply-To: <20261012213337.2466524-1-luis.augenstein@tngtech.com>
fixdep currently writes the .cmd file content while parsing the .dep
file. Separate the parsing from the printing: parse_dep_file() now
collects the source file and all dependencies in a list, and
print_dep_file() emits the assignments afterwards. No functional
change intended.
Assisted-by: LLM
Co-developed-by: Maximilian Huber <maximilian.huber@tngtech.com>
Signed-off-by: Maximilian Huber <maximilian.huber@tngtech.com>
Signed-off-by: Luis Augenstein <luis.augenstein@tngtech.com>
---
scripts/basic/fixdep.c | 109 ++++++++++++++++++++++++++++++++++-------
1 file changed, 92 insertions(+), 17 deletions(-)
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 54063d98044..f514ef606ec 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -114,6 +114,17 @@ struct item {
char name[];
};
+struct dep_item {
+ struct dep_item *next;
+ char name[];
+};
+
+struct dep_info {
+ char *source;
+ struct dep_item *deps;
+ struct dep_item *last_dep;
+};
+
#define HASHSZ 256
static struct item *config_hashtab[HASHSZ], *file_hashtab[HASHSZ];
@@ -163,16 +174,42 @@ static bool in_hashtable(const char *name, int len, struct item *hashtab[])
return false;
}
+/*
+ * Append a dependency or include/config/<SYM> path to the info linked list.
+ */
+static void dep_info_add(struct dep_info *info, const char *name, int len)
+{
+ struct dep_item *dep = xmalloc(sizeof(*dep) + len + 1);
+
+ memcpy(dep->name, name, len);
+ dep->name[len] = '\0';
+ dep->next = NULL;
+
+ if (info->last_dep)
+ info->last_dep->next = dep;
+ else
+ info->deps = dep;
+ info->last_dep = dep;
+}
+
/*
* Record the use of a CONFIG_* word.
*/
-static void use_config(const char *m, int slen)
+static void use_config(const char *m, int slen, struct dep_info *info)
{
if (in_hashtable(m, slen, config_hashtab))
return;
- /* Print out a dependency path from a symbol name. */
- printf(" $(wildcard include/config/%.*s) \\\n", slen, m);
+ /* Build a dependency path from a symbol name. */
+ static const char config_path[] = "include/config/";
+ char *path;
+ int path_len = sizeof(config_path) - 1 + slen;
+
+ path = xmalloc(path_len);
+ memcpy(path, config_path, sizeof(config_path) - 1);
+ memcpy(path + sizeof(config_path) - 1, m, slen);
+ dep_info_add(info, path, path_len);
+ free(path);
}
/* test if s ends in sub */
@@ -186,7 +223,12 @@ static int str_ends_with(const char *s, int slen, const char *sub)
return !memcmp(s + slen - sublen, sub, sublen);
}
-static void parse_config_file(const char *p)
+/*
+ * Scan dependency p for CONFIG_ words, map each to an
+ * include/config/ path and append to the dep_info list if not
+ * already included.
+ */
+static void parse_config_file(const char *p, struct dep_info *info)
{
const char *q, *r;
const char *start = p;
@@ -205,7 +247,7 @@ static void parse_config_file(const char *p)
else
r = q;
if (r > p)
- use_config(p, r - p);
+ use_config(p, r - p, info);
p = q;
}
}
@@ -253,13 +295,9 @@ static int is_no_parse_file(const char *s, int len)
str_ends_with(s, len, ".so");
}
-/*
- * Important: The below generated source_foo.o and deps_foo.o variable
- * assignments are parsed not only by make, but also by the rather simple
- * parser in scripts/mod/sumversion.c.
- */
-static void parse_dep_file(char *p, const char *target)
+static struct dep_info parse_dep_file(char *p)
{
+ struct dep_info info = {};
bool saw_any_target = false;
bool is_target = true;
bool is_source = false;
@@ -375,13 +413,12 @@ static void parse_dep_file(char *p, const char *target)
*/
if (!saw_any_target) {
saw_any_target = true;
- printf("source_%s := %s\n\n", target, p);
- printf("deps_%s := \\\n", target);
+ info.source = xstrdup(p);
need_parse = true;
}
} else if (!is_ignored_file(p, q - p) &&
!in_hashtable(p, q - p, file_hashtab)) {
- printf(" %s \\\n", p);
+ dep_info_add(&info, p, q - p);
need_parse = true;
}
@@ -389,7 +426,7 @@ static void parse_dep_file(char *p, const char *target)
void *buf;
buf = read_file(p);
- parse_config_file(buf);
+ parse_config_file(buf, &info);
free(buf);
}
@@ -403,6 +440,40 @@ static void parse_dep_file(char *p, const char *target)
exit(1);
}
+ return info;
+}
+
+static void free_dep_info(struct dep_info *info)
+{
+ struct dep_item *dep, *next;
+
+ for (dep = info->deps; dep; dep = next) {
+ next = dep->next;
+ free(dep);
+ }
+ free(info->source);
+}
+
+/*
+ * Important: The below generated source_foo.o and deps_foo.o variable
+ * assignments are parsed not only by make, but also by the rather simple
+ * parser in scripts/mod/sumversion.c.
+ */
+static void print_dep_file(const char *target, const struct dep_info *info)
+{
+ static const char config_path[] = "include/config/";
+ const struct dep_item *dep;
+
+ printf("source_%s := %s\n\n", target, info->source);
+ printf("deps_%s := \\\n", target);
+
+ for (dep = info->deps; dep; dep = dep->next) {
+ if (!strncmp(dep->name, config_path, sizeof(config_path) - 1))
+ printf(" $(wildcard %s) \\\n", dep->name);
+ else
+ printf(" %s \\\n", dep->name);
+ }
+
printf("\n%s: $(deps_%s)\n\n", target, target);
printf("$(deps_%s):\n", target);
}
@@ -410,6 +481,7 @@ static void parse_dep_file(char *p, const char *target)
int main(int argc, char *argv[])
{
const char *depfile, *target, *cmdline;
+ struct dep_info info;
void *buf;
if (argc != 4)
@@ -419,10 +491,13 @@ int main(int argc, char *argv[])
target = argv[2];
cmdline = argv[3];
+ buf = read_file(depfile);
+ info = parse_dep_file(buf);
+
printf("savedcmd_%s := %s\n\n", target, cmdline);
+ print_dep_file(target, &info);
- buf = read_file(depfile);
- parse_dep_file(buf, target);
+ free_dep_info(&info);
free(buf);
fflush(stdout);
--
2.43.0
next prev parent reply other threads:[~2026-10-12 21:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 21:33 [PATCH v3 0/7] kbuild: record cmd-prereqs in .cmd files Luis Augenstein
2026-10-12 21:33 ` [PATCH v3 1/7] scripts/make_fit: limit .cmd file parsing to the savedcmd_ line Luis Augenstein
2026-10-12 21:33 ` Luis Augenstein [this message]
2026-10-12 21:33 ` [PATCH v3 3/7] scripts/sbom: skip make_prereqs lines when parsing .cmd files Luis Augenstein
2026-10-12 21:33 ` [PATCH v3 4/7] kbuild: record cmd-prereqs in " Luis Augenstein
2026-10-12 21:33 ` [PATCH v3 5/7] scripts/sbom: parse make_prereqs from " Luis Augenstein
2026-10-12 21:33 ` [PATCH v3 6/7] scripts/sbom: use make_prereqs to determine build inputs Luis Augenstein
2026-10-12 21:33 ` [PATCH v3 7/7] scripts/sbom: remove the command-specific parsers Luis Augenstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261012213337.2466524-3-luis.augenstein@tngtech.com \
--to=luis.augenstein@tngtech.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maximilian.huber@tngtech.com \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®