1#!/usr/bin/env python 2 3import glob 4import os 5import re 6import sys 7 8 9# It's fragile to rely on the location of this script to find the top-level 10# source directory. 11TOP_LEVEL_DIRECTORY = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) 12WEBKIT_LIBRARIES = os.environ['WEBKIT_LIBRARIES']; 13 14def main(): 15 react_to_vsprops_changes() 16 react_to_webkit1_interface_changes() 17 18 19def react_to_vsprops_changes(): 20 vsprops_directory = os.path.join(WEBKIT_LIBRARIES, 'tools', 'vsprops') 21 newest_vsprops_time = mtime_of_newest_file_matching_glob(os.path.join(vsprops_directory, '*.props')) 22 23 obj_directory = os.path.join(os.environ['CONFIGURATIONBUILDDIR'], 'obj32') 24 25 # Visual Studio isn't smart enough to figure out it needs to rebuild these file types when 26 # .vsprops files change (even if we touch wtf/Platform.h below), so we delete them to force them 27 # to be rebuilt. 28 for extension in ('dep', 'manifest', 'pch', 'res'): 29 for filepath in glob.iglob(os.path.join(obj_directory, '*', '*.%s' % extension)): 30 delete_if_older_than(filepath, newest_vsprops_time) 31 32 # Touch wtf/Platform.h so all files will be recompiled. This is necessary 33 # to pick up changes to preprocessor macros (e.g., ENABLE_*). 34 wtf_platform_h = os.path.join(TOP_LEVEL_DIRECTORY, 'Source', 'WTF', 'wtf', 'Platform.h') 35 touch_if_older_than(wtf_platform_h, newest_vsprops_time) 36 37 38def react_to_webkit1_interface_changes(): 39 interfaces_directory = os.path.join(TOP_LEVEL_DIRECTORY, 'Source', 'WebKit', 'win', 'Interfaces') 40 newest_idl_time = mtime_of_newest_file_matching_glob(os.path.join(interfaces_directory, '*.idl')) 41 # WebKit.idl includes all the other IDL files, so needs to be rebuilt if any IDL file changes. 42 # But Visual Studio isn't smart enough to figure this out, so we touch WebKit.idl to ensure that 43 # it gets rebuilt. 44 touch_if_older_than(os.path.join(interfaces_directory, 'WebKit.idl'), newest_idl_time) 45 46 47def mtime_of_newest_file_matching_glob(glob_pattern): 48 files = glob.glob(glob_pattern) 49 assert len(files), "Couldn't find any files matching glob %s" % glob_pattern 50 return max(map(os.path.getmtime, files)) 51 52 53def delete_if_older_than(path, reference_time): 54 if os.path.getmtime(path) < reference_time: 55 print 'Deleting %s' % path 56 os.remove(path) 57 58 59def touch_if_older_than(path, reference_time): 60 if os.path.getmtime(path) < reference_time: 61 print 'Touching %s' % path 62 os.utime(path, None) 63 64 65if __name__ == '__main__': 66 sys.exit(main()) 67