2 * Copyright (c) 2019 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * This code uses concepts and configuration based on 'synth', by
8 * John R. Marino <draco@marino.st>, which was written in ada.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
20 * 3. Neither the name of The DragonFly Project nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific, prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #define PKG_HSIZE 32768
41 #define PKG_HMASK 32767
43 static int parsepkglist_file(const char *path, int debugstop);
44 static void childGetPackageInfo(bulk_t *bulk);
45 static void childGetBinaryDistInfo(bulk_t *bulk);
46 static void childOptimizeEnv(bulk_t *bulk);
47 static pkg_t *resolveDeps(pkg_t *dep_list, pkg_t ***list_tailp, int gentopo);
48 static void resolveFlavors(pkg_t *pkg, char *flavors, int gentopo);
49 static void resolveDepString(pkg_t *pkg, char *depstr,
50 int gentopo, int dep_type);
51 static pkg_t *processPackageListBulk(int total);
52 static int scan_and_queue_dir(const char *path, const char *level1, int level);
53 static int scan_binary_repo(const char *path);
55 static void pkgfree(pkg_t *pkg);
58 static int PrepareSystemFlag;
60 pkg_t *PkgHash1[PKG_HSIZE]; /* by portdir */
61 pkg_t *PkgHash2[PKG_HSIZE]; /* by pkgfile */
64 * Allocate a new pkg structure plus basic initialization.
66 static __inline pkg_t *
71 pkg = calloc(1, sizeof(*pkg));
72 pkg->idepon_list.next = &pkg->idepon_list;
73 pkg->idepon_list.prev = &pkg->idepon_list;
74 pkg->deponi_list.next = &pkg->deponi_list;
75 pkg->deponi_list.prev = &pkg->deponi_list;
81 * Simple hash for lookups
84 pkghash(const char *str)
88 hv = (hv << 5) ^ *str;
91 hv = hv ^ (hv / PKG_HSIZE) ^ (hv / PKG_HSIZE / PKG_HSIZE);
92 return (hv & PKG_HMASK);
102 pkgp = &PkgHash1[pkghash(pkg->portdir)];
103 while ((scan = *pkgp) != NULL) {
104 if (strcmp(pkg->portdir, scan->portdir) == 0)
106 pkgp = &scan->hnext1;
108 ddassert(scan == NULL || (scan->flags & PKGF_PLACEHOLD));
109 if (scan && (scan->flags & PKGF_PLACEHOLD)) {
110 ddassert(scan->idepon_list.next == &scan->idepon_list);
111 ddassert(scan->deponi_list.next == &scan->deponi_list);
113 pkg->hnext1 = scan->hnext1;
123 pkgp = &PkgHash2[pkghash(pkg->pkgfile)];
124 while ((scan = *pkgp) != NULL) {
125 if (strcmp(pkg->pkgfile, scan->pkgfile) == 0)
127 pkgp = &scan->hnext2;
135 pkg_find(const char *match)
140 pkgp = &PkgHash1[pkghash(match)];
141 for (pkg = *pkgp; pkg; pkg = pkg->hnext1) {
142 if (strcmp(pkg->portdir, match) == 0)
145 pkgp = &PkgHash2[pkghash(match)];
146 for (pkg = *pkgp; pkg; pkg = pkg->hnext2) {
147 if (strcmp(pkg->pkgfile, match) == 0)
154 * Parse a specific list of ports via origin name (portdir/subdir)
157 ParsePackageList(int n, char **ary, int debugstop)
166 initbulk(childGetPackageInfo, MaxBulk);
169 * Always include ports-mgmt/pkg. s4 is "x" meaning not a manual
170 * selection, "d" meaning DEBUGSTOP mode, or NULL.
172 queuebulk("ports-mgmt", "pkg", NULL, "x");
174 for (i = 0; i < n; ++i) {
181 if (stat(l1, &st) == 0 && S_ISREG(st.st_mode)) {
182 total += parsepkglist_file(l1, debugstop);
186 l2 = strchr(l1, '/');
188 printf("Bad portdir specification: %s\n", l1);
194 l3 = strchr(l2, '@');
197 queuebulk(l1, l2, l3, (debugstop ? "d" : NULL));
201 printf("Processing %d ports\n", total);
203 list = processPackageListBulk(total);
205 dfatal("Bad specifications, exiting");
214 parsepkglist_file(const char *path, int debugstop)
224 if ((fp = fopen(path, "r")) == NULL) {
225 dpanic_errno("Cannot read %s\n", path);
232 while ((base = fgetln(fp, &len)) != NULL) {
233 if (len == 0 || base[len-1] != '\n')
236 l1 = strtok(base, " \t\r\n");
238 printf("Badly formatted pkg info line: %s\n", base);
241 l2 = strchr(l1, '/');
243 printf("Badly formatted specification: %s\n", l1);
247 l3 = strchr(l2, '@');
250 queuebulk(l1, l2, l3, (debugstop ? "d" : NULL));
259 * Parse packages from the list installed on the system.
262 GetLocalPackageList(void)
275 PrepareSystemFlag = 1;
276 initbulk(childGetPackageInfo, MaxBulk);
283 fp = popen("pkg info -a -o -A", "r");
286 * Always include ports-mgmt/pkg. s4 is "x" meaning not a manual
287 * selection, "d" meaning DEBUGSTOP mode, or NULL.
289 queuebulk("ports-mgmt", "pkg", NULL, "x");
291 while ((base = fgetln(fp, &len)) != NULL) {
292 if (len == 0 || base[len-1] != '\n')
296 data = strchr(base, ':');
301 base = strtok(base, " \t\r");
302 data = strtok(data, " \t\r");
304 if (base == NULL || data == NULL)
307 if (strcmp(base, "Origin") == 0) {
309 queuebulk(l1, l2, NULL, NULL);
314 if (strchr(data, '/') == NULL) {
315 printf("Badly formatted origin: %s\n", l1);
322 l2 = strchr(l1, '/');
324 l3 = strchr(l2, '@'); /* typically NULL */
331 * Don't queue ports-mgmt/pkg twice, we already
332 * queued it manually.
334 if (strcmp(l1, "ports-mgmt") != 0 ||
335 strcmp(l2, "pkg") != 0) {
340 if (state == 1 && strcmp(base, "flavor") == 0) {
341 queuebulk(l1, l2, data, NULL);
347 queuebulk(l1, l2, NULL, NULL);
348 /*state = 0; not needed */
357 printf("Processing %d ports\n", total);
359 list = processPackageListBulk(total);
365 GetFullPackageList(void)
369 initbulk(childGetPackageInfo, MaxBulk);
370 total = scan_and_queue_dir(DPortsPath, NULL, 1);
371 printf("Scanning %d ports\n", total);
373 return processPackageListBulk(total);
377 * Caller has queued the process list for bulk operation. We retrieve
378 * the results and clean up the bulk operation (we may have to do a second
379 * bulk operation so we have to be the ones to clean it up).
382 processPackageListBulk(int total)
399 while ((bulk = getbulk()) != NULL) {
401 if ((count & 255) == 0) {
403 (double)count * 100.0 / (double)total + 0.001);
407 *list_tail = bulk->list;
409 while ((scan = *list_tail) != NULL) {
410 if (bulk->s4 == NULL || bulk->s4[0] != 'x')
411 scan->flags |= PKGF_MANUALSEL;
413 list_tail = &scan->bnext;
418 printf("100.00%%\n");
419 printf("\nTotal %d\n", count);
423 * Resolve all dependencies for the related packages, potentially
424 * adding anything that could not be found to the list. This will
425 * continue to issue bulk operations and process the result until
426 * no dependencies are left.
428 printf("Resolving dependencies...");
432 dep_list = resolveDeps(dep_list, &list_tail, 0);
439 * Generate the topology
441 resolveDeps(list, NULL, 1);
444 * Do a final count, ignore place holders.
446 * Also set stop_fail if appropriate. Check for direct specifications
447 * which fail to probe and any direct dependencies of those
448 * specifications, but don't recurse (for now)... don't check indirect
449 * dependencies (i.e. A -> B -> C where A is directly specified, B
450 * is adirect dependency, and C fails to probe).
455 for (scan = list; scan; scan = scan->bnext) {
456 if ((scan->flags & PKGF_ERROR) == 0) {
459 if ((scan->flags & PKGF_MANUALSEL) && MaskProbeAbort == 0) {
463 * Directly specified package failed to probe
465 if (scan->flags & PKGF_CORRUPT) {
471 * Directly specified package had a direct dependency
472 * that failed to probe (don't go further).
474 PKGLIST_FOREACH(link, &scan->idepon_list) {
476 (link->pkg->flags & PKGF_CORRUPT)) {
482 printf("Total Returned %d\n", count);
485 * Check to see if any PKGF_MANUALSEL packages
488 printf("%d packages failed to probe\n", stop_fail);
489 if (PrepareSystemFlag) {
490 if (stop_fail == stop_base_list) {
492 "prepare-system: Some of your installed packages no longer exist in\n"
493 "dports, do you wish to continue rebuilding what does exist?\n");
494 if (askyn("Continue anyway? "))
498 "prepare-system: Some of your installed packages have dependencies\n"
499 "which could not be found in dports, cannot continue, aborting\n");
502 printf("unable to continue, aborting\n");
504 if (remove_corrupt == 0)
509 * Remove corrupt packages before continuing
511 if (remove_corrupt) {
513 while ((scan = *list_tail) != NULL) {
514 if (scan->flags & PKGF_CORRUPT)
515 *list_tail = scan->bnext;
517 list_tail = &scan->bnext;
522 * Scan our binary distributions and related dependencies looking
523 * for any packages that have already been built.
525 initbulk(childGetBinaryDistInfo, MaxBulk);
526 total = scan_binary_repo(RepositoryPath);
528 printf("Scanning %d packages\n", total);
530 while ((bulk = getbulk()) != NULL) {
532 if ((count & 255) == 0) {
534 (double)count * 100.0 / (double)total + 0.001);
539 printf("100.00%%\n");
540 printf("\nTotal %d\n", count);
544 printf("all done\n");
550 GetPkgPkg(pkg_t *list)
555 for (scan = list; scan; scan = scan->bnext) {
556 if (strcmp(scan->portdir, "ports-mgmt/pkg") == 0)
561 * This will force pkg to be built, but generally this code
562 * is not reached because the package list processing code
563 * adds ports-mgmt/pkg unconditionally.
565 initbulk(childGetPackageInfo, MaxBulk);
566 queuebulk("ports-mgmt", "pkg", NULL, "x");
568 dassert(bulk, "Cannot find ports-mgmt/pkg");
578 * Try to optimize the environment by supplying information that
579 * the ports system would generally have to run stuff to get on
582 * See childOptimizeEnv() for the actual handling. We execute
583 * a single make -V... -V... for ports-mgmt/pkg from within the
584 * bulk system (which handles the environment and disables
585 * /etc/make.conf), and we then call addbuildenv() as appropriate.
595 initbulk(childOptimizeEnv, MaxBulk);
596 queuebulk("ports-mgmt", "pkg", NULL, NULL);
603 * Run through the list resolving dependencies and constructing the topology
604 * linkages. This may append packages to the list. Dependencies to dummy
605 * nodes which do not specify a flavor do not need special handling, the
606 * search code in build.c will properly follow the first flavor.
609 resolveDeps(pkg_t *list, pkg_t ***list_tailp, int gentopo)
611 pkg_t *ret_list = NULL;
616 for (scan = list; scan; scan = scan->bnext) {
617 use = pkg_find(scan->portdir);
618 resolveFlavors(use, scan->flavors, gentopo);
619 resolveDepString(use, scan->fetch_deps,
620 gentopo, DEP_TYPE_FETCH);
621 resolveDepString(use, scan->ext_deps,
622 gentopo, DEP_TYPE_EXT);
623 resolveDepString(use, scan->patch_deps,
624 gentopo, DEP_TYPE_PATCH);
625 resolveDepString(use, scan->build_deps,
626 gentopo, DEP_TYPE_BUILD);
627 resolveDepString(use, scan->lib_deps,
628 gentopo, DEP_TYPE_LIB);
629 resolveDepString(use, scan->run_deps,
630 gentopo, DEP_TYPE_RUN);
634 * No bulk ops are queued when doing the final topology
637 * Avoid entering duplicate results from the bulk ops. Duplicate
638 * results are mostly filtered out, but not always. A dummy node
639 * representing multiple flavors will parse-out the flavors
643 while ((bulk = getbulk()) != NULL) {
645 if (ret_list == NULL)
646 ret_list = bulk->list;
647 **list_tailp = bulk->list;
649 while ((scan = **list_tailp) != NULL) {
651 *list_tailp = &scan->bnext;
660 * Resolve a generic node that has flavors, queue to retrieve info for
661 * each flavor and setup linkages as appropriate.
664 resolveFlavors(pkg_t *pkg, char *flavors, int gentopo)
675 if ((pkg->flags & PKGF_DUMMY) == 0)
677 if (pkg->flavors == NULL || pkg->flavors[0] == 0)
679 flavor_base = strdup(flavors);
680 flavor_scan = flavor_base;
684 flavor = strsep(&flavor_scan, " \t");
685 } while (flavor && *flavor == 0);
690 * Iterate each flavor generating "s1/s2@flavor".
692 * queuebulk() info for each flavor, and set-up the
693 * linkages in the topology generation pass.
695 asprintf(&portdir, "%s@%s", pkg->portdir, flavor);
696 s1 = strdup(pkg->portdir);
697 s2 = strchr(s1, '/');
700 dpkg = pkg_find(portdir);
701 if (dpkg && gentopo) {
707 link = calloc(1, sizeof(*link));
709 link->next = &pkg->idepon_list;
710 link->prev = pkg->idepon_list.prev;
711 link->next->prev = link;
712 link->prev->next = link;
713 link->dep_type = DEP_TYPE_BUILD;
715 link = calloc(1, sizeof(*link));
717 link->next = &dpkg->deponi_list;
718 link->prev = dpkg->deponi_list.prev;
719 link->next->prev = link;
720 link->prev->next = link;
721 link->dep_type = DEP_TYPE_BUILD;
723 } else if (gentopo == 0 && dpkg == NULL) {
725 * Use a place-holder to prevent duplicate
726 * dependencies from being processed. The placeholder
727 * will be replaced by the actual dependency.
730 dpkg->portdir = portdir;
731 dpkg->flags = PKGF_PLACEHOLD;
733 queuebulk(s1, s2, flavor, NULL);
741 resolveDepString(pkg_t *pkg, char *depstr, int gentopo, int dep_type)
751 if (depstr == NULL || depstr[0] == 0)
754 copy_base = strdup(depstr);
759 dep = strsep(©, " \t");
760 } while (dep && *dep == 0);
765 * Ignore dependencies prefixed with ${NONEXISTENT}
767 if (strncmp(dep, "/nonexistent:", 13) == 0)
770 dep = strchr(dep, ':');
771 if (dep == NULL || *dep != ':') {
772 printf("Error parsing dependency for %s: %s\n",
773 pkg->portdir, copy_base);
779 * Strip-off any DPortsPath prefix. EXTRACT_DEPENDS
780 * often (always?) generates this prefix.
782 if (strncmp(dep, DPortsPath, strlen(DPortsPath)) == 0) {
783 dep += strlen(DPortsPath);
789 * Strip-off any tag (such as :patch). We don't try to
790 * organize dependencies at this fine a grain (for now).
792 tag = strchr(dep, ':');
797 * Locate the dependency
799 if ((dpkg = pkg_find(dep)) != NULL) {
804 * NOTE: idep_count is calculated recursively
807 ddprintf(0, "Add Dependency %s -> %s\n",
808 pkg->portdir, dpkg->portdir);
809 link = calloc(1, sizeof(*link));
811 link->next = &pkg->idepon_list;
812 link->prev = pkg->idepon_list.prev;
813 link->next->prev = link;
814 link->prev->next = link;
815 link->dep_type = dep_type;
817 link = calloc(1, sizeof(*link));
819 link->next = &dpkg->deponi_list;
820 link->prev = dpkg->deponi_list.prev;
821 link->next->prev = link;
822 link->prev->next = link;
823 link->dep_type = dep_type;
830 * This shouldn't happen because we already took a first
831 * pass and should have generated the pkgs.
834 printf("Topology Generate failed for %s: %s\n",
835 pkg->portdir, copy_base);
840 * Separate out the two dports directory components and
841 * extract the optional '@flavor' specification.
843 sep = strchr(dep, '/');
845 printf("Error parsing dependency for %s: %s\n",
846 pkg->portdir, copy_base);
852 * The flavor hangs off the separator, not the tag
854 flavor = strrchr(sep, '@');
857 flavor = strrchr(tag, '@');
859 flavor = strrchr(sep, '@');
865 ddprintf(0, "QUEUE DEPENDENCY FROM PKG %s: %s/%s@%s\n",
866 pkg->portdir, dep, sep, flavor);
868 ddprintf(0, "QUEUE DEPENDENCY FROM PKG %s: %s/%s\n",
869 pkg->portdir, dep, sep);
872 * Use a place-holder to prevent duplicate dependencies from
873 * being processed. The placeholder will be replaced by
874 * the actual dependency.
878 asprintf(&dpkg->portdir, "%s/%s@%s", dep, sep, flavor);
880 asprintf(&dpkg->portdir, "%s/%s", dep, sep);
881 dpkg->flags = PKGF_PLACEHOLD;
884 queuebulk(dep, sep, flavor, NULL);
890 FreePackageList(pkg_t *pkgs __unused)
892 dfatal("not implemented");
896 * Scan some or all dports to allocate the related pkg structure. Dependencies
897 * are stored but not processed.
902 childGetPackageInfo(bulk_t *bulk)
912 const char *cav[MAXCAC];
917 * If the package has flavors we will loop on each one. If a flavor
918 * is not passed in s3 we will loop on all flavors, otherwise we will
919 * only process the passed-in flavor.
921 flavor = bulk->s3; /* usually NULL */
925 asprintf(&portpath, "%s/%s/%s", DPortsPath, bulk->s1, bulk->s2);
927 asprintf(&flavarg, "FLAVOR=%s", flavor);
932 cav[cac++] = MAKE_BINARY;
934 cav[cac++] = portpath;
936 cav[cac++] = flavarg;
937 cav[cac++] = "-VPKGVERSION";
938 cav[cac++] = "-VPKGFILE:T";
939 cav[cac++] = "-VALLFILES";
940 cav[cac++] = "-VDIST_SUBDIR";
941 cav[cac++] = "-VMAKE_JOBS_NUMBER";
942 cav[cac++] = "-VIGNORE";
943 cav[cac++] = "-VFETCH_DEPENDS";
944 cav[cac++] = "-VEXTRACT_DEPENDS";
945 cav[cac++] = "-VPATCH_DEPENDS";
946 cav[cac++] = "-VBUILD_DEPENDS";
947 cav[cac++] = "-VLIB_DEPENDS";
948 cav[cac++] = "-VRUN_DEPENDS";
949 cav[cac++] = "-VSELECTED_OPTIONS";
950 cav[cac++] = "-VDESELECTED_OPTIONS";
951 cav[cac++] = "-VUSE_LINUX";
952 cav[cac++] = "-VFLAVORS";
953 cav[cac++] = "-VUSES";
955 fp = dexec_open(cav, cac, &pid, NULL, 1, 1);
961 asprintf(&pkg->portdir, "%s/%s@%s", bulk->s1, bulk->s2, flavor);
963 asprintf(&pkg->portdir, "%s/%s", bulk->s1, bulk->s2);
966 while ((ptr = fgetln(fp, &len)) != NULL) {
967 if (len == 0 || ptr[len-1] != '\n') {
968 dfatal("Bad package info for %s/%s response line %d",
969 bulk->s1, bulk->s2, line);
974 case 1: /* PKGVERSION */
975 asprintf(&pkg->version, "%s", ptr);
977 case 2: /* PKGFILE */
978 asprintf(&pkg->pkgfile, "%s", ptr);
980 case 3: /* ALLFILES (aka DISTFILES + patch files) */
981 asprintf(&pkg->distfiles, "%s", ptr);
983 case 4: /* DIST_SUBDIR */
984 pkg->distsubdir = strdup_or_null(ptr);
986 case 5: /* MAKE_JOBS_NUMBER */
987 pkg->make_jobs_number = strtol(ptr, NULL, 0);
990 pkg->ignore = strdup_or_null(ptr);
992 case 7: /* FETCH_DEPENDS */
993 pkg->fetch_deps = strdup_or_null(ptr);
995 case 8: /* EXTRACT_DEPENDS */
996 pkg->ext_deps = strdup_or_null(ptr);
998 case 9: /* PATCH_DEPENDS */
999 pkg->patch_deps = strdup_or_null(ptr);
1001 case 10: /* BUILD_DEPENDS */
1002 pkg->build_deps = strdup_or_null(ptr);
1004 case 11: /* LIB_DEPENDS */
1005 pkg->lib_deps = strdup_or_null(ptr);
1007 case 12: /* RUN_DEPENDS */
1008 pkg->run_deps = strdup_or_null(ptr);
1010 case 13: /* SELECTED_OPTIONS */
1011 pkg->pos_options = strdup_or_null(ptr);
1013 case 14: /* DESELECTED_OPTIONS */
1014 pkg->neg_options = strdup_or_null(ptr);
1016 case 15: /* USE_LINUX */
1020 case 16: /* FLAVORS */
1021 asprintf(&pkg->flavors, "%s", ptr);
1024 asprintf(&pkg->uses, "%s", ptr);
1025 if (strstr(pkg->uses, "metaport"))
1026 pkg->flags |= PKGF_META;
1029 printf("EXTRA LINE: %s\n", ptr);
1035 printf("DPort not found: %s/%s\n", bulk->s1, bulk->s2);
1036 pkg->flags |= PKGF_NOTFOUND;
1037 } else if (line != 17 + 1) {
1038 printf("DPort corrupt: %s/%s\n", bulk->s1, bulk->s2);
1039 pkg->flags |= PKGF_CORRUPT;
1041 if (dexec_close(fp, pid)) {
1042 printf("make -V* command for %s/%s failed\n",
1043 bulk->s1, bulk->s2);
1044 pkg->flags |= PKGF_CORRUPT;
1051 if (bulk->s4 && bulk->s4[0] == 'd')
1052 pkg->flags |= PKGF_DEBUGSTOP;
1055 * Mark as a dummy node, the front-end will iterate the flavors
1056 * and create sub-nodes for us.
1058 * Get rid of elements returned that are for the first flavor.
1059 * We are creating a dummy node here, not the node for the first
1062 if (flavor == NULL && pkg->flavors && pkg->flavors[0]) {
1063 pkg->flags |= PKGF_DUMMY;
1064 freestrp(&pkg->fetch_deps);
1065 freestrp(&pkg->ext_deps);
1066 freestrp(&pkg->patch_deps);
1067 freestrp(&pkg->build_deps);
1068 freestrp(&pkg->lib_deps);
1069 freestrp(&pkg->run_deps);
1070 freestrp(&pkg->pkgfile);
1074 * Only one pkg is put on the return list now. This code no
1075 * longer creates pseudo-nodes for flavors (the frontend requests
1076 * each flavor instead).
1082 * Query the package (at least to make sure it hasn't been truncated)
1083 * and mark it as PACKAGED if found.
1088 childGetBinaryDistInfo(bulk_t *bulk)
1094 const char *cav[MAXCAC];
1101 asprintf(&repopath, "%s/%s", RepositoryPath, bulk->s1);
1104 cav[cac++] = PKG_BINARY;
1105 cav[cac++] = "query";
1107 cav[cac++] = repopath;
1108 cav[cac++] = "%n-%v";
1110 fp = dexec_open(cav, cac, &pid, NULL, 1, 0);
1111 deleteme = DeleteObsoletePkgs;
1113 while ((ptr = fgetln(fp, &len)) != NULL) {
1114 if (len == 0 || ptr[len-1] != '\n')
1117 snprintf(buf, sizeof(buf), "%s%s", ptr, UsePkgSufx);
1119 pkg = pkg_find(buf);
1121 pkg->flags |= PKGF_PACKAGED;
1124 ddprintf(0, "Note: package scan, not in list, "
1125 "skipping %s\n", buf);
1128 if (dexec_close(fp, pid)) {
1129 printf("pkg query command failed for %s\n", repopath);
1132 dlog(DLOG_ALL | DLOG_STDOUT,
1133 "Deleting obsolete package %s\n", repopath);
1140 childOptimizeEnv(bulk_t *bulk)
1147 const char *cav[MAXCAC];
1151 asprintf(&portpath, "%s/%s/%s", DPortsPath, bulk->s1, bulk->s2);
1154 cav[cac++] = MAKE_BINARY;
1156 cav[cac++] = portpath;
1157 cav[cac++] = "-V_PERL5_FROM_BIN";
1159 fp = dexec_open(cav, cac, &pid, NULL, 1, 1);
1163 while ((ptr = fgetln(fp, &len)) != NULL) {
1164 if (len == 0 || ptr[len-1] != '\n') {
1165 dfatal("Bad package info for %s/%s response line %d",
1166 bulk->s1, bulk->s2, line);
1171 case 1: /* _PERL5_FROM_BIN */
1172 addbuildenv("_PERL5_FROM_BIN", ptr, BENV_ENVIRONMENT);
1175 printf("childOptimizeEnv: EXTRA LINE: %s\n", ptr);
1181 printf("DPort not found: %s/%s\n", bulk->s1, bulk->s2);
1182 } else if (line != 1 + 1) {
1183 printf("DPort corrupt: %s/%s\n", bulk->s1, bulk->s2);
1185 if (dexec_close(fp, pid)) {
1186 printf("childOptimizeEnv() failed\n");
1191 scan_and_queue_dir(const char *path, const char *level1, int level)
1200 dir = opendir(path);
1201 dassert(dir, "Cannot open dports path \"%s\"", path);
1203 while ((den = readdir(dir)) != NULL) {
1204 if (den->d_namlen == 1 && den->d_name[0] == '.')
1206 if (den->d_namlen == 2 &&
1207 den->d_name[0] == '.' && den->d_name[1] == '.')
1209 asprintf(&s1, "%s/%s", path, den->d_name);
1210 if (lstat(s1, &st) < 0 || !S_ISDIR(st.st_mode)) {
1215 count += scan_and_queue_dir(s1, den->d_name, 2);
1219 asprintf(&s2, "%s/Makefile", s1);
1220 if (lstat(s2, &st) == 0) {
1221 queuebulk(level1, den->d_name, NULL, NULL);
1233 scan_binary_repo(const char *path)
1241 dir = opendir(path);
1242 dassert(dir, "Cannot open repository path \"%s\"", path);
1245 * NOTE: Test includes the '.' in the suffix.
1247 while ((den = readdir(dir)) != NULL) {
1248 len = strlen(den->d_name);
1250 strcmp(den->d_name + len - 4, UsePkgSufx) == 0) {
1251 queuebulk(den->d_name, NULL, NULL, NULL);
1264 freestrp(&pkg->portdir);
1265 freestrp(&pkg->version);
1266 freestrp(&pkg->pkgfile);
1267 freestrp(&pkg->ignore);
1268 freestrp(&pkg->fetch_deps);
1269 freestrp(&pkg->ext_deps);
1270 freestrp(&pkg->patch_deps);
1271 freestrp(&pkg->build_deps);
1272 freestrp(&pkg->lib_deps);
1273 freestrp(&pkg->run_deps);
1274 freestrp(&pkg->pos_options);
1275 freestrp(&pkg->neg_options);
1276 freestrp(&pkg->flavors);