automake-patches
[Top][All Lists]
Advanced

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

Re: avoid a 1-second sleep in every configure script


From: Jim Meyering
Subject: Re: avoid a 1-second sleep in every configure script
Date: Fri, 14 Aug 2009 09:33:11 +0200

Ralf Wildenhues wrote:
> * Jim Meyering wrote on Thu, Jul 30, 2009 at 04:20:52PM CEST:
>> I noticed (by inspection, since I was looking at AM_SANITY_CHECK)
>> the unconditional 1-second sleep in coreutils' configure script,
>> and realized that it'd be easy to avoid it on modern systems:
>> either because configure was created more than a second before,
>> or because the file system supports subsecond time stamps.
>
>> I deliberately chose not to use ls, because parsing
>> its output is not worth the trouble.
>
> Could that bring any more portability though?  IOW, is there a portable
> (not limited to coreutils) way to get at subsecond time stamps?

Hi Ralf,

Thanks for the review.

You can get subsecond time stamps via GNU ls' --full-time option,
but if you have that version of ls, you probably also have coreutils'
stat program.  If you really want to go for it, Perl is probably the
most portable tool.  I haven't tried.  After all, it's just 1 second,
and not worth the added complexity.

...
>> +am_sanity_d1=`stat --format=%y conftest.file 2>/dev/null` || am_sleep=1
>> +am_sanity_d2=`stat --format=%y "$srcdir/configure" 2>/dev/null` || 
>> am_sleep=1
>
> 'info Autoconf Assignments' tells me that I shouldn't rely upon the exit
> status of an assignment, due to some arcane shells.  IIUC then this

Good catch.  So let's cater also to those um, arcane, shells ;-)
Updated patch that does not rely on that, below.

> should not cause a semantic change here; but that is a bit non obvious,
> and makes me wonder why you need the am_sleep=1 case at all.
>
> The other very very minor issue is that this forks twice more also on
> slow-fork non-GNU systems, where it then also sleeps.  We can probably
> ignore this.

I agree.  Consider that part of the sleep penalty.

>From 3cb8feacb35d9a547fb5bf36ce1feab706aff063 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 30 Jul 2009 15:55:04 +0200
Subject: [PATCH] AM_SANITY_CHECK: avoid a 1-second sleep, if possible

* m4/sanity.m4 (AM_SANITY_CHECK): Use stat to compare timestamps.
Perform the 1-second sleep only if necessary.
---
 ChangeLog    |    6 ++++++
 m4/sanity.m4 |   24 ++++++++++++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bab1dcb..f8c392e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-07-30  Jim Meyering  <address@hidden>
+
+       AM_SANITY_CHECK: avoid a 1-second sleep, if possible
+       * m4/sanity.m4 (AM_SANITY_CHECK): Use stat to compare timestamps.
+       Perform the 1-second sleep only if necessary.
+
 2009-07-08  Jim Meyering  <address@hidden>

        manual: fix a trivial grammar error.
diff --git a/m4/sanity.m4 b/m4/sanity.m4
index 3d2f304..a16162e 100644
--- a/m4/sanity.m4
+++ b/m4/sanity.m4
@@ -1,21 +1,37 @@
 # Check to make sure that the build environment is sane.    -*- Autoconf -*-

-# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008, 2009
 # Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.

-# serial 5
+# serial 6

 # AM_SANITY_CHECK
 # ---------------
 AC_DEFUN([AM_SANITY_CHECK],
 [AC_MSG_CHECKING([whether build environment is sane])
-# Just in case
-sleep 1
+# We want conftest.file to have an mtime newer than configure.
+# On some file systems we may have to sleep a second to ensure that.
+# On others, with subsecond timestamp resolution, there is no need.
+# Sleep only if a stat invocation produces no output, or if the
+# time stamps are identical.
 echo timestamp > conftest.file
+am_sleep=1
+am_sanity_d1=`stat --format=%y       conftest.file 2>/dev/null`
+am_sanity_d2=`stat --format=%y "$srcdir/configure" 2>/dev/null`
+test -n "$am_sanity_d1"                                \
+  && test -n "$am_sanity_d2"                   \
+  && test "$am_sanity_d1" != "$am_sanity_d2"   \
+  && am_sleep=0
+
+if test $am_sleep = 1; then
+   sleep 1
+   echo timestamp > conftest.file
+fi
+
 # Reject unsafe characters in $srcdir or the absolute working directory
 # name.  Accept space and tab only in the latter.
 am_lf='
--
1.6.4.174.gc193a




reply via email to

[Prev in Thread] Current Thread [Next in Thread]