Re: improved timestamp resolution test (was: 1.16.90 regression: configure now takes 7 seconds to start)

Jacob Bachmeyer <[email protected]> Wed, 12 Jun 2024 23:31:27 -0500
Newsgroups gmane.comp.sysutils.automake.general
Message-ID <[email protected]>
Karl Berry wrote:
>     Does BSD ls(1) support "--time=ctime --time-style=full-iso"?  
>
> BSD ls does not support any --longopts. Looking at the man page,
> I don't see "millisecond" or "subsecond" etc. mentioned, though I could
> easily be missing it. E.g.,
>   https://man.freebsd.org/cgi/man.cgi?ls
>
> Even if there is such an option, I am skeptical of how portable it would
> be, or trying to discern whether it is really working or not. All the
> evidence so far is that it is very difficult to determine whether
> subsecond mtimes are sufficiently supported or not. Speaking in general,
> I don't think trying to get into system-specific behaviors, of whatever
> kind, is going to help.

[*sigh*]

It seems that there is no good way for configure to read timestamps, so 
we are limited to testing if file ages are distinguishable.

Still, could we use make(1) for *all* of the testing and not use `ls -t` 
at all?  A rough outline would be something like:  (lightly tested; runs 
in about 2.2s here)

8<------
# The case below depends on the 1/10 + 9/10 = 10/10 pattern.
am_try_resolutions="0.01 0.09 0.1 0.9 1"
echo '#' > conftest.mk
i=0
for am_try_res in $am_try_resolutions; do
  echo ts${i} > conftest.ts${i}
  sleep $am_try_res
  echo "conftest.ts${i}: conftest.ts"`expr 1 + $i` >> conftest.mk
  echo "	echo $am_try_res" >> conftest.mk
  i=`expr 1 + $i`
done
echo end > conftest.ts${i}
# This guess can be one step too fast, if the shorter delay just
#  happened to span a clock tick boundary.
am_resolution_guess=`make -f conftest.mk conftest.ts0 | tail -1`
case $am_resolution_guess in
  *9)
    i=no
    for am_try_res in $am_try_resolutions; do
      if test x$i = xyes; then
	am_resolution=$am_try_res
	break
      fi
      test x$am_try_res = x$am_resolution_guess && i=yes
    done
  ;;
  *)
    am_resolution=$am_resolution_guess
  ;;
esac
8<------


The trick is that the various options form a dependency chain, but the 
command make will execute does /not/ actually touch the target, so it 
stops when the files are no longer distinguishable.  This distinguishes 
between a tmpfs (which has nanosecond resolution here) and /home (which 
is an older filesystem with only 1-second resolution).  I am not sure 
what it does with FAT yet.  There should be some way to use 0.1+0.9+1 = 
2 and 0.01+0.09+0.1+0.9+1 > 2 to check for that (accurately!) without 
further sleeps.


-- Jacob