summaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/confdata.c
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-11-30 04:15:50 -0500
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-12-07 20:42:30 -0500
commit1508fec82e394149212aca836dd925d7e8fa3228 (patch)
tree73b2092c4e13e9ddf5e1fcca30c73200d40f1301 /scripts/kconfig/confdata.c
parent0849d212e39523e2289c2a6d685b899f944746eb (diff)
kconfig: split out code touching a file to conf_touch_dep()
conf_touch_deps() iterates over symbols, touching corresponding include/config/*.h files as needed. Split the part that touches a single file into a new helper so it can be reused. The new helper, conf_touch_dep(), takes a symbol name as a parameter, and touches the corresponding include/config/*.h file. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r--scripts/kconfig/confdata.c92
1 files changed, 49 insertions, 43 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 4c76d561d383..39dfe463de15 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -74,6 +74,47 @@ static int make_parent_dir(const char *path)
74 return 0; 74 return 0;
75} 75}
76 76
77static char depfile_path[PATH_MAX];
78static size_t depfile_prefix_len;
79
80/* touch depfile for symbol 'name' */
81static int conf_touch_dep(const char *name)
82{
83 int fd, ret;
84 const char *s;
85 char *d, c;
86
87 /* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */
88 if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path))
89 return -1;
90
91 d = depfile_path + depfile_prefix_len;
92 s = name;
93
94 while ((c = *s++))
95 *d++ = (c == '_') ? '/' : tolower(c);
96 strcpy(d, ".h");
97
98 /* Assume directory path already exists. */
99 fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
100 if (fd == -1) {
101 if (errno != ENOENT)
102 return -1;
103
104 ret = make_parent_dir(depfile_path);
105 if (ret)
106 return ret;
107
108 /* Try it again. */
109 fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
110 if (fd == -1)
111 return -1;
112 }
113 close(fd);
114
115 return 0;
116}
117
77struct conf_printer { 118struct conf_printer {
78 void (*print_symbol)(FILE *, struct symbol *, const char *, void *); 119 void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
79 void (*print_comment)(FILE *, const char *, void *); 120 void (*print_comment)(FILE *, const char *, void *);
@@ -909,21 +950,16 @@ static int conf_write_dep(const char *name)
909static int conf_touch_deps(void) 950static int conf_touch_deps(void)
910{ 951{
911 const char *name; 952 const char *name;
912 char path[PATH_MAX+1];
913 char *s, *d, c;
914 struct symbol *sym; 953 struct symbol *sym;
915 int res, i, fd; 954 int res, i;
955
956 strcpy(depfile_path, "include/config/");
957 depfile_prefix_len = strlen(depfile_path);
916 958
917 name = conf_get_autoconfig_name(); 959 name = conf_get_autoconfig_name();
918 conf_read_simple(name, S_DEF_AUTO); 960 conf_read_simple(name, S_DEF_AUTO);
919 sym_calc_value(modules_sym); 961 sym_calc_value(modules_sym);
920 962
921 if (make_parent_dir("include/config/foo.h"))
922 return 1;
923 if (chdir("include/config"))
924 return 1;
925
926 res = 0;
927 for_all_symbols(i, sym) { 963 for_all_symbols(i, sym) {
928 sym_calc_value(sym); 964 sym_calc_value(sym);
929 if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) 965 if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
@@ -975,42 +1011,12 @@ static int conf_touch_deps(void)
975 * different from 'no'). 1011 * different from 'no').
976 */ 1012 */
977 1013
978 /* Replace all '_' and append ".h" */ 1014 res = conf_touch_dep(sym->name);
979 s = sym->name; 1015 if (res)
980 d = path; 1016 return res;
981 while ((c = *s++)) {
982 c = tolower(c);
983 *d++ = (c == '_') ? '/' : c;
984 }
985 strcpy(d, ".h");
986
987 /* Assume directory path already exists. */
988 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
989 if (fd == -1) {
990 if (errno != ENOENT) {
991 res = 1;
992 break;
993 }
994
995 if (make_parent_dir(path)) {
996 res = 1;
997 goto out;
998 }
999
1000 /* Try it again. */
1001 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1002 if (fd == -1) {
1003 res = 1;
1004 break;
1005 }
1006 }
1007 close(fd);
1008 } 1017 }
1009out:
1010 if (chdir("../.."))
1011 return 1;
1012 1018
1013 return res; 1019 return 0;
1014} 1020}
1015 1021
1016int conf_write_autoconf(int overwrite) 1022int conf_write_autoconf(int overwrite)