summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2020-01-13 14:05:21 +0000
committerespie <espie@openbsd.org>2020-01-13 14:05:21 +0000
commit483cbdb0ce89a7af749edc2e6b955db8e65dd38b (patch)
tree6f9016f4d054527484b097813cee002902b09f8a
parentmove documentation around to be more specific to suff.c (diff)
downloadwireguard-openbsd-483cbdb0ce89a7af749edc2e6b955db8e65dd38b.tar.xz
wireguard-openbsd-483cbdb0ce89a7af749edc2e6b955db8e65dd38b.zip
move a large chunk of suff.c into its own file (independent functions which
are not really directly related to suffix handling), so that I can eventually understand how this whole thing works.
-rw-r--r--usr.bin/make/Makefile6
-rw-r--r--usr.bin/make/expandchildren.c246
-rw-r--r--usr.bin/make/expandchildren.h16
-rw-r--r--usr.bin/make/make.c3
-rw-r--r--usr.bin/make/suff.c224
-rw-r--r--usr.bin/make/suff.h14
6 files changed, 288 insertions, 221 deletions
diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile
index 0cd84fce842..85640c3e517 100644
--- a/usr.bin/make/Makefile
+++ b/usr.bin/make/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.62 2017/07/19 10:19:25 espie Exp $
+# $OpenBSD: Makefile,v 1.63 2020/01/13 14:05:21 espie Exp $
PROG= make
CFLAGS+= -I${.OBJDIR} -I${.CURDIR}
@@ -16,8 +16,8 @@ CFLAGS+=${CDEFS}
HOSTCFLAGS+=${CDEFS}
SRCS= arch.c buf.c cmd_exec.c compat.c cond.c dir.c direxpand.c dump.c \
- engine.c \
- error.c for.c init.c job.c lowparse.c main.c make.c memory.c parse.c \
+ engine.c error.c expandchildren.c \
+ for.c init.c job.c lowparse.c main.c make.c memory.c parse.c \
parsevar.c str.c stats.c suff.c targ.c targequiv.c timestamp.c \
var.c varmodifiers.c varname.c
diff --git a/usr.bin/make/expandchildren.c b/usr.bin/make/expandchildren.c
new file mode 100644
index 00000000000..c16ed95691e
--- /dev/null
+++ b/usr.bin/make/expandchildren.c
@@ -0,0 +1,246 @@
+/* $OpenBSD: expandchildren.c,v 1.1 2020/01/13 14:05:21 espie Exp $ */
+/* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */
+
+/*
+ * Copyright (c) 1988, 1989, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1989 by Berkeley Softworks
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Adam de Boor.
+ *
+ * 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 University 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 REGENTS 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 REGENTS 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.
+ */
+
+/*-
+ * expandchildren.c --
+ * Dealing with final children expansion before building stuff
+ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "config.h"
+#include "defines.h"
+#include "direxpand.h"
+#include "engine.h"
+#include "arch.h"
+#include "expandchildren.h"
+#include "var.h"
+#include "targ.h"
+#include "lst.h"
+#include "gnode.h"
+#include "suff.h"
+
+static void ExpandChildren(LstNode, GNode *);
+static void ExpandVarChildren(LstNode, GNode *, GNode *);
+static void ExpandWildChildren(LstNode, GNode *, GNode *);
+
+void
+LinkParent(GNode *cgn, GNode *pgn)
+{
+ Lst_AtEnd(&cgn->parents, pgn);
+ if (!has_been_built(cgn))
+ pgn->children_left++;
+ else if ( ! (cgn->type & (OP_EXEC|OP_USE))) {
+ if (cgn->built_status == REBUILT)
+ pgn->child_rebuilt = true;
+ (void)Make_TimeStamp(pgn, cgn);
+ }
+}
+
+static void
+ExpandVarChildren(LstNode after, GNode *cgn, GNode *pgn)
+{
+ GNode *gn; /* New source 8) */
+ char *cp; /* Expanded value */
+ LIST members;
+
+
+ if (DEBUG(SUFF))
+ printf("Expanding \"%s\"...", cgn->name);
+
+ cp = Var_Subst(cgn->name, &pgn->localvars, true);
+ if (cp == NULL) {
+ printf("Problem substituting in %s", cgn->name);
+ printf("\n");
+ return;
+ }
+
+ Lst_Init(&members);
+
+ if (cgn->type & OP_ARCHV) {
+ /*
+ * Node was an archive(member) target, so we want to call
+ * on the Arch module to find the nodes for us, expanding
+ * variables in the parent's context.
+ */
+ const char *sacrifice = (const char *)cp;
+
+ (void)Arch_ParseArchive(&sacrifice, &members, &pgn->localvars);
+ } else {
+ /* Break the result into a vector of strings whose nodes
+ * we can find, then add those nodes to the members list.
+ * Unfortunately, we can't use brk_string because it
+ * doesn't understand about variable specifications with
+ * spaces in them... */
+ const char *start, *cp2;
+
+ for (start = cp; *start == ' ' || *start == '\t'; start++)
+ continue;
+ for (cp2 = start; *cp2 != '\0';) {
+ if (ISSPACE(*cp2)) {
+ /* White-space -- terminate element, find the
+ * node, add it, skip any further spaces. */
+ gn = Targ_FindNodei(start, cp2, TARG_CREATE);
+ cp2++;
+ Lst_AtEnd(&members, gn);
+ while (ISSPACE(*cp2))
+ cp2++;
+ /* Adjust cp2 for increment at start of loop,
+ * but set start to first non-space. */
+ start = cp2;
+ } else if (*cp2 == '$')
+ /* Start of a variable spec -- contact variable
+ * module to find the end so we can skip over
+ * it. */
+ Var_ParseSkip(&cp2, &pgn->localvars);
+ else if (*cp2 == '\\' && cp2[1] != '\0')
+ /* Escaped something -- skip over it. */
+ cp2+=2;
+ else
+ cp2++;
+ }
+
+ if (cp2 != start) {
+ /* Stuff left over -- add it to the list too. */
+ gn = Targ_FindNodei(start, cp2, TARG_CREATE);
+ Lst_AtEnd(&members, gn);
+ }
+ }
+ /* Add all elements of the members list to the parent node. */
+ while ((gn = Lst_DeQueue(&members)) != NULL) {
+ if (DEBUG(SUFF))
+ printf("%s...", gn->name);
+ if (Lst_Member(&pgn->children, gn) == NULL) {
+ Lst_Append(&pgn->children, after, gn);
+ after = Lst_Adv(after);
+ LinkParent(gn, pgn);
+ }
+ }
+ /* Free the result. */
+ free(cp);
+ if (DEBUG(SUFF))
+ printf("\n");
+}
+
+static void
+ExpandWildChildren(LstNode after, GNode *cgn, GNode *pgn)
+{
+ char *cp; /* Expanded value */
+
+ LIST exp; /* List of expansions */
+ Lst path; /* Search path along which to expand */
+
+ if (DEBUG(SUFF))
+ printf("Wildcard expanding \"%s\"...", cgn->name);
+
+ /* Find a path along which to expand the word: if
+ * the word has a known suffix, use the path for that suffix,
+ * otherwise use the default path. */
+ path = find_best_path(cgn->name);
+
+ /* Expand the word along the chosen path. */
+ Lst_Init(&exp);
+ Dir_Expand(cgn->name, path, &exp);
+
+ /* Fetch next expansion off the list and find its GNode. */
+ while ((cp = Lst_DeQueue(&exp)) != NULL) {
+ GNode *gn; /* New source 8) */
+ if (DEBUG(SUFF))
+ printf("%s...", cp);
+ gn = Targ_FindNode(cp, TARG_CREATE);
+
+ /* If gn isn't already a child of the parent, make it so and
+ * up the parent's count of children to build. */
+ if (Lst_Member(&pgn->children, gn) == NULL) {
+ Lst_Append(&pgn->children, after, gn);
+ after = Lst_Adv(after);
+ LinkParent(gn, pgn);
+ }
+ }
+
+ if (DEBUG(SUFF))
+ printf("\n");
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * ExpandChildren --
+ * Expand the names of any children of a given node that contain
+ * variable invocations or file wildcards into actual targets.
+ *
+ * Side Effects:
+ * The expanded node is removed from the parent's list of children,
+ * and the parent's children to build counter is decremented,
+ * but other nodes may be added.
+ *-----------------------------------------------------------------------
+ */
+static void
+ExpandChildren(LstNode ln, /* LstNode of child, so we can replace it */
+ GNode *pgn)
+{
+ GNode *cgn = Lst_Datum(ln);
+
+ /* First do variable expansion -- this takes precedence over wildcard
+ * expansion. If the result contains wildcards, they'll be gotten to
+ * later since the resulting words are tacked on to the end of the
+ * children list. */
+ if (strchr(cgn->name, '$') != NULL)
+ ExpandVarChildren(ln, cgn, pgn);
+ else if (Dir_HasWildcards(cgn->name))
+ ExpandWildChildren(ln, cgn, pgn);
+ else
+ /* Third case: nothing to expand. */
+ return;
+
+ /* Since the source was expanded, remove it from the list of children to
+ * keep it from being processed. */
+ pgn->children_left--;
+ Lst_Remove(&pgn->children, ln);
+}
+
+void
+expand_children_from(GNode *parent, LstNode from)
+{
+ LstNode np, ln;
+
+ for (ln = from; ln != NULL; ln = np) {
+ np = Lst_Adv(ln);
+ ExpandChildren(ln, parent);
+ }
+}
diff --git a/usr.bin/make/expandchildren.h b/usr.bin/make/expandchildren.h
new file mode 100644
index 00000000000..22ac91e853b
--- /dev/null
+++ b/usr.bin/make/expandchildren.h
@@ -0,0 +1,16 @@
+#ifndef EXPANDCHILDREN_H
+#define EXPANDCHILDREN_H
+/* $OpenBSD: expandchildren.h,v 1.1 2020/01/13 14:05:21 espie Exp $ */
+
+extern void LinkParent(GNode *, GNode *);
+
+/* partial expansion of children. */
+extern void expand_children_from(GNode *, LstNode);
+/* expand_all_children(gn):
+ * figure out all variable/wildcards expansions in gn.
+ * TODO pretty sure this is independent from the main suff module.
+ */
+#define expand_all_children(gn) \
+ expand_children_from(gn, Lst_First(&(gn)->children))
+
+#endif
diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c
index a1788ee6ac1..e408ec7fa64 100644
--- a/usr.bin/make/make.c
+++ b/usr.bin/make/make.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: make.c,v 1.77 2020/01/08 14:09:29 espie Exp $ */
+/* $OpenBSD: make.c,v 1.78 2020/01/13 14:05:21 espie Exp $ */
/* $NetBSD: make.c,v 1.10 1996/11/06 17:59:15 christos Exp $ */
/*
@@ -71,6 +71,7 @@
#include "suff.h"
#include "var.h"
#include "error.h"
+#include "expandchildren.h"
#include "make.h"
#include "gnode.h"
#include "extern.h"
diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c
index b3edf78692c..1d1b38bed7d 100644
--- a/usr.bin/make/suff.c
+++ b/usr.bin/make/suff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: suff.c,v 1.99 2020/01/13 14:03:12 espie Exp $ */
+/* $OpenBSD: suff.c,v 1.100 2020/01/13 14:05:21 espie Exp $ */
/* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */
/*
@@ -42,7 +42,6 @@
*/
#include <ctype.h>
-#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -52,9 +51,7 @@
#include "config.h"
#include "defines.h"
#include "dir.h"
-#include "direxpand.h"
#include "engine.h"
-#include "arch.h"
#include "suff.h"
#include "var.h"
#include "targ.h"
@@ -66,6 +63,7 @@
#include "make.h"
#include "stats.h"
#include "dump.h"
+#include "expandchildren.h"
/* XXX the suffixes hash is stored using a specific hash function, suitable
* for looking up suffixes in reverse.
@@ -165,9 +163,6 @@ static bool SuffRemoveSrc(Lst);
static void SuffAddLevel(Lst, Src *);
static Src *SuffFindThem(Lst, Lst);
static Src *SuffFindCmds(Src *, Lst);
-static void SuffExpandChildren(LstNode, GNode *);
-static void SuffExpandVarChildren(LstNode, GNode *, GNode *);
-static void SuffExpandWildChildren(LstNode, GNode *, GNode *);
static bool SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
static void SuffFindDeps(GNode *, Lst);
static void SuffFindArchiveDeps(GNode *, Lst);
@@ -456,6 +451,18 @@ find_best_suffix(const char *s, const char *e)
return best;
}
+Lst
+find_best_path(const char *name)
+{
+ Suff *s = find_best_suffix(name, name + strlen(name));
+ if (s != NULL) {
+ if (DEBUG(SUFF))
+ printf("suffix is \"%s\"...", s->name);
+ return &s->searchPath;
+ } else
+ return defaultPath;
+}
+
/*-
*-----------------------------------------------------------------------
* Suff_ParseAsTransform --
@@ -876,203 +883,6 @@ SuffFindCmds(Src *targ, Lst slst)
return NULL;
}
-static void
-SuffLinkParent(GNode *cgn, GNode *pgn)
-{
- Lst_AtEnd(&cgn->parents, pgn);
- if (!has_been_built(cgn))
- pgn->children_left++;
- else if ( ! (cgn->type & (OP_EXEC|OP_USE))) {
- if (cgn->built_status == REBUILT)
- pgn->child_rebuilt = true;
- (void)Make_TimeStamp(pgn, cgn);
- }
-}
-
-static void
-SuffExpandVarChildren(LstNode after, GNode *cgn, GNode *pgn)
-{
- GNode *gn; /* New source 8) */
- char *cp; /* Expanded value */
- LIST members;
-
-
- if (DEBUG(SUFF))
- printf("Expanding \"%s\"...", cgn->name);
-
- cp = Var_Subst(cgn->name, &pgn->localvars, true);
- if (cp == NULL) {
- printf("Problem substituting in %s", cgn->name);
- printf("\n");
- return;
- }
-
- Lst_Init(&members);
-
- if (cgn->type & OP_ARCHV) {
- /*
- * Node was an archive(member) target, so we want to call
- * on the Arch module to find the nodes for us, expanding
- * variables in the parent's context.
- */
- const char *sacrifice = (const char *)cp;
-
- (void)Arch_ParseArchive(&sacrifice, &members, &pgn->localvars);
- } else {
- /* Break the result into a vector of strings whose nodes
- * we can find, then add those nodes to the members list.
- * Unfortunately, we can't use brk_string because it
- * doesn't understand about variable specifications with
- * spaces in them... */
- const char *start, *cp2;
-
- for (start = cp; *start == ' ' || *start == '\t'; start++)
- continue;
- for (cp2 = start; *cp2 != '\0';) {
- if (ISSPACE(*cp2)) {
- /* White-space -- terminate element, find the
- * node, add it, skip any further spaces. */
- gn = Targ_FindNodei(start, cp2, TARG_CREATE);
- cp2++;
- Lst_AtEnd(&members, gn);
- while (ISSPACE(*cp2))
- cp2++;
- /* Adjust cp2 for increment at start of loop,
- * but set start to first non-space. */
- start = cp2;
- } else if (*cp2 == '$')
- /* Start of a variable spec -- contact variable
- * module to find the end so we can skip over
- * it. */
- Var_ParseSkip(&cp2, &pgn->localvars);
- else if (*cp2 == '\\' && cp2[1] != '\0')
- /* Escaped something -- skip over it. */
- cp2+=2;
- else
- cp2++;
- }
-
- if (cp2 != start) {
- /* Stuff left over -- add it to the list too. */
- gn = Targ_FindNodei(start, cp2, TARG_CREATE);
- Lst_AtEnd(&members, gn);
- }
- }
- /* Add all elements of the members list to the parent node. */
- while ((gn = Lst_DeQueue(&members)) != NULL) {
- if (DEBUG(SUFF))
- printf("%s...", gn->name);
- if (Lst_Member(&pgn->children, gn) == NULL) {
- Lst_Append(&pgn->children, after, gn);
- after = Lst_Adv(after);
- SuffLinkParent(gn, pgn);
- }
- }
- /* Free the result. */
- free(cp);
- if (DEBUG(SUFF))
- printf("\n");
-}
-
-static void
-SuffExpandWildChildren(LstNode after, GNode *cgn, GNode *pgn)
-{
- Suff *s;
- char *cp; /* Expanded value */
-
- LIST exp; /* List of expansions */
- Lst path; /* Search path along which to expand */
-
- if (DEBUG(SUFF))
- printf("Wildcard expanding \"%s\"...", cgn->name);
-
- /* Find a path along which to expand the word.
- *
- * If the word has a known suffix, use that path.
- * If it has no known suffix and we're allowed to use the null
- * suffix, use its path.
- * Else use the default system search path. */
- s = find_best_suffix(cgn->name, cgn->name + strlen(cgn->name));
-
- if (s != NULL) {
- if (DEBUG(SUFF))
- printf("suffix is \"%s\"...", s->name);
- path = &s->searchPath;
- } else
- /* Use default search path. */
- path = defaultPath;
-
- /* Expand the word along the chosen path. */
- Lst_Init(&exp);
- Dir_Expand(cgn->name, path, &exp);
-
- /* Fetch next expansion off the list and find its GNode. */
- while ((cp = Lst_DeQueue(&exp)) != NULL) {
- GNode *gn; /* New source 8) */
- if (DEBUG(SUFF))
- printf("%s...", cp);
- gn = Targ_FindNode(cp, TARG_CREATE);
-
- /* If gn isn't already a child of the parent, make it so and
- * up the parent's count of children to build. */
- if (Lst_Member(&pgn->children, gn) == NULL) {
- Lst_Append(&pgn->children, after, gn);
- after = Lst_Adv(after);
- SuffLinkParent(gn, pgn);
- }
- }
-
- if (DEBUG(SUFF))
- printf("\n");
-}
-
-/*-
- *-----------------------------------------------------------------------
- * SuffExpandChildren --
- * Expand the names of any children of a given node that contain
- * variable invocations or file wildcards into actual targets.
- *
- * Side Effects:
- * The expanded node is removed from the parent's list of children,
- * and the parent's children to build counter is decremented,
- * but other nodes may be added.
- *-----------------------------------------------------------------------
- */
-static void
-SuffExpandChildren(LstNode ln, /* LstNode of child, so we can replace it */
- GNode *pgn)
-{
- GNode *cgn = Lst_Datum(ln);
-
- /* First do variable expansion -- this takes precedence over wildcard
- * expansion. If the result contains wildcards, they'll be gotten to
- * later since the resulting words are tacked on to the end of the
- * children list. */
- if (strchr(cgn->name, '$') != NULL)
- SuffExpandVarChildren(ln, cgn, pgn);
- else if (Dir_HasWildcards(cgn->name))
- SuffExpandWildChildren(ln, cgn, pgn);
- else
- /* Third case: nothing to expand. */
- return;
-
- /* Since the source was expanded, remove it from the list of children to
- * keep it from being processed. */
- pgn->children_left--;
- Lst_Remove(&pgn->children, ln);
-}
-
-void
-expand_children_from(GNode *parent, LstNode from)
-{
- LstNode np, ln;
-
- for (ln = from; ln != NULL; ln = np) {
- np = Lst_Adv(ln);
- SuffExpandChildren(ln, parent);
- }
-}
-
/*-
*-----------------------------------------------------------------------
* SuffApplyTransform --
@@ -1104,7 +914,7 @@ SuffApplyTransform(
if (Lst_AddNew(&tGn->children, sGn)) {
/* Not already linked, so form the proper links between the
* target and source. */
- SuffLinkParent(sGn, tGn);
+ LinkParent(sGn, tGn);
}
if ((sGn->type & OP_OPMASK) == OP_DOUBLEDEP) {
@@ -1118,7 +928,7 @@ SuffApplyTransform(
if (Lst_AddNew(&tGn->children, gn)) {
/* Not already linked, so form the proper links
* between the target and source. */
- SuffLinkParent(gn, tGn);
+ LinkParent(gn, tGn);
}
}
}
@@ -1211,7 +1021,7 @@ SuffFindArchiveDeps(
/* Create the link between the two nodes right off. */
if (Lst_AddNew(&gn->children, mem))
- SuffLinkParent(mem, gn);
+ LinkParent(mem, gn);
/* Copy variables from member node to this one. */
Var(TARGET_INDEX, gn) = Var(TARGET_INDEX, mem);
diff --git a/usr.bin/make/suff.h b/usr.bin/make/suff.h
index 41f423e6db6..f0ae8b3939a 100644
--- a/usr.bin/make/suff.h
+++ b/usr.bin/make/suff.h
@@ -1,6 +1,6 @@
#ifndef SUFF_H
#define SUFF_H
-/* $OpenBSD: suff.h,v 1.11 2020/01/13 14:03:12 espie Exp $ */
+/* $OpenBSD: suff.h,v 1.12 2020/01/13 14:05:21 espie Exp $ */
/*
* Copyright (c) 2001-2019 Marc Espie.
@@ -59,14 +59,8 @@ extern Lst find_suffix_path(GNode *);
/* Suff_PrintAll():
* displays all suffix information. */
extern void Suff_PrintAll(void);
-/* XXX internal to suff.c, only the following macro is used elsewhere. */
-extern void expand_children_from(GNode *, LstNode);
-
-/* expand_all_children(gn):
- * figure out all variable/wildcards expansions in gn.
- * TODO pretty sure this is independent from the main suff module.
+/* path = find_best_path(name):
+ * find the best path for the name, according to known suffixes.
*/
-#define expand_all_children(gn) \
- expand_children_from(gn, Lst_First(&(gn)->children))
-
+extern Lst find_best_path(const char *name);
#endif