diff --git a/build.py b/build.py index d25316a3..274197ca 100755 --- a/build.py +++ b/build.py @@ -13,6 +13,7 @@ import glob import shutil import subprocess import optparse +import tempfile from distutils.dep_util import newer, newer_group from buildtools.config import Config, msg, opj, posixjoin, loadETG, etg2sip @@ -374,6 +375,7 @@ def sip(options, args): msg('Running command: sip') cfg = Config() for src_name in glob.glob(opj(cfg.SIPGEN, '_*.sip')): + tmpdir = tempfile.mkdtemp() src_name = src_name.replace('\\', '/') base = os.path.basename(os.path.splitext(src_name)[0]) sbf = posixjoin(cfg.SIPOUT, base) + '.sbf' @@ -381,10 +383,39 @@ def sip(options, args): pycode = posixjoin(cfg.PKGDIR, pycode) + '.py' pycode = '-X pycode:'+pycode cmd = '%s %s -c %s -b %s %s %s' % \ - (cfg.SIP, cfg.SIPOPTS, cfg.SIPOUT, sbf, pycode, src_name) + (cfg.SIP, cfg.SIPOPTS, tmpdir, sbf, pycode, src_name) runcmd(cmd) - + # Check each file in tmpdir to see if it is different than the same file + # in cfg.SIPOUT. If so then copy the new one to cfg.SIPOUT, otherwise + # ignore it. + for src in glob.glob(tmpdir + '/*'): + dest = opj(cfg.SIPOUT, os.path.basename(src)) + if not os.path.exists(dest): + msg('%s is a new file, copying...' % os.path.basename(src)) + shutil.copy2(src, dest) + continue + + with file(src, 'rb') as f: + srcTxt = f.read() + srcTxt = srcTxt.replace(tmpdir, cfg.SIPOUT) + # TODO remove lines starting with '#line'? + with file(dest, 'rb') as f: + destTxt = f.read() + + if srcTxt == destTxt: + pass + else: + msg('%s is changed, copying...' % os.path.basename(src)) + f = file(dest, 'wb') + f.write(srcTxt) + f.close() + + # Remove tmpdir and its contents + shutil.rmtree(tmpdir) + + + def touch(options, args): msg('Running command: touch') pwd = pushDir(phoenixDir()) @@ -664,6 +695,7 @@ def clean_py(options, args): clean_py(options, args) options.both = True + def clean(options, args): clean_wx(options, args) clean_py(options, args) diff --git a/buildtools/config.py b/buildtools/config.py index 35064882..19e56ddc 100644 --- a/buildtools/config.py +++ b/buildtools/config.py @@ -170,11 +170,11 @@ class Configuration(object): else: self.VCDLL = 'vc_dll' - self.includes = ['include', 'src', - opj(self.WXDIR, 'lib', self.VCDLL, 'msw' + self.libFlag()), - opj(self.WXDIR, 'include'), - opj(self.WXDIR, 'contrib', 'include'), - ] + self.includes += ['include', + opj(self.WXDIR, 'lib', self.VCDLL, 'msw' + self.libFlag()), + opj(self.WXDIR, 'include'), + opj(self.WXDIR, 'contrib', 'include'), + ] self.defines = [ ('WIN32', None), ('_WINDOWS', None), @@ -218,7 +218,7 @@ class Configuration(object): # Posix (wxGTK, wxMac or mingw32) settings elif os.name == 'posix' or COMPILER == 'mingw32': self.Verify_WX_CONFIG() - self.includes = ['include', 'src'] + self.includes += ['include'] self.defines = [ ('NDEBUG',), # using a 1-tuple makes it do an undef ] self.libdirs = [] @@ -560,6 +560,24 @@ def loadETG(name): def etg2sip(etgfile): cfg = Config() sipfile = os.path.splitext(os.path.basename(etgfile))[0] + '.sip' + sipfile = posixjoin(cfg.SIPGEN, sipfile) return sipfile + +def _getSbfValue(etg, keyName): + cfg = Config() + sbf = opj(cfg.SIPOUT, etg.NAME + '.sbf') + out = list() + for line in file(sbf): + key, value = line.split('=') + if key.strip() == keyName: + return [opj(cfg.SIPOUT, v) for v in value.strip().split()] + return None + +def getEtgSipCppFiles(etg): + return _getSbfValue(etg, 'sources') + +def getEtgSipHeaders(etg): + return _getSbfValue(etg, 'headers') + diff --git a/buildtools/distutils_hacks.py b/buildtools/distutils_hacks.py index c841756d..8c055121 100644 --- a/buildtools/distutils_hacks.py +++ b/buildtools/distutils_hacks.py @@ -234,7 +234,23 @@ class MyUnixCCompiler(distutils.unixccompiler.UnixCCompiler): except DistutilsExecError, msg: raise CompileError, msg - + def _setup_compile(self, outdir, macros, incdirs, sources, depends, extra): + m = distutils.ccompiler.CCompiler._setup_compile + macros, objects, extra, pp_opts, build = \ + m(self, outdir, macros, incdirs, sources, depends, extra) + + # Remove items from the build collection that don't need to be built + # because their obj file is newer than the source fle and any other + # dependencies. + # TODO + for obj in objects: + src, ext = build[obj] + if not newer_group([src] + depends, obj): + del build[obj] + + return macros, objects, extra, pp_opts, build + + _orig_parse_makefile = distutils.sysconfig.parse_makefile def _parse_makefile(filename, g=None): rv = _orig_parse_makefile(filename, g) @@ -331,6 +347,7 @@ class etgsip_build_ext(build_ext): cfg = Config() return cfg.SIPOUT + def build_extension(self, extension): """ Modify the dependency list, adding the sip files generated diff --git a/setup.py b/setup.py index 534a08ea..f7e7d384 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,8 @@ from distutils.dir_util import mkpath from distutils.dep_util import newer, newer_group from distutils.spawn import spawn -from buildtools.config import Config, msg, opj, loadETG +from buildtools.config import Config, msg, opj, loadETG, \ + getEtgSipCppFiles, getEtgSipHeaders import buildtools.distutils_hacks as hacks @@ -138,12 +139,11 @@ extensions.append( )) + + etg = loadETG('etg/_core.py') -etgDepends = etg.DEPENDS + etg.OTHERDEPS -ext = Extension('_core', - #['src/core_utils.cpp'] + - etg.ETGFILES + rc_file, - depends = etgDepends, +ext = Extension('_core', getEtgSipCppFiles(etg) + rc_file, + depends = getEtgSipHeaders(etg), include_dirs = cfg.includes, define_macros = cfg.defines, library_dirs = cfg.libdirs, @@ -155,6 +155,23 @@ extensions.append(ext) cfg.CLEANUP.append(opj(cfg.PKGDIR, 'core.py')) +#etg = loadETG('etg/_core.py') +#etgDepends = etg.DEPENDS + etg.OTHERDEPS +#ext = Extension('_core', + ##['src/core_utils.cpp'] + + #etg.ETGFILES + rc_file, + #depends = etgDepends, + #include_dirs = cfg.includes, + #define_macros = cfg.defines, + #library_dirs = cfg.libdirs, + #libraries = cfg.libs, + #extra_compile_args = cfg.cflags, + #extra_link_args = cfg.lflags, + #) +#extensions.append(ext) +#cfg.CLEANUP.append(opj(cfg.PKGDIR, 'core.py')) + + #---------------------------------------------------------------------- if __name__ == '__main__': @@ -177,7 +194,7 @@ if __name__ == '__main__': ext_modules = extensions, options = { 'build' : BUILD_OPTIONS, - 'build_ext' : {'sip_opts' : cfg.SIPOPTS }, + #**'build_ext' : {'sip_opts' : cfg.SIPOPTS }, }, scripts = SCRIPTS, @@ -189,7 +206,7 @@ if __name__ == '__main__': 'install_data' : hacks.wx_smart_install_data, 'install_headers' : hacks.wx_install_headers, 'clean' : hacks.wx_extra_clean, - 'build_ext' : hacks.etgsip_build_ext, + #**'build_ext' : hacks.etgsip_build_ext, }, )