Sun Oct 25 17:12:51 2020 UTC ()
make(1): add more details to DEBUG_SRC log


(rillig)
diff -r1.223 -r1.224 src/usr.bin/make/suff.c

cvs diff -r1.223 -r1.224 src/usr.bin/make/suff.c (expand / switch to unified diff)

--- src/usr.bin/make/suff.c 2020/10/25 10:00:20 1.223
+++ src/usr.bin/make/suff.c 2020/10/25 17:12:51 1.224
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.223 2020/10/25 10:00:20 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.224 2020/10/25 17:12:51 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -119,27 +119,27 @@ @@ -119,27 +119,27 @@
119 * Suff_FindDeps Find implicit sources for and the location of 119 * Suff_FindDeps Find implicit sources for and the location of
120 * a target based on its suffix. Returns the 120 * a target based on its suffix. Returns the
121 * bottom-most node added to the graph or NULL 121 * bottom-most node added to the graph or NULL
122 * if the target had no implicit sources. 122 * if the target had no implicit sources.
123 * 123 *
124 * Suff_FindPath Return the appropriate path to search in order to 124 * Suff_FindPath Return the appropriate path to search in order to
125 * find the node. 125 * find the node.
126 */ 126 */
127 127
128#include "make.h" 128#include "make.h"
129#include "dir.h" 129#include "dir.h"
130 130
131/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */ 131/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
132MAKE_RCSID("$NetBSD: suff.c,v 1.223 2020/10/25 10:00:20 rillig Exp $"); 132MAKE_RCSID("$NetBSD: suff.c,v 1.224 2020/10/25 17:12:51 rillig Exp $");
133 133
134#define SUFF_DEBUG0(text) DEBUG0(SUFF, text) 134#define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
135#define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1) 135#define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
136#define SUFF_DEBUG2(fmt, arg1, arg2) DEBUG2(SUFF, fmt, arg1, arg2) 136#define SUFF_DEBUG2(fmt, arg1, arg2) DEBUG2(SUFF, fmt, arg1, arg2)
137#define SUFF_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(SUFF, fmt, arg1, arg2, arg3) 137#define SUFF_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(SUFF, fmt, arg1, arg2, arg3)
138#define SUFF_DEBUG4(fmt, arg1, arg2, arg3, arg4) \ 138#define SUFF_DEBUG4(fmt, arg1, arg2, arg3, arg4) \
139 DEBUG4(SUFF, fmt, arg1, arg2, arg3, arg4) 139 DEBUG4(SUFF, fmt, arg1, arg2, arg3, arg4)
140 140
141typedef List SuffList; 141typedef List SuffList;
142typedef ListNode SuffListNode; 142typedef ListNode SuffListNode;
143 143
144typedef List SrcList; 144typedef List SrcList;
145typedef ListNode SrcListNode; 145typedef ListNode SrcListNode;
@@ -865,27 +865,28 @@ SrcNew(char *name, char *pref, Suff *suf @@ -865,27 +865,28 @@ SrcNew(char *name, char *pref, Suff *suf
865 return src; 865 return src;
866} 866}
867 867
868static void 868static void
869SuffAddSrc(Suff *suff, SrcList *srcList, Src *targ, char *srcName, 869SuffAddSrc(Suff *suff, SrcList *srcList, Src *targ, char *srcName,
870 const char *debug_tag) 870 const char *debug_tag)
871{ 871{
872 Src *s2 = SrcNew(srcName, targ->pref, suff, targ, NULL); 872 Src *s2 = SrcNew(srcName, targ->pref, suff, targ, NULL);
873 suff->refCount++; 873 suff->refCount++;
874 targ->children++; 874 targ->children++;
875 Lst_Append(srcList, s2); 875 Lst_Append(srcList, s2);
876#ifdef DEBUG_SRC 876#ifdef DEBUG_SRC
877 Lst_Append(targ->childrenList, s2); 877 Lst_Append(targ->childrenList, s2);
878 debug_printf("%s add %p %p to %p:", debug_tag, targ, s2, srcList); 878 debug_printf("%s add suff %p src %p to list %p:",
 879 debug_tag, targ, s2, srcList);
879 SrcList_PrintAddrs(srcList); 880 SrcList_PrintAddrs(srcList);
880#endif 881#endif
881} 882}
882 883
883/* Add a suffix as a Src structure to the given list with its parent 884/* Add a suffix as a Src structure to the given list with its parent
884 * being the given Src structure. If the suffix is the null suffix, 885 * being the given Src structure. If the suffix is the null suffix,
885 * the prefix is used unaltered as the file name in the Src structure. 886 * the prefix is used unaltered as the file name in the Src structure.
886 * 887 *
887 * Input: 888 * Input:
888 * suff suffix for which to create a Src structure 889 * suff suffix for which to create a Src structure
889 * srcList list for the new Src 890 * srcList list for the new Src
890 * targ parent for the new Src 891 * targ parent for the new Src
891 */ 892 */
@@ -917,56 +918,58 @@ SuffAddLevel(SrcList *l, Src *targ) @@ -917,56 +918,58 @@ SuffAddLevel(SrcList *l, Src *targ)
917 Suff *childSuff = ln->datum; 918 Suff *childSuff = ln->datum;
918 SuffAddSources(childSuff, l, targ); 919 SuffAddSources(childSuff, l, targ);
919 } 920 }
920} 921}
921 922
922/* Free the first Src in the list that is not referenced anymore. 923/* Free the first Src in the list that is not referenced anymore.
923 * Return whether a Src was removed. */ 924 * Return whether a Src was removed. */
924static Boolean 925static Boolean
925SuffRemoveSrc(SrcList *l) 926SuffRemoveSrc(SrcList *l)
926{ 927{
927 SrcListNode *ln; 928 SrcListNode *ln;
928 929
929#ifdef DEBUG_SRC 930#ifdef DEBUG_SRC
930 debug_printf("cleaning %p:", l); 931 debug_printf("cleaning list %p:", l);
931 SrcList_PrintAddrs(l); 932 SrcList_PrintAddrs(l);
932#endif 933#endif
933 934
934 for (ln = l->first; ln != NULL; ln = ln->next) { 935 for (ln = l->first; ln != NULL; ln = ln->next) {
935 Src *s = ln->datum; 936 Src *s = ln->datum;
936 937
937 if (s->children == 0) { 938 if (s->children == 0) {
938 free(s->file); 939 free(s->file);
939 if (s->parent == NULL) 940 if (s->parent == NULL)
940 free(s->pref); 941 free(s->pref);
941 else { 942 else {
942#ifdef DEBUG_SRC 943#ifdef DEBUG_SRC
943 SrcListNode *ln2 = Lst_FindDatum(s->parent->childrenList, s); 944 SrcListNode *ln2 = Lst_FindDatum(s->parent->childrenList, s);
944 if (ln2 != NULL) 945 if (ln2 != NULL)
945 Lst_Remove(s->parent->childrenList, ln2); 946 Lst_Remove(s->parent->childrenList, ln2);
946#endif 947#endif
947 s->parent->children--; 948 s->parent->children--;
948 } 949 }
949#ifdef DEBUG_SRC 950#ifdef DEBUG_SRC
950 debug_printf("free: [l=%p] p=%p %d\n", l, s, s->children); 951 debug_printf("free: list %p src %p children %d\n",
 952 l, s, s->children);
951 Lst_Free(s->childrenList); 953 Lst_Free(s->childrenList);
952#endif 954#endif
953 Lst_Remove(l, ln); 955 Lst_Remove(l, ln);
954 free(s); 956 free(s);
955 return TRUE; 957 return TRUE;
956 } 958 }
957#ifdef DEBUG_SRC 959#ifdef DEBUG_SRC
958 else { 960 else {
959 debug_printf("keep: [l=%p] p=%p %d:", l, s, s->children); 961 debug_printf("keep: list %p src %p children %d:",
 962 l, s, s->children);
960 SrcList_PrintAddrs(s->childrenList); 963 SrcList_PrintAddrs(s->childrenList);
961 } 964 }
962#endif 965#endif
963 } 966 }
964 967
965 return FALSE; 968 return FALSE;
966} 969}
967 970
968/* Find the first existing file/target in the list srcs. 971/* Find the first existing file/target in the list srcs.
969 * 972 *
970 * Input: 973 * Input:
971 * srcs list of Src structures to search through 974 * srcs list of Src structures to search through
972 * 975 *
@@ -979,38 +982,38 @@ SuffFindThem(SrcList *srcs, SrcList *sls @@ -979,38 +982,38 @@ SuffFindThem(SrcList *srcs, SrcList *sls
979 Src *retsrc = NULL; 982 Src *retsrc = NULL;
980 983
981 while (!Lst_IsEmpty(srcs)) { 984 while (!Lst_IsEmpty(srcs)) {
982 Src *src = Lst_Dequeue(srcs); 985 Src *src = Lst_Dequeue(srcs);
983 986
984 SUFF_DEBUG1("\ttrying %s...", src->file); 987 SUFF_DEBUG1("\ttrying %s...", src->file);
985 988
986 /* 989 /*
987 * A file is considered to exist if either a node exists in the 990 * A file is considered to exist if either a node exists in the
988 * graph for it or the file actually exists. 991 * graph for it or the file actually exists.
989 */ 992 */
990 if (Targ_FindNode(src->file) != NULL) { 993 if (Targ_FindNode(src->file) != NULL) {
991#ifdef DEBUG_SRC 994#ifdef DEBUG_SRC
992 debug_printf("remove %p from %p\n", src, srcs); 995 debug_printf("remove from list %p src %p\n", srcs, src);
993#endif 996#endif
994 retsrc = src; 997 retsrc = src;
995 break; 998 break;
996 } 999 }
997 1000
998 { 1001 {
999 char *file = Dir_FindFile(src->file, src->suff->searchPath); 1002 char *file = Dir_FindFile(src->file, src->suff->searchPath);
1000 if (file != NULL) { 1003 if (file != NULL) {
1001 retsrc = src; 1004 retsrc = src;
1002#ifdef DEBUG_SRC 1005#ifdef DEBUG_SRC
1003 debug_printf("remove %p from %p\n", src, srcs); 1006 debug_printf("remove from list %p src %p\n", srcs, src);
1004#endif 1007#endif
1005 free(file); 1008 free(file);
1006 break; 1009 break;
1007 } 1010 }
1008 } 1011 }
1009 1012
1010 SUFF_DEBUG0("not there\n"); 1013 SUFF_DEBUG0("not there\n");
1011 1014
1012 SuffAddLevel(srcs, src); 1015 SuffAddLevel(srcs, src);
1013 Lst_Append(slst, src); 1016 Lst_Append(slst, src);
1014 } 1017 }
1015 1018
1016 if (retsrc) { 1019 if (retsrc) {
@@ -1089,27 +1092,27 @@ SuffFindCmds(Src *targ, SrcList *slst) @@ -1089,27 +1092,27 @@ SuffFindCmds(Src *targ, SrcList *slst)
1089 if (gln == NULL) 1092 if (gln == NULL)
1090 return NULL; 1093 return NULL;
1091 1094
1092 /* 1095 /*
1093 * Hot Damn! Create a new Src structure to describe 1096 * Hot Damn! Create a new Src structure to describe
1094 * this transformation (making sure to duplicate the 1097 * this transformation (making sure to duplicate the
1095 * source node's name so Suff_FindDeps can free it 1098 * source node's name so Suff_FindDeps can free it
1096 * again (ick)), and return the new structure. 1099 * again (ick)), and return the new structure.
1097 */ 1100 */
1098 ret = SrcNew(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn); 1101 ret = SrcNew(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn);
1099 suff->refCount++; 1102 suff->refCount++;
1100 targ->children++; 1103 targ->children++;
1101#ifdef DEBUG_SRC 1104#ifdef DEBUG_SRC
1102 debug_printf("3 add %p %p\n", targ, ret); 1105 debug_printf("3 add targ %p ret %p\n", targ, ret);
1103 Lst_Append(targ->childrenList, ret); 1106 Lst_Append(targ->childrenList, ret);
1104#endif 1107#endif
1105 Lst_Append(slst, ret); 1108 Lst_Append(slst, ret);
1106 SUFF_DEBUG1("\tusing existing source %s\n", sgn->name); 1109 SUFF_DEBUG1("\tusing existing source %s\n", sgn->name);
1107 return ret; 1110 return ret;
1108} 1111}
1109 1112
1110/* Expand the names of any children of a given node that contain variable 1113/* Expand the names of any children of a given node that contain variable
1111 * expressions or file wildcards into actual targets. 1114 * expressions or file wildcards into actual targets.
1112 * 1115 *
1113 * The expanded node is removed from the parent's list of children, and the 1116 * The expanded node is removed from the parent's list of children, and the
1114 * parent's unmade counter is decremented, but other nodes may be added. 1117 * parent's unmade counter is decremented, but other nodes may be added.
1115 * 1118 *