forked from RedBeard0531/mongo_module_ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch_compiler_timestamps.py
41 lines (33 loc) · 1.33 KB
/
touch_compiler_timestamps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import os
import math
def createIfNeeded(path):
if not os.path.exists(path):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
open(path, 'w').close()
def run_if_needed(base_file, then_file, now_file):
# Python uses doubles for mtime so it can't precisely represent linux's
# nanosecond precision. Round up to next whole second to ensure we get a
# stable timestamp that is guaranteed to be >= the timestamp of the
# compiler. This also avoids issues if the compiler is on a file system
# with high-precision timestamps, but the build directory isn't.
base_stat = os.stat(base_file)
mtime = math.ceil(base_stat.st_mtime)
atime = math.ceil(base_stat.st_atime)
if (os.path.exists(then_file)
and os.path.exists(now_file)
and os.stat(then_file).st_mtime == mtime):
return # Don't need to do anything.
createIfNeeded(now_file)
os.utime(now_file, None) # None means now
createIfNeeded(then_file)
os.utime(then_file, (atime, mtime))
if __name__ == '__main__':
if len(sys.argv) != 4:
print((sys.argv[0] + ': base_file then_file now_file'))
sys.exit(1)
base_file = sys.argv[1]
then_file = sys.argv[2]
now_file = sys.argv[3]
run_if_needed(base_file, then_file, now_file)