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