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

Unified Diff: pylib/gyp/win_tool.py

Issue 10837168: Use flock-style lock on Windows to limit number of concurrent links (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/win_tool.py
===================================================================
--- pylib/gyp/win_tool.py (revision 1462)
+++ pylib/gyp/win_tool.py (working copy)
@@ -13,6 +13,9 @@
import shutil
import subprocess
import sys
+import win32con
+import win32file
+import pywintypes
def main(args):
@@ -22,6 +25,22 @@
sys.exit(exit_code)
+class LinkLock(object):
+ """A flock-style lock to limit the number of concurrent links to one. Based on
+ http://code.activestate.com/recipes/65203-portalocker-cross-platform-posixnt-api-for-flock-s/
+ """
+ def __enter__(self):
+ self.file = open('LinkLock', 'w+')
+ self.file_handle = win32file._get_osfhandle(self.file.fileno())
+ win32file.LockFileEx(self.file_handle, win32con.LOCKFILE_EXCLUSIVE_LOCK,
+ 0, -0x10000, pywintypes.OVERLAPPED())
+
+ def __exit__(self, type, value, traceback):
+ win32file.UnlockFileEx(
+ self.file_handle, 0, -0x10000, pywintypes.OVERLAPPED())
+ self.file.close()
+
+
class WinTool(object):
"""This class performs all the Windows tooling steps. The methods can either
be executed directly, or dispatched from an argument list."""
@@ -68,14 +87,15 @@
' Creating library ui.dll.lib and object ui.dll.exp'
This happens when there are exports from the dll or exe.
"""
- env = self._GetEnv(arch)
- popen = subprocess.Popen(args, shell=True, env=env,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- out, _ = popen.communicate()
- for line in out.splitlines():
- if not line.startswith(' Creating library '):
- print line
- return popen.returncode
+ with LinkLock():
+ env = self._GetEnv(arch)
+ popen = subprocess.Popen(args, shell=True, env=env,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ out, _ = popen.communicate()
+ for line in out.splitlines():
+ if not line.startswith(' Creating library '):
+ print line
+ return popen.returncode
def ExecManifestWrapper(self, arch, *args):
"""Run manifest tool with environment set. Strip out undesirable warning
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698