regen_checker.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2015-2016 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import sys, os
  12. import pickle, subprocess
  13. # This could also be used for XCode.
  14. def need_regen(regeninfo, regen_timestamp):
  15. for i in regeninfo.depfiles:
  16. curfile = os.path.join(regeninfo.build_dir, i)
  17. curtime = os.stat(curfile).st_mtime
  18. if curtime > regen_timestamp:
  19. return True
  20. # The timestamp file gets automatically deleted by MSBuild during a 'Clean' build.
  21. # We must make sure to recreate it, even if we do not regenerate the solution.
  22. # Otherwise, Visual Studio will always consider the REGEN project out of date.
  23. print("Everything is up-to-date, regeneration of build files is not needed.")
  24. from ..backend.vs2010backend import Vs2010Backend
  25. Vs2010Backend.touch_regen_timestamp(regeninfo.build_dir)
  26. return False
  27. def regen(regeninfo, meson_command, backend):
  28. cmd = meson_command + ['--internal',
  29. 'regenerate',
  30. regeninfo.build_dir,
  31. regeninfo.source_dir,
  32. '--backend=' + backend]
  33. subprocess.check_call(cmd)
  34. def run(args):
  35. private_dir = args[0]
  36. dumpfile = os.path.join(private_dir, 'regeninfo.dump')
  37. coredata = os.path.join(private_dir, 'coredata.dat')
  38. with open(dumpfile, 'rb') as f:
  39. regeninfo = pickle.load(f)
  40. with open(coredata, 'rb') as f:
  41. coredata = pickle.load(f)
  42. backend = coredata.get_builtin_option('backend')
  43. regen_timestamp = os.stat(dumpfile).st_mtime
  44. if need_regen(regeninfo, regen_timestamp):
  45. regen(regeninfo, coredata.meson_command, backend)
  46. sys.exit(0)
  47. if __name__ == '__main__':
  48. run(sys.argv[1:])