Print this page
make: remove SCCS ident stuff
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/make/common/rep.cc
+++ new/usr/src/cmd/make/bin/make/common/rep.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 -/*
26 - * @(#)rep.cc 1.25 06/12/12
27 - */
28 -
29 -#pragma ident "@(#)rep.cc 1.25 06/12/12"
30 25
31 26 /*
32 27 * rep.c
33 28 *
34 29 * This file handles the .nse_depinfo file
35 30 */
36 31
37 32 /*
38 33 * Included files
39 34 */
40 35 #include <mk/defs.h>
41 36 #include <mksh/misc.h> /* retmem() */
42 37 #include <vroot/report.h> /* NSE_DEPINFO */
43 38
44 39 /*
45 40 * Static variables
46 41 */
47 42 static Recursive_make recursive_list;
48 43 static Recursive_make *bpatch = &recursive_list;
49 44 static Boolean changed;
50 45
51 46 /*
52 47 * File table of contents
53 48 */
54 49
55 50
56 51 /*
57 52 * report_recursive_init()
58 53 *
59 54 * Read the .nse_depinfo file and make a list of all the
60 55 * .RECURSIVE entries.
61 56 *
62 57 * Parameters:
63 58 *
64 59 * Static variables used:
65 60 * bpatch Points to slot where next cell should be added
66 61 *
67 62 * Global variables used:
68 63 * recursive_name The Name ".RECURSIVE", compared against
69 64 */
70 65
71 66 void
72 67 report_recursive_init(void)
73 68 {
74 69 char *search_dir;
75 70 char nse_depinfo[MAXPATHLEN];
76 71 FILE *fp;
77 72 int line_size, line_index;
78 73 wchar_t *line;
79 74 wchar_t *bigger_line;
80 75 wchar_t *colon;
81 76 wchar_t *dollar;
82 77 Recursive_make rp;
83 78
84 79 /*
85 80 * This routine can be called more than once, don't do
86 81 * anything after the first time.
87 82 */
88 83 if (depinfo_already_read) {
89 84 return;
90 85 } else {
91 86 depinfo_already_read = true;
92 87 }
93 88
94 89 search_dir = getenv(NOCATGETS("NSE_DEP"));
95 90 if (search_dir == NULL) {
96 91 return;
97 92 }
98 93 (void) sprintf(nse_depinfo, "%s/%s", search_dir, NSE_DEPINFO);
99 94 fp = fopen(nse_depinfo, "r");
100 95 if (fp == NULL) {
101 96 return;
102 97 }
103 98 line_size = MAXPATHLEN;
104 99 line_index = line_size - 1;
105 100 line = ALLOC_WC(line_size);
106 101 Wstring rns(recursive_name);
107 102 wchar_t * wcb = rns.get_string();
108 103 while (fgetws(line, line_size, fp) != NULL) {
109 104 while (wslen(line) == line_index) {
110 105 if (line[wslen(line) - 1] == '\n') {
111 106 continue;
112 107 }
113 108 bigger_line = ALLOC_WC(2 * line_size);
114 109 wscpy(bigger_line, line);
115 110 retmem(line);
116 111 line = bigger_line;
117 112 if (fgetws(&line[line_index], line_size, fp) == NULL)
118 113 continue;
119 114 line_index = 2 * line_index;
120 115 line_size = 2 * line_size;
121 116 }
122 117
123 118 colon = (wchar_t *) wschr(line, (int) colon_char);
124 119 if (colon == NULL) {
125 120 continue;
126 121 }
127 122 dollar = (wchar_t *) wschr(line, (int) dollar_char);
128 123 line[wslen(line) - 1] = (int) nul_char;
129 124 if (IS_WEQUALN(&colon[2], wcb,
130 125 (int) recursive_name->hash.length)) {
131 126 /*
132 127 * If this entry is an old entry, ignore it
133 128 */
134 129 MBSTOWCS(wcs_buffer, DEPINFO_FMT_VERSION);
135 130 if (dollar == NULL ||
136 131 !IS_WEQUALN(wcs_buffer, (dollar+1) - VER_LEN, VER_LEN)){
137 132 continue;
138 133 }
139 134 rp = ALLOC(Recursive_make);
140 135 (void) memset((char *) rp, 0, sizeof (Recursive_make_rec));
141 136 /*
142 137 * set conditional_macro_string if string is present
143 138 */
144 139 rp->oldline = (wchar_t *) wsdup(line);
145 140 if ( dollar != NULL ){
146 141 rp->cond_macrostring =
147 142 (wchar_t *) wsdup(dollar - VER_LEN + 1);
148 143 }
149 144 /*
150 145 * get target name into recursive struct
151 146 */
152 147 *colon = (int) nul_char;
153 148 rp->target = (wchar_t *) wsdup(line);
154 149 *bpatch = rp;
155 150 bpatch = &rp->next;
156 151 }
157 152 }
158 153 (void) fclose(fp);
159 154 }
160 155
161 156 /*
162 157 * report_recursive_dep(target, line)
163 158 *
164 159 * Report a target as recursive.
165 160 *
166 161 * Parameters:
167 162 * line Dependency line reported
168 163 *
169 164 * Static variables used:
170 165 * bpatch Points to slot where next cell should be added
171 166 * changed Written if report set changed
172 167 */
173 168 void
174 169 report_recursive_dep(Name target, wchar_t *line)
175 170 {
176 171 Recursive_make rp;
177 172 wchar_t rec_buf[STRING_BUFFER_LENGTH];
178 173 String_rec string;
179 174
180 175 INIT_STRING_FROM_STACK(string, rec_buf);
181 176 cond_macros_into_string(target, &string);
182 177 /*
183 178 * find an applicable recursive entry, if there isn't one, create it
184 179 */
185 180 rp = find_recursive_target(target);
186 181 if (rp == NULL) {
187 182 rp = ALLOC(Recursive_make);
188 183 (void) memset((char *) rp, 0, sizeof (Recursive_make_rec));
189 184 wchar_t * wcb = get_wstring(target->string_mb); // XXX Tolik: needs retmem
190 185 rp->target = wcb;
191 186 rp->newline = (wchar_t *) wsdup(line);
192 187 rp->cond_macrostring = (wchar_t *) wsdup(rec_buf);
193 188 *bpatch = rp;
194 189 bpatch = &rp->next;
195 190 changed = true;
196 191 } else {
197 192 if ((rp->oldline != NULL) && !IS_WEQUAL(rp->oldline, line)) {
198 193 rp->newline = (wchar_t *) wsdup(line);
199 194 changed = true;
200 195 }
201 196 rp->removed = false;
202 197 }
203 198 }
204 199
205 200 /*
206 201 * find_recursive_target(target)
207 202 *
208 203 * Search the list for a given target.
209 204 *
210 205 * Return value:
211 206 * The target cell
212 207 *
213 208 * Parameters:
214 209 * target The target we need
215 210 * top_level_target more info used to determinde the
216 211 * target we need
217 212 *
218 213 * Static variables used:
219 214 * recursive_list The list of targets
220 215 */
221 216 Recursive_make
222 217 find_recursive_target(Name target)
223 218 {
224 219 Recursive_make rp;
225 220 String_rec string;
226 221 wchar_t rec_buf[STRING_BUFFER_LENGTH];
227 222
228 223 INIT_STRING_FROM_STACK(string, rec_buf);
229 224 cond_macros_into_string(target, &string);
230 225
231 226 Wstring tstr(target);
232 227 wchar_t * wcb = tstr.get_string();
233 228 for (rp = recursive_list; rp != NULL; rp = rp->next) {
234 229 /*
235 230 * If this entry has already been removed, ignore it.
236 231 */
237 232 if (rp->removed)
238 233 continue;
239 234 /*
240 235 * If this target, and the target on the list are the same
241 236 * and if one of them contains conditional macro info, while
242 237 * the other doesn't, remove this entry from the list of
243 238 * recursive entries. This can only happen if the Makefile
244 239 * has changed to no longer contain conditional macros.
245 240 */
246 241 if (IS_WEQUAL(rp->target, wcb)) {
247 242 if (rp->cond_macrostring[VER_LEN] == '\0' &&
248 243 string.buffer.start[VER_LEN] != '\0'){
249 244 rp->removed = true;
250 245 continue;
251 246 } else if (rp->cond_macrostring[VER_LEN] != '\0' &&
252 247 string.buffer.start[VER_LEN] == '\0'){
253 248 rp->removed = true;
254 249 continue;
255 250 }
256 251 }
257 252 /*
258 253 * If this is not a VERS2 entry, only need to match
259 254 * the target name. toptarg information from VERS1 entries
260 255 * are ignored.
261 256 */
262 257 MBSTOWCS(wcs_buffer, DEPINFO_FMT_VERSION);
263 258 if (IS_WEQUALN(wcs_buffer, string.buffer.start, VER_LEN)) {
264 259 if (IS_WEQUAL(rp->cond_macrostring,
265 260 string.buffer.start) &&
266 261 IS_WEQUAL(rp->target, wcb)) {
267 262 return rp;
268 263 }
269 264 } else {
270 265 if (IS_WEQUAL(rp->target, wcb)) {
271 266 return rp;
272 267 }
273 268 }
274 269 }
275 270 return NULL;
276 271 }
277 272
278 273 /*
279 274 * remove_recursive_dep(target, top_level_target)
280 275 *
281 276 * Mark a target as no longer recursive.
282 277 *
283 278 * Parameters:
284 279 * target The target we want to remove
285 280 * top_level_target target we want to remove must be built from
286 281 * the same top level target
287 282 *
288 283 * Static variables used:
289 284 * changed Written if report set changed
290 285 */
291 286 void
292 287 remove_recursive_dep(Name target)
293 288 {
294 289 Recursive_make rp;
295 290
296 291 rp = find_recursive_target(target);
297 292
298 293 if ( rp != NULL ) {
299 294 rp->removed = true;
300 295 changed = true;
301 296 if(rp->target) {
302 297 retmem(rp->target);
303 298 rp->target = NULL;
304 299 }
305 300 if(rp->newline) {
306 301 retmem(rp->newline);
307 302 rp->newline = NULL;
308 303 }
309 304 if(rp->oldline) {
310 305 retmem(rp->oldline);
311 306 rp->oldline = NULL;
312 307 }
313 308 if(rp->cond_macrostring) {
314 309 retmem(rp->cond_macrostring);
315 310 rp->cond_macrostring = NULL;
316 311 }
317 312 }
318 313 }
319 314
320 315 #ifdef NSE
321 316 /*
322 317 * report_recursive_done()
323 318 *
324 319 * Write the .nse_depinfo file.
325 320 *
326 321 * Parameters:
327 322 *
328 323 * Static variables used:
329 324 * recursive_list The list of targets
330 325 * changed Written if report set changed
331 326 *
332 327 * Global variables used:
333 328 * recursive_name The Name ".RECURSIVE", compared against
334 329 */
335 330 void
336 331 report_recursive_done(void)
337 332 {
338 333 char *search_dir;
339 334 char nse_depinfo[MAXPATHLEN];
340 335 char tmpfile[MAXPATHLEN];
341 336 FILE *ofp;
342 337 FILE *ifp;
343 338 wchar_t *space;
344 339 wchar_t *data;
345 340 wchar_t *line;
346 341 wchar_t *bigger_line;
347 342 int line_size, line_index;
348 343 int lock_err;
349 344 Recursive_make rp;
350 345
351 346 if (changed == false) {
352 347 return;
353 348 }
354 349
355 350 search_dir = getenv(NOCATGETS("NSE_DEP"));
356 351 if (search_dir == NULL) {
357 352 return;
358 353 }
359 354 (void) sprintf(nse_depinfo, "%s/%s", search_dir, NSE_DEPINFO);
360 355 (void) sprintf(tmpfile, "%s.%d", nse_depinfo, getpid());
361 356 ofp = fopen(tmpfile, "w");
362 357 if (ofp == NULL) {
363 358 (void) fprintf(stderr,
364 359 catgets(catd, 1, 116, "Cannot open `%s' for writing\n"),
365 360 tmpfile);
366 361 return;
367 362 }
368 363 (void) sprintf(nse_depinfo_lockfile,
369 364 "%s/%s", search_dir, NSE_DEPINFO_LOCK);
370 365 if (lock_err = file_lock(nse_depinfo,
371 366 nse_depinfo_lockfile,
372 367 (int *) &nse_depinfo_locked, 0)) {
373 368 (void) fprintf(stderr,
374 369 catgets(catd, 1, 117, "writing .RECURSIVE lines to %s\n"),
375 370 tmpfile);
376 371 (void) fprintf(stderr,
377 372 catgets(catd, 1, 118, "To recover, merge .nse_depinfo.%d with .nse_depinfo\n"),
378 373 getpid(),
379 374 catgets(catd, 1, 119, "with .nse_depinfo"));
380 375 }
381 376
382 377 if (nse_depinfo_locked) {
383 378 ifp = fopen(nse_depinfo, "r");
384 379 if (ifp != NULL) {
385 380 /*
386 381 * Copy all the non-.RECURSIVE lines from
387 382 * the old file to the new one.
388 383 */
389 384 line_size = MAXPATHLEN;
390 385 line_index = line_size - 1;
391 386 line = ALLOC_WC(line_size);
392 387 while (fgetws(line, line_size, ifp) != NULL) {
393 388 while (wslen(line) == line_index) {
394 389 if (line[wslen(line) - 1] == '\n') {
395 390 continue;
396 391 }
397 392 bigger_line = ALLOC_WC(2 * line_size);
398 393 wscpy(bigger_line, line);
399 394 retmem(line);
400 395 line = bigger_line;
401 396 if (fgetws(&line[line_index],
402 397 line_size, ifp) == NULL)
403 398 continue;
404 399 line_index = 2 * line_index;
405 400 line_size = 2 * line_size;
406 401 }
407 402
408 403 space = wschr(line, (int) space_char);
409 404 if (space != NULL &&
410 405 IS_WEQUALN(&space[1],
411 406 recursive_name->string,
412 407 (int) recursive_name->hash.length)) {
413 408 continue;
414 409 }
415 410 WCSTOMBS(mbs_buffer, line);
416 411 (void) fprintf(ofp, "%s", mbs_buffer);
417 412 }
418 413 (void) fclose(ifp);
419 414 }
420 415 }
421 416
422 417 /*
423 418 * Write out the .RECURSIVE lines.
424 419 */
425 420 for (rp = recursive_list; rp != NULL; rp = rp->next) {
426 421 if (rp->removed) {
427 422 continue;
428 423 }
429 424 if (rp->newline != NULL) {
430 425 data = rp->newline;
431 426 } else {
432 427 data = rp->oldline;
433 428 }
434 429 if (data != NULL) {
435 430 WCSTOMBS(mbs_buffer, data);
436 431 (void) fprintf(ofp, "%s\n", mbs_buffer);
437 432 }
438 433 }
439 434 (void) fclose(ofp);
440 435
441 436 if (nse_depinfo_locked) {
442 437 (void) rename(tmpfile, nse_depinfo);
443 438 (void) unlink(nse_depinfo_lockfile);
444 439 nse_depinfo_locked = false;
445 440 nse_depinfo_lockfile[0] = '\0';
446 441 (void) chmod(nse_depinfo, 0666);
447 442 }
448 443 }
449 444 #endif // NSE
450 445
451 446 /* gather_recursive_deps()
452 447 *
453 448 * Create or update list of recursive targets.
454 449 */
455 450 void
456 451 gather_recursive_deps(void)
457 452 {
458 453 Name_set::iterator np, e;
459 454 String_rec rec;
460 455 wchar_t rec_buf[STRING_BUFFER_LENGTH];
461 456 register Property lines;
462 457 Boolean has_recursive;
463 458 Dependency dp;
464 459
465 460 report_recursive_init();
466 461
467 462 /* Go thru all targets and dump recursive dependencies */
468 463 for (np = hashtab.begin(), e = hashtab.end(); np != e; np++) {
469 464 if (np->has_recursive_dependency){
470 465 has_recursive = false;
471 466 /*
472 467 * start .RECURSIVE line with target:
473 468 */
474 469 INIT_STRING_FROM_STACK(rec, rec_buf);
475 470 APPEND_NAME(np, &rec, FIND_LENGTH);
476 471 append_char((int) colon_char, &rec);
477 472 append_char((int) space_char, &rec);
478 473
479 474 for (lines = get_prop(np->prop,recursive_prop);
480 475 lines != NULL;
481 476 lines = get_prop(lines->next, recursive_prop)) {
482 477 /*
483 478 * if entry is already in depinfo
484 479 * file or entry was not built, ignore it
485 480 */
486 481 if (lines->body.recursive.in_depinfo)
487 482 continue;
488 483 if (!lines->body.recursive.has_built)
489 484 continue;
490 485 has_recursive = true;
491 486 lines->body.recursive.in_depinfo=true;
492 487
493 488 /*
494 489 * Write the remainder of the
495 490 * .RECURSIVE line
496 491 */
497 492 APPEND_NAME(recursive_name, &rec,
498 493 FIND_LENGTH);
499 494 append_char((int) space_char, &rec);
500 495 APPEND_NAME(lines->body.recursive.directory,
501 496 &rec, FIND_LENGTH);
502 497 append_char((int) space_char, &rec);
503 498 APPEND_NAME(lines->body.recursive.target,
504 499 &rec, FIND_LENGTH);
505 500 append_char((int) space_char, &rec);
506 501
507 502 /* Complete list of makefiles used */
508 503 for (dp = lines->body.recursive.makefiles;
509 504 dp != NULL;
510 505 dp = dp->next) {
511 506 APPEND_NAME(dp->name, &rec, FIND_LENGTH);
512 507 append_char((int) space_char, &rec);
513 508 }
514 509 }
515 510 /*
516 511 * dump list of conditional targets,
517 512 * and report recursive entry, if needed
518 513 */
519 514 cond_macros_into_string(np, &rec);
520 515 if (has_recursive){
521 516 report_recursive_dep(np, rec.buffer.start);
522 517 }
523 518
524 519 } else if ( np->has_built ) {
525 520 remove_recursive_dep(np);
526 521 }
527 522 }
528 523 }
529 524
↓ open down ↓ |
490 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX