All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion
@ 2018-01-11 13:05 Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 2/7] fixdep: use malloc() and read() to load dep_file to buffer Masahiro Yamada
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-11 13:05 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, linux-kernel

<arpa/inet.h> was included for ntohl(), but it was removed by
commit dee81e988674 ("fixdep: faster CONFIG_ search").

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
  - newly added

 scripts/basic/fixdep.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 86a61d6..b9b4bbf 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -112,7 +112,6 @@
 #include <stdio.h>
 #include <limits.h>
 #include <ctype.h>
-#include <arpa/inet.h>
 
 int insert_extra_deps;
 char *target;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/7] fixdep: use malloc() and read() to load dep_file to buffer
  2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
@ 2018-01-11 13:05 ` Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 3/7] fixdep: factor out common code for reading files Masahiro Yamada
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-11 13:05 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, linux-kernel

Commit dee81e988674 ("fixdep: faster CONFIG_ search") changed how to
read files in which CONFIG options are searched.  It used malloc()
and read() instead of mmap() because it needed to zero-terminate the
buffer in order to use strstr().  print_deps() was left untouched
since there was no reason to change it.

Now, I have two motivations to change it in the same way.

 - do_config_file() and print_deps() do quite similar things; they
   open a file, load it onto memory, and pass it to a parser function.
   If we use malloc() and read() for print_deps() too, we can factor
   out the common code.  (I will do this in the next commit.)

 - parse_dep_file() copies each token to a temporary buffer because
   it needs to zero-terminate it to be passed to printf().  It is not
   possible to modify the buffer directly because it is mmap'ed with
   O_RDONLY.  If we load the file content into a malloc'ed buffer, we
   can insert '\0' after each token, and save memcpy().  (I will do
   this in the commit after next.)

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
  - Remove #include <sys/mman.h>

 scripts/basic/fixdep.c | 56 ++++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index b9b4bbf..91bb4c1 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -104,7 +104,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
@@ -308,24 +307,27 @@ static void do_config_file(const char *filename)
  * assignments are parsed not only by make, but also by the rather simple
  * parser in scripts/mod/sumversion.c.
  */
-static void parse_dep_file(void *map, size_t len)
+static void parse_dep_file(char *m)
 {
-	char *m = map;
-	char *end = m + len;
 	char *p;
 	char s[PATH_MAX];
-	int is_target;
+	int is_last, is_target;
 	int saw_any_target = 0;
 	int is_first_dep = 0;
 
-	while (m < end) {
+	while (1) {
 		/* Skip any "white space" */
-		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
+		while (*m == ' ' || *m == '\\' || *m == '\n')
 			m++;
+
+		if (!*m)
+			break;
+
 		/* Find next "white space" */
 		p = m;
-		while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
+		while (*p && *p != ' ' && *p != '\\' && *p != '\n')
 			p++;
+		is_last = (*p == '\0');
 		/* Is the token we found a target name? */
 		is_target = (*(p-1) == ':');
 		/* Don't write any target names into the dependency file */
@@ -373,6 +375,10 @@ static void parse_dep_file(void *map, size_t len)
 				do_config_file(s);
 			}
 		}
+
+		if (is_last)
+			break;
+
 		/*
 		 * Start searching for next token immediately after the first
 		 * "whitespace" character that follows this token.
@@ -391,40 +397,42 @@ static void parse_dep_file(void *map, size_t len)
 	printf("$(deps_%s):\n", target);
 }
 
-static void print_deps(void)
+static void print_deps(const char *filename)
 {
 	struct stat st;
 	int fd;
-	void *map;
+	char *buf;
 
-	fd = open(depfile, O_RDONLY);
+	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
 		fprintf(stderr, "fixdep: error opening depfile: ");
-		perror(depfile);
+		perror(filename);
 		exit(2);
 	}
 	if (fstat(fd, &st) < 0) {
 		fprintf(stderr, "fixdep: error fstat'ing depfile: ");
-		perror(depfile);
+		perror(filename);
 		exit(2);
 	}
 	if (st.st_size == 0) {
-		fprintf(stderr,"fixdep: %s is empty\n",depfile);
 		close(fd);
 		return;
 	}
-	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-	if ((long) map == -1) {
-		perror("fixdep: mmap");
-		close(fd);
-		return;
+	buf = malloc(st.st_size + 1);
+	if (!buf) {
+		perror("fixdep: malloc");
+		exit(2);
 	}
+	if (read(fd, buf, st.st_size) != st.st_size) {
+		perror("fixdep: read");
+		exit(2);
+	}
+	buf[st.st_size] = '\0';
+	close(fd);
 
-	parse_dep_file(map, st.st_size);
-
-	munmap(map, st.st_size);
+	parse_dep_file(buf);
 
-	close(fd);
+	free(buf);
 }
 
 int main(int argc, char *argv[])
@@ -440,7 +448,7 @@ int main(int argc, char *argv[])
 	cmdline = argv[3];
 
 	print_cmdline();
-	print_deps();
+	print_deps(depfile);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/7] fixdep: factor out common code for reading files
  2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 2/7] fixdep: use malloc() and read() to load dep_file to buffer Masahiro Yamada
@ 2018-01-11 13:05 ` Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 4/7] fixdep: remove unneeded memcpy() in parse_dep_file() Masahiro Yamada
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-11 13:05 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, linux-kernel

