#!/bin/sh

# This script is for the use with 'start_test' as the system-wide preexec, when
# network time-sync problems (or similar) cause file modification times to look
# wrong to gmake.

# This typically occurs when a remote-mounted NFS file system is used as a workspace.
# It has also been observed less frequently on VMs, even when using a local vdisk.

# In either case, it is not unusual to see lines like these in chpl compiler output:
#
# gmake: Warning: File `.../something' has modification time 0.01 s in the future
# gmake: warning:  Clock skew detected.  Your build may be incomplete.

# This preexec file removes such lines, so that they will not generate false test
# errors in start_test.

# To use this preexec file with start_test (assuming bash):
#
# export CHPL_SYSTEM_PREEXEC=$CHPL_HOME/util/test/preexec-for-gmake-clock-skew-warning
# start_test ...

outfile=$2
temp=$outfile.temp

if [ -s "$outfile" ]; then
    grep < $outfile > $temp -v \
        -e '^g*make\(\[[0-9]*\]\)*: Warning: File .* has modification time .* in the future *$' \
        -e '^g*make\(\[[0-9]*\]\)*: warning:  Clock skew detected\.  Your build may be incomplete\. *$'
    mv $temp $outfile
fi
