Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): sort variables in debug output



details:   https://anonhg.NetBSD.org/src/rev/cbceeb2ef575
branches:  trunk
changeset: 955962:cbceeb2ef575
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 18 08:47:54 2020 +0000

description:
make(1): sort variables in debug output

This way it's easier to see whether an expected variable is missing, or
to compare the values of related variables, since they usually share a
common prefix.  Any sorting criterion is better than the hash code.

Sorting the variables by name changed the order of the output in
varname.mk.  That test didn't test anything meaningful, it was just a
playground to understand and demonstrate the current implementation of
how the variables are stored, therefore it has been removed.

diffstat:

 usr.bin/make/unit-tests/varname.exp |  18 ----------------
 usr.bin/make/unit-tests/varname.mk  |  41 ++----------------------------------
 usr.bin/make/var.c                  |  36 ++++++++++++++++++++-----------
 3 files changed, 26 insertions(+), 69 deletions(-)

diffs (131 lines):

diff -r 8d9a2c714164 -r cbceeb2ef575 usr.bin/make/unit-tests/varname.exp
--- a/usr.bin/make/unit-tests/varname.exp       Sun Oct 18 08:24:01 2020 +0000
+++ b/usr.bin/make/unit-tests/varname.exp       Sun Oct 18 08:47:54 2020 +0000
@@ -1,19 +1,1 @@
-MAGIC1B1B1B      = 1
-MAGIC1B1B0a      = 2
-MAGIC1B0a1B      = 3
-MAGIC1B0a0a      = 4
-MAGIC0a1B1B      = 5
-MAGIC0a1B0a      = 6
-MAGIC0a0a1B      = 7
-MAGIC0a0a0a      = 8
-ORDER_01         = yes
-MAGIC0a0a0a      = 1
-MAGIC0a0a1B      = 2
-MAGIC0a1B0a      = 3
-MAGIC0a1B1B      = 4
-MAGIC1B0a0a      = 5
-MAGIC1B0a1B      = 6
-MAGIC1B1B0a      = 7
-MAGIC1B1B1B      = 8
-ORDER_10         = yes
 exit status 0
diff -r 8d9a2c714164 -r cbceeb2ef575 usr.bin/make/unit-tests/varname.mk
--- a/usr.bin/make/unit-tests/varname.mk        Sun Oct 18 08:24:01 2020 +0000
+++ b/usr.bin/make/unit-tests/varname.mk        Sun Oct 18 08:47:54 2020 +0000
@@ -1,43 +1,8 @@
-# $NetBSD: varname.mk,v 1.3 2020/09/05 12:59:07 rillig Exp $
+# $NetBSD: varname.mk,v 1.4 2020/10/18 08:47:54 rillig Exp $
 #
 # Tests for special variables, such as .MAKE or .PARSEDIR.
 
-# These following MAGIC variables have the same hash code, at least with
-# the default hashing algorithm, which is the same as in Java.  The order
-# in which these variables are defined determines the order in which they
-# appear in the Hash_Table.  New entries are prepended to the bucket lists,
-# therefore this test numbers the values in descending order.
-
-.if defined(ORDER_01)
-
-MAGIC0a0a0a=   8
-MAGIC0a0a1B=   7
-MAGIC0a1B0a=   6
-MAGIC0a1B1B=   5
-MAGIC1B0a0a=   4
-MAGIC1B0a1B=   3
-MAGIC1B1B0a=   2
-MAGIC1B1B1B=   1
-
-all: # nothing
-
-.elif defined(ORDER_10)
-
-MAGIC1B1B1B=   8
-MAGIC1B1B0a=   7
-MAGIC1B0a1B=   6
-MAGIC1B0a0a=   5
-MAGIC0a1B1B=   4
-MAGIC0a1B0a=   3
-MAGIC0a0a1B=   2
-MAGIC0a0a0a=   1
-
-all: # nothing
-
-.else
+# TODO: Implementation
 
 all:
-       @${.MAKE} -f ${MAKEFILE} -dg1 ORDER_01=yes
-       @${.MAKE} -f ${MAKEFILE} -dg1 ORDER_10=yes
-
-.endif
+       @:;
diff -r 8d9a2c714164 -r cbceeb2ef575 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Oct 18 08:24:01 2020 +0000
+++ b/usr.bin/make/var.c        Sun Oct 18 08:47:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.572 2020/10/17 21:32:30 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.573 2020/10/18 08:47:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.572 2020/10/17 21:32:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.573 2020/10/18 08:47:54 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -3852,18 +3852,28 @@
     Hash_DebugStats(&VAR_GLOBAL->context, "VAR_GLOBAL");
 }
 
-
-/****************** PRINT DEBUGGING INFO *****************/
-static void
-VarPrintVar(void *vp, void *data MAKE_ATTR_UNUSED)
-{
-    Var *v = (Var *)vp;
-    debug_printf("%-16s = %s\n", v->name, Buf_GetAll(&v->val, NULL));
-}
-
-/* Print all variables in a context, unordered. */
+/* Print all variables in a context, sorted by name. */
 void
 Var_Dump(GNode *ctxt)
 {
-    Hash_ForEach(&ctxt->context, VarPrintVar, NULL);
+    Stack varnames;
+    Hash_Search iter;
+    Hash_Entry *he;
+    size_t i;
+
+    Stack_Init(&varnames);
+    for (he = Hash_EnumFirst(&ctxt->context, &iter);
+        he != NULL;
+        he = Hash_EnumNext(&iter))
+        Stack_Push(&varnames, he->name);
+
+    qsort(varnames.items, varnames.len, sizeof varnames.items[0], str_cmp_asc);
+
+    for (i = 0; i < varnames.len; i++) {
+        const char *varname = varnames.items[i];
+        Var *var = Hash_FindValue(&ctxt->context, varname);
+       debug_printf("%-16s = %s\n", varname, Buf_GetAll(&var->val, NULL));
+    }
+
+    Stack_Done(&varnames);
 }



Home | Main Index | Thread Index | Old Index