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

Side by Side Diff: tools/dom/scripts/multiemitter.py

Issue 69343006: Avoid regenerating unchanged bindings files for Dartium. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """Templating to help generate structured text.""" 6 """Templating to help generate structured text."""
7 7
8 import os 8 import os
9 import sys 9 import sys
10 import subprocess 10 import subprocess
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 def _WriteFile(path, lines): 71 def _WriteFile(path, lines):
72 (dir, file) = os.path.split(path) 72 (dir, file) = os.path.split(path)
73 73
74 # Ensure dir exists. 74 # Ensure dir exists.
75 if dir: 75 if dir:
76 if not os.path.isdir(dir): 76 if not os.path.isdir(dir):
77 _logger.info('Mkdir - %s' % dir) 77 _logger.info('Mkdir - %s' % dir)
78 os.makedirs(dir) 78 os.makedirs(dir)
79 79
80 # Remove file if pre-existing. 80 # If file exists and is unchanged, return.
81 new_contents = ''.join(lines)
81 if os.path.exists(path): 82 if os.path.exists(path):
82 _logger.info('Removing - %s' % path) 83 with open(path) as fd:
83 os.remove(path) 84 contents = fd.read()
84 if os.path.exists(path): 85 if new_contents == contents:
85 _logger.info('Warning: File still exists- %s' % path) 86 _logger.info('Unchanged file %s' % path)
87 return
88 else:
89 _logger.info('Modified file %s' % path)
90 # Remove old file.
91 _logger.info('Removing - %s' % path)
92 os.remove(path)
93 if os.path.exists(path):
94 _logger.info('Warning: File still exists- %s' % path)
kustermann 2013/11/12 11:47:34 Please remove the whole else part: - No need to re
86 95
87 # Write the file. 96 # Write the file.
88 num_attempts = 4 97 num_attempts = 4
89 for i in range(num_attempts): 98 for i in range(num_attempts):
90 try: 99 try:
91 _logger.info('Writing (attempt %d) - %s' % (i + 1, path)) 100 _logger.info('Writing (attempt %d) - %s' % (i + 1, path))
92 f = open(path, 'w') 101 with open(path, 'w') as fd:
93 f.writelines(lines) 102 fd.write(new_contents)
94 f.close()
95 return 103 return
96 except IOError as error: 104 except IOError as error:
97 last_attempt = (i == (num_attempts - 1)) 105 last_attempt = (i == (num_attempts - 1))
98 if not last_attempt: 106 if not last_attempt:
99 # Sleep for 50 ms and try again 107 # Sleep for 50 ms and try again
100 time.sleep(0.05) 108 time.sleep(0.05)
101 else: 109 else:
102 # FIXME(kustermann): Remove this later on. 110 # FIXME(kustermann): Remove this later on.
103 # We try to get more debugging information to figure out why we 111 # We try to get more debugging information to figure out why we
104 # sometimes get a "Permission denied" error when opening the file for 112 # sometimes get a "Permission denied" error when opening the file for
105 # writing. (hypothesis: Another process has already opened the file.) 113 # writing. (hypothesis: Another process has already opened the file.)
106 _logger.info('Got exception (%s) ' % error) 114 _logger.info('Got exception (%s) ' % error)
107 115
108 if sys.platform == 'win32': 116 if sys.platform == 'win32':
109 handle_file = r'E:\handle.exe' 117 handle_file = r'E:\handle.exe'
110 if os.path.exists(handle_file): 118 if os.path.exists(handle_file):
111 _logger.info('Running handle.exe for debugging purposes') 119 _logger.info('Running handle.exe for debugging purposes')
112 subprocess.call([handle_file, '-a', r'E:\b\build\slave']) 120 subprocess.call([handle_file, '-a', r'E:\b\build\slave'])
113 else: 121 else:
114 _logger.info("Couldn't find %s. Not printing open handles." 122 _logger.info("Couldn't find %s. Not printing open handles."
115 % handle_file) 123 % handle_file)
116 raise error 124 raise error
117
OLDNEW
« 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