def build(self, status): LOGGER.info("Processing %s [%s]", self.name, self.sectionName) #1 get versions from pypi pypi = self.pypiKlass() versions = pypi.package_releases(self.name, show_hidden=True) status.setVersions(self, versions) def skip(version): for target in self.targets: status.setStatus(self, version, "skip", target) #1.1 filter versions according to minVersion and maxVersion: if self.minVersion: minver = StrictVersion(self.minVersion) ov = [] for v in versions: try: if StrictVersion(v) >= minver: ov.append(v) else: skip(v) except ValueError: pass versions = ov if self.maxVersion: maxver = StrictVersion(self.maxVersion) ov = [] for v in versions: try: if StrictVersion(v) <= maxver: ov.append(v) else: skip(v) except ValueError: pass versions = ov ov = [] for v in versions: if v in self.excludeVersions: skip(v) else: ov.append(v) versions = ov versions.sort() if len(versions) == 0: #nothing to do LOGGER.info('%s no versions, nothing to do', self.name) return #2 get file list of each version LOGGER.debug('getting %s', self.pypiurl) verFiles = defaultdict(list) simple = self.urlGetterKlass().get(self.pypiurl) soup = BeautifulSoup.BeautifulSoup(simple) VERSION = re.compile(self.name + r'-(\d+\.\d+(\.\d+\w*){0,2})') gotSource = False for tag in soup('a'): cntnt = str(tag.contents[0]) # str: re does not like non-strings m = VERSION.search(cntnt) if m: version = m.group(1) if version not in versions: continue LOGGER.debug('Got a file: %s', cntnt) verFiles[version].append(cntnt) if (cntnt.endswith('.zip') or cntnt.endswith('.tar.gz') or cntnt.endswith('tgz')): gotSource = True if self.needSource and not gotSource: LOGGER.info("No source release (.zip/.tar.gz/.tgz) found") for version in versions: #3 check whether we need a build needs = [] for target in self.targets: needBuild = target.checkBuild( self, version, verFiles.get(version, [])) if needBuild: needs.append(target) else: status.setStatus(self, version, "existed", target) if needs: tmpfolder = tempfile.mkdtemp('wineggbuilder') try: try: if self.repotype == 'svn': #3.1 svn co tag svn = self.svnKlass(exitOnError=False) svnurl = "%s/%s" % (self.tagurl, version) svn.co(svnurl, tmpfolder) if self.repotype == 'git': git = self.gitKlass(exitOnError=False) git.clone(self.repourl, tmpfolder) git.checkout(version) if self.repotype == 'download': # download source from pypi dl = self.dlKlass() dl.download(self.name, self.repourl, tmpfolder, version) if self.repotype == 'none': # noop pass except OSError: status.setStatus(self, version, "SVN/Git error") else: #3.2 build missing for target in needs: needBuild = target.build( self, version, verFiles.get(version, []), tmpfolder, status) finally: #3.3 del temp folder base.rmtree(tmpfolder)
def run(self, lxmlver): LOGGER.info("-----------------------") LOGGER.info("Building %s", self.compiler.name) # let's stick to a non random temp folder bdir = addtmp('lxmlbuild') if os.path.exists(bdir): base.rmtree(bdir) os.makedirs(bdir) idata = dict(version=lxmlver, package='lxml', #sourceFolder=sourceFolder, curdir=os.getcwd(), python=self.compiler.python) ##################### zlib = 'zlib-%s.tar.bz2' % ZLIBVER zlibfolder = os.path.join(bdir, 'zlib') download(ZLIBURL, zlib) extract(addtmp(zlib), bdir, 'zlib') cmd = r"nmake -f win32\Makefile.msc" command = self.compiler.setup + '\r\n' + cmd command = command % idata output = do(command, cwd=os.path.join(bdir, 'zlib')) if not LOGOUTPUT: output = 'suppressed' LOGGER.info('ZLIB build done, output: \n%s', output) ###################### iconv = 'libiconv-%s.tar.bz2' % ICONVVER iconvfolder = os.path.join(bdir, 'libiconv') download(ICONVURL, iconv) extract(addtmp(iconv), bdir, 'libiconv') cmd = r"nmake /a -f Makefile.msvc NO_NLS=1" command = self.compiler.setup + '\r\n' + cmd command = command % idata output = do(command, cwd=os.path.join(bdir, 'libiconv')) shutil.copy( os.path.join(iconvfolder, 'lib', 'iconv.lib'), os.path.join(iconvfolder, 'lib', 'iconv_a.lib')) if not LOGOUTPUT: output = 'suppressed' LOGGER.info('ICONV build done, output: \n%s', output) ###################### libxml = 'libxml2-%s.tar.bz2' % LIBXMLVER libxmlfolder = os.path.join(bdir, 'libxml2') download(LIBXMLURL, libxml) extract(addtmp(libxml), bdir, 'libxml2') cmd1 = r"cscript configure.js compiler=msvc iconv=yes zlib=yes include=%s;%s\include lib=%s;%s\lib" % ( zlibfolder, iconvfolder, zlibfolder, iconvfolder) cmd2 = r"nmake all" command = self.compiler.setup + '\r\n' + cmd1 + '\r\n' + cmd2 command = command % idata output = do(command, cwd=os.path.join(bdir, 'libxml2', 'win32')) if not LOGOUTPUT: output = 'suppressed' LOGGER.info('LIBXML build done, output: \n%s', output) ###################### libxslt = 'libxslt-%s.tar.bz2' % LIBXSLTVER libxsltfolder = os.path.join(bdir, 'libxslt') download(LIBXSLTURL, libxslt) extract(addtmp(libxslt), bdir, 'libxslt') cmd1 = r"cscript configure.js compiler=msvc iconv=yes zlib=yes include=%s\include;%s;%s\include lib=%s\win32\bin.msvc;%s;%s\lib" % ( libxmlfolder, zlibfolder, iconvfolder, libxmlfolder, zlibfolder, iconvfolder) cmd2 = r"nmake all" command = self.compiler.setup + '\r\n' + cmd1 + '\r\n' + cmd2 command = command % idata output = do(command, cwd=os.path.join(bdir, 'libxslt', 'win32')) if not LOGOUTPUT: output = 'suppressed' LOGGER.info('LIBXSLT build done, output: \n%s', output) #################### url = LXMLURL % lxmlver lxml = 'lxml-%s.tar.gz' % lxmlver lxmlfolder = os.path.join(bdir, 'lxml') download(url, lxml) extract(addtmp(lxml), bdir, 'lxml') # patch the include/lib folders for a static build subst = dict(zlib=zlibfolder, iconv=iconvfolder, xml=libxmlfolder, xslt=libxsltfolder) newinc = r""" STATIC_INCLUDE_DIRS = [ r"%(xml)s\include", r"%(xslt)s", r"%(zlib)s", r"%(iconv)s\include" ]""" % subst newlib = r""" STATIC_LIBRARY_DIRS = [ r"%(xml)s\win32\bin.msvc", r"%(xslt)s\win32\bin.msvc", r"%(zlib)s", r"%(iconv)s\lib" ] """ % subst setuppy = open(os.path.join(lxmlfolder, 'setup.py'), 'rb').read() setuppy = setuppy.replace("STATIC_INCLUDE_DIRS = []", newinc) setuppy = setuppy.replace("STATIC_LIBRARY_DIRS = []", newlib) open(os.path.join(lxmlfolder, 'setup.py'), 'wb').write(setuppy) if not self.compiler.options.notest: # build the pyds cmd = "%s setup.py build --static" % self.compiler.python command = self.compiler.setup + '\r\n' + cmd command = command % idata output = do(command, cwd=lxmlfolder) # copy testing stuff to the build buildlibdir = None for fn in os.listdir(os.path.join(lxmlfolder, 'build')): if fn.startswith('lib.win'): buildlibdir = os.path.join(lxmlfolder, 'build', fn) break shutil.copy( os.path.join(lxmlfolder, 'selftest.py'), os.path.join(buildlibdir, 'selftest.py')) shutil.copy( os.path.join(lxmlfolder, 'selftest2.py'), os.path.join(buildlibdir, 'selftest2.py')) shutil.copytree( os.path.join(lxmlfolder, 'samples'), os.path.join(buildlibdir, 'samples')) command = "%s selftest.py" % self.compiler.python output = do(command, cwd=buildlibdir) LOGGER.info("selftest.py output: %s", output) output = output.lower() if 'failure' in output or 'error' in output: # an exitcode != 0 will bail out, but to be sure we'll check the output raise CompileError() command = "%s selftest2.py" % self.compiler.python output = do(command, cwd=buildlibdir) LOGGER.info("selftest2.py output: %s", output) output = output.lower() if 'failure' in output or 'error' in output: # an exitcode != 0 will bail out, but to be sure we'll check the output raise CompileError() # clean slate before making the binary base.rmtree(os.path.join(lxmlfolder, 'build')) # now let's build the binary if self.compiler.options.dryrun: cmd = "%s setup.py --static bdist_wininst" % self.compiler.python else: # upload to pypi if it's not a dry run cmd = "%s setup.py --static bdist_wininst upload" % self.compiler.python command = self.compiler.setup + '\r\n' + cmd command = command % idata output = do(command, cwd=lxmlfolder) # build.py Compiler.build needs this output LOGGER.info(output)