Import bmake-20150505 detect typo's in .if variable references.

This commit is contained in:
Simon J. Gerraty 2015-05-10 20:01:54 +00:00
parent 023e89e5ef
commit c21ae9a30b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/NetBSD/bmake/dist/; revision=282732
svn path=/vendor/NetBSD/bmake/20150505/; revision=282733; tag=vendor/NetBSD/bmake/20150505
13 changed files with 106 additions and 26 deletions

View File

@ -1,3 +1,16 @@
2015-05-05 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20150505
Merge with NetBSD make, pick up
o cond.c: be strict about lhs of comparison when evaluating .if
but less so when called from variable expansion.
o unit-tests/cond2.mk: test various error conditions
2015-05-04 Simon J. Gerraty <sjg@bad.crufty.net>
* machine.sh (MACHINE): Add Bitrig
patch from joerg@netbsd.org
2015-04-18 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20150418

2
FILES
View File

@ -96,6 +96,8 @@ unit-tests/comment.exp
unit-tests/comment.mk
unit-tests/cond1.exp
unit-tests/cond1.mk
unit-tests/cond2.exp
unit-tests/cond2.mk
unit-tests/doterror.exp
unit-tests/doterror.mk
unit-tests/dotwait.exp

View File

@ -1,7 +1,7 @@
# $Id: Makefile,v 1.36 2015/04/18 19:58:53 sjg Exp $
# $Id: Makefile,v 1.38 2015/05/05 21:58:05 sjg Exp $
# Base version on src date
MAKE_VERSION= 20150418
MAKE_VERSION= 20150505
PROG= bmake
@ -94,7 +94,7 @@ SUBDIR+= unit-tests
# we skip a lot of this when building as part of FreeBSD etc.
# list of OS's which are derrived from BSD4.4
BSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly
BSD44_LIST= NetBSD FreeBSD OpenBSD DragonFly MirBSD Bitrig
# we are...
OS!= uname -s
# are we 4.4BSD ?

37
cond.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $ */
/* $NetBSD: cond.c,v 1.68 2015/05/05 21:51:09 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $";
static char rcsid[] = "$NetBSD: cond.c,v 1.68 2015/05/05 21:51:09 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $");
__RCSID("$NetBSD: cond.c,v 1.68 2015/05/05 21:51:09 sjg Exp $");
#endif
#endif /* not lint */
#endif
@ -181,6 +181,15 @@ static Token condPushBack=TOK_NONE; /* Single push-back token used in
static unsigned int cond_depth = 0; /* current .if nesting level */
static unsigned int cond_min_depth = 0; /* depth at makefile open */
/*
* Indicate when we should be strict about lhs of comparisons.
* TRUE when Cond_EvalExpression is called from Cond_Eval (.if etc)
* FALSE when Cond_EvalExpression is called from var.c:ApplyModifiers
* since lhs is already expanded and we cannot tell if
* it was a variable reference or not.
*/
static Boolean lhsStrict;
static int
istoken(const char *str, const char *tok, size_t len)
{
@ -517,7 +526,7 @@ CondCvtArg(char *str, double *value)
*/
/* coverity:[+alloc : arg-*2] */
static char *
CondGetString(Boolean doEval, Boolean *quoted, void **freeIt)
CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS)
{
Buffer buf;
char *cp;
@ -601,6 +610,16 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt)
condExpr--; /* don't skip over next char */
break;
default:
if (strictLHS && !qt && *start != '$' &&
!isdigit((unsigned char) *start)) {
/* lhs must be quoted, a variable reference or number */
if (*freeIt) {
free(*freeIt);
*freeIt = NULL;
}
str = NULL;
goto cleanup;
}
Buf_AddByte(&buf, *condExpr);
break;
}
@ -648,7 +667,7 @@ compare_expression(Boolean doEval)
* Parse the variable spec and skip over it, saving its
* value in lhs.
*/
lhs = CondGetString(doEval, &lhsQuoted, &lhsFree);
lhs = CondGetString(doEval, &lhsQuoted, &lhsFree, lhsStrict);
if (!lhs)
goto done;
@ -709,7 +728,7 @@ compare_expression(Boolean doEval)
goto done;
}
rhs = CondGetString(doEval, &rhsQuoted, &rhsFree);
rhs = CondGetString(doEval, &rhsQuoted, &rhsFree, FALSE);
if (!rhs)
goto done;
@ -1135,7 +1154,7 @@ CondE(Boolean doEval)
*-----------------------------------------------------------------------
*/
int
Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprint)
Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprint, Boolean strictLHS)
{
static const struct If *dflt_info;
const struct If *sv_if_info = if_info;
@ -1143,6 +1162,8 @@ Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprin
Token sv_condPushBack = condPushBack;
int rval;
lhsStrict = strictLHS;
while (*line == ' ' || *line == '\t')
line++;
@ -1359,7 +1380,7 @@ Cond_Eval(char *line)
}
/* And evaluate the conditional expresssion */
if (Cond_EvalExpression(ifp, line, &value, 1) == COND_INVALID) {
if (Cond_EvalExpression(ifp, line, &value, 1, TRUE) == COND_INVALID) {
/* Syntax error in conditional, error message already output. */
/* Skip everything to matching .endif */
cond_state[cond_depth] = SKIP_TO_ELSE;

View File

@ -2,7 +2,7 @@
# derrived from /etc/rc_d/os.sh
# RCSid:
# $Id: machine.sh,v 1.16 2010/10/17 00:05:51 sjg Exp $
# $Id: machine.sh,v 1.17 2015/05/05 00:10:54 sjg Exp $
#
# @(#) Copyright (c) 1994-2002 Simon J. Gerraty
#
@ -49,6 +49,10 @@ OpenBSD)
arch=`Which arch /usr/bin:/usr/ucb:$PATH`
MACHINE_ARCH=`$arch -s`;
;;
Bitrig)
MACHINE=$OS$OSMAJOR.$machine
MACHINE_ARCH=`uname -m`;
;;
*BSD)
MACHINE=$OS$OSMAJOR.$machine
;;

