Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in portage-utils: main.c
Date: Thu, 22 Dec 2011 20:26:34
Message-Id: 20111222202620.4C9852004C@flycatcher.gentoo.org
1 vapier 11/12/22 20:26:20
2
3 Modified: main.c
4 Log:
5 support PORTAGE_CONFIGROOT with make.conf files, stop reading /etc/make.globals (since portage has too), and support sourcing files in make.conf via relative paths
6
7 Revision Changes Path
8 1.214 portage-utils/main.c
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.214&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.214&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?r1=1.213&r2=1.214
13
14 Index: main.c
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/portage-utils/main.c,v
17 retrieving revision 1.213
18 retrieving revision 1.214
19 diff -u -r1.213 -r1.214
20 --- main.c 22 Dec 2011 17:49:19 -0000 1.213
21 +++ main.c 22 Dec 2011 20:26:20 -0000 1.214
22 @@ -1,7 +1,7 @@
23 /*
24 * Copyright 2005-2008 Gentoo Foundation
25 * Distributed under the terms of the GNU General Public License v2
26 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.213 2011/12/22 17:49:19 vapier Exp $
27 + * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.214 2011/12/22 20:26:20 vapier Exp $
28 *
29 * Copyright 2005-2008 Ned Ludd - <solar@g.o>
30 * Copyright 2005-2008 Mike Frysinger - <vapier@g.o>
31 @@ -531,20 +531,28 @@
32 }
33
34 /* Helper to read a portage env file (e.g. make.conf) */
35 -_q_static void read_portage_env_file(const char *file, env_vars vars[])
36 +_q_static void read_portage_env_file(const char *configroot, const char *file, env_vars vars[])
37 {
38 - size_t i, buflen, line;
39 + size_t i, buflen, line, configroot_len, file_len;
40 FILE *fp;
41 char *buf, *s, *p;
42
43 IF_DEBUG(fprintf(stderr, "profile %s\n", file));
44
45 - fp = fopen(file, "r");
46 + configroot_len = strlen(configroot);
47 + file_len = strlen(file);
48 + buflen = configroot_len + file_len + 1;
49 + buf = xmalloc(buflen);
50 +
51 + memcpy(buf, configroot, configroot_len);
52 + memcpy(buf + configroot_len, file, file_len);
53 + buf[buflen - 1] = '\0';
54 +
55 + fp = fopen(buf, "r");
56 if (fp == NULL)
57 - return;
58 + goto done;
59
60 line = 0;
61 - buf = NULL;
62 while (getline(&buf, &buflen, fp) != -1) {
63 ++line;
64 rmspace(buf);
65 @@ -552,8 +560,27 @@
66 continue;
67
68 /* Handle "source" keyword */
69 - if (!strncmp(buf, "source ", 7))
70 - read_portage_env_file(buf + 7, vars);
71 + if (!strncmp(buf, "source ", 7)) {
72 + const char *sfile = buf + 7;
73 +
74 + if (sfile[0] != '/') {
75 + /* handle relative paths */
76 + size_t file_path_len, source_len;
77 +
78 + s = strrchr(file, '/');
79 + file_path_len = s - file + 1;
80 + source_len = strlen(sfile);
81 +
82 + if (buflen <= source_len + file_path_len)
83 + buf = xrealloc(buf, buflen = source_len + file_path_len + 1);
84 + memmove(buf + file_path_len, buf + 7, source_len + 1);
85 + memcpy(buf, file, file_path_len);
86 + sfile = buf;
87 + }
88 +
89 + read_portage_env_file(configroot, sfile, vars);
90 + continue;
91 + }
92
93 /* look for our desired variables and grab their value */
94 for (i = 0; vars[i].name; ++i) {
95 @@ -607,8 +634,9 @@
96 }
97 }
98
99 - free(buf);
100 fclose(fp);
101 + done:
102 + free(buf);
103 }
104
105 /* Helper to recursively read stacked make.defaults in profiles */
106 @@ -631,12 +659,12 @@
107
108 /* first consume the profile's make.defaults */
109 strcpy(sub_file, "make.defaults");
110 - read_portage_env_file(profile_file, vars);
111 + read_portage_env_file("", profile_file, vars);
112
113 /* now walk all the parents */
114 strcpy(sub_file, "parent");
115 if (eat_file(profile_file, buf, sizeof(buf)) == 0)
116 - return;
117 + goto done;
118 rmspace(buf);
119
120 s = strtok(buf, "\n");
121 @@ -646,6 +674,7 @@
122 s = strtok(NULL, "\n");
123 }
124
125 + done:
126 free(profile_file);
127 }
128
129 @@ -654,12 +683,6 @@
130 size_t i;
131 const char *s;
132
133 - static const char * const files[] = {
134 - CONFIG_EPREFIX "etc/make.globals",
135 - CONFIG_EPREFIX "usr/share/portage/config/make.globals",
136 - CONFIG_EPREFIX "etc/make.conf",
137 - CONFIG_EPREFIX "etc/portage/make.conf",
138 - };
139 bool nocolor = 0;
140
141 env_vars *var;
142 @@ -702,17 +725,19 @@
143 *var->value.s = xstrdup(var->default_value);
144 }
145
146 - /* walk all the stacked profiles */
147 + /* figure out where to find our config files */
148 s = getenv("PORTAGE_CONFIGROOT");
149 if (!s)
150 s = "/";
151
152 + /* walk all the stacked profiles */
153 read_portage_profile(s, CONFIG_EPREFIX "etc/make.profile", vars_to_read);
154 read_portage_profile(s, CONFIG_EPREFIX "etc/portage/make.profile", vars_to_read);
155
156 /* now read all the config files */
157 - for (i = 0; i < ARRAY_SIZE(files); ++i)
158 - read_portage_env_file(files[i], vars_to_read);
159 + read_portage_env_file("", CONFIG_EPREFIX "usr/share/portage/config/make.globals", vars_to_read);
160 + read_portage_env_file(s, CONFIG_EPREFIX "etc/make.conf", vars_to_read);
161 + read_portage_env_file(s, CONFIG_EPREFIX "etc/portage/make.conf", vars_to_read);
162
163 /* finally, check the env */
164 for (i = 0; vars_to_read[i].name; ++i) {