Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests make: add :mtime to provide mtime of...
details: https://anonhg.NetBSD.org/src/rev/c9c37ec29bc4
branches: trunk
changeset: 374669:c9c37ec29bc4
user: sjg <sjg%NetBSD.org@localhost>
date: Tue May 09 20:14:27 2023 +0000
description:
make: add :mtime to provide mtime of file
The value of the variable is passed to stat(2)
and st_mtime is new value.
An optional arg can be used if stat(2) fails, otherwise
the current time is used.
See varmod-mtime.mk for usage examples.
diffstat:
distrib/sets/lists/tests/mi | 4 ++-
usr.bin/make/make.1 | 16 +++++++++++-
usr.bin/make/unit-tests/Makefile | 3 +-
usr.bin/make/unit-tests/varmod-mtime.exp | 1 +
usr.bin/make/unit-tests/varmod-mtime.mk | 30 ++++++++++++++++++++++++
usr.bin/make/var.c | 39 ++++++++++++++++++++++++++++++-
6 files changed, 87 insertions(+), 6 deletions(-)
diffs (178 lines):
diff -r ebfb0e58fd27 -r c9c37ec29bc4 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Tue May 09 20:02:59 2023 +0000
+++ b/distrib/sets/lists/tests/mi Tue May 09 20:14:27 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1258 2023/04/23 08:47:27 rillig Exp $
+# $NetBSD: mi,v 1.1259 2023/05/09 20:14:28 sjg Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6099,6 +6099,8 @@
./usr/tests/usr.bin/make/unit-tests/varmod-match-escape.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-match.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-match.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-mtime.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-mtime.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-no-match.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-no-match.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-order-numeric.exp tests-usr.bin-tests compattestfile,atf
diff -r ebfb0e58fd27 -r c9c37ec29bc4 usr.bin/make/make.1
--- a/usr.bin/make/make.1 Tue May 09 20:02:59 2023 +0000
+++ b/usr.bin/make/make.1 Tue May 09 20:14:27 2023 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: make.1,v 1.363 2023/05/07 16:43:50 sjg Exp $
+.\" $NetBSD: make.1,v 1.364 2023/05/09 20:14:27 sjg Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
-.Dd May 6, 2023
+.Dd May 9, 2023
.Dt MAKE 1
.Os
.Sh NAME
@@ -1510,6 +1510,18 @@ producing the formatted timestamp.
If a
.Ar timestamp
value is not provided or is 0, the current time is used.
+.It Cm \&:mtime Ns Oo Cm = Ns Ar timestamp Oc
+call
+.Xr stat 2
+with the value as pathname;
+use
+.Ql st_mtime
+as the new value.
+If
+.Xr stat 2
+fails; use
+.Ar timestamp
+or current time.
.It Cm \&:tA
Attempts to convert the value to an absolute path using
.Xr realpath 3 .
diff -r ebfb0e58fd27 -r c9c37ec29bc4 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile Tue May 09 20:02:59 2023 +0000
+++ b/usr.bin/make/unit-tests/Makefile Tue May 09 20:14:27 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.333 2023/02/25 19:30:32 sjg Exp $
+# $NetBSD: Makefile,v 1.334 2023/05/09 20:14:27 sjg Exp $
#
# Unit tests for make(1)
#
@@ -374,6 +374,7 @@ TESTS+= varmod-loop-delete
TESTS+= varmod-loop-varname
TESTS+= varmod-match
TESTS+= varmod-match-escape
+TESTS+= varmod-mtime
TESTS+= varmod-no-match
TESTS+= varmod-order
TESTS+= varmod-order-numeric
diff -r ebfb0e58fd27 -r c9c37ec29bc4 usr.bin/make/unit-tests/varmod-mtime.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-mtime.exp Tue May 09 20:14:27 2023 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r ebfb0e58fd27 -r c9c37ec29bc4 usr.bin/make/unit-tests/varmod-mtime.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-mtime.mk Tue May 09 20:14:27 2023 +0000
@@ -0,0 +1,30 @@
+# $NetBSD: varmod-mtime.mk,v 1.1 2023/05/09 20:14:27 sjg Exp $
+#
+# Tests for the :mtime variable modifier, which provides mtime
+# of variable value assumed to be a pathname.
+
+all:
+
+# mtime of this makefile
+mtime:= ${MAKEFILE:mtime}
+
+# if pathname does not exist and timestamp is provided
+# that is the result
+.if ${no/such:L:mtime=0} != "0"
+. error
+.endif
+
+.if ${no/such:L:mtime=42} != "42"
+. error
+.endif
+
+# if no timestamp is provided and stat(2) fails use current time
+.if ${no/such:L:mtime} < ${mtime}
+. error no/such:L:mtime ${no/such:L:mtime} < ${mtime}
+.endif
+
+COOKIE = ${TMPDIR}/varmod-mtime.cookie
+x!= touch ${COOKIE}
+.if ${COOKIE:mtime=0} < ${mtime}
+. error COOKIE:mtime=0 ${COOKIE:mtime=0} < ${mtime}
+.endif
diff -r ebfb0e58fd27 -r c9c37ec29bc4 usr.bin/make/var.c
--- a/usr.bin/make/var.c Tue May 09 20:02:59 2023 +0000
+++ b/usr.bin/make/var.c Tue May 09 20:14:27 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1050 2023/05/09 16:26:59 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1051 2023/05/09 20:14:27 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1050 2023/05/09 16:26:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1051 2023/05/09 20:14:27 sjg Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -2833,6 +2833,39 @@ ApplyModifier_Match(const char **pp, Mod
return AMR_OK;
}
+/* :mtime */
+static ApplyModifierResult
+ApplyModifier_Mtime(const char **pp, ModChain *ch)
+{
+ char buf[BUFSIZ];
+ Expr *expr = ch->expr;
+ const char *args, *mod = *pp;
+ struct stat st;
+ int i = -1;
+
+ if (!ModMatchEq(mod, "mtime", ch))
+ return AMR_UNKNOWN;
+ *pp += 5;
+ args = *pp;
+ if (args[0] == '=') {
+ args++;
+ if (!TryParseIntBase0(&args, &i))
+ return AMR_BAD;
+ *pp = args;
+ }
+ if (!ModChain_ShouldEval(ch))
+ return AMR_OK;
+ if (stat(Expr_Str(expr), &st) < 0) {
+ if (i < 0)
+ time(&st.st_mtime);
+ else
+ st.st_mtime = (time_t)i;
+ }
+ snprintf(buf, sizeof(buf), "%u", (unsigned)st.st_mtime);
+ Expr_SetValueOwn(expr, bmake_strdup(buf));
+ return AMR_OK;
+}
+
static void
ParsePatternFlags(const char **pp, PatternFlags *pflags, bool *oneBigWord)
{
@@ -3815,6 +3848,8 @@ ApplyModifier(const char **pp, ModChain
case 'M':
case 'N':
return ApplyModifier_Match(pp, ch);
+ case 'm':
+ return ApplyModifier_Mtime(pp, ch);
case 'O':
return ApplyModifier_Order(pp, ch);
case 'P':
Home |
Main Index |
Thread Index |
Old Index