View File

@ -1,3 +1,9 @@
2015-04-30 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20150430
* dirdeps.mk: fix _count_dirdeps for non-cache case.
2015-04-16 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20150411

View File

@ -1,4 +1,4 @@
# $Id: dirdeps.mk,v 1.49 2015/03/11 21:39:28 sjg Exp $
# $Id: dirdeps.mk,v 1.51 2015/05/06 06:07:30 sjg Exp $
# Copyright (c) 2010-2013, Juniper Networks, Inc.
# All rights reserved.
@ -349,7 +349,7 @@ BUILD_DIRDEPS ?= yes
.if !defined(NO_DIRDEPS)
.if ${MK_DIRDEPS_CACHE} == "yes"
# this is where we will cache all our work
DIRDEPS_CACHE?= ${_OBJDIR}/dirdeps.cache${.TARGETS:Nall:O:u:ts-:S,^,.,:N.}
DIRDEPS_CACHE?= ${_OBJDIR}/dirdeps.cache${.TARGETS:Nall:O:u:ts-:S,/,_,g:S,^,.,:N.}
# just ensure this exists
build-dirdeps:
@ -394,13 +394,14 @@ _count_dirdeps: .NOMETA
@echo '.info $${.newline}$${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]}' >&3
.endif
.endif
.elif !target(_count_dirdeps)
.elif !make(dirdeps) && !target(_count_dirdeps)
beforedirdeps: _count_dirdeps
_count_dirdeps: .NOMETA
@echo "${TRACER}Makefiles read: total=${.MAKE.MAKEFILES:[#]} depend=${.MAKE.MAKEFILES:M*depend*:[#]} dirdeps=${.ALLTARGETS:M${SRCTOP}*:O:u:[#]} seconds=`expr ${now_utc} - ${start_utc}`"
.endif
.endif
.if ${BUILD_DIRDEPS} == "yes"
.if ${DEBUG_DIRDEPS:@x@${DEP_RELDIR:M$x}${${DEP_RELDIR}.${DEP_MACHINE}:L:M$x}@} != ""
_debug_reldir = 1

View File