Now, do_config_files() and print_deps() are almost the same.  Only
the difference is the parser function called (parse_config_file vs
parse_dep_file).

We can reduce the code duplication by factoring out the common code
into read_file() - this function allocates a buffer and loads a file
to it.  It returns the pointer to the allocated buffer.  (As before,
it bails out by exit(2) for any error.)  The caller must free the
buffer when done.

Having empty source files is possible; fixdep should simply skip them.
I deleted the "st.st_size == 0" check, so read_file() allocates 1-byte
buffer for an empty file.  strstr() will immediately return NULL, and
this is what we expect.

On the other hand, an empty dep_file should be treated as an error.
In this case, parse_dep_file() will error out with "no targets found"
and it is a correct error message.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
  - rename load_file to read_file

 scripts/basic/fixdep.c | 75 ++++++++++++++------------------------------------
 1 file changed, 20 insertions(+), 55 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 91bb4c1..9f9238e 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -264,42 +264,36 @@ static int strrcmp(const char *s, const char *sub)
 	return memcmp(s + slen - sublen, sub, sublen);
 }
 
-static void do_config_file(const char *filename)
+static void *read_file(const char *filename)
 {
 	struct stat st;
 	int fd;
-	char *map;
+	char *buf;
 
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
-		fprintf(stderr, "fixdep: error opening config file: ");
+		fprintf(stderr, "fixdep: error opening file: ");
 		perror(filename);
 		exit(2);
 	}
 	if (fstat(fd, &st) < 0) {
-		fprintf(stderr, "fixdep: error fstat'ing config file: ");
+		fprintf(stderr, "fixdep: error fstat'ing file: ");
 		perror(filename);
 		exit(2);
 	}
-	if (st.st_size == 0) {
-		close(fd);
-		return;
-	}
-	map = malloc(st.st_size + 1);
-	if (!map) {
+	buf = malloc(st.st_size + 1);
+	if (!buf) {
 		perror("fixdep: malloc");
 		exit(2);
 	}
-	if (read(fd, map, st.st_size) != st.st_size) {
+	if (read(fd, buf, st.st_size) != st.st_size) {
 		perror("fixdep: read");
 		exit(2);
 	}
-	map[st.st_size] = '\0';
+	buf[st.st_size] = '\0';
 	close(fd);
 
-	parse_config_file(map);
-
-	free(map);
+	return buf;
 }
 
 /*
@@ -314,6 +308,7 @@ static void parse_dep_file(char *m)
 	int is_last, is_target;
 	int saw_any_target = 0;
 	int is_first_dep = 0;
+	void *buf;
 
 	while (1) {
 		/* Skip any "white space" */
@@ -372,7 +367,10 @@ static void parse_dep_file(char *m)
 					is_first_dep = 0;
 				} else
 					printf("  %s \\\n", s);
