def osx(): info = otool(filename) # soname is None for an executable if info.soname is not None: info.libs[info.soname] = info.sopath for soname, sopath in info.libs.iteritems(): # /tmp/build/install/lib/libvwCore.5.dylib # base = libvwCore.5.dylib # looks for @executable_path/../lib/libvwCore.5.dylib # /opt/local/libexec/qt4-mac/lib/QtXml.framework/Versions/4/QtXml # base = QtXml.framework/Versions/4/QtXml # looks for @executable_path/../lib/QtXml.framework/Versions/4/QtXml # OSX rpath points to one specific file, not anything that matches the # library SONAME. We've already done a whitelist check earlier, so # ignore it if we can't find the lib we want # XXX: This code carries an implicit assumption that all # executables are one level below the root (because # @executable_path is always the exe path, not the path of the # current binary like $ORIGIN in linux) for rpath in searchpath: if P.exists(P.join(toplevel, rpath, soname)): new_path = P.join('@executable_path', '..', rpath, soname) # If the entry is the "self" one, it has to be changed differently if info.sopath == sopath: run('install_name_tool', '-id', new_path, filename) break else: run('install_name_tool', '-change', sopath, new_path, filename) break
def osx(): info = otool(filename) # soname is None for an executable if info.soname is not None: info.libs[info.soname] = info.sopath logger.debug('Soname: %s' % info.soname) for soname, sopath in info.libs.iteritems(): logger.debug(' Processing soname: %s' % soname) # OSX rpath points to one specific file, not anything that matches the # library SONAME. We've already done a whitelist check earlier, so # ignore it if we can't find the lib we want if info.sopath == sopath: run('install_name_tool', '-id', filename, filename) continue for rpath in searchpath: if P.exists(P.join(toplevel, rpath, soname)): new_path = P.join('@loader_path', P.relpath(P.join(toplevel,rpath,soname),P.dirname(filename))) # new_path = P.join('@loader_path', '..', rpath, soname) # If the entry is the "self" one, it has to be changed differently run('install_name_tool', '-change', sopath, new_path, filename) break
def strip(filename): '''Discard all symbols from this object file with OS specific flags''' flags = None def linux_flags(): typ = run('file', filename, output=True) if typ.find('current ar archive') != -1: return ['-g'] elif typ.find('SB executable') != -1 or typ.find( 'SB shared object') != -1: save_elf_debug(filename) return ['--strip-unneeded', '-R', '.comment'] elif typ.find('SB relocatable') != -1: return ['--strip-unneeded'] return [] def osx_flags(): return ['-S'] # Get flags from one of the two functions above then run the strip command. flags = [] os_type = get_platform().os if os_type == 'linux': flags = linux_flags() elif os_type == 'osx': flags = osx_flags() else: raise Exception('Unknown platform: ' + os_type) flags.append(filename) try: run('strip', *flags) except Exception as e: print("Failed running strip with flags: ", flags, ". Got the error: ", e)
def otool(filename): ''' Run otool on a binary >>> otool('/usr/lib/libSystem.B.dylib') otool(soname='libSystem.B.dylib', sopath='/usr/lib/libSystem.B.dylib', libs={'libmathCommon.A.dylib': '/usr/lib/system/libmathCommon.A.dylib'}) >>> otool('/bin/ls') otool(soname=None, sopath=None, libs={'libSystem.B.dylib': '/usr/lib/libSystem.B.dylib', 'libncurses.5.4.dylib': '/usr/lib/libncurses.5.4.dylib'}) ''' Ret = namedtuple('otool', 'soname sopath libs abs_rpaths rel_rpaths') r = re.compile('^\s*(\S+)') lines = run('otool', '-L', filename, output=True).split('\n') libs = {} out = filter(lambda x: len(x.strip()), run('otool', '-D', filename, output=True).split('\n')) assert len(out) > 0, 'Empty output for otool -D %s' % filename assert len(out) < 3, 'Unexpected otool output: %s' % out this_soname = None this_sopath = None if len(out) == 2: this_sopath = out[1] this_soname = P.basename(this_sopath) for i in range(1, len(lines)): m = r.search(lines[i]) if m: sopath = m.group(1) if this_sopath is not None and this_sopath == sopath: continue fidx = sopath.rfind('.framework') if fidx >= 0: soname = sopath[sopath.rfind('/', 0, fidx)+1:] else: soname = P.basename(sopath) libs[soname] = sopath # Identify the absolute RPATH dirs in the current install dir. # We'll wipe those later. Record the relative ones separately. abs_rpaths = [] rel_rpaths = [] lines = run('otool', '-l', filename, output=True).split('\n') for i in range(0, len(lines)): if re.search('cmd LC_RPATH', lines[i]): if i+2 >= len(lines): continue #print('found LC_RPATH: ' + lines[i+2]) m = re.match('^.*?path\s+([^\s]+)', lines[i+2]) if m: rpath_val = m.group(1) if re.search(os.getcwd(), rpath_val): # Keep only those in current dir, not system # ones. Not sure about this, but it works. abs_rpaths.append(rpath_val) else: rel_rpaths.append(rpath_val) return Ret(soname=this_soname, sopath=this_sopath, libs=libs, abs_rpaths=abs_rpaths, rel_rpaths=rel_rpaths)
def save_elf_debug(filename): debug = '%s.debug' % filename try: run('objcopy', '--only-keep-debug', filename, debug) run('objcopy', '--add-gnu-debuglink=%s' % debug, filename) except Exception: logger.warning('Failed to split debug info for %s' % filename) if P.exists(debug): remove(debug)
def osx(): info = otool(filename) # soname is None for an executable if info.soname is not None: info.libs[info.soname] = info.sopath # If we are not using relative paths .. always fix the install name. if not relative_name: run('install_name_tool', '-id', filename, filename) logger.debug("Trying to Bake %s" % filename) logger.debug("Info sopath %s" % info.sopath) logger.debug("Toplevel var %s" % toplevel) logger.debug("Possible search path %s" % searchpath) for soname, sopath in info.libs.iteritems(): logger.debug("Soname %s Sopath %s" % (soname, sopath)) # /tmp/build/install/lib/libvwCore.5.dylib # base = libvwCore.5.dylib # looks for @executable_path/../lib/libvwCore.5.dylib # /opt/local/libexec/qt4-mac/lib/QtXml.framework/Versions/4/QtXml # base = QtXml.framework/Versions/4/QtXml # looks for @executable_path/../lib/QtXml.framework/Versions/4/QtXml # OSX rpath points to one specific file, not anything that matches the # library SONAME. We've already done a whitelist check earlier, so # ignore it if we can't find the lib we want # XXX: This code carries an implicit assumption that all # executables are one level below the root (because # @executable_path is always the exe path, not the path of the # current binary like $ORIGIN in linux) for rpath in searchpath: if P.exists(P.join(toplevel, rpath, soname)): new_path = P.join('@rpath', soname) # If the entry is the "self" one, it has to be # changed differently if info.sopath == sopath: if relative_name: run('install_name_tool', '-id', new_path, filename) break else: run('install_name_tool', '-change', sopath, new_path, filename) break if len(info.libs): for rpath in searchpath: if run('install_name_tool', '-add_rpath', P.join('@executable_path', '..', rpath), filename, raise_on_failure=False) is None: logger.warn('Failed to add rpath on %s' % filename) if run('install_name_tool', '-add_rpath', P.join('@loader_path', '..', rpath), filename, raise_on_failure=False) is None: logger.warn('Failed to add rpath on %s' % filename)
def linux(): rel_to_top = P.relpath(toplevel, P.dirname(filename)) rpath = [P.join('$ORIGIN', rel_to_top, path) for path in searchpath] if run( 'chrpath', '-r', ':'.join(rpath), filename, raise_on_failure=False) is None: logger.warn('Failed to set_rpath on %s' % filename)
def linux(): rel_to_top = P.relpath(toplevel, P.dirname(filename)) rpath = [P.join('$ORIGIN', rel_to_top, path) for path in searchpath] if run('chrpath', '-r', ':'.join(rpath), filename, raise_on_failure = False) is None: # TODO: Apparently patchelf is better than chrpath when the # latter fails. Here, can use instead: # patchelf --set-rpath ':'.join(rpath) filename logger.warn('Failed to set_rpath on %s' % filename)
def bake(self, searchpath, baker = default_baker): logger.debug('Baking list------------------------------------------') for filename in self.distlist: logger.debug(' %s' % filename) for filename in self.distlist: baker(filename, self.distdir, searchpath) [remove(i) for i in run('find', self.distdir, '-name', '.*', '-print0').split('\0') if len(i) > 0 and i != '.' and i != '..'] [chmod(file, 0755) for file in glob(self.distdir.libexec('*')) + glob(self.distdir.bin('*'))]
def find_filter(self, *filter, **kw): dir = kw.get('dir', self.tarname) cwd = kw.get('cwd', P.dirname(self.distdir)) cmd = ['find', dir] + list(filter) out = run(*cmd, cwd=cwd) files = NamedTemporaryFile() files.write(out) files.flush() return files
def osx(): info = otool(filename) # soname is None for an executable if info.soname is not None: info.libs[info.soname] = info.sopath # If we are not using relative paths .. always fix the install name. if not relative_name: run('install_name_tool', '-id', filename, filename) logger.debug("Trying to Bake %s" % filename) logger.debug("Info sopath %s" % info.sopath) logger.debug("Toplevel var %s" % toplevel) logger.debug("Possible search path %s" % searchpath) for soname, sopath in info.libs.iteritems(): logger.debug("Soname %s Sopath %s" % (soname, sopath)) # /tmp/build/install/lib/libvwCore.5.dylib # base = libvwCore.5.dylib # looks for @executable_path/../lib/libvwCore.5.dylib # /opt/local/libexec/qt4-mac/lib/QtXml.framework/Versions/4/QtXml # base = QtXml.framework/Versions/4/QtXml # looks for @executable_path/../lib/QtXml.framework/Versions/4/QtXml # OSX rpath points to one specific file, not anything that matches the # library SONAME. We've already done a whitelist check earlier, so # ignore it if we can't find the lib we want # XXX: This code carries an implicit assumption that all # executables are one level below the root (because # @executable_path is always the exe path, not the path of the # current binary like $ORIGIN in linux) for rpath in searchpath: if P.exists(P.join(toplevel, rpath, soname)): new_path = P.join('@rpath', soname) # If the entry is the "self" one, it has to be # changed differently if info.sopath == sopath: if relative_name: run('install_name_tool', '-id', new_path, filename) break else: run('install_name_tool', '-change', sopath, new_path, filename) break if len(info.libs): for rpath in searchpath: if run('install_name_tool','-add_rpath',P.join('@executable_path','..',rpath), filename, raise_on_failure = False) is None: logger.warn('Failed to add rpath on %s' % filename) if run('install_name_tool','-add_rpath',P.join('@loader_path','..',rpath), filename, raise_on_failure = False) is None: logger.warn('Failed to add rpath on %s' % filename)
def find_filter(self, *filter, **kw): '''Call "find" with a filter argument and write results to an opened temporary file''' dir = kw.get('dir', self.tarname) cwd = kw.get('cwd', P.dirname(self.distdir)) cmd = ['find', dir] + list(filter) out = run(*cmd, cwd=cwd) files = NamedTemporaryFile() files.write(out) files.flush() return files
def linux(): typ = run('file', filename, output=True) if typ.find('current ar archive') != -1: return ['-g'] elif typ.find('SB executable') != -1 or typ.find('SB shared object') != -1: save_elf_debug(filename) return ['--strip-unneeded', '-R', '.comment'] elif typ.find('SB relocatable') != -1: return ['--strip-unneeded'] return None
def strip(filename): flags = None def linux(): typ = run('file', filename, output=True) if typ.find('current ar archive') != -1: return ['-g'] elif typ.find('SB executable') != -1 or typ.find('SB shared object') != -1: save_elf_debug(filename) return ['--strip-unneeded', '-R', '.comment'] elif typ.find('SB relocatable') != -1: return ['--strip-unneeded'] return None def osx(): return ['-S'] flags = locals()[get_platform().os]() flags.append(filename) run('strip', *flags)
def make_tarball(self, include = (), exclude = (), name = None): ''' exclude takes priority over include ''' if name is None: name = '%s.tar.gz' % self.tarname if isinstance(include, basestring): include = [include] if isinstance(exclude, basestring): exclude = [exclude] cmd = ['tar', 'czf', name, '-C', P.dirname(self.distdir)] if include: cmd += ['--no-recursion'] for i in include: cmd += ['-T', i] for e in exclude: cmd += ['-X', e] cmd.append(self.tarname) logger.info('Creating tarball %s' % name) run(*cmd)
def linux(): rel_to_top = P.relpath(toplevel, P.dirname(filename)) #small_path = searchpath[0:1] # truncate this as it can't fit rpath = [P.join('$ORIGIN', rel_to_top, path) for path in searchpath] if run( 'chrpath', '-r', ':'.join(rpath), filename, raise_on_failure=False) is None: # TODO: Apparently patchelf is better than chrpath when the # latter fails. Here, can use instead: # patchelf --set-rpath ':'.join(rpath) filename pass
def make_tarball(self, include=(), exclude=(), name=None): ''' exclude takes priority over include ''' if name is None: name = '%s.tar.bz2' % self.tarname if isinstance(include, basestring): include = [include] if isinstance(exclude, basestring): exclude = [exclude] cmd = ['tar', 'cf', name, '--use-compress-prog=pbzip2'] cmd += ['-C', P.dirname(self.distdir)] if include: cmd += ['--no-recursion'] for i in include: cmd += ['-T', i] for e in exclude: cmd += ['-X', e] cmd.append(self.tarname) logger.info('Creating tarball %s' % name) run(*cmd)
def strip(filename): flags = None def linux(): typ = run('file', filename, output=True) if typ.find('current ar archive') != -1: return ['-g'] elif typ.find('SB executable') != -1 or typ.find( 'SB shared object') != -1: save_elf_debug(filename) return ['--strip-unneeded', '-R', '.comment'] elif typ.find('SB relocatable') != -1: return ['--strip-unneeded'] return None def osx(): return ['-S'] flags = locals()[get_platform().os]() flags.append(filename) run('strip', *flags)
def strip(filename): '''Discard all symbols from this object file with OS specific flags''' flags = None def linux(): typ = run('file', filename, output=True) if typ.find('current ar archive') != -1: return ['-g'] elif typ.find('SB executable') != -1 or typ.find('SB shared object') != -1: save_elf_debug(filename) return ['--strip-unneeded', '-R', '.comment'] elif typ.find('SB relocatable') != -1: return ['--strip-unneeded'] return None def osx(): return ['-S'] # Get flags from one of the two functions above then run the strip command. flags = locals()[get_platform().os]() flags.append(filename) run('strip', *flags)
def make_tarball(self, include=(), exclude=(), name=None): '''Tar up all the files we have written to self.distdir. exclude takes priority over include ''' if name is None: name = '%s.tar.bz2' % self.tarname if isinstance(include, str): include = [include] if isinstance(exclude, str): exclude = [exclude] # For some reason permissions are wrong cmd = ['chmod', '-R', 'a+r', P.dirname(self.distdir)] run(*cmd) # Also use the current modification time. This also is not working # by default or some reason. cmd = ['touch', self.distdir] run(*cmd) cmd = ['tar', 'cf', name, '--use-compress-prog=pbzip2'] cmd += ['-C', P.dirname(self.distdir)] if include: cmd += ['--no-recursion'] for i in include: cmd += ['-T', i] for e in exclude: if os.path.exists(e): cmd += ['-X', e] cmd.append(self.tarname) logger.info('Creating tarball %s' % name) run(*cmd)
def make_tarball(self, include = (), exclude = (), name = None): '''Tar up all the files we have written to self.distdir. exclude takes priority over include ''' if name is None: name = '%s.tar.bz2' % self.tarname if isinstance(include, basestring): include = [include] if isinstance(exclude, basestring): exclude = [exclude] cmd = ['tar', 'cf', name, '--use-compress-prog=pbzip2'] cmd += ['-C', P.dirname(self.distdir)] if include: cmd += ['--no-recursion'] for i in include: cmd += ['-T', i] for e in exclude: cmd += ['-X', e] cmd.append(self.tarname) logger.info('Creating tarball %s' % name) run(*cmd)
def bake(self, searchpath, baker = default_baker): '''Updates the rpath of all files to be relative to distdir and strips it of symbols. Also cleans up some junk in self.distdir and sets file permissions.''' logger.debug('Baking list------------------------------------------') for filename in self.distlist: logger.debug(' %s' % filename) for filename in self.distlist: baker(filename, self.distdir, searchpath) # Delete all hidden files from the self.distdir folder [remove(i) for i in run('find', self.distdir, '-name', '.*', '-print0').split('\0') if len(i) > 0 and i != '.' and i != '..'] # Enable read/execute on all files in libexec and bin [chmod(file, 0755) for file in glob(self.distdir.libexec('*')) + glob(self.distdir.bin('*'))]
def otool(filename): ''' Run otool on a binary >>> otool('/usr/lib/libSystem.B.dylib') otool(soname='libSystem.B.dylib', sopath='/usr/lib/libSystem.B.dylib', libs={'libmathCommon.A.dylib': '/usr/lib/system/libmathCommon.A.dylib'}) >>> otool('/bin/ls') otool(soname=None, sopath=None, libs={'libSystem.B.dylib': '/usr/lib/libSystem.B.dylib', 'libncurses.5.4.dylib': '/usr/lib/libncurses.5.4.dylib'}) ''' Ret = namedtuple('otool', 'soname sopath libs') r = re.compile('^\s*(\S+)') lines = run('otool', '-L', filename, output=True).split('\n') libs = {} out = filter(lambda x: len(x.strip()), run('otool', '-D', filename, output=True).split('\n')) assert len(out) > 0, 'Empty output for otool -D %s' % filename assert len(out) < 3, 'Unexpected otool output: %s' % out this_soname = None this_sopath = None if len(out) == 2: this_sopath = out[1] this_soname = P.basename(this_sopath) for i in range(1, len(lines)): m = r.search(lines[i]) if m: sopath = m.group(1) if this_sopath is not None and this_sopath == sopath: continue fidx = sopath.rfind('.framework') if fidx >= 0: soname = sopath[sopath.rfind('/', 0, fidx) + 1:] else: soname = P.basename(sopath) libs[soname] = sopath return Ret(soname=this_soname, sopath=this_sopath, libs=libs)
def otool(filename): ''' Run otool on a binary >>> otool('/usr/lib/libSystem.B.dylib') otool(soname='libSystem.B.dylib', sopath='/usr/lib/libSystem.B.dylib', libs={'libmathCommon.A.dylib': '/usr/lib/system/libmathCommon.A.dylib'}) >>> otool('/bin/ls') otool(soname=None, sopath=None, libs={'libSystem.B.dylib': '/usr/lib/libSystem.B.dylib', 'libncurses.5.4.dylib': '/usr/lib/libncurses.5.4.dylib'}) ''' Ret = namedtuple('otool', 'soname sopath libs') r = re.compile('^\s*(\S+)') lines = run('otool', '-L', filename, output=True).split('\n') libs = {} out = filter(lambda x: len(x.strip()), run('otool', '-D', filename, output=True).split('\n')) assert len(out) > 0, 'Empty output for otool -D %s' % filename assert len(out) < 3, 'Unexpected otool output: %s' % out this_soname = None this_sopath = None if len(out) == 2: this_sopath = out[1] this_soname = P.basename(this_sopath) for i in range(1, len(lines)): m = r.search(lines[i]) if m: sopath = m.group(1) if this_sopath is not None and this_sopath == sopath: continue fidx = sopath.rfind('.framework') if fidx >= 0: soname = sopath[sopath.rfind('/', 0, fidx)+1:] else: soname = P.basename(sopath) libs[soname] = sopath return Ret(soname=this_soname, sopath=this_sopath, libs=libs)
def bake(self, searchpath, baker=default_baker): logger.debug('Baking list------------------------------------------') for filename in self.distlist: logger.debug(' %s' % filename) for filename in self.distlist: baker(filename, self.distdir, searchpath) [ remove(i) for i in run('find', self.distdir, '-name', '.*', '-print0').split('\0') if len(i) > 0 and i != '.' and i != '..' ] [ chmod(file, 0755) for file in glob(self.distdir.libexec('*')) + glob(self.distdir.bin('*')) ]
def ldd(filename): ''' Run ldd on a file >>> ldd('/lib/libc.so.6') {} >>> ldd('/bin/ls') # doctest:+ELLIPSIS {..., 'libc.so.6': '/lib/libc.so.6'} ''' libs = {} r = re.compile('^\s*(\S+) => (\S+)') for line in run('ldd', filename, output=True).split('\n'): m = r.search(line) if m: libs[m.group(1)] = (None if m.group(2) == 'not' else m.group(2)) return libs
def readelf(filename): ''' Run readelf on a file >>> readelf('/lib/libc.so.6') # doctest:+ELLIPSIS readelf(needed=['ld-linux-...'], soname='libc.so.6', rpath=[]) >>> readelf('/bin/ls') # doctest:+ELLIPSIS readelf(needed=[..., 'libc.so.6'], soname=None, rpath=[]) ''' Ret = namedtuple('readelf', 'needed soname rpath') r = re.compile(' \((.*?)\).*\[(.*?)\]') needed = [] soname = None rpath = [] for line in run('readelf', '-d', filename, output=True).split('\n'): m = r.search(line) if m: if m.group(1) == 'NEEDED': needed.append(m.group(2)) elif m.group(1) == 'SONAME': soname = m.group(2) elif m.group(1) == 'RPATH' : rpath = m.group(2).split(':') return Ret(needed, soname, rpath)
if opt.ld_library_path is not None: build_env['LD_LIBRARY_PATH'] = opt.ld_library_path # Bugfix, add compiler's libraries to LD_LIBRARY_PATH. comp_path = which(build_env['CC']) libdir1 = P.join(P.dirname(P.dirname(comp_path)), "lib") libdir2 = P.join(P.dirname(P.dirname(comp_path)), "lib64") if 'LD_LIBRARY_PATH' not in build_env: build_env['LD_LIBRARY_PATH'] = "" build_env['LD_LIBRARY_PATH'] += ":" + libdir1 + ":" + libdir2 arch = get_platform() # Check compiler version for compilers we hate output = run(build_env['CC'],'--version') if 'gcc' in build_env['CC']: output = output.lower() if "llvm" in output or "clang" in output: die('Your compiler is an LLVM-GCC hybrid. It is our experience that these tools can not compile Vision Workbench and Stereo Pipeline correctly. Please change your compiler choice.') if arch.os == 'linux': ver1 = get_prog_version(build_env['CC']) ver2 = get_prog_version(build_env['CXX']) if ver1 < MIN_CC_VERSION or ver2 < MIN_CC_VERSION: die('Expecting gcc and g++ version >= ' + str(MIN_CC_VERSION)) if arch.os == 'linux': build_env.append('LDFLAGS', '-Wl,-O1 -Wl,--enable-new-dtags -Wl,--hash-style=both') build_env.append_many(ALL_FLAGS, '-m%i' % arch.bits)
def is_binary(filename): '''Use the linux "file" tool to deterimen if a given file is a binary file''' ret = run('file', filename, output=True) return (ret.find('ELF') != -1) or (ret.find('Mach-O') != -1)
if not opt.dev: build.extend([visionworkbench, stereopipeline]) else: build = (globals()[pkg] for pkg in args) if opt.pretend: info('I want to build:\n%s' % ' '.join(map(lambda x: x.__name__, build))) summary(e) sys.exit(0) makelink(opt.build_root, 'last-run') if opt.base: print('Untarring base system') for base in opt.base: run('tar', 'xf', base, '-C', e['INSTALL_DIR'], '--strip-components', '1') modes = dict( all = lambda pkg : Package.build(pkg, skip_fetch=False), fetch = lambda pkg : pkg.fetch(), nofetch = lambda pkg : Package.build(pkg, skip_fetch=True)) try: for pkg in build: modes[opt.mode](pkg(e.copy_set_default())) except PackageError, e: die(e) makelink(opt.build_root, 'last-completed-run') info('\n\nAll done!')
if not len(args) == 2: usage("Missing required argument: installdir", code) tarball = P.realpath(args[0]) installdir = P.realpath(args[1]) if not P.exists(tarball): usage("Invalid tarball %s (does not exist)" % tarball, code) if not (P.exists(installdir)): os.makedirs(installdir) if not (P.isdir(installdir)): usage("Invalid installdir %s (not a directory)" % installdir, code) logging.basicConfig(level=opt.loglevel) if not opt.skip_extraction: print("Extracting tarball") run("tar", "xf", tarball, "-C", installdir, "--strip-components", "1") arch = get_platform() fix_install_paths(installdir, arch) # Replace /home/user with $HOME, looks nicer in the output vardir = installdir r = re.compile("^" + os.environ["HOME"] + "(.*?)$") m = r.search(vardir) if m: vardir = "$HOME" + m.group(1) prefix = "$PWD/build" config_file = P.join(installdir, "config.options.vw") write_vw_config(prefix, vardir, arch, config_file)
usage('Missing required argument: installdir') tarball = P.realpath(args[0]) installdir = P.realpath(args[1]) if not P.exists(tarball): usage('Invalid tarball %s (does not exist)' % tarball) if not (P.exists(installdir) and P.isdir(installdir)): usage('Invalid installdir %s (not a directory)' % installdir) logging.basicConfig(level=opt.loglevel) arch = get_platform() library_ext = "so" if arch.os == 'osx': library_ext = "dylib" print('Extracting tarball') run('tar', 'xf', tarball, '-C', installdir, '--strip-components', '1') ISISROOT = P.join(installdir,'isis') SEARCHPATH = [P.join(ISISROOT, 'lib'), P.join(ISISROOT,'3rdParty','lib'), P.join(installdir,'lib')] print('Fixing RPATHs') for curr_path in SEARCHPATH: for library in glob(P.join(curr_path,'*.'+library_ext+'*')): if not is_binary(library): continue print(' %s' % P.basename(library)) try: set_rpath_library(library, installdir, map(lambda path: P.relpath(path, installdir), SEARCHPATH)) #strip(filename) # Use this if you want to remove the debug symbols except: print(' Failed %s' % P.basename(library))
if not len(args) == 2: usage('Missing required argument: installdir', code) tarball = P.realpath(args[0]) installdir = P.realpath(args[1]) if not P.exists(tarball): usage('Invalid tarball %s (does not exist)' % tarball, code) if not (P.exists(installdir)): os.makedirs(installdir) if not (P.isdir(installdir)): usage('Invalid installdir %s (not a directory)' % installdir, code) logging.basicConfig(level=opt.loglevel) if not opt.skip_extraction: print('Extracting tarball') run('tar', 'xf', tarball, '-C', installdir, '--strip-components', '1') arch = get_platform() fix_install_paths(installdir, arch) # Replace /home/user with $HOME, looks nicer in the output vardir = installdir r = re.compile('^' + os.environ["HOME"] + '(.*?)$') m = r.search(vardir) if m: vardir = '$HOME' + m.group(1) prefix = '$PWD/build' config_file = P.join(installdir, 'config.options.vw') write_vw_config(prefix, vardir, arch, config_file)
def linux(): rel_to_top = P.relpath(toplevel, P.dirname(filename)) rpath = [P.join('$ORIGIN', rel_to_top, path) for path in searchpath] if run('chrpath', '-r', ':'.join(rpath), filename, raise_on_failure = False) is None: logger.warn('Failed to set_rpath on %s' % filename)
if opt.ld_library_path is not None: build_env['LD_LIBRARY_PATH'] = opt.ld_library_path # Bugfix, add compiler's libraries to LD_LIBRARY_PATH. comp_path = which(build_env['CC']) libdir1 = P.join(P.dirname(P.dirname(comp_path)), "lib") libdir2 = P.join(P.dirname(P.dirname(comp_path)), "lib64") if 'LD_LIBRARY_PATH' not in build_env: build_env['LD_LIBRARY_PATH'] = "" build_env['LD_LIBRARY_PATH'] += ":" + libdir1 + ":" + libdir2 arch = get_platform() # Check compiler version for compilers we hate output = run(build_env['CC'], '--version') if 'gcc' in build_env['CC']: output = output.lower() if "llvm" in output or "clang" in output: die('Your compiler is an LLVM-GCC hybrid. It is our experience that these tools can not compile Vision Workbench and Stereo Pipeline correctly. Please change your compiler choice.' ) if arch.os == 'linux': ver1 = get_prog_version(build_env['CC']) ver2 = get_prog_version(build_env['CXX']) if ver1 < MIN_CC_VERSION or ver2 < MIN_CC_VERSION: die('Expecting gcc and g++ version >= ' + str(MIN_CC_VERSION)) if arch.os == 'linux': build_env.append( 'LDFLAGS', '-Wl,-O1 -Wl,--enable-new-dtags -Wl,--hash-style=both')
def is_binary(filename): ret = run('file', filename, output=True) return (ret.find('ELF') != -1) or (ret.find('Mach-O') != -1)