Import bmake-20220208

* unit-tests/Makefile: disable opt-debug-x-trace on Linux if there
	is any chance we have dash as .SHELL

	* meta.c: use a variable to hold command line to be filtered
	to avoid any side effects from content of command line.
This commit is contained in:
Simon J. Gerraty 2022-02-09 09:22:21 -08:00
parent cdde9e894d
commit 535c59a6a9
14 changed files with 163 additions and 28 deletions

View File

@ -1,3 +1,14 @@
2022-02-08 Simon J Gerraty <sjg@beast.crufty.net>
* unit-tests/Makefile: disable opt-debug-x-trace on Linux if there
is any chance we have dash as .SHELL
* VERSION (_MAKE_VERSION): 20220208
Merge with NetBSD make, pick up
o more unit tests
o meta.c: use a variable to hold command line to be filtered
to avoid any side effects from content of command line.
2022-02-04 Simon J Gerraty <sjg@beast.crufty.net>
* VERSION (_MAKE_VERSION): 20220204

2
FILES
View File

@ -616,6 +616,8 @@ unit-tests/suff-transform-expand.exp
unit-tests/suff-transform-expand.mk
unit-tests/suff-transform-select.exp
unit-tests/suff-transform-select.mk
unit-tests/suff-use.exp
unit-tests/suff-use.mk
unit-tests/sunshcmd.exp
unit-tests/sunshcmd.mk
unit-tests/ternary.exp

View File

@ -1,2 +1,2 @@
# keep this compatible with sh and make
_MAKE_VERSION=20220204
_MAKE_VERSION=20220208

25
meta.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: meta.c,v 1.196 2022/02/04 23:22:19 rillig Exp $ */
/* $NetBSD: meta.c,v 1.197 2022/02/08 22:36:02 sjg Exp $ */
/*
* Implement 'meta' mode.
@ -1055,36 +1055,31 @@ append_if_new(StringList *list, const char *str)
Lst_Append(list, bmake_strdup(str));
}
/* A "reserved" variable to store the command to be filtered */
#define META_CMD_FILTER_VAR ".MAKE.cmd_filtered"
static char *
meta_filter_cmd(Buffer *buf, GNode *gn, char *s)
meta_filter_cmd(GNode *gn, char *s)
{
Buf_Clear(buf);
Buf_AddStr(buf, "${");
Buf_AddStr(buf, s);
Buf_AddStr(buf, ":L:${" MAKE_META_CMP_FILTER ":ts:}}");
Var_Subst(buf->data, gn, VARE_WANTRES, &s);
Var_Set(gn, META_CMD_FILTER_VAR, s);
Var_Subst("${" META_CMD_FILTER_VAR ":${" MAKE_META_CMP_FILTER ":ts:}}", gn, VARE_WANTRES, &s);
return s;
}
static int
meta_cmd_cmp(GNode *gn, char *a, char *b, bool filter)
{
static bool once = false;
static Buffer buf;
int rc;
rc = strcmp(a, b);
if (rc == 0 || !filter)
return rc;
if (!once) {
once = true;
Buf_Init(&buf);
}
a = meta_filter_cmd(&buf, gn, a);
b = meta_filter_cmd(&buf, gn, b);
a = meta_filter_cmd(gn, a);
b = meta_filter_cmd(gn, b);
rc = strcmp(a, b);
free(a);
free(b);
Var_Delete(gn, META_CMD_FILTER_VAR);
return rc;
}

View File

@ -1,3 +1,14 @@
2022-02-06 Simon J Gerraty <sjg@beast.crufty.net>
* install-mk (MK_VERSION): 20220206
* cc-wrap.mk: docuement how CCACHE etc might be set for
maximum flexibility
2022-02-05 Simon J Gerraty <sjg@beast.crufty.net>
* sys.vars.mk: use JOT_CMD (jot or seq) if available for M_JOT
2022-02-04 Simon J Gerraty <sjg@beast.crufty.net>
* install-mk (MK_VERSION): 20220204

View File

