Merge pull request #2712 from etiktin/add_chrome_version_2_gitignore

Fix `create_chrome_version_h` so it will generate chrome_version.h only if needed
This commit is contained in:
Cheng Zhao 2015-09-08 13:24:12 +08:00
commit 1ca6534dcd

View file

@ -162,13 +162,16 @@ def create_chrome_version_h():
version = f.read() version = f.read()
with open(template_file, 'r') as f: with open(template_file, 'r') as f:
template = f.read() template = f.read()
if sys.platform in ['win32', 'cygwin']: content = template.replace('{PLACEHOLDER}', version.strip())
open_mode = 'wb+'
else: # We update the file only if the content has changed (ignoring line ending
open_mode = 'w+' # differences).
with open(target_file, open_mode) as f: should_write = True
content = template.replace('{PLACEHOLDER}', version.strip()) if os.path.isfile(target_file):
if f.read() != content: with open(target_file, 'r') as f:
should_write = f.read().replace('r', '') != content.replace('r', '')
if should_write:
with open(target_file, 'w') as f:
f.write(content) f.write(content)