-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathupdate-dependencies.py
executable file
·42 lines (34 loc) · 1.36 KB
/
update-dependencies.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
41
42
#!/usr/bin/env python2
# update-dependencies.py simulates a Swift compilation for the purposes of
# dependency analysis. That means it has two tasks:
#
# 1. Update the main output of the compilation job.
# 2. Update the associated dependencies file, in case anything changed.
#
# Since we only care about the timestamp of the output, the script just makes
# sure the file's mtime is set to $NOW, creating it if it doesn't exist.
# We don't actually care about the content of the input file, either, so we
# actually stick *the new dependencies* in the input file, and copy that over
# the old dependencies (if present).
#
# If invoked in non-primary-file mode, it only creates the output file.
import os
import shutil
import sys
assert sys.argv[1] == '-frontend'
if '-primary-file' in sys.argv:
primaryFile = sys.argv[sys.argv.index('-primary-file') + 1]
depsFile = sys.argv[sys.argv.index('-emit-reference-dependencies-path') + 1]
# Replace the dependencies file with the input file.
shutil.copyfile(primaryFile, depsFile)
else:
primaryFile = None
outputFile = sys.argv[sys.argv.index('-o') + 1]
# Update the output file mtime, or create it if necessary.
# From http://stackoverflow.com/a/1160227.
with open(outputFile, 'a'):
os.utime(outputFile, None)
if primaryFile:
print "Handled", os.path.basename(primaryFile)
else:
print "Produced", os.path.basename(outputFile)