def do_install(self,src,tgt,chmod=0644): if Options.commands['install']: if not Options.options.force: try: t1=os.stat(tgt).st_mtime t2=os.stat(src).st_mtime except OSError: pass else: if t1>=t2: return False srclbl=src.replace(self.srcnode.abspath(None)+os.sep,'') info("* installing %s as %s"%(srclbl,tgt)) try:os.remove(tgt) except OSError:pass try: shutil.copy2(src,tgt) os.chmod(tgt,chmod) except IOError: try: os.stat(src) except IOError: error('File %r does not exist'%src) raise Utils.WafError('Could not install the file %r'%tgt) return True elif Options.commands['uninstall']: info("* uninstalling %s"%tgt) self.uninstall.append(tgt) try:os.remove(tgt) except OSError:pass return True
def distcheck(appname="", version=""): import tempfile, tarfile import pproc if not appname: appname = getattr(Utils.g_module, APPNAME, "noname") if not version: version = getattr(Utils.g_module, VERSION, "1.0") waf = os.path.abspath(sys.argv[0]) tarball = dist(appname, version) t = tarfile.open(tarball) for x in t: t.extract(x) t.close() instdir = tempfile.mkdtemp(".inst", "%s-%s" % (appname, version)) cwd_before = os.getcwd() retval = pproc.Popen( "%(waf)s configure && %(waf)s " "&& %(waf)s check && %(waf)s install --destdir=%(instdir)s" " && %(waf)s uninstall --destdir=%(instdir)s" % vars(), shell=True, ).wait() if retval: raise Utils.WafError("distcheck failed with code %i" % (retval)) if os.path.exists(instdir): raise Utils.WafError("distcheck succeeded, but files were left in %s" % (instdir)) else: info("distcheck finished successfully")
def symlink_as(self, path, src, env=None): if not self.is_install: return if not path: return tgt = self.get_install_path(path, env) dir, name = os.path.split(tgt) Utils.check_dir(dir) if self.is_install > 0: link = False if not os.path.islink(tgt): link = True elif os.readlink(tgt) != src: link = True try: os.remove(tgt) except OSError: pass if link: info('* symlink %s (-> %s)' % (tgt, src)) os.symlink(src, tgt) return 0 else: try: info("* removing %s" % (tgt)) os.remove(tgt) return 0 except OSError: return 1
def dist(appname="", version=""): import tarfile if not appname: appname = getattr(Utils.g_module, APPNAME, "noname") if not version: version = getattr(Utils.g_module, VERSION, "1.0") tmp_folder = appname + "-" + version arch_name = tmp_folder + ".tar." + g_gz try: shutil.rmtree(tmp_folder) except (OSError, IOError): pass try: os.remove(arch_name) except (OSError, IOError): pass copytree(".", tmp_folder, getattr(Utils.g_module, BLDDIR, None)) dist_hook = getattr(Utils.g_module, "dist_hook", None) if dist_hook: os.chdir(tmp_folder) try: dist_hook() finally: os.chdir("..") tar = tarfile.open(arch_name, "w:" + g_gz) tar.add(tmp_folder) tar.close() info("Your archive is ready -> %s" % arch_name) if os.path.exists(tmp_folder): shutil.rmtree(tmp_folder) return arch_name
def install_pyfile(self,node): path=self.bld.get_install_path(self.install_path+os.sep+node.name,self.env) self.bld.install_files(self.install_path,[node],self.env,self.chmod,postpone=False) if self.bld.is_install<0: info("* removing byte compiled python files") for x in'co': try: os.remove(path+x) except OSError: pass if self.bld.is_install>0: if self.env['PYC']or self.env['PYO']: info("* byte compiling %r"%path) if self.env['PYC']: program=(""" import sys, py_compile for pyfile in sys.argv[1:]: py_compile.compile(pyfile, pyfile + 'c') """) argv=[self.env['PYTHON'],'-c',program,path] ret=Utils.pproc.Popen(argv).wait() if ret: raise Utils.WafError('bytecode compilation failed %r'%path) if self.env['PYO']: program=(""" import sys, py_compile for pyfile in sys.argv[1:]: py_compile.compile(pyfile, pyfile + 'o') """) argv=[self.env['PYTHON'],self.env['PYFLAGS_OPT'],'-c',program,path] ret=Utils.pproc.Popen(argv).wait() if ret: raise Utils.WafError('bytecode compilation failed %r'%path)
def main(): global commands commands=Options.arg_line[:] while commands: x=commands.pop(0) ini=datetime.datetime.now() if x=='configure': fun=configure elif x=='build': fun=build else: fun=getattr(Utils.g_module,x,None) if not fun: raise Utils.WscriptError('No such command %r'%x) ctx=getattr(Utils.g_module,x+'_context',Utils.Context)() if x in['init','shutdown','dist','distclean','distcheck']: try: fun(ctx) except TypeError: fun() else: fun(ctx) ela='' if not Options.options.progress_bar: ela=' (%s)'%Utils.get_elapsed_time(ini) if x!='init'and x!='shutdown': info('%r finished successfully%s'%(x,ela)) if not commands and x!='shutdown': commands.append('shutdown')
def do_install(self,src,tgt,chmod=O644): if self.is_install>0: if not Options.options.force: try: st1=os.stat(tgt) st2=os.stat(src) except OSError: pass else: if st1.st_mtime>=st2.st_mtime and st1.st_size==st2.st_size: return False srclbl=src.replace(self.srcnode.abspath(None)+os.sep,'') info("* installing %s as %s"%(srclbl,tgt)) try:os.remove(tgt) except OSError:pass try: shutil.copy2(src,tgt) os.chmod(tgt,chmod) except IOError: try: os.stat(src) except(OSError,IOError): error('File %r does not exist'%src) raise Utils.WafError('Could not install the file %r'%tgt) return True elif self.is_install<0: info("* uninstalling %s"%tgt) self.uninstall.append(tgt) try:os.remove(tgt) except OSError:pass return True
def build_impl(bld): # compile the project and/or install the files try: proj = Environment.Environment(Options.lockfile) except IOError: raise Utils.WafError("Project not configured (run 'waf configure' first)") bld.load_dirs(proj[SRCDIR], proj[BLDDIR]) bld.load_envs() info("Waf: Entering directory `%s'" % bld.bldnode.abspath()) bld.add_subdirs([os.path.split(Utils.g_module.root_path)[0]]) # execute something immediately before the build starts bld.pre_build() try: bld.compile() finally: if Options.options.progress_bar: print('') info("Waf: Leaving directory `%s'" % bld.bldnode.abspath()) # execute something immediately after a successful build bld.post_build() bld.install()
def build_impl(bld): # compile the project and/or install the files try: proj = Environment.Environment(Options.lockfile) except IOError: raise Utils.WafError( "Project not configured (run 'waf configure' first)") bld.load_dirs(proj[SRCDIR], proj[BLDDIR]) bld.load_envs() info("Waf: Entering directory `%s'" % bld.bldnode.abspath()) bld.add_subdirs([os.path.split(Utils.g_module.root_path)[0]]) # execute something immediately before the build starts bld.pre_build() try: bld.compile() finally: if Options.options.progress_bar: print('') info("Waf: Leaving directory `%s'" % bld.bldnode.abspath()) # execute something immediately after a successful build bld.post_build() bld.install()
def symlink_as(self,path,src,env=None): if not self.is_install:return if not path:return tgt=self.get_install_path(path,env) dir,name=os.path.split(tgt) Utils.check_dir(dir) if self.is_install>0: link=False if not os.path.islink(tgt): link=True elif os.readlink(tgt)!=src: link=True try:os.remove(tgt) except OSError:pass if link: info('* symlink %s (-> %s)'%(tgt,src)) os.symlink(src,tgt) return 0 else: try: info("* removing %s"%(tgt)) os.remove(tgt) return 0 except OSError: return 1
def do_install(self, src, tgt, chmod=O644): if self.is_install > 0: if not Options.options.force: try: st1 = os.stat(tgt) st2 = os.stat(src) except OSError: pass else: if st1.st_mtime >= st2.st_mtime and st1.st_size == st2.st_size: return False srclbl = src.replace(self.srcnode.abspath(None) + os.sep, '') info("* installing %s as %s" % (srclbl, tgt)) try: os.remove(tgt) except OSError: pass try: shutil.copy2(src, tgt) os.chmod(tgt, chmod) except IOError: try: os.stat(src) except (OSError, IOError): error('File %r does not exist' % src) raise Utils.WafError('Could not install the file %r' % tgt) return True elif self.is_install < 0: info("* uninstalling %s" % tgt) self.uninstall.append(tgt) try: os.remove(tgt) except OSError: pass return True
def main(): global commands commands = Options.arg_line[:] while commands: x = commands.pop(0) ini = datetime.datetime.now() if x == "configure": fun = configure elif x == "build": fun = build else: fun = getattr(Utils.g_module, x, None) if not fun: raise Utils.WscriptError("No such command %r" % x) ctx = getattr(Utils.g_module, x + "_context", Utils.Context)() if x in ["init", "shutdown", "dist", "distclean", "distcheck"]: try: fun(ctx) except TypeError: fun() else: fun(ctx) ela = "" if not Options.options.progress_bar: ela = " (%s)" % Utils.get_elapsed_time(ini) if x != "init" and x != "shutdown": info("%r finished successfully%s" % (x, ela)) if not commands and x != "shutdown": commands.append("shutdown")
def symlink_as(self, path, src, env=None, cwd=None): if sys.platform == "win32": return if not path: raise Utils.WafError("where do you want to install %r? (%r?)" % (src, path)) tgt = self.get_install_path(path, env) dir, name = os.path.split(tgt) Utils.check_dir(dir) if self.is_install > 0: link = False if not os.path.islink(tgt): link = True elif os.readlink(tgt) != src: link = True if link: try: os.remove(tgt) except OSError: pass info("* symlink %s (-> %s)" % (tgt, src)) os.symlink(src, tgt) return 0 else: try: info("* removing %s" % (tgt)) os.remove(tgt) return 0 except OSError: return 1
def distcheck(appname='', version=''): """Makes some sanity checks on the waf dist generated tarball""" import tempfile, tarfile import pproc if not appname: appname = getattr(Utils.g_module, APPNAME, 'noname') if not version: version = getattr(Utils.g_module, VERSION, '1.0') waf = os.path.abspath(sys.argv[0]) tarball = dist(appname, version) t = tarfile.open(tarball) for x in t: t.extract(x) t.close() instdir = tempfile.mkdtemp('.inst', '%s-%s' % (appname, version)) retval = pproc.Popen( '%(waf)s configure && %(waf)s' ' && %(waf)s check && %(waf)s install --destdir=%(instdir)s' ' && %(waf)s uninstall --destdir=%(instdir)s' % vars(), shell=True).wait() if retval: raise Utils.WafError('distcheck failed with code %i' % (retval)) if os.path.exists(instdir): raise Utils.WafError('distcheck succeeded, but files were left in %s' % (instdir)) else: info('distcheck finished successfully')
def symlink_as(self, path, src, env=None, cwd=None): if sys.platform == 'win32': return if not path: raise Utils.WafError("where do you want to install %r? (%r?)" % (src, path)) tgt = self.get_install_path(path, env) dir, name = os.path.split(tgt) Utils.check_dir(dir) if self.is_install > 0: link = False if not os.path.islink(tgt): link = True elif os.readlink(tgt) != src: link = True if link: try: os.remove(tgt) except OSError: pass info('* symlink %s (-> %s)' % (tgt, src)) os.symlink(src, tgt) return 0 else: try: info('* removing %s' % (tgt)) os.remove(tgt) return 0 except OSError: return 1
def dist(appname='', version=''): '''makes a tarball for redistributing the sources''' # return return (distdirname, tarballname) import tarfile if not appname: appname = Utils.g_module.APPNAME if not version: version = Utils.g_module.VERSION tmp_folder = appname + '-' + version if g_gz in ['gz', 'bz2']: arch_name = tmp_folder + '.tar.' + g_gz else: arch_name = tmp_folder + '.' + 'zip' # remove the previous dir try: shutil.rmtree(tmp_folder) except (OSError, IOError): pass # remove the previous archive try: os.remove(arch_name) except (OSError, IOError): pass # copy the files into the temporary folder copytree('.', tmp_folder, getattr(Utils.g_module, BLDDIR, None)) # undocumented hook for additional cleanup dist_hook = getattr(Utils.g_module, 'dist_hook', None) if dist_hook: back = os.getcwd() os.chdir(tmp_folder) try: dist_hook() finally: # go back to the root directory os.chdir(back) if g_gz in ['gz', 'bz2']: tar = tarfile.open(arch_name, 'w:' + g_gz) tar.add(tmp_folder) tar.close() else: Utils.zip_folder(tmp_folder, arch_name, tmp_folder) try: from hashlib import sha1 as sha except ImportError: from sha import sha try: digest = " (sha=%r)" % sha(Utils.readf(arch_name)).hexdigest() except: digest = '' info('New archive created: %s%s' % (arch_name, digest)) if os.path.exists(tmp_folder): shutil.rmtree(tmp_folder) return arch_name
def dist(appname='', version=''): '''makes a tarball for redistributing the sources''' # return return (distdirname, tarballname) import tarfile if not appname: appname = getattr(Utils.g_module, APPNAME, 'noname') if not version: version = getattr(Utils.g_module, VERSION, '1.0') tmp_folder = appname + '-' + version arch_name = tmp_folder + '.tar.' + g_gz # remove the previous dir try: shutil.rmtree(tmp_folder) except (OSError, IOError): pass # remove the previous archive try: os.remove(arch_name) except (OSError, IOError): pass # copy the files into the temporary folder copytree('.', tmp_folder, getattr(Utils.g_module, BLDDIR, None)) # undocumented hook for additional cleanup dist_hook = getattr(Utils.g_module, 'dist_hook', None) if dist_hook: back = os.getcwd() os.chdir(tmp_folder) try: dist_hook() finally: # go back to the root directory os.chdir(back) tar = tarfile.open(arch_name, 'w:' + g_gz) tar.add(tmp_folder) tar.close() try: from hashlib import sha1 as sha except ImportError: from sha import sha try: digest = " (sha=%r)" % sha(Utils.readf(arch_name)).hexdigest() except: digest = '' info('New archive created: %s%s' % (arch_name, digest)) if os.path.exists(tmp_folder): shutil.rmtree(tmp_folder) return arch_name
def do_install(self, src, tgt, chmod=O644): """returns true if the file was effectively installed or uninstalled, false otherwise""" if self.is_install > 0: if not Options.options.force: # check if the file is already there to avoid a copy try: st1 = os.stat(tgt) st2 = os.stat(src) except OSError: pass else: # same size and identical timestamps -> make no copy if st1.st_mtime >= st2.st_mtime and st1.st_size == st2.st_size: return False srclbl = src.replace(self.srcnode.abspath(None) + os.sep, '') info("* installing %s as %s" % (srclbl, tgt)) # following is for shared libs and stale inodes (-_-) try: os.remove(tgt) except OSError: pass try: shutil.copy2(src, tgt) if chmod >= 0: os.chmod(tgt, chmod) except IOError: try: os.stat(src) except (OSError, IOError): error('File %r does not exist' % src) raise Utils.WafError('Could not install the file %r' % tgt) return True elif self.is_install < 0: info("* uninstalling %s" % tgt) self.uninstall.append(tgt) try: os.remove(tgt) except OSError, e: if e.errno != errno.ENOENT: if not getattr(self, 'uninstall_error', None): self.uninstall_error = True Logs.warn( 'build: some files could not be uninstalled (retry with -vv to list them)' ) if Logs.verbose > 1: Logs.warn('could not remove %s (error code %r)' % (e.filename, e.errno)) return True
def main(): if Options.commands['configure']: ini = time.time() configure() ela = '' if not Options.options.progress_bar: ela = time.strftime(' (%H:%M:%S)', time.gmtime(time.time() - ini)) info('Configuration finished successfully%s; project is now ready to build.' % ela) sys.exit(0) # compile the project and/or install the files bld = Build.BuildContext() try: proj = Environment.Environment(Options.lockfile) except IOError: if Options.commands['clean']: raise Utils.WafError("Nothing to clean (project not configured)") else: if Configure.autoconfig: warn("Reconfiguring the project") configure() bld = Build.BuildContext() proj = Environment.Environment(Options.lockfile) else: raise Utils.WafError("Project not configured (run 'waf configure' first)") if Configure.autoconfig: if not Options.commands['clean'] and not Options.commands['uninstall']: reconf = 0 h = 0 try: for file in proj['files']: mod = Utils.load_module(file) h = Utils.hash_function_with_globals(h, mod.configure) reconf = (h != proj['hash']) except Exception, e: warn("Reconfiguring the project (an exception occurred: %s)" % (str(e),)) reconf = 1 if reconf: warn("Reconfiguring the project (the configuration has changed)") back = (Options.commands, Options.options, Logs.zones, Logs.verbose) Options.commands = proj['commands'] Options.options.__dict__ = proj['options'] configure() (Options.commands, Options.options, Logs.zones, Logs.verbose) = back bld = Build.BuildContext() proj = Environment.Environment(Options.lockfile)
def install_dir(self,path,env=None): if env: assert isinstance(env,Environment.Environment),"invalid parameter" else: env=self.env if not path: return[] destpath=self.get_install_path(path,env) if self.is_install>0: info('* creating %s'%destpath) Utils.check_dir(destpath) elif self.is_install<0: info('* removing %s'%destpath) self.uninstall.append(destpath+'/xxx')
def install_dir(self, path, env=None): if env: assert isinstance(env, Environment.Environment), "invalid parameter" else: env = self.env if not path: return [] destpath = self.get_install_path(path, env) if self.is_install > 0: info('* creating %s' % destpath) Utils.check_dir(destpath) elif self.is_install < 0: info('* removing %s' % destpath) self.uninstall.append(destpath + '/xxx')
def do_install(self, src, tgt, chmod=O644): """returns true if the file was effectively installed or uninstalled, false otherwise""" if self.is_install > 0: if not Options.options.force: # check if the file is already there to avoid a copy try: st1 = os.stat(tgt) st2 = os.stat(src) except OSError: pass else: # same size and identical timestamps -> make no copy if st1.st_mtime >= st2.st_mtime and st1.st_size == st2.st_size: return False srclbl = src.replace(self.srcnode.abspath(None)+os.sep, '') info("* installing %s as %s" % (srclbl, tgt)) # following is for shared libs and stale inodes (-_-) try: os.remove(tgt) except OSError: pass try: shutil.copy2(src, tgt) os.chmod(tgt, chmod) except IOError: try: os.stat(src) except (OSError, IOError): error('File %r does not exist' % src) raise Utils.WafError('Could not install the file %r' % tgt) return True elif self.is_install < 0: info("* uninstalling %s" % tgt) self.uninstall.append(tgt) try: os.remove(tgt) except OSError, e: if e.errno != errno.ENOENT: if not getattr(self, 'uninstall_error', None): self.uninstall_error = True Logs.warn('build: some files could not be uninstalled (retry with -vv to list them)') if Logs.verbose > 1: Logs.warn('could not remove %s (error code %r)' % (e.filename, e.errno)) return True
def distclean(): lst = os.listdir(".") for f in lst: if f == Options.lockfile: try: proj = Environment.Environment(f) shutil.rmtree(proj[BLDDIR]) except (OSError, IOError): pass try: os.remove(f) except (OSError, IOError): pass if f.startswith(".waf-"): shutil.rmtree(f, ignore_errors=True) info("distclean finished successfully")
def dist(appname='', version=''): '''makes a tarball for redistributing the sources''' import tarfile if not appname: appname = Utils.g_module.APPNAME if not version: version = Utils.g_module.VERSION tmp_folder = appname + '-' + version if g_gz in ['gz', 'bz2']: arch_name = tmp_folder + '.tar.' + g_gz else: arch_name = tmp_folder + '.' + 'zip' try: shutil.rmtree(tmp_folder) except (OSError, IOError): pass try: os.remove(arch_name) except (OSError, IOError): pass blddir = getattr(Utils.g_module, BLDDIR, None) if not blddir: blddir = getattr(Utils.g_module, 'out', None) copytree('.', tmp_folder, blddir) dist_hook = getattr(Utils.g_module, 'dist_hook', None) if dist_hook: back = os.getcwd() os.chdir(tmp_folder) try: dist_hook() finally: os.chdir(back) if g_gz in ['gz', 'bz2']: tar = tarfile.open(arch_name, 'w:' + g_gz) tar.add(tmp_folder) tar.close() else: Utils.zip_folder(tmp_folder, arch_name, tmp_folder) try: from hashlib import sha1 as sha except ImportError: from sha import sha try: digest = " (sha=%r)" % sha(Utils.readf(arch_name)).hexdigest() except: digest = '' info('New archive created: %s%s' % (arch_name, digest)) if os.path.exists(tmp_folder): shutil.rmtree(tmp_folder) return arch_name
def dist(appname='',version=''): '''makes a tarball for redistributing the sources''' import tarfile if not appname:appname=getattr(Utils.g_module,APPNAME,'noname') if not version:version=get_version() tmp_folder=appname+'-'+version if dist_format=='zip': arch_name=tmp_folder+'.zip' elif dist_format=='tar': arch_name=tmp_folder+'.tar.'+g_gz else: raise ValueError("invalid dist_format option %r"%dist_format) try: shutil.rmtree(tmp_folder) except(OSError,IOError): pass try: os.remove(arch_name) except(OSError,IOError): pass copytree('.',tmp_folder,getattr(Utils.g_module,BLDDIR,None)) dist_hook=getattr(Utils.g_module,'dist_hook',None) if dist_hook: back=os.getcwd() os.chdir(tmp_folder) try: dist_hook() finally: os.chdir(back) if dist_format=='tar': tar=tarfile.open(arch_name,'w:'+g_gz) tar.add(tmp_folder) tar.close() elif dist_format=='zip': zipper(tmp_folder,arch_name,tmp_folder) else: raise ValueError("invalid dist_format option %r"%dist_format) try:from hashlib import sha1 as sha except ImportError:from sha import sha try: digest=" (sha=%r)"%sha(Utils.readf(arch_name)).hexdigest() except: digest='' info('New archive created: %s%s'%(arch_name,digest)) if os.path.exists(tmp_folder):shutil.rmtree(tmp_folder) return arch_name
def build_impl(bld): try: proj=Environment.Environment(Options.lockfile) except IOError: raise Utils.WafError("Project not configured (run 'waf configure' first)") bld.load_dirs(proj[SRCDIR],proj[BLDDIR]) bld.load_envs() info("Waf: Entering directory `%s'"%bld.bldnode.abspath()) bld.add_subdirs([os.path.split(Utils.g_module.root_path)[0]]) bld.pre_build() try: bld.compile() finally: if Options.options.progress_bar:print('') info("Waf: Leaving directory `%s'"%bld.bldnode.abspath()) bld.post_build() bld.install()
def dist(appname='',version=''): '''makes a tarball for redistributing the sources''' import tarfile if not appname:appname=Utils.g_module.APPNAME if not version:version=Utils.g_module.VERSION tmp_folder=appname+'-'+version if g_gz in['gz','bz2']: arch_name=tmp_folder+'.tar.'+g_gz else: arch_name=tmp_folder+'.'+'zip' try: shutil.rmtree(tmp_folder) except(OSError,IOError): pass try: os.remove(arch_name) except(OSError,IOError): pass blddir=getattr(Utils.g_module,BLDDIR,None) if not blddir: blddir=getattr(Utils.g_module,'out',None) copytree('.',tmp_folder,blddir) dist_hook=getattr(Utils.g_module,'dist_hook',None) if dist_hook: back=os.getcwd() os.chdir(tmp_folder) try: dist_hook() finally: os.chdir(back) if g_gz in['gz','bz2']: tar=tarfile.open(arch_name,'w:'+g_gz) tar.add(tmp_folder) tar.close() else: Utils.zip_folder(tmp_folder,arch_name,tmp_folder) try:from hashlib import sha1 as sha except ImportError:from sha import sha try: digest=" (sha=%r)"%sha(Utils.readf(arch_name)).hexdigest() except: digest='' info('New archive created: %s%s'%(arch_name,digest)) if os.path.exists(tmp_folder):shutil.rmtree(tmp_folder) return arch_name
def do_install(self, src, tgt, chmod=O644): if self.is_install > 0: if not Options.options.force: try: st1 = os.stat(tgt) st2 = os.stat(src) except OSError: pass else: if st1.st_mtime >= st2.st_mtime and st1.st_size == st2.st_size: return False srclbl = src.replace(self.srcnode.abspath(None) + os.sep, '') info("* installing %s as %s" % (srclbl, tgt)) try: os.remove(tgt) except OSError: pass try: shutil.copy2(src, tgt) os.chmod(tgt, chmod) except IOError: try: os.stat(src) except (OSError, IOError): error('File %r does not exist' % src) raise Utils.WafError('Could not install the file %r' % tgt) return True elif self.is_install < 0: info("* uninstalling %s" % tgt) self.uninstall.append(tgt) try: os.remove(tgt) except OSError, e: if e.errno != errno.ENOENT: if not getattr(self, 'uninstall_error', None): self.uninstall_error = True Logs.warn( 'build: some files could not be uninstalled (retry with -vv to list them)' ) if Logs.verbose > 1: Logs.warn('could not remove %s (error code %r)' % (e.filename, e.errno)) return True
def byte_compile_py(self): if self.bld.is_install and self.install_path: installed_files = self._py_installed_files if not installed_files: return if self.bld.is_install < 0: info("* removing byte compiled python files") for fname in installed_files: try: os.remove(fname + 'c') except OSError: pass try: os.remove(fname + 'o') except OSError: pass if self.bld.is_install > 0: if self.env['PYC'] or self.env['PYO']: info("* byte compiling python files") if self.env['PYC']: program = (""" import sys, py_compile for pyfile in sys.argv[1:]: py_compile.compile(pyfile, pyfile + 'c') """) argv = [self.env['PYTHON'], "-c", program] argv.extend(installed_files) retval = Utils.pproc.Popen(argv).wait() if retval: raise Utils.WafError("bytecode compilation failed") if self.env['PYO']: program = (""" import sys, py_compile for pyfile in sys.argv[1:]: py_compile.compile(pyfile, pyfile + 'o') """) argv = [ self.env['PYTHON'], self.env['PYFLAGS_OPT'], "-c", program ] argv.extend(installed_files) retval = Utils.pproc.Popen(argv).wait() if retval: raise Utils.WafError("bytecode compilation failed")
def dist(appname='', version=''): """make a tarball with all the sources in it; return (distdirname, tarballname)""" import tarfile if not appname: appname = getattr(Utils.g_module, APPNAME, 'noname') if not version: version = getattr(Utils.g_module, VERSION, '1.0') tmp_folder = appname + '-' + version arch_name = tmp_folder+'.tar.'+g_gz # remove the previous dir try: shutil.rmtree(tmp_folder) except (OSError, IOError): pass # remove the previous archive try: os.remove(arch_name) except (OSError, IOError): pass # copy the files into the temporary folder copytree('.', tmp_folder, getattr(Utils.g_module, BLDDIR, None)) # undocumented hook for additional cleanup dist_hook = getattr(Utils.g_module, 'dist_hook', None) if dist_hook: os.chdir(tmp_folder) try: dist_hook() finally: # go back to the root directory os.chdir('..') tar = tarfile.open(arch_name, 'w:' + g_gz) tar.add(tmp_folder) tar.close() info('Your archive is ready -> %s' % arch_name) if os.path.exists(tmp_folder): shutil.rmtree(tmp_folder) return arch_name
def dist(appname="", version=""): """makes a tarball for redistributing the sources""" import tarfile if not appname: appname = getattr(Utils.g_module, APPNAME, "noname") if not version: version = getattr(Utils.g_module, VERSION, "1.0") tmp_folder = appname + "-" + version arch_name = tmp_folder + ".tar." + g_gz try: shutil.rmtree(tmp_folder) except (OSError, IOError): pass try: os.remove(arch_name) except (OSError, IOError): pass copytree(".", tmp_folder, getattr(Utils.g_module, BLDDIR, None)) dist_hook = getattr(Utils.g_module, "dist_hook", None) if dist_hook: back = os.getcwd() os.chdir(tmp_folder) try: dist_hook() finally: os.chdir(back) tar = tarfile.open(arch_name, "w:" + g_gz) tar.add(tmp_folder) tar.close() try: from hashlib import sha1 as sha except ImportError: from sha import sha try: digest = " (sha=%r)" % sha(Utils.readf(arch_name)).hexdigest() except: digest = "" info("New archive created: %s%s" % (arch_name, digest)) if os.path.exists(tmp_folder): shutil.rmtree(tmp_folder) return arch_name
def distclean(): """clean the project""" lst = os.listdir('.') for f in lst: if f == Options.lockfile: try: proj = Environment.Environment(f) shutil.rmtree(proj[BLDDIR]) except (OSError, IOError): pass try: os.remove(f) except (OSError, IOError): pass # remove the local waf if f.startswith('.waf-'): shutil.rmtree(f, ignore_errors=True) info('distclean finished successfully')
def install_dir(self, path, env=None): """ create empty folders for the installation (very rarely used) """ if env: assert isinstance(env, Environment.Environment), "invalid parameter" else: env = self.env if not path: return [] destpath = self.get_install_path(path, env) if self.is_install > 0: info('* creating %s' % destpath) Utils.check_dir(destpath) elif self.is_install < 0: info('* removing %s' % destpath) self.uninstall.append(destpath + '/xxx') # yes, ugly
def byte_compile_py(self): if self.bld.is_install and self.install_path: installed_files=self._py_installed_files if not installed_files: return if self.bld.is_install<0: info("* removing byte compiled python files") for fname in installed_files: try: os.remove(fname+'c') except OSError: pass try: os.remove(fname+'o') except OSError: pass if self.bld.is_install>0: if self.env['PYC']or self.env['PYO']: info("* byte compiling python files") if self.env['PYC']: program=(""" import sys, py_compile for pyfile in sys.argv[1:]: py_compile.compile(pyfile, pyfile + 'c') """) argv=[self.env['PYTHON'],"-c",program] argv.extend(installed_files) retval=Utils.pproc.Popen(argv).wait() if retval: raise Utils.WafError("bytecode compilation failed") if self.env['PYO']: program=(""" import sys, py_compile for pyfile in sys.argv[1:]: py_compile.compile(pyfile, pyfile + 'o') """) argv=[self.env['PYTHON'],self.env['PYFLAGS_OPT'],"-c",program] argv.extend(installed_files) retval=Utils.pproc.Popen(argv).wait() if retval: raise Utils.WafError("bytecode compilation failed")
def symlink_as(self,path,src,env=None): if not Options.is_install:return if not path:return tgt=self.get_install_path(path,env) dir,name=os.path.split(tgt) Utils.check_dir(dir) if Options.commands['install']: try: if not os.path.islink(tgt)or os.readlink(tgt)!=src: info("* symlink %s (-> %s)"%(tgt,src)) os.symlink(src,tgt) return 0 except OSError: return 1 elif Options.commands['uninstall']: try: info("* removing %s"%(tgt)) os.remove(tgt) return 0 except OSError: return 1
def symlink_as(self, path, src, env=None, cwd=None): """example: bld.symlink_as('${PREFIX}/lib/libfoo.so', 'libfoo.so.1.2.3') """ if sys.platform == 'win32': # well, this *cannot* work return if not path: raise Utils.WafError("where do you want to install %r? (%r?)" % (src, path)) tgt = self.get_install_path(path, env) dir, name = os.path.split(tgt) Utils.check_dir(dir) if self.is_install > 0: link = False if not os.path.islink(tgt): link = True elif os.readlink(tgt) != src: link = True if link: try: os.remove(tgt) except OSError: pass info('* symlink %s (-> %s)' % (tgt, src)) os.symlink(src, tgt) return 0 else: # UNINSTALL try: info('* removing %s' % (tgt)) os.remove(tgt) return 0 except OSError: return 1
def do_install(self, src, tgt, chmod=O644): if self.is_install > 0: if not Options.options.force: try: st1 = os.stat(tgt) st2 = os.stat(src) except OSError: pass else: if st1.st_mtime >= st2.st_mtime and st1.st_size == st2.st_size: return False srclbl = src.replace(self.srcnode.abspath(None) + os.sep, "") info("* installing %s as %s" % (srclbl, tgt)) try: os.remove(tgt) except OSError: pass try: shutil.copy2(src, tgt) os.chmod(tgt, chmod) except IOError: try: os.stat(src) except (OSError, IOError): error("File %r does not exist" % src) raise Utils.WafError("Could not install the file %r" % tgt) return True elif self.is_install < 0: info("* uninstalling %s" % tgt) self.uninstall.append(tgt) try: os.remove(tgt) except OSError, e: if e.errno != errno.ENOENT: if not getattr(self, "uninstall_error", None): self.uninstall_error = True Logs.warn("build: some files could not be uninstalled (retry with -vv to list them)") if Logs.verbose > 1: Logs.warn("could not remove %s (error code %r)" % (e.filename, e.errno)) return True
def do_install(self, src, tgt, chmod=O644): """returns true if the file was effectively installed or uninstalled, false otherwise""" if Options.commands['install']: if not Options.options.force: # check if the file is already there to avoid a copy try: t1 = os.stat(tgt).st_mtime t2 = os.stat(src).st_mtime except OSError: pass else: if t1 >= t2: return False srclbl = src.replace(self.srcnode.abspath(None)+os.sep, '') info("* installing %s as %s" % (srclbl, tgt)) # following is for shared libs and stale inodes (-_-) try: os.remove(tgt) except OSError: pass try: shutil.copy2(src, tgt) os.chmod(tgt, chmod) except IOError: try: os.stat(src) except (OSError, IOError): error('File %r does not exist' % src) raise Utils.WafError('Could not install the file %r' % tgt) return True elif Options.commands['uninstall']: info("* uninstalling %s" % tgt) self.uninstall.append(tgt) try: os.remove(tgt) except OSError: pass return True
def main(): global commands commands = Options.arg_line[:] while commands: x = commands.pop(0) ini = datetime.datetime.now() if x == 'configure': fun = configure elif x == 'build': fun = build else: fun = getattr(Utils.g_module, x, None) if not fun: raise Utils.WscriptError('No such command {0!r}'.format(x)) ctx = getattr(Utils.g_module, x + '_context', Utils.Context)() if x in ['init', 'shutdown', 'dist', 'distclean', 'distcheck']: # compatibility TODO remove in waf 1.6 try: fun(ctx) except TypeError: fun() else: fun(ctx) ela = '' if not Options.options.progress_bar: ela = ' ({0!s})'.format(Utils.get_elapsed_time(ini)) if x != 'init' and x != 'shutdown': info('{0!r} finished successfully{1!s}'.format(x, ela)) if not commands and x != 'shutdown': commands.append('shutdown')
def print_all_msvc_detected(conf): for version,targets in conf.env['MSVC_INSTALLED_VERSIONS']: info(version) for target,l in targets: info("\t"+target)
def print_all_msvc_detected(conf): for version, targets in conf.env['MSVC_INSTALLED_VERSIONS']: info(version) for target, l in targets: info("\t" + target)