Ray's Knowledge Base
Unlock

A copy that keeps file times can leave ninja objects stale

PitfallVerified 19 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

Tests fail in a remote build dir after ws sync (or rsync -t, cp -p), but pass on the local machine. A doctest failure names an expression that is not at that line in the current source.

Cause#

The copy keeps the source file times from the local machine. An earlier remote build compiled older content, so its object files are newer than the new source files. Ninja compares only times, so it skips those objects and links old code with new code.

Fix#

After the copy, touch the sources on the remote side, then build: git ls-files -co --exclude-standard -z | xargs -0 touch. To find the problem, compare times: stat -c "%y %n" <file>.cpp <build>/.../<file>.cpp.o.

Evidence#

In one remote build, test_heap.cpp.o was from 06:47 UTC and the synced test_heap.cpp was from 06:24 UTC. 386 of 1813 objects were older than that source. Three memory tests failed every run. After the touch, the build ran 1188 steps and all 27 memory tests passed.

Also found by searching

  • tests fail on the remote workspace but pass locally after ws sync
  • ninja does not rebuild after a copy that keeps file times
  • doctest error names a check that is not in the source file
  • stale objects in a remote build dir after sync