setup.py
changeset 28418 121d25719e92
parent 28398 712298942c82
child 28430 17b85d739b62
equal deleted inserted replaced
28417:588874c33b4d 28418:121d25719e92
   205             version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
   205             version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
   206     else:
   206     else:
   207         version = kw.get('node', '')[:12]
   207         version = kw.get('node', '')[:12]
   208 
   208 
   209 if version:
   209 if version:
   210     f = open("mercurial/__version__.py", "w")
   210     with open("mercurial/__version__.py", "w") as f:
   211     f.write('# this file is autogenerated by setup.py\n')
   211         f.write('# this file is autogenerated by setup.py\n')
   212     f.write('version = "%s"\n' % version)
   212         f.write('version = "%s"\n' % version)
   213     f.close()
       
   214 
       
   215 
   213 
   216 try:
   214 try:
   217     from mercurial import __version__
   215     from mercurial import __version__
   218     version = __version__.version
   216     version = __version__.version
   219 except ImportError:
   217 except ImportError:
   343     def finalize_options(self):
   341     def finalize_options(self):
   344         pass
   342         pass
   345 
   343 
   346     def run(self):
   344     def run(self):
   347         if os.path.exists(self._indexfilename):
   345         if os.path.exists(self._indexfilename):
   348             f = open(self._indexfilename, 'w')
   346             with open(self._indexfilename, 'w') as f:
   349             f.write('# empty\n')
   347                 f.write('# empty\n')
   350             f.close()
       
   351 
   348 
   352         # here no extension enabled, disabled() lists up everything
   349         # here no extension enabled, disabled() lists up everything
   353         code = ('import pprint; from mercurial import extensions; '
   350         code = ('import pprint; from mercurial import extensions; '
   354                 'pprint.pprint(extensions.disabled())')
   351                 'pprint.pprint(extensions.disabled())')
   355         out, err = runcmd([sys.executable, '-c', code], env)
   352         out, err = runcmd([sys.executable, '-c', code], env)
   356         if err:
   353         if err:
   357             raise DistutilsExecError(err)
   354             raise DistutilsExecError(err)
   358 
   355 
   359         f = open(self._indexfilename, 'w')
   356         with open(self._indexfilename, 'w') as f:
   360         f.write('# this file is autogenerated by setup.py\n')
   357             f.write('# this file is autogenerated by setup.py\n')
   361         f.write('docs = ')
   358             f.write('docs = ')
   362         f.write(out)
   359             f.write(out)
   363         f.close()
       
   364 
   360 
   365 class buildhgexe(build_ext):
   361 class buildhgexe(build_ext):
   366     description = 'compile hg.exe from mercurial/exewrapper.c'
   362     description = 'compile hg.exe from mercurial/exewrapper.c'
   367 
   363 
   368     def build_extensions(self):
   364     def build_extensions(self):
   371         if isinstance(self.compiler, HackedMingw32CCompiler):
   367         if isinstance(self.compiler, HackedMingw32CCompiler):
   372             self.compiler.compiler_so = self.compiler.compiler # no -mdll
   368             self.compiler.compiler_so = self.compiler.compiler # no -mdll
   373             self.compiler.dll_libraries = [] # no -lmsrvc90
   369             self.compiler.dll_libraries = [] # no -lmsrvc90
   374         hv = sys.hexversion
   370         hv = sys.hexversion
   375         pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff)
   371         pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff)
   376         f = open('mercurial/hgpythonlib.h', 'wb')
   372         with open('mercurial/hgpythonlib.h', 'wb') as f:
   377         f.write('/* this file is autogenerated by setup.py */\n')
   373             f.write('/* this file is autogenerated by setup.py */\n')
   378         f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
   374             f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
   379         f.close()
       
   380         objects = self.compiler.compile(['mercurial/exewrapper.c'],
   375         objects = self.compiler.compile(['mercurial/exewrapper.c'],
   381                                          output_dir=self.build_temp)
   376                                          output_dir=self.build_temp)
   382         dir = os.path.dirname(self.get_ext_fullpath('dummy'))
   377         dir = os.path.dirname(self.get_ext_fullpath('dummy'))
   383         target = os.path.join(dir, 'hg')
   378         target = os.path.join(dir, 'hg')
   384         self.compiler.link_executable(objects, target,
   379         self.compiler.link_executable(objects, target,
   474             uplevel = len([n for n in os.path.split(rest) if n])
   469             uplevel = len([n for n in os.path.split(rest) if n])
   475 
   470 
   476             libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common):]
   471             libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common):]
   477 
   472 
   478         for outfile in self.outfiles:
   473         for outfile in self.outfiles:
   479             fp = open(outfile, 'rb')
   474             with open(outfile, 'rb') as fp:
   480             data = fp.read()
   475                 data = fp.read()
   481             fp.close()
       
   482 
   476 
   483             # skip binary files
   477             # skip binary files
   484             if b'\0' in data:
   478             if b'\0' in data:
   485                 continue
   479                 continue
   486 
   480 
   491                 log.info('not rewriting @LIBDIR@ in %s because install path '
   485                 log.info('not rewriting @LIBDIR@ in %s because install path '
   492                          'not known' % outfile)
   486                          'not known' % outfile)
   493                 continue
   487                 continue
   494 
   488 
   495             data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
   489             data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
   496             fp = open(outfile, 'wb')
   490             with open(outfile, 'wb') as fp:
   497             fp.write(data)
   491                 fp.write(data)
   498             fp.close()
       
   499 
   492 
   500 cmdclass = {'build': hgbuild,
   493 cmdclass = {'build': hgbuild,
   501             'build_mo': hgbuildmo,
   494             'build_mo': hgbuildmo,
   502             'build_ext': hgbuildext,
   495             'build_ext': hgbuildext,
   503             'build_py': hgbuildpy,
   496             'build_py': hgbuildpy,