Debian Codegraph @

mesonbuild/scripts/regen_checker.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2015-2016 The Meson development team
3
4 from __future__ import annotations
5
6 import sys, os
7 import pickle, subprocess
8 import typing as T
9 from ..coredata import CoreData
10 from ..backend.backends import RegenInfo
11 from ..options import OptionKey
12
13 # This could also be used for XCode.
14
15 def need_regen(regeninfo: RegenInfo, regen_timestamp: float) -> bool:
16 for i in regeninfo.depfiles:
17 curfile = os.path.join(regeninfo.build_dir, i)
18 curtime = os.stat(curfile).st_mtime
19 if curtime > regen_timestamp:
20 return True
21 # The timestamp file gets automatically deleted by MSBuild during a 'Clean' build.
22 # We must make sure to recreate it, even if we do not regenerate the solution.
23 # Otherwise, Visual Studio will always consider the REGEN project out of date.
24 print("Everything is up-to-date, regeneration of build files is not needed.")
25 from ..backend.vs2010backend import Vs2010Backend
26 Vs2010Backend.touch_regen_timestamp(regeninfo.build_dir)
27 return False
28
29 def regen(regeninfo: RegenInfo, meson_command: T.List[str], backend: str) -> None:
30 cmd = meson_command + ['--internal',
31 'regenerate',
32 regeninfo.build_dir,
33 regeninfo.source_dir,
34 '--backend=' + backend]
35 subprocess.check_call(cmd)
36
37 def run(args: T.List[str]) -> int:
38 private_dir = args[0]
39 dumpfile = os.path.join(private_dir, 'regeninfo.dump')
40 coredata_file = os.path.join(private_dir, 'coredata.dat')
41 with open(dumpfile, 'rb') as f:
42 regeninfo = pickle.load(f)
43 assert isinstance(regeninfo, RegenInfo)
44 with open(coredata_file, 'rb') as f:
45 coredata = pickle.load(f)
46 assert isinstance(coredata, CoreData)
47 backend = coredata.optstore.get_value_for(OptionKey('backend'))
48 assert isinstance(backend, str)
49 regen_timestamp = os.stat(dumpfile).st_mtime
50 if need_regen(regeninfo, regen_timestamp):
51 regen(regeninfo, coredata.meson_command, backend)
52 return 0
53
54 if __name__ == '__main__':
55 sys.exit(run(sys.argv[1:]))