History

fixdep: refactor parse_dep_file()

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.

Masahiro Yamada committed 8 years ago

Commit 87b95a81 parent 5d1ef761 file · +40 −40Browse files

Showing the changes to scripts/basic (1 of 1 file). Show all

Unified · Split

scripts/basic/fixdep.c+40−40
@@ -239,15 +239,14 @@ static void parse_config_file(const char *p) · 238 unmodified lines
239}239}
240 240
241/* test if s ends in sub */241/* test if s ends in sub */
242static int strrcmp(const char *s, const char *sub)242static int str_ends_with(const char *s, int slen, const char *sub)
243{243{
244 int slen = strlen(s);
245 int sublen = strlen(sub);244 int sublen = strlen(sub);
246 245
247 if (sublen > slen)246 if (sublen > slen)
248 return 1;247 return 0;
249 248
250 return memcmp(s + slen - sublen, sub, sublen);249 return !memcmp(s + slen - sublen, sub, sublen);
251}250}
252 251
253static void *read_file(const char *filename)252static void *read_file(const char *filename)
@@ -282,6 +281,16 @@ static void *read_file(const char *filename) · 28 unmodified lines
282 return buf;281 return buf;
283}282}
284 283
284/* Ignore certain dependencies */
285static int is_ignored_file(const char *s, int len)
286{
287 return str_ends_with(s, len, "include/generated/autoconf.h") ||
288 str_ends_with(s, len, "include/generated/autoksyms.h") ||
289 str_ends_with(s, len, "arch/um/include/uml-config.h") ||
290 str_ends_with(s, len, "include/linux/kconfig.h") ||
291 str_ends_with(s, len, ".ver");
292}
293
285/*294/*
286 * Important: The below generated source_foo.o and deps_foo.o variable295 * Important: The below generated source_foo.o and deps_foo.o variable
287 * assignments are parsed not only by make, but also by the rather simple296 * 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) · 26 unmodified lines
314 if (is_target) {323 if (is_target) {
315 /* The /next/ file is the first dependency */324 /* The /next/ file is the first dependency */
316 is_first_dep = 1;325 is_first_dep = 1;
317 } else {326 } else if (!is_ignored_file(m, p - m)) {
318 *p = '\0';327 *p = '\0';
319 328
320 /* Ignore certain dependencies */329 /*
321 if (strrcmp(m, "include/generated/autoconf.h") &&330 * Do not list the source file as dependency, so that
322 strrcmp(m, "include/generated/autoksyms.h") &&331 * kbuild is not confused if a .c file is rewritten
323 strrcmp(m, "arch/um/include/uml-config.h") &&332 * into .S or vice versa. Storing it in source_* is
324 strrcmp(m, "include/linux/kconfig.h") &&333 * needed for modpost to compute srcversions.
325 strrcmp(m, ".ver")) {334 */
335 if (is_first_dep) {
326 /*336 /*
327 * Do not list the source file as dependency,337 * If processing the concatenation of multiple
328 * so that kbuild is not confused if a .c file338 * dependency files, only process the first
329 * is rewritten into .S or vice versa. Storing339 * target name, which will be the original
330 * it in source_* is needed for modpost to340 * source name, and ignore any other target
331 * compute srcversions.341 * names, which will be intermediate temporary
342 * files.
332 */343 */
333 if (is_first_dep) {344 if (!saw_any_target) {
334 /*345 saw_any_target = 1;
335 * If processing the concatenation of346 printf("source_%s := %s\n\n",
336 * multiple dependency files, only347 target, m);
337 * process the first target name, which348 printf("deps_%s := \\\n", target);
338 * will be the original source name,349 }
339 * and ignore any other target names,350 is_first_dep = 0;
340 * which will be intermediate temporary351 } else {
341 * files.352 printf(" %s \\\n", m);
342 */
343 if (!saw_any_target) {
344 saw_any_target = 1;
345 printf("source_%s := %s\n\n",
346 target, m);
347 printf("deps_%s := \\\n",
348 target);
349 }
350 is_first_dep = 0;
351 } else
352 printf(" %s \\\n", m);
353
354 buf = read_file(m);
355 parse_config_file(buf);
356 free(buf);
357 }353 }
354
355 buf = read_file(m);
356 parse_config_file(buf);
357 free(buf);
358 }358 }
359 359
360 if (is_last)360 if (is_last)