initial import
[vuplus_webkit] / Source / JavaScriptCore / JavaScriptCore.vcproj / JavaScriptCore / work-around-vs-dependency-tracking-bugs.py
1 #!/usr/bin/env python
2
3 import glob
4 import os
5 import re
6 import sys
7
8
9 # It's fragile to rely on the location of this script to find the top-level
10 # source directory.
11 TOP_LEVEL_DIRECTORY = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
12
13
14 def main():
15     react_to_vsprops_changes()
16     react_to_webkit1_interface_changes()
17
18
19 def react_to_vsprops_changes():
20     vsprops_directory = os.path.join(TOP_LEVEL_DIRECTORY, 'WebKitLibraries', 'win', 'tools', 'vsprops')
21     newest_vsprops_time = mtime_of_newest_file_matching_glob(os.path.join(vsprops_directory, '*.vsprops'))
22
23     obj_directory = os.path.join(os.environ['CONFIGURATIONBUILDDIR'], 'obj')
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', 'JavaScriptCore', 'wtf', 'Platform.h')
35     touch_if_older_than(wtf_platform_h, newest_vsprops_time)
36
37
38 def 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
47 def 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
53 def 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
59 def 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
65 if __name__ == '__main__':
66     sys.exit(main())