##// END OF EJS Templates
setup: only write some autogenerated files if they change...
Gregory Szorc -
r35229:61ff0d7d default
parent child Browse files
Show More
@@ -136,6 +136,18 b' from distutils.errors import ('
136 from distutils.sysconfig import get_python_inc, get_config_var
136 from distutils.sysconfig import get_python_inc, get_config_var
137 from distutils.version import StrictVersion
137 from distutils.version import StrictVersion
138
138
139 def write_if_changed(path, content):
140 """Write content to a file iff the content hasn't changed."""
141 if os.path.exists(path):
142 with open(path, 'rb') as fh:
143 current = fh.read()
144 else:
145 current = b''
146
147 if current != content:
148 with open(path, 'wb') as fh:
149 fh.write(content)
150
139 scripts = ['hg']
151 scripts = ['hg']
140 if os.name == 'nt':
152 if os.name == 'nt':
141 # We remove hg.bat if we are able to build hg.exe.
153 # We remove hg.bat if we are able to build hg.exe.
@@ -317,9 +329,14 b" elif os.path.exists('.hg_archival.txt'):"
317 version = kw.get('node', '')[:12]
329 version = kw.get('node', '')[:12]
318
330
319 if version:
331 if version:
320 with open("mercurial/__version__.py", "w") as f:
332 versionb = version
321 f.write('# this file is autogenerated by setup.py\n')
333 if not isinstance(versionb, bytes):
322 f.write('version = "%s"\n' % version)
334 versionb = versionb.encode('ascii')
335
336 write_if_changed('mercurial/__version__.py', b''.join([
337 b'# this file is autogenerated by setup.py\n'
338 b'version = "%s"\n' % versionb,
339 ]))
323
340
324 try:
341 try:
325 oldpolicy = os.environ.get('HGMODULEPOLICY', None)
342 oldpolicy = os.environ.get('HGMODULEPOLICY', None)
@@ -478,9 +495,13 b' class hgbuildpy(build_py):'
478 modulepolicy = 'allow'
495 modulepolicy = 'allow'
479 else:
496 else:
480 modulepolicy = 'c'
497 modulepolicy = 'c'
481 with open(os.path.join(basepath, '__modulepolicy__.py'), "w") as f:
498
482 f.write('# this file is autogenerated by setup.py\n')
499 content = b''.join([
483 f.write('modulepolicy = b"%s"\n' % modulepolicy)
500 b'# this file is autogenerated by setup.py\n',
501 b'modulepolicy = b"%s"\n' % modulepolicy.encode('ascii'),
502 ])
503 write_if_changed(os.path.join(basepath, '__modulepolicy__.py'),
504 content)
484
505
485 build_py.run(self)
506 build_py.run(self)
486
507
General Comments 0
You need to be logged in to leave comments. Login now