-				do_config_file(s);
+
+				buf = read_file(s);
+				parse_config_file(buf);
+				free(buf);
 			}
 		}
 
@@ -397,46 +395,10 @@ static void parse_dep_file(char *m)
 	printf("$(deps_%s):\n", target);
 }
 
-static void print_deps(const char *filename)
-{
-	struct stat st;
-	int fd;
-	char *buf;
-
-	fd = open(filename, O_RDONLY);
-	if (fd < 0) {
-		fprintf(stderr, "fixdep: error opening depfile: ");
-		perror(filename);
-		exit(2);
-	}
-	if (fstat(fd, &st) < 0) {
-		fprintf(stderr, "fixdep: error fstat'ing depfile: ");
-		perror(filename);
-		exit(2);
-	}
-	if (st.st_size == 0) {
-		close(fd);
-		return;
-	}
-	buf = malloc(st.st_size + 1);
-	if (!buf) {
-		perror("fixdep: malloc");
-		exit(2);
-	}
-	if (read(fd, buf, st.st_size) != st.st_size) {
-		perror("fixdep: read");
-		exit(2);
-	}
-	buf[st.st_size] = '\0';
-	close(fd);
-
-	parse_dep_file(buf);
-
-	free(buf);
-}
-
 int main(int argc, char *argv[])
 {
+	void *buf;
+
 	if (argc == 5 && !strcmp(argv[1], "-e")) {
 		insert_extra_deps = 1;
 		argv++;
@@ -448,7 +410,10 @@ int main(int argc, char *argv[])
 	cmdline = argv[3];
 
 	print_cmdline();
-	print_deps(depfile);
+
+	buf = read_file(depfile);
+	parse_dep_file(buf);
+	free(buf);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/7] fixdep: remove unneeded memcpy() in parse_dep_file()
  2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 2/7] fixdep: use malloc() and read() to load dep_file to buffer Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 3/7] fixdep: factor out common code for reading files Masahiro Yamada
@ 2018-01-11 13:05 ` Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 5/7] fixdep: move global variables to local variables of main() Masahiro Yamada
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-11 13:05 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, linux-kernel

Each token in the depfile is copied to the temporary buffer 's' to
terminate the token with zero.  We do not need to do this any more
because the parsed buffer is now writable.  Insert '\0' directly in
the buffer without calling memcpy().

<limits.h> is no longer necessary. (It was needed for PATH_MAX).

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2: None

 scripts/basic/fixdep.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 9f9238e..dfba77b 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -109,7 +109,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <limits.h>
 #include <ctype.h>
 
 int insert_extra_deps;
@@ -304,7 +303,6 @@ static void *read_file(const char *filename)
 static void parse_dep_file(char *m)
 {
 	char *p;
-	char s[PATH_MAX];
 	int is_last, is_target;
 	int saw_any_target = 0;
 	int is_first_dep = 0;
@@ -330,16 +328,14 @@ static void parse_dep_file(char *m)
 			/* The /next/ file is the first dependency */
 			is_first_dep = 1;
 		} else {
-			/* Save this token/filename */
-			memcpy(s, m, p-m);
-			s[p - m] = 0;
+			*p = '\0';
 
 			/* Ignore certain dependencies */
-			if (strrcmp(s, "include/generated/autoconf.h") &&
-			    strrcmp(s, "include/generated/autoksyms.h") &&
-			    strrcmp(s, "arch/um/include/uml-config.h") &&
-			    strrcmp(s, "include/linux/kconfig.h") &&
-			    strrcmp(s, ".ver")) {
+			if (strrcmp(m, "include/generated/autoconf.h") &&
+			    strrcmp(m, "include/generated/autoksyms.h") &&
+			    strrcmp(m, "arch/um/include/uml-config.h") &&
+			    strrcmp(m, "include/linux/kconfig.h") &&
+			    strrcmp(m, ".ver")) {
 				/*
 				 * Do not list the source file as dependency,
 				 * so that kbuild is not confused if a .c file
@@ -360,15 +356,15 @@ static void parse_dep_file(char *m)
 					if (!saw_any_target) {
 						saw_any_target = 1;
 						printf("source_%s := %s\n\n",
-							target, s);
+							target, m);
 						printf("deps_%s := \\\n",
 							target);
 					}
 					is_first_dep = 0;
 				} else
-					printf("  %s \\\n", s);
+					printf("  %s \\\n", m);
 
-				buf = read_file(s);
+				buf = read_file(m);
 				parse_config_file(buf);
 				free(buf);
 			}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/7] fixdep: move global variables to local variables of main()
  2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
                   ` (2 preceding siblings ...)
  2018-01-11 13:05 ` [PATCH v2 4/7] fixdep: remove unneeded memcpy() in parse_dep_file() Masahiro Yamada
@ 2018-01-11 13:05 ` Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 6/7] fixdep: refactor parse_dep_file() Masahiro Yamada
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-11 13:05 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, linux-kernel