@ -1,4 +1,4 @@
# $Id: cc-wrap.mk,v 1.4 2022/02/02 17:41:56 sjg Exp $
# $Id: cc-wrap.mk,v 1.5 2022/02/07 19:02:55 sjg Exp $
#
# @(#) Copyright (c) 2022, Simon J. Gerraty
#
@ -30,6 +30,11 @@ CC_WRAP_LIST := ${CC_WRAP_LIST:O:u}
# what might we wrap them with?
CC_WRAPPERS += ccache distcc icecc
CC_WRAPPERS := ${CC_WRAPPERS:O:u}
# $W can be as simple or complicated as you like (default is just $w)
# eg.
# CCACHE ?= ${CCACHE_ENV_VARS:@v@$v='${$v}'@} ${CCACHE_CMD} ${CCACHE_FLAGS}
# or if you want global vars to be used modifiable after this include:
# CCACHE ?= $${CCACHE_ENV_VARS:@v@$$v='$${$$v}'@} $${CCACHE_CMD} $${CCACHE_FLAGS}
.for w in ${CC_WRAPPERS}
${w:tu} ?= $w
.endfor

View File

@ -55,7 +55,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: install-mk,v 1.213 2022/02/05 01:39:12 sjg Exp $
# $Id: install-mk,v 1.214 2022/02/07 19:02:55 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
@ -70,7 +70,7 @@
# sjg@crufty.net
#
MK_VERSION=20220204
MK_VERSION=20220206
OWNER=
GROUP=
MODE=444

View File

