-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkglist.c
1400 lines (1263 loc) · 31.6 KB
/
pkglist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2019 The DragonFly Project. All rights reserved.
*
* This code is derived from software contributed to The DragonFly Project
* by Matthew Dillon <[email protected]>
*
* This code uses concepts and configuration based on 'synth', by
* John R. Marino <[email protected]>, which was written in ada.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of The DragonFly Project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific, prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "dsynth.h"
#define PKG_HSIZE 32768
#define PKG_HMASK 32767
static int parsepkglist_file(const char *path, int debugstop);
static void childGetPackageInfo(bulk_t *bulk);
static void childGetBinaryDistInfo(bulk_t *bulk);
static void childOptimizeEnv(bulk_t *bulk);
static pkg_t *resolveDeps(pkg_t *dep_list, pkg_t ***list_tailp, int gentopo);
static void resolveFlavors(pkg_t *pkg, char *flavors, int gentopo);
static void resolveDepString(pkg_t *pkg, char *depstr,
int gentopo, int dep_type);
static pkg_t *processPackageListBulk(int total);
static int scan_and_queue_dir(const char *path, const char *level1, int level);
static int scan_binary_repo(const char *path);
#if 0
static void pkgfree(pkg_t *pkg);
#endif
static int PrepareSystemFlag;
static pkg_t *PkgHash1[PKG_HSIZE]; /* by portdir */
static pkg_t *PkgHash2[PKG_HSIZE]; /* by pkgfile */
/*
* Allocate a new pkg structure plus basic initialization.
*/
static __inline pkg_t *
allocpkg(void)
{
pkg_t *pkg;
pkg = calloc(1, sizeof(*pkg));
pkg->idepon_list.next = &pkg->idepon_list;
pkg->idepon_list.prev = &pkg->idepon_list;
pkg->deponi_list.next = &pkg->deponi_list;
pkg->deponi_list.prev = &pkg->deponi_list;
return pkg;
}
/*
* Simple hash for lookups
*/
static __inline int
pkghash(const char *str)
{
int hv = 0xABC32923;
while (*str) {
hv = (hv << 5) ^ *str;
++str;
}
hv = hv ^ (hv / PKG_HSIZE) ^ (hv / PKG_HSIZE / PKG_HSIZE);
return (hv & PKG_HMASK);
}
static __inline const char *
deptype2str(int dep_type)
{
switch (dep_type) {
case DEP_TYPE_FETCH:
return("FETCH_DEPENDS");
case DEP_TYPE_EXT:
return("EXTRACT_DEPENDS");
case DEP_TYPE_PATCH:
return("PATCH_DEPENDS");
case DEP_TYPE_BUILD:
return("BUILD_DEPENDS");
case DEP_TYPE_LIB:
return("LIB_DEPENDS");
case DEP_TYPE_RUN:
return("RUN_DEPENDS");
default:
return("UNKNOWN");
}
}
static void
pkg_enter(pkg_t *pkg)
{
pkg_t **pkgp;
pkg_t *scan;
if (pkg->portdir) {
pkgp = &PkgHash1[pkghash(pkg->portdir)];
while ((scan = *pkgp) != NULL) {
if (strcmp(pkg->portdir, scan->portdir) == 0)
break;
pkgp = &scan->hnext1;
}
ddassert(scan == NULL || (scan->flags & PKGF_PLACEHOLD));
if (scan && (scan->flags & PKGF_PLACEHOLD)) {
ddassert(scan->idepon_list.next == &scan->idepon_list);
ddassert(scan->deponi_list.next == &scan->deponi_list);
*pkgp = pkg;
pkg->hnext1 = scan->hnext1;
free(scan->portdir);
free(scan);
scan = NULL;
}
if (scan == NULL)
*pkgp = pkg;
}
if (pkg->pkgfile) {
pkgp = &PkgHash2[pkghash(pkg->pkgfile)];
while ((scan = *pkgp) != NULL) {
if (strcmp(pkg->pkgfile, scan->pkgfile) == 0)
break;
pkgp = &scan->hnext2;
}
if (scan == NULL)
*pkgp = pkg;
}
}
static pkg_t *
pkg_find(const char *match)
{
pkg_t **pkgp;
pkg_t *pkg;
pkgp = &PkgHash1[pkghash(match)];
for (pkg = *pkgp; pkg; pkg = pkg->hnext1) {
if (strcmp(pkg->portdir, match) == 0)
return pkg;
}
pkgp = &PkgHash2[pkghash(match)];
for (pkg = *pkgp; pkg; pkg = pkg->hnext2) {
if (strcmp(pkg->pkgfile, match) == 0)
return pkg;
}
return NULL;
}
/*
* Parse a specific list of ports via origin name (portdir/subdir)
*/
pkg_t *
ParsePackageList(int n, char **ary, int debugstop)
{
pkg_t *list;
int total;
int fail;
int i;
total = 0;
fail = 0;
initbulk(childGetPackageInfo, MaxBulk);
/*
* Always include ports-mgmt/pkg. s4 is "x" meaning not a manual
* selection, "d" meaning DEBUGSTOP mode, or NULL.
*/
queuebulk("ports-mgmt", "pkg", NULL, "x");
for (i = 0; i < n; ++i) {
char *l1;
char *l2;
char *l3;
struct stat st;
l1 = strdup(ary[i]);
if (stat(l1, &st) == 0 && S_ISREG(st.st_mode)) {
total += parsepkglist_file(l1, debugstop);
continue;
}
l2 = strchr(l1, '/');
if (l2 == NULL) {
printf("Bad portdir specification: %s\n", l1);
free(l1);
fail = 1;
continue;
}
*l2++ = 0;
l3 = strchr(l2, '@');
if (l3)
*l3++ = 0;
/*
* Silently ignore any manually specified ports-mgmt/pkg,
* which we already auto-added.
*/
if (strcmp(l1, "ports-mgmt") != 0 ||
strcmp(l2, "pkg") != 0)
{
queuebulk(l1, l2, l3, (debugstop ? "d" : NULL));
}
++total;
free(l1);
}
printf("Processing %d ports\n", total);
list = processPackageListBulk(total);
if (fail) {
dfatal("Bad specifications, exiting");
exit(1);
}
return list;
}
static
int
parsepkglist_file(const char *path, int debugstop)
{
FILE *fp;
char *base;
char *l1;
char *l2;
char *l3;
size_t len;
int total;
if ((fp = fopen(path, "r")) == NULL) {
dpanic_errno("Cannot read %s\n", path);
/* NOT REACHED */
return 0;
}
total = 0;
while ((base = fgetln(fp, &len)) != NULL) {
if (len == 0 || base[len-1] != '\n')
continue;
base[--len] = 0;
l1 = strtok(base, " \t\r\n");
if (l1 == NULL) {
printf("Badly formatted pkg info line: %s\n", base);
continue;
}
l2 = strchr(l1, '/');
if (l2 == NULL) {
printf("Badly formatted specification: %s\n", l1);
continue;
}
*l2++ = 0;
l3 = strchr(l2, '@');
if (l3)
*l3++ = 0;
queuebulk(l1, l2, l3, (debugstop ? "d" : NULL));
++total;
}
fclose(fp);
return total;
}
/*
* Parse packages from the list installed on the system.
*/
pkg_t *
GetLocalPackageList(void)
{
pkg_t *list;
FILE *fp;
char *base;
char *data;
char *l1;
char *l2;
char *l3;
int total;
int state;
size_t len;
PrepareSystemFlag = 1;
initbulk(childGetPackageInfo, MaxBulk);
total = 0;
state = 0;
l1 = NULL;
l2 = NULL;
l3 = NULL;
fp = popen("pkg info -a -o -A", "r");
/*
* Always include ports-mgmt/pkg. s4 is "x" meaning not a manual
* selection, "d" meaning DEBUGSTOP mode, or NULL.
*/
queuebulk("ports-mgmt", "pkg", NULL, "x");
while ((base = fgetln(fp, &len)) != NULL) {
if (len == 0 || base[len-1] != '\n')
continue;
base[--len] = 0;
data = strchr(base, ':');
if (data == NULL)
continue;
*data++ = 0;
base = strtok(base, " \t\r");
data = strtok(data, " \t\r");
if (base == NULL || data == NULL)
continue;
if (strcmp(base, "Origin") == 0) {
if (state == 1) {
queuebulk(l1, l2, NULL, NULL);
state = 0;
++total;
}
if (strchr(data, '/') == NULL) {
printf("Badly formatted origin: %s\n", l1);
}
if (l1)
free(l1);
if (l3)
free(l3);
l1 = strdup(data);
l2 = strchr(l1, '/');
*l2++ = 0;
l3 = strchr(l2, '@'); /* typically NULL */
if (l3) {
*l3++ = 0;
l3 = strdup(l3);
}
/*
* Don't queue ports-mgmt/pkg twice, we already
* queued it manually.
*/
if (strcmp(l1, "ports-mgmt") != 0 ||
strcmp(l2, "pkg") != 0) {
state = 1;
}
continue;
}
if (state == 1 && strcmp(base, "flavor") == 0) {
queuebulk(l1, l2, data, NULL);
state = 0;
++total;
}
}
if (state == 1) {
queuebulk(l1, l2, NULL, NULL);
/*state = 0; not needed */
}
if (l1)
free(l1);
if (l3)
free(l3);
pclose(fp);
printf("Processing %d ports\n", total);
list = processPackageListBulk(total);
return list;
}
pkg_t *
GetFullPackageList(void)
{
int total;
initbulk(childGetPackageInfo, MaxBulk);
total = scan_and_queue_dir(DPortsPath, NULL, 1);
printf("Scanning %d ports\n", total);
return processPackageListBulk(total);
}
/*
* Caller has queued the process list for bulk operation. We retrieve
* the results and clean up the bulk operation (we may have to do a second
* bulk operation so we have to be the ones to clean it up).
*/
static pkg_t *
processPackageListBulk(int total)
{
bulk_t *bulk;
pkg_t *scan;
pkg_t *list;
pkg_t *dep_list;
pkg_t **list_tail;
int count;
int stop_fail;
int stop_base_list;
int remove_corrupt;
list = NULL;
list_tail = &list;
count = 0;
remove_corrupt = 0;
while ((bulk = getbulk()) != NULL) {
++count;
if ((count & 255) == 0) {
printf("%6.2f%%\r",
(double)count * 100.0 / (double)total + 0.001);
fflush(stdout);
}
if (bulk->list) {
*list_tail = bulk->list;
bulk->list = NULL;
while ((scan = *list_tail) != NULL) {
if (bulk->s4 == NULL || bulk->s4[0] != 'x')
scan->flags |= PKGF_MANUALSEL;
pkg_enter(scan);
list_tail = &scan->bnext;
}
}
freebulk(bulk);
}
printf("100.00%%\n");
printf("\nTotal %d\n", count);
fflush(stdout);
/*
* Resolve all dependencies for the related packages, potentially
* adding anything that could not be found to the list. This will
* continue to issue bulk operations and process the result until
* no dependencies are left.
*/
printf("Resolving dependencies...");
fflush(stdout);
dep_list = list;
while (dep_list) {
dep_list = resolveDeps(dep_list, &list_tail, 0);
}
printf("done\n");
donebulk();
/*
* Generate the topology
*/
resolveDeps(list, NULL, 1);
/*
* Do a final count, ignore place holders.
*
* Also set stop_fail if appropriate. Check for direct specifications
* which fail to probe and any direct dependencies of those
* specifications, but don't recurse (for now)... don't check indirect
* dependencies (i.e. A -> B -> C where A is directly specified, B
* is adirect dependency, and C fails to probe).
*/
count = 0;
stop_fail = 0;
stop_base_list = 0;
for (scan = list; scan; scan = scan->bnext) {
if ((scan->flags & PKGF_ERROR) == 0) {
++count;
}
if ((scan->flags & PKGF_MANUALSEL) && MaskProbeAbort == 0) {
pkglink_t *link;
/*
* Directly specified package failed to probe
*/
if (scan->flags & PKGF_CORRUPT) {
++stop_fail;
++stop_base_list;
}
/*
* Directly specified package had a direct dependency
* that failed to probe (don't go further).
*/
PKGLIST_FOREACH(link, &scan->idepon_list) {
if (link->pkg &&
(link->pkg->flags & PKGF_CORRUPT)) {
++stop_fail;
}
}
}
}
printf("Total Returned %d\n", count);
/*
* Check to see if any PKGF_MANUALSEL packages
*/
if (stop_fail) {
printf("%d packages failed to probe\n", stop_fail);
if (PrepareSystemFlag) {
if (stop_fail == stop_base_list) {
printf(
"prepare-system: Some of your installed packages no longer exist in\n"
"ports, do you wish to continue rebuilding what does exist?\n");
if (askyn("Continue anyway? "))
remove_corrupt = 1;
} else {
printf(
"prepare-system: Some of your installed packages have dependencies\n"
"which could not be found in ports, cannot continue, aborting\n");
}
} else {
printf("unable to continue, aborting\n");
}
if (remove_corrupt == 0)
exit(1);
}
/*
* Remove corrupt packages before continuing
*/
if (remove_corrupt) {
list_tail = &list;
while ((scan = *list_tail) != NULL) {
if (scan->flags & PKGF_CORRUPT)
*list_tail = scan->bnext;
else
list_tail = &scan->bnext;
}
}
/*
* Scan our binary distributions and related dependencies looking
* for any packages that have already been built.
*/
initbulk(childGetBinaryDistInfo, MaxBulk);
total = scan_binary_repo(RepositoryPath);
count = 0;
printf("Scanning %d packages\n", total);
while ((bulk = getbulk()) != NULL) {
++count;
if ((count & 255) == 0) {
printf("%6.2f%%\r",
(double)count * 100.0 / (double)total + 0.001);
fflush(stdout);
}
freebulk(bulk);
}
printf("100.00%%\n");
printf("\nTotal %d\n", count);
fflush(stdout);
donebulk();
printf("all done\n");
return list;
}
pkg_t *
GetPkgPkg(pkg_t **listp)
{
bulk_t *bulk;
pkg_t *scan;
pkg_t *s2;
for (scan = *listp; scan; scan = scan->bnext) {
if (strcmp(scan->portdir, "ports-mgmt/pkg") == 0)
return scan;
}
/*
* This will force pkg to be built, but generally this code
* is not reached because the package list processing code
* adds ports-mgmt/pkg unconditionally.
*/
initbulk(childGetPackageInfo, MaxBulk);
queuebulk("ports-mgmt", "pkg", NULL, "x");
bulk = getbulk();
dassert(bulk, "Cannot find ports-mgmt/pkg");
scan = bulk->list;
bulk->list = NULL;
freebulk(bulk);
donebulk();
/*
* Include added packages to the total and add the initial bulk
* built packages to the list so they get counted.
*/
for (s2 = scan; s2->bnext; s2 = s2->bnext)
++BuildTotal;
for (s2 = scan; s2->bnext; s2 = s2->bnext)
;
s2->bnext = *listp;
*listp = scan;
++BuildTotal;
return scan;
}
/*
* Try to optimize the environment by supplying information that
* the ports system would generally have to run stuff to get on
* every package.
*
* See childOptimizeEnv() for the actual handling. We execute
* a single make -V... -V... for ports-mgmt/pkg from within the
* bulk system (which handles the environment and disables
* /etc/make.conf), and we then call addbuildenv() as appropriate.
*
* _PERL5_FROM_BIN
* add others...
*/
void
OptimizeEnv(void)
{
bulk_t *bulk;
initbulk(childOptimizeEnv, MaxBulk);
queuebulk("ports-mgmt", "pkg", NULL, NULL);
bulk = getbulk();
freebulk(bulk);
donebulk();
}
/*
* Run through the list resolving dependencies and constructing the topology
* linkages. This may append packages to the list. Dependencies to dummy
* nodes which do not specify a flavor do not need special handling, the
* search code in build.c will properly follow the first flavor.
*/
static pkg_t *
resolveDeps(pkg_t *list, pkg_t ***list_tailp, int gentopo)
{
pkg_t *ret_list = NULL;
pkg_t *scan;
pkg_t *use;
bulk_t *bulk;
for (scan = list; scan; scan = scan->bnext) {
use = pkg_find(scan->portdir);
resolveFlavors(use, scan->flavors, gentopo);
resolveDepString(use, scan->fetch_deps,
gentopo, DEP_TYPE_FETCH);
resolveDepString(use, scan->ext_deps,
gentopo, DEP_TYPE_EXT);
resolveDepString(use, scan->patch_deps,
gentopo, DEP_TYPE_PATCH);
resolveDepString(use, scan->build_deps,
gentopo, DEP_TYPE_BUILD);
resolveDepString(use, scan->lib_deps,
gentopo, DEP_TYPE_LIB);
resolveDepString(use, scan->run_deps,
gentopo, DEP_TYPE_RUN);
}
/*
* No bulk ops are queued when doing the final topology
* generation.
*
* Avoid entering duplicate results from the bulk ops. Duplicate
* results are mostly filtered out, but not always. A dummy node
* representing multiple flavors will parse-out the flavors
*/
if (gentopo)
return NULL;
while ((bulk = getbulk()) != NULL) {
if (bulk->list) {
if (ret_list == NULL)
ret_list = bulk->list;
**list_tailp = bulk->list;
bulk->list = NULL;
while ((scan = **list_tailp) != NULL) {
pkg_enter(scan);
*list_tailp = &scan->bnext;
}
}
freebulk(bulk);
}
return (ret_list);
}
/*
* Resolve a generic node that has flavors, queue to retrieve info for
* each flavor and setup linkages as appropriate.
*/
static void
resolveFlavors(pkg_t *pkg, char *flavors, int gentopo)
{
char *flavor_base;
char *flavor_scan;
char *flavor;
char *portdir;
char *s1;
char *s2;
pkg_t *dpkg;
pkglink_t *link;
if ((pkg->flags & PKGF_DUMMY) == 0)
return;
if (pkg->flavors == NULL || pkg->flavors[0] == 0)
return;
flavor_base = strdup(flavors);
flavor_scan = flavor_base;
for (;;) {
do {
flavor = strsep(&flavor_scan, " \t");
} while (flavor && *flavor == 0);
if (flavor == NULL)
break;
/*
* Iterate each flavor generating "s1/s2@flavor".
*
* queuebulk() info for each flavor, and set-up the
* linkages in the topology generation pass.
*/
asprintf(&portdir, "%s@%s", pkg->portdir, flavor);
s1 = strdup(pkg->portdir);
s2 = strchr(s1, '/');
*s2++ = 0;
dpkg = pkg_find(portdir);
if (dpkg && gentopo) {
/*
* Setup linkages
*/
free(portdir);
link = calloc(1, sizeof(*link));
link->pkg = dpkg;
link->next = &pkg->idepon_list;
link->prev = pkg->idepon_list.prev;
link->next->prev = link;
link->prev->next = link;
link->dep_type = DEP_TYPE_BUILD;
link = calloc(1, sizeof(*link));
link->pkg = pkg;
link->next = &dpkg->deponi_list;
link->prev = dpkg->deponi_list.prev;
link->next->prev = link;
link->prev->next = link;
link->dep_type = DEP_TYPE_BUILD;
++dpkg->depi_count;
} else if (gentopo == 0 && dpkg == NULL) {
/*
* Use a place-holder to prevent duplicate
* dependencies from being processed. The placeholder
* will be replaced by the actual dependency.
*/
dpkg = allocpkg();
dpkg->portdir = portdir;
dpkg->flags = PKGF_PLACEHOLD;
pkg_enter(dpkg);
queuebulk(s1, s2, flavor, NULL);
}
free(s1);
}
free(flavor_base);
}
static void
resolveDepString(pkg_t *pkg, char *depstr, int gentopo, int dep_type)
{
char *copy_base;
char *copy;
char *dep;
char *log_component;
char *sep;
char *tag;
char *flavor;
pkg_t *dpkg;
if (depstr == NULL || depstr[0] == 0)
return;
copy_base = strdup(depstr);
copy = copy_base;
log_component = copy;
for (;;) {
do {
dep = strsep(©, " \t");
} while (dep && *dep == 0);
if (dep == NULL)
break;
/*
* Ignore dependencies prefixed with ${NONEXISTENT}
*/
if (strncmp(dep, "/nonexistent:", 13) == 0)
continue;
log_component = dep;
dep = strchr(dep, ':');
if (dep == NULL || *dep != ':') {
printf("Error parsing %s dependency for "
"%s: '%s' at index %zd '%s' "
"(looking for ':')\n",
deptype2str(dep_type),
pkg->portdir, depstr,
log_component - copy_base,
log_component);
continue;
}
++dep;
/*
* Strip-off any DPortsPath prefix. EXTRACT_DEPENDS
* often (always?) generates this prefix.
*/
if (strncmp(dep, DPortsPath, strlen(DPortsPath)) == 0) {
dep += strlen(DPortsPath);
if (*dep == '/')
++dep;
}
/*
* Strip-off any tag (such as :patch). We don't try to
* organize dependencies at this fine a grain (for now).
*/
tag = strchr(dep, ':');
if (tag)
*tag++ = 0;
log_component = dep;
/*
* Locate the dependency
*/
if ((dpkg = pkg_find(dep)) != NULL) {
if (gentopo) {
pkglink_t *link;
/*
* NOTE: idep_count is calculated recursively
* at build-time
*/
ddprintf(0, "Add Dependency %s -> %s\n",
pkg->portdir, dpkg->portdir);
link = calloc(1, sizeof(*link));
link->pkg = dpkg;
link->next = &pkg->idepon_list;
link->prev = pkg->idepon_list.prev;
link->next->prev = link;
link->prev->next = link;
link->dep_type = dep_type;
link = calloc(1, sizeof(*link));
link->pkg = pkg;
link->next = &dpkg->deponi_list;
link->prev = dpkg->deponi_list.prev;
link->next->prev = link;
link->prev->next = link;
link->dep_type = dep_type;
++dpkg->depi_count;
}
continue;
}
/*
* This shouldn't happen because we already took a first
* pass and should have generated the pkgs.
*/
if (gentopo) {
printf("Topology Generate failed for %s: %s\n",
pkg->portdir, copy_base);
continue;
}
/*
* Separate out the two ports directory components and
* extract the optional '@flavor' specification.
*/
sep = strchr(dep, '/');
if (sep == NULL) {
printf("Error parsing %s dependency for "
"%s: '%s' at index %zd '%s' "
"(looking for '/')\n",
deptype2str(dep_type),
pkg->portdir, depstr,
log_component - copy_base,
log_component);
continue;
}
*sep++ = 0;
/*
* The flavor hangs off the separator, not the tag
*/
flavor = strrchr(sep, '@');
#if 0
if (tag)
flavor = strrchr(tag, '@');
else
flavor = strrchr(sep, '@');
#endif
if (flavor)
*flavor++ = 0;
if (flavor)
ddprintf(0, "QUEUE DEPENDENCY FROM PKG %s: %s/%s@%s\n",
pkg->portdir, dep, sep, flavor);
else
ddprintf(0, "QUEUE DEPENDENCY FROM PKG %s: %s/%s\n",
pkg->portdir, dep, sep);
/*
* Use a place-holder to prevent duplicate dependencies from
* being processed. The placeholder will be replaced by
* the actual dependency.
*/
dpkg = allocpkg();
if (flavor)
asprintf(&dpkg->portdir, "%s/%s@%s", dep, sep, flavor);
else
asprintf(&dpkg->portdir, "%s/%s", dep, sep);
dpkg->flags = PKGF_PLACEHOLD;
pkg_enter(dpkg);
queuebulk(dep, sep, flavor, NULL);
}
free(copy_base);
}
void
FreePackageList(pkg_t *pkgs __unused)
{
dfatal("not implemented");
}
/*
* Scan some or all ports to allocate the related pkg structure. Dependencies
* are stored but not processed.
*
* Threaded function
*/
static void
childGetPackageInfo(bulk_t *bulk)
{
pkg_t *pkg;
char *flavor;
char *ptr;
FILE *fp;
int line;
size_t len;
char *portpath;
char *flavarg;
char *localbase;
const char *cav[MAXCAC];
pid_t pid;
int cac;
/*
* If the package has flavors we will loop on each one. If a flavor
* is not passed in s3 we will loop on all flavors, otherwise we will
* only process the passed-in flavor.
*/
flavor = bulk->s3; /* usually NULL */
bulk->list = NULL;
asprintf(&portpath, "%s/%s/%s", DPortsPath, bulk->s1, bulk->s2);
if (flavor)
asprintf(&flavarg, "FLAVOR=%s", flavor);
else
flavarg = NULL;
cac = 0;
cav[cac++] = MAKE_BINARY;
cav[cac++] = "-C";
cav[cac++] = portpath;
if (flavarg)
cav[cac++] = flavarg;
/*
* Prevent postgresql, mysql, and other package Makefile tests
* from accessing the host system's /usr/local by setting LOCALBASE
* to an empty directory.