I do not mind global variables where they are useful enough.  In this
case, I do not see a good reason to use global variables since they
are just referenced in shallow places.  It is easy to pass them via
function arguments.

I squashed print_cmdline() into main() since it is just one line code.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
  - Squash print_cmdline() into main()

 scripts/basic/fixdep.c | 42 ++++++++++++++++--------------------------
 1 file changed, 16 insertions(+), 26 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index dfba77b..d33b5a4 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -111,11 +111,6 @@
 #include <stdio.h>
 #include <ctype.h>
 
-int insert_extra_deps;
-char *target;
-char *depfile;
-char *cmdline;
-
 static void usage(void)
 {
 	fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n");
@@ -124,14 +119,6 @@ static void usage(void)
 }
 
 /*
- * Print out the commandline prefixed with cmd_<target filename> :=
- */
-static void print_cmdline(void)
-{
-	printf("cmd_%s := %s\n\n", target, cmdline);
-}
-
-/*
  * Print out a dependency path from a symbol name
  */
 static void print_config(const char *m, int slen)
@@ -152,16 +139,16 @@ static void print_config(const char *m, int slen)
 
 static void do_extra_deps(void)
 {
-	if (insert_extra_deps) {
-		char buf[80];
-		while(fgets(buf, sizeof(buf), stdin)) {
-			int len = strlen(buf);
-			if (len < 2 || buf[len-1] != '\n') {
-				fprintf(stderr, "fixdep: bad data on stdin\n");
-				exit(1);
-			}
-			print_config(buf, len-1);
+	char buf[80];
+
+	while (fgets(buf, sizeof(buf), stdin)) {
+		int len = strlen(buf);
+
+		if (len < 2 || buf[len - 1] != '\n') {
+			fprintf(stderr, "fixdep: bad data on stdin\n");
+			exit(1);
 		}
+		print_config(buf, len - 1);
 	}
 }
 
@@ -300,7 +287,7 @@ static void *read_file(const char *filename)
  * 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 *m)
+static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
 {
 	char *p;
 	int is_last, is_target;
@@ -385,7 +372,8 @@ static void parse_dep_file(char *m)
 		exit(1);
 	}
 
-	do_extra_deps();
+	if (insert_extra_deps)
+		do_extra_deps();
 
 	printf("\n%s: $(deps_%s)\n\n", target, target);
 	printf("$(deps_%s):\n", target);
@@ -393,6 +381,8 @@ static void parse_dep_file(char *m)
 
 int main(int argc, char *argv[])
 {
+	const char *depfile, *target, *cmdline;
+	int insert_extra_deps = 0;
 	void *buf;
 
 	if (argc == 5 && !strcmp(argv[1], "-e")) {
@@ -405,10 +395,10 @@ int main(int argc, char *argv[])
 	target = argv[2];
 	cmdline = argv[3];
 
-	print_cmdline();
+	printf("cmd_%s := %s\n\n", target, cmdline);
 
 	buf = read_file(depfile);
-	parse_dep_file(buf);
+	parse_dep_file(buf, target, insert_extra_deps);
 	free(buf);
 
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 6/7] fixdep: refactor parse_dep_file()
  2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
                   ` (3 preceding siblings ...)
  2018-01-11 13:05 ` [PATCH v2 5/7] fixdep: move global variables to local variables of main() Masahiro Yamada
@ 2018-01-11 13:05 ` Masahiro Yamada
  2018-01-11 13:05 ` [PATCH v2 7/7] fixdep: use existing helper to check modular CONFIG options Masahiro Yamada
  2018-01-16 16:44 ` [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
  6 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-11 13:05 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, linux-kernel

parse_dep_file() has too much indentation, and puts the code far to
the right.  This commit refactors the code and reduces the one level
of indentation.

strrcmp() computes 'slen' by itself, but the caller already knows the
length of the token, so 'slen' can be passed via function argument.
With this, we can swap the order of strrcmp() and "*p = \0;"

Also, strrcmp() is an ambiguous function name.  Flip the logic and
rename it to str_ends_with().

I added a new helper is_ignored_file() - this returns 1 if the token
represents a file that should be ignored.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2: None

 scripts/basic/fixdep.c | 80 +++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index d33b5a4..0abc15778 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -239,15 +239,14 @@ static void parse_config_file(const char *p)
 }
 
 /* test if s ends in sub */
-static int strrcmp(const char *s, const char *sub)
+static int str_ends_with(const char *s, int slen, const char *sub)
 {
-	int slen = strlen(s);
 	int sublen = strlen(sub);
 
 	if (sublen > slen)
-		return 1;
+		return 0;
 
-	return memcmp(s + slen - sublen, sub, sublen);
+	return !memcmp(s + slen - sublen, sub, sublen);
 }
 
 static void *read_file(const char *filename)
@@ -282,6 +281,16 @@ static void *read_file(const char *filename)
 	return buf;
 }
 
+/* Ignore certain dependencies */
+static int is_ignored_file(const char *s, int len)
+{
+	return str_ends_with(s, len, "include/generated/autoconf.h") ||
+	       str_ends_with(s, len, "include/generated/autoksyms.h") ||
+	       str_ends_with(s, len, "arch/um/include/uml-config.h") ||
+	       str_ends_with(s, len, "include/linux/kconfig.h") ||
+	       str_ends_with(s, len, ".ver");
+}
+
 /*
  * 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
@@ -314,47 +323,38 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
 		if (is_target) {
 			/* The /next/ file is the first dependency */
 			is_first_dep = 1;
-		} else {
+		} else if (!is_ignored_file(m, p - m)) {
 			*p = '\0';
 
-			/* Ignore certain dependencies */
-			if (strrcmp(m, "include/generated/autoconf.h") &&
-			    strrcmp(m, "include/generated/autoksyms.h") &&
-			    strrcmp(m, "arch/um/include/uml-config.h") &&
-			    strrcmp(m, "include/linux/kconfig.h") &&
-			    strrcmp(m, ".ver")) {
+			/*
+			 * Do not list the source file as dependency, so that
+			 * kbuild is not confused if a .c file is rewritten
+			 * into .S or vice versa. Storing it in source_* is
+			 * needed for modpost to compute srcversions.
+			 */
+			if (is_first_dep) {
 				/*
-				 * Do not list the source file as dependency,
-				 * so that kbuild is not confused if a .c file
-				 * is rewritten into .S or vice versa. Storing
-				 * it in source_* is needed for modpost to
-				 * compute srcversions.
+				 * If processing the concatenation of multiple
+				 * dependency files, only process the first
+				 * target name, which will be the original
+				 * source name, and ignore any other target
+				 * names, which will be intermediate temporary
+				 * files.
 				 */
-				if (is_first_dep) {
-					/*
-					 * If processing the concatenation of
-					 * multiple dependency files, only
-					 * process the first target name, which
-					 * will be the original source name,
-					 * and ignore any other target names,
-					 * which will be intermediate temporary
-					 * files.
-					 */
-					if (!saw_any_target) {
-						saw_any_target = 1;
-						printf("source_%s := %s\n\n",
-							target, m);
-						printf("deps_%s := \\\n",
-							target);
-					}
-					is_first_dep = 0;
-				} else
-					printf("  %s \\\n", m);
-
-				buf = read_file(m);
-				parse_config_file(buf);
-				free(buf);
+				if (!saw_any_target) {
+					saw_any_target = 1;
+					printf("source_%s := %s\n\n",
+					       target, m);
+					printf("deps_%s := \\\n", target);
+				}
+				is_first_dep = 0;
+			} else {
+				printf("  %s \\\n", m);
 			}
+
+			buf = read_file(m);
+			parse_config_file(buf);
+			free(buf);
 		}
 
 		if (is_last)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 7/7] fixdep: use existing helper to check modular CONFIG options
  2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
                   ` (4 preceding siblings ...)
  2018-01-11 13:05 ` [PATCH v2 6/7] fixdep: refactor parse_dep_file() Masahiro Yamada
@ 2018-01-11 13:05 ` Masahiro Yamada
  2018-01-16 16:44 ` [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
  6 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-11 13:05 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, linux-kernel

str_ends_with() tests if the given token ends with a particular string.
Currently, it is used to check file paths without $(srctree).

Actually, we have one more place where this helper is useful.  Use it
to check if CONFIG option ends with _MODULE.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2: None

 scripts/basic/fixdep.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 0abc15778..fa3d39b6 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -219,6 +219,17 @@ static void use_config(const char *m, int slen)
 	print_config(m, slen);
 }
 
+/* test if s ends in sub */
+static int str_ends_with(const char *s, int slen, const char *sub)
+{
+	int sublen = strlen(sub);
+
+	if (sublen > slen)
+		return 0;
+
+	return !memcmp(s + slen - sublen, sub, sublen);
+}
+
 static void parse_config_file(const char *p)
 {
 	const char *q, *r;
@@ -228,7 +239,7 @@ static void parse_config_file(const char *p)
 		q = p;
 		while (*q && (isalnum(*q) || *q == '_'))
 			q++;
-		if (memcmp(q - 7, "_MODULE", 7) == 0)
+		if (str_ends_with(p, q - p, "_MODULE"))
 			r = q - 7;
 		else
 			r = q;
@@ -238,17 +249,6 @@ static void parse_config_file(const char *p)
 	}
 }
 
-/* test if s ends in sub */
-static int str_ends_with(const char *s, int slen, const char *sub)
-{
-	int sublen = strlen(sub);
-
-	if (sublen > slen)
-		return 0;
-
-	return !memcmp(s + slen - sublen, sub, sublen);
-}
-
 static void *read_file(const char *filename)
 {
 	struct stat st;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion
  2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
                   ` (5 preceding siblings ...)
  2018-01-11 13:05 ` [PATCH v2 7/7] fixdep: use existing helper to check modular CONFIG options Masahiro Yamada
@ 2018-01-16 16:44 ` Masahiro Yamada
  6 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2018-01-16 16:44 UTC (permalink / raw)
  To: Linux Kbuild mailing list
  Cc: Michal Marek, Sam Ravnborg, Masahiro Yamada, Linux Kernel Mailing List

2018-01-11 22:05 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> <arpa/inet.h> was included for ntohl(), but it was removed by
> commit dee81e988674 ("fixdep: faster CONFIG_ search").
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>

Series, applied to linux-kbuild/kbuild.


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-01-16 16:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-11 13:05 [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada
2018-01-11 13:05 ` [PATCH v2 2/7] fixdep: use malloc() and read() to load dep_file to buffer Masahiro Yamada
2018-01-11 13:05 ` [PATCH v2 3/7] fixdep: factor out common code for reading files Masahiro Yamada
2018-01-11 13:05 ` [PATCH v2 4/7] fixdep: remove unneeded memcpy() in parse_dep_file() Masahiro Yamada
2018-01-11 13:05 ` [PATCH v2 5/7] fixdep: move global variables to local variables of main() Masahiro Yamada
2018-01-11 13:05 ` [PATCH v2 6/7] fixdep: refactor parse_dep_file() Masahiro Yamada
2018-01-11 13:05 ` [PATCH v2 7/7] fixdep: use existing helper to check modular CONFIG options Masahiro Yamada
2018-01-16 16:44 ` [PATCH v2 1/7] fixdep: remove unnecessary <arpa/inet.h> inclusion Masahiro Yamada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.