@ -1,4 +1,4 @@
# $Id: sys.vars.mk,v 1.7 2021/12/08 05:56:50 sjg Exp $
# $Id: sys.vars.mk,v 1.9 2022/02/05 19:04:53 sjg Exp $
#
# @(#) Copyright (c) 2003-2009, Simon J. Gerraty
#
@ -57,12 +57,26 @@ _type_sh = which
M_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g
M_whence = ${M_type}:M/*:[1]
# produce similar output to jot(1)
# produce similar output to jot(1) or seq(1)
# eg. ${LIST:[#]:${M_JOT}}
# would be 1 2 3 4 5 if LIST has 5 words
# ${9:L:${M_JOT}}
# would be 1 2 3 4 5 6 7 8 9
M_JOT = @x@i=1;while [ $$$$i -le $$x ]; do echo $$$$i; i=$$$$((i + 1)); done;@:sh
.if ${.MAKE.LEVEL} == 0
.for x in jot seq
.if empty(JOT_CMD)
JOT_CMD := ${$x:L:${M_whence}}
.endif
.endfor
.if !empty(JOT_CMD)
.export JOT_CMD
.endif
.endif
.if !empty(JOT_CMD)
M_JOT = [1]:S,^,${JOT_CMD} ,:sh
.else
M_JOT = [1]:@x@i=1;while [ $$$$i -le $$x ]; do echo $$$$i; i=$$$$((i + 1)); done;@:sh
.endif
# ${LIST:${M_RANGE}} is 1 2 3 4 5 if LIST has 5 words
.if ${MAKE_VERSION} >= 20170130

0
os.sh Normal file → Executable file
View File

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.662 2022/02/05 00:37:19 sjg Exp $ */
/* $NetBSD: parse.c,v 1.663 2022/02/07 23:24:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -121,7 +121,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: parse.c,v 1.662 2022/02/05 00:37:19 sjg Exp $");
MAKE_RCSID("$NetBSD: parse.c,v 1.663 2022/02/07 23:24:26 rillig Exp $");
/*
* A file being read.
@ -722,7 +722,6 @@ ApplyDependencySourceWait(bool isSpecial)
RememberLocation(gn);
gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN;
LinkToTargets(gn, isSpecial);
}
static bool

View File

@ -1,6 +1,6 @@
# $Id: Makefile,v 1.171 2022/01/28 21:33:18 sjg Exp $
# $Id: Makefile,v 1.174 2022/02/09 02:42:59 sjg Exp $
#
# $NetBSD: Makefile,v 1.302 2022/01/27 21:50:50 sjg Exp $
# $NetBSD: Makefile,v 1.303 2022/02/07 22:43:50 rillig Exp $
#
# Unit tests for make(1)
#
@ -315,6 +315,7 @@ TESTS+= suff-transform-debug
TESTS+= suff-transform-endless
TESTS+= suff-transform-expand
TESTS+= suff-transform-select
TESTS+= suff-use
TESTS+= sunshcmd
TESTS+= ternary
TESTS+= unexport
@ -444,6 +445,17 @@ BROKEN_TESTS+= sh-flags
.if ${.MAKE.OS:NDarwin} == ""
BROKEN_TESTS+= shell-ksh
.endif
.if ${.MAKE.OS} == "Linux" && ${.SHELL:tA:T} != "bash"
.if exists(/etc/os-release)
distro!= . /etc/os-release && echo $$NAME
.endif
# dash fails -x output
# .SHELL is not bash so may be dash
# if distro is Ubuntu or we cannot tell, assume the worst
.if ${distro:U:NUbuntu} == ""
BROKEN_TESTS+= opt-debug-x-trace
.endif
.endif
.if ${.MAKE.OS} == "SCO_SV"
BROKEN_TESTS+= \
opt-debug-graph[23] \

7
unit-tests/suff-use.exp Normal file
View File

@ -0,0 +1,7 @@
: 'Making demo.c out of nothing'
make: don't know how to make demo.o (continuing)
`all' not remade because of errors.
Stop.
make: stopped in unit-tests
exit status 1

50
unit-tests/suff-use.mk Normal file
View File

@ -0,0 +1,50 @@
# $NetBSD: suff-use.mk,v 1.1 2022/02/07 22:43:50 rillig Exp $
#
# This test combines a .USE node with suffix rules, trying to add an
# additional command before and after successful compilation of a .c file.
#
# History:
# bin/make-2001.11.12.21.58.18-plain
# | : 'Making demo.c out of nothing'
# | make: don't know how to make demo.o. Stop
# |
# | make: stopped in /home/rillig/proj/make-archive
# | exit status 2
# bin/make-2007.10.11.21.19.28-plain
#
# bin/make-2014.08.23.15.05.40-plain
# | : 'Making demo.c out of nothing'
# | : 'Compiling demo.c to demo.o'
# | exit status 0
# bin/make-2014.09.05.06.57.20-plain
#
# bin/make-2014.09.07.20.55.34-plain
# | : 'Making demo.c out of nothing'
# | make: don't know how to make demo.o. Stop
# |
# | make: stopped in /home/rillig/proj/make-archive
# | exit status 2
# ...
#
# See also:
# https://gnats.netbsd.org/20993
.SUFFIXES: .c .o
all: demo.o
.c.o:
: 'Compiling ${.IMPSRC} to ${.TARGET}'
demo.c:
: 'Making ${.TARGET} out of nothing'
using-before: .USEBEFORE
: 'Before making ${.TARGET} from ${.ALLSRCS}'
using-after: .USE
: 'After making ${.TARGET} from ${.ALLSRCS}'
# expect: make: don't know how to make demo.o (continuing)
.c.o: using-before using-after

View File

@ -1,4 +1,4 @@
# $NetBSD: var-scope-local.mk,v 1.3 2022/01/29 00:52:53 rillig Exp $
# $NetBSD: var-scope-local.mk,v 1.4 2022/02/05 10:41:15 rillig Exp $
#
# Tests for target-local variables, such as ${.TARGET} or $@. These variables
# are relatively short-lived as they are created just before making the
@ -198,3 +198,32 @@ a_use: .USE VAR=use
all: var-scope-local-use.o
var-scope-local-use.o: a_use
# Since parse.c 1.656 from 2022-01-27 and before parse.c 1.662 from
# 2022-02-05, there was an out-of-bounds read in Parse_IsVar when looking for
# a variable assignment in a dependency line with trailing whitespace. Lines
# without trailing whitespace were not affected. Global variable assignments
# were guaranteed to have no trailing whitespace and were thus not affected.
#
# Try to reproduce some variants that may lead to a crash, depending on the
# memory allocator. To get a crash, the terminating '\0' of the line must be
# the last byte of a memory page. The expression '${:U}' forces this trailing
# whitespace.
# On FreeBSD x86_64, a crash could in some cases be forced using the following
# line, which has length 47, so the terminating '\0' may end up at an address
# of the form 0xXXXX_XXXX_XXXX_Xfff:
Try_to_crash_FreeBSD.xxxxxxxxxxxxxxxxxx: 12345 ${:U}
# The following line has length 4095, so line[4095] == '\0'. If the line is
# allocated on a page boundary and the following page is not mapped, this line
# leads to a segmentation fault.
${:U:range=511:@_@1234567@:ts.}: 12345 ${:U}
# The following line has length 8191, so line[8191] == '\0'. If the line is
# allocated on a page boundary and the following page is not mapped, this line
# leads to a segmentation fault.
${:U:range=1023:@_@1234567@:ts.}: 12345 ${:U}
12345: