[cmake-developers] Time truncation bug in cmake -E touch

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu May 30 08:26:46 EDT 2013


To illustrate the problem on Linux:

wine at raven> touch test1; cmake -E touch test2; touch test3
wine at raven> ls -lrt --time-style=full-iso test[123]
-rw-r--r-- 1 wine wine 0 2013-05-30 04:18:25.000000000 -0700 test2
-rw-r--r-- 1 wine wine 0 2013-05-30 04:18:25.761281846 -0700 test1
-rw-r--r-- 1 wine wine 0 2013-05-30 04:18:25.765281683 -0700 test3

Note the time on test2 generated by cmake -E touch has been truncated to the nearest second so
it is not in the correct time order compared to test1 and test3.
I checked that both CMake-2.8.10.2 and CMake-2.8.0 had this issue
so it appears this is a bug that has been around for a while.

It turns out the problem is in kwsys/SystemTools.cxx where utime is
used to update the file access and modification times.  Turns out
utime is obsolete and is only good to nearest second which is the
source of the "cmake -E touch" problem.  The library function utimes
should be used instead.

According to the man page

utime conforms to SVr4, POSIX.1-2001 while utimes conforms to 4.3BSD,
POSIX.1-2001.  So I don't think access to utimes will be an issue on
Unix.  According to http://www.mkssoftware.com/docs/man3/utimes.3.asp
it is available for Microsoft Windows as well (at least for
the NTFS filesystem).

Any chance for a quick fix without going through bug triage?

Errors of a second can be serious since they allow lots to happen out of order in Makefiles such
as the ExternalProject_Add_Step issue I discussed recently on the cmake list.

In particular this bug makes the ExternalProject_Add_Step problematic
when combined with add_custom_command OUTPUT results that are accessed
by the DEPENDS since those OUTPUT results are created with the correct untruncated
times and the timestamps are created by cmake -E touch (i.e., with
truncated times as above) which are out of order relative to the OUTPUT
results.  This ends up generating unnecessary builds.

ExternalProject_Add also systematically uses truncated time stamps
which means two different steps can have the same time for the
time stamp files.  Which will likely also lead to unnecessary rebuilds
if a step requires significantly less than a second to complete.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________



More information about the cmake-developers mailing list