OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 Google Inc. All rights reserved. | 2 # Copyright (c) 2011 Google Inc. 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 """These functions are executed via gyp-flock-tool when using the Makefile | 6 """These functions are executed via gyp-flock-tool when using the Makefile |
7 generator. Used on systems that don't have a built-in flock.""" | 7 generator. Used on systems that don't have a built-in flock.""" |
8 | 8 |
9 import fcntl | 9 import fcntl |
10 import os | 10 import os |
(...skipping 21 matching lines...) Expand all Loading... |
32 """Transforms a tool name like copy-info-plist to CopyInfoPlist""" | 32 """Transforms a tool name like copy-info-plist to CopyInfoPlist""" |
33 return name_string.title().replace('-', '') | 33 return name_string.title().replace('-', '') |
34 | 34 |
35 def ExecFlock(self, lockfile, *cmd_list): | 35 def ExecFlock(self, lockfile, *cmd_list): |
36 """Emulates the most basic behavior of Linux's flock(1).""" | 36 """Emulates the most basic behavior of Linux's flock(1).""" |
37 # Rely on exception handling to report errors. | 37 # Rely on exception handling to report errors. |
38 # Note that the stock python on SunOS has a bug | 38 # Note that the stock python on SunOS has a bug |
39 # where fcntl.flock(fd, LOCK_EX) always fails | 39 # where fcntl.flock(fd, LOCK_EX) always fails |
40 # with EBADF, that's why we use this F_SETLK | 40 # with EBADF, that's why we use this F_SETLK |
41 # hack instead. | 41 # hack instead. |
42 fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0666) | 42 fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0o666) |
43 if sys.platform.startswith('aix'): | 43 if sys.platform.startswith('aix'): |
44 # Python on AIX is compiled with LARGEFILE support, which changes the | 44 # Python on AIX is compiled with LARGEFILE support, which changes the |
45 # struct size. | 45 # struct size. |
46 op = struct.pack('hhIllqq', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) | 46 op = struct.pack('hhIllqq', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) |
47 else: | 47 else: |
48 op = struct.pack('hhllhhl', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) | 48 op = struct.pack('hhllhhl', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) |
49 fcntl.fcntl(fd, fcntl.F_SETLK, op) | 49 fcntl.fcntl(fd, fcntl.F_SETLK, op) |
50 return subprocess.call(cmd_list) | 50 return subprocess.call(cmd_list) |
51 | 51 |
52 | 52 |
53 if __name__ == '__main__': | 53 if __name__ == '__main__': |
54 sys.exit(main(sys.argv[1:])) | 54 sys.exit(main(sys.argv[1:])) |
OLD | NEW |