@ -55,7 +55,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: install-mk,v 1.109 2015/04/16 16:59:00 sjg Exp $
# $Id: install-mk,v 1.110 2015/05/01 06:37:49 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
@ -70,7 +70,7 @@
# sjg@crufty.net
#
MK_VERSION=20150411
MK_VERSION=20150430
OWNER=
GROUP=
MODE=444

View File

@ -1,4 +1,4 @@
/* $NetBSD: nonints.h,v 1.67 2014/09/07 20:55:34 joerg Exp $ */
/* $NetBSD: nonints.h,v 1.68 2015/05/05 21:51:09 sjg Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@ -91,7 +91,7 @@ int Compat_Make(void *, void *);
/* cond.c */
struct If;
int Cond_EvalExpression(const struct If *, char *, Boolean *, int);
int Cond_EvalExpression(const struct If *, char *, Boolean *, int, Boolean);
int Cond_Eval(char *);
void Cond_restore_depth(unsigned int);
unsigned int Cond_save_depth(void);

View File

@ -1,6 +1,6 @@
# $Id: Makefile.in,v 1.46 2014/11/06 01:47:57 sjg Exp $
# $Id: Makefile.in,v 1.47 2015/05/05 21:58:06 sjg Exp $
#
# $NetBSD: Makefile,v 1.51 2014/10/20 23:21:11 sjg Exp $
# $NetBSD: Makefile,v 1.52 2015/05/05 21:51:09 sjg Exp $
#
# Unit tests for make(1)
# The main targets are:
@ -27,6 +27,7 @@ UNIT_TESTS:= ${srcdir}
TESTNAMES= \
comment \
cond1 \
cond2 \
error \
export \
export-all \

7
unit-tests/cond2.exp Normal file
View File

@ -0,0 +1,7 @@
make: Bad conditional expression ` == "empty"' in == "empty"?oops:ok
make: "cond2.mk" line 13: Malformed conditional ({TEST_TYPO} == "Ok")
TEST_NOT_SET is empty or not defined
make: "cond2.mk" line 20: Malformed conditional (${TEST_NOT_SET} == "empty")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

25
unit-tests/cond2.mk Normal file
View File

@ -0,0 +1,25 @@
# $Id: cond2.mk,v 1.1.1.1 2015/05/05 21:53:13 sjg Exp $
TEST_UNAME_S= NetBSD
# this should be ok
X:= ${${TEST_UNAME_S} == "NetBSD":?Ok:fail}
.if $X == "Ok"
Y= good
.endif
# expect: Bad conditional expression ` == "empty"' in == "empty"?oops:ok
X:= ${${TEST_NOT_SET} == "empty":?oops:ok}
# expect: Malformed conditional ({TEST_TYPO} == "Ok")
.if {TEST_TYPO} == "Ok"
Y= oops
.endif
.if empty(TEST_NOT_SET)
Y!= echo TEST_NOT_SET is empty or not defined >&2; echo
.endif
# expect: Malformed conditional (${TEST_NOT_SET} == "empty")
.if ${TEST_NOT_SET} == "empty"
Y= oops
.endif
all:
@echo $@

8
var.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.191 2014/09/14 02:32:51 dholland Exp $ */
/* $NetBSD: var.c,v 1.192 2015/05/05 21:51:09 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: var.c,v 1.191 2014/09/14 02:32:51 dholland Exp $";
static char rcsid[] = "$NetBSD: var.c,v 1.192 2015/05/05 21:51:09 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: var.c,v 1.191 2014/09/14 02:32:51 dholland Exp $");
__RCSID("$NetBSD: var.c,v 1.192 2015/05/05 21:51:09 sjg Exp $");
#endif
#endif /* not lint */
#endif
@ -3260,7 +3260,7 @@ ApplyModifiers(char *nstr, const char *tstr,
termc = *--cp;
delim = '\0';
if (Cond_EvalExpression(NULL, v->name, &value, 0)
if (Cond_EvalExpression(NULL, v->name, &value, 0, FALSE)
== COND_INVALID) {
Error("Bad conditional expression `%s' in %s?%s:%s",
v->name, v->name, pattern.lhs, pattern.rhs);