Dump coredata earlier.

Unfortunately, `time.time` and file timestamps are not guaranteed to be
in sync and due to various kernel caches may be different enough to
cause rebuilds to fail [1]. This was masked by older ninja versions that
could not read sub-second timestamps.

[1] https://travis-ci.org/mesonbuild/meson/jobs/296797872
pull/2589/head
Elliott Sales de Andrade 7 years ago committed by Jussi Pakkanen
parent c647db96d5
commit 6715087598
  1. 3
      mesonbuild/environment.py
  2. 28
      mesonbuild/mesonmain.py

@ -349,10 +349,9 @@ class Environment:
def is_cross_build(self):
return self.cross_info is not None
def dump_coredata(self, mtime):
def dump_coredata(self):
cdf = os.path.join(self.get_build_dir(), Environment.coredata_file)
coredata.save(self.coredata, cdf)
os.utime(cdf, times=(mtime, mtime))
return cdf
def get_script_dir(self):

@ -193,23 +193,19 @@ class MesonApp:
mlog.log('Build machine cpu family:', mlog.bold(intr.builtin['build_machine'].cpu_family_method([], {})))
mlog.log('Build machine cpu:', mlog.bold(intr.builtin['build_machine'].cpu_method([], {})))
intr.run()
coredata_mtime = time.time()
g.generate(intr)
dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat')
with open(dumpfile, 'wb') as f:
pickle.dump(b, f)
# Write this as late as possible since we use the existence of this
# file to check if we generated the build file successfully, so we
# don't want an error that pops up during generation, etc to cause us to
# incorrectly signal a successful meson run which will cause an error
# about an already-configured build directory when the user tries again.
#
# However, we set the mtime to an earlier value to ensure that doing an
# mtime comparison between the coredata dump and other build files
# shows the build files to be newer, not older.
cdf = env.dump_coredata(coredata_mtime)
# Post-conf scripts must be run after writing coredata or else introspection fails.
try:
# We would like to write coredata as late as possible since we use the existence of
# this file to check if we generated the build file successfully. Since coredata
# includes settings, the build files must depend on it and appear newer. However, due
# to various kernel caches, we cannot guarantee that any time in Python is exactly in
# sync with the time that gets applied to any files. Thus, we dump this file as late as
# possible, but before build files, and if any error occurs, delete it.
cdf = env.dump_coredata()
g.generate(intr)
dumpfile = os.path.join(env.get_scratch_dir(), 'build.dat')
with open(dumpfile, 'wb') as f:
pickle.dump(b, f)
# Post-conf scripts must be run after writing coredata or else introspection fails.
g.run_postconf_scripts()
except:
os.unlink(cdf)

Loading…
Cancel
Save