Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: build/symlink.py

Issue 2344243002: Add work-around to symlink.gni to avoid "not up-to-date" ninja errors (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/symlink.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Make a symlink and optionally touch a file (to handle dependencies). 6 """Make a symlink and optionally touch a file (to handle dependencies).
7 7
8 Usage: 8 Usage:
9 symlink.py [options] sources... target 9 symlink.py [options] sources... target
10 10
11 A sym link to source is created at target. If multiple sources are specfied, 11 A sym link to source is created at target. If multiple sources are specfied,
12 then target is assumed to be a directory, and will contain all the links to 12 then target is assumed to be a directory, and will contain all the links to
13 the sources (basenames identical to their source). 13 the sources (basenames identical to their source).
14 """ 14 """
15 15
16 import errno 16 import errno
17 import optparse 17 import optparse
18 import os.path 18 import os.path
19 import shutil 19 import shutil
20 import sys 20 import sys
21 21
22 22
23 def Main(argv): 23 def Main(argv):
24 parser = optparse.OptionParser() 24 parser = optparse.OptionParser()
25 parser.add_option('-f', '--force', action='store_true') 25 parser.add_option('-f', '--force', action='store_true')
26 parser.add_option('--touch') 26 parser.add_option('--touch')
27 parser.add_option('--update-target-mtimes', action='store_true')
27 28
28 options, args = parser.parse_args(argv[1:]) 29 options, args = parser.parse_args(argv[1:])
29 if len(args) < 2: 30 if len(args) < 2:
30 parser.error('at least two arguments required.') 31 parser.error('at least two arguments required.')
31 32
32 target = args[-1] 33 target = args[-1]
33 sources = args[:-1] 34 sources = args[:-1]
34 for s in sources: 35 for s in sources:
35 t = os.path.join(target, os.path.basename(s)) 36 t = os.path.join(target, os.path.basename(s))
36 if len(sources) == 1 and not os.path.isdir(target): 37 if len(sources) == 1 and not os.path.isdir(target):
37 t = target 38 t = target
38 t = os.path.expanduser(t) 39 t = os.path.expanduser(t)
39 if os.path.realpath(t) == s: 40 if os.path.realpath(t) == s:
40 continue 41 continue
41 try: 42 try:
42 os.symlink(s, t) 43 os.symlink(s, t)
43 except OSError, e: 44 except OSError, e:
44 if e.errno == errno.EEXIST and options.force: 45 if e.errno == errno.EEXIST and options.force:
45 if os.path.isdir(t): 46 if os.path.isdir(t):
46 shutil.rmtree(t, ignore_errors=True) 47 shutil.rmtree(t, ignore_errors=True)
47 else: 48 else:
48 os.remove(t) 49 os.remove(t)
49 os.symlink(s, t) 50 os.symlink(s, t)
50 else: 51 else:
51 raise 52 raise
53 if options.update_target_mtimes:
54 # Work-around for ninja bug:
55 # https://github.com/ninja-build/ninja/issues/1186
56 os.utime(s, None)
Jackie Quinn 2016/09/20 22:09:52 Should this be os.utime(t, None) rather than s? Th
52 57
53 58
54 if options.touch: 59 if options.touch:
55 with open(options.touch, 'w') as f: 60 with open(options.touch, 'w') as f:
56 pass 61 pass
57 62
58 63
59 if __name__ == '__main__': 64 if __name__ == '__main__':
60 sys.exit(Main(sys.argv)) 65 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « build/symlink.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698