Exemplo n.º 1
0
 def execute(self):
   env = dict(self.__env)
   import os
   env.update(os.environ)
   # Patch
   if self.__patch is not None:
     patch_path = str(drake.path_root() / self.__patch.path())
     patch_cmd = ['patch', '-N', '-p', '1', '-i', patch_path],
     if not self.cmd('Patch %s' % self.work_directory,
                     patch_cmd,
                     cwd = self.work_directory):
       return False
   # Configure step
   if self.__configure is not None:
      if not self.cmd('Configure %s' % self.work_directory,
                      self.command_configure,
                      cwd = self.work_directory,
                      env = env,
                      leave_stdout = self.__configure_stdout):
          return False
   # Build step
   if not self.cmd('Build %s' % self.work_directory,
                   self.command_build,
                   cwd = self.work_directory,
                   env = env,
                   leave_stdout = self.__build_stdout):
     return False
   for target in self.__targets:
     path = target.path().without_prefix(self.work_directory)
     if isinstance(target, drake.cxx.DynLib):
       rpath = '.'
     elif isinstance(target, drake.cxx.Executable):
       rpath = '../lib'
     else:
       continue
     with drake.WritePermissions(target):
       cmd = self.__toolkit.rpath_set_command(target.path(), rpath)
       if self.__toolkit.os is not drake.os.windows:
         if not self.cmd('Fix rpath for %s' % target.path(), cmd):
           return False
       if self.__toolkit.os is drake.os.macos:
         cmd = ['install_name_tool',
                '-id', '@rpath/%s' % target.name().basename(),
                 str(target.path())]
         if not self.cmd('Fix rpath for %s' % target.path(), cmd):
           return False
         lib_dependecies = self.parse_otool_libraries(target.path())
         for dep in lib_dependecies:
           if dep.basename() in (t.path().basename() for t in self.__targets):
             cmd = [
               'install_name_tool',
               '-change',
               str(dep),
               '@rpath/%s' % dep.basename(),
               str(target.path()),
             ]
             if not self.cmd('Fix dependency name for %s' % target.path(), cmd):
               return False
   return True
Exemplo n.º 2
0
 def _set_local_libcxx(tgt):
     if cxx_toolkit.os in [drake.os.macos]:
         with drake.WritePermissions(drake.node(tgt)):
             return drake.command([
                 'install_name_tool', '-change', '/usr/lib/libc++.1.dylib',
                 '@rpath/libc++.1.dylib',
                 str(drake.path_build(tgt, True))
             ])
     else:
         return True
Exemplo n.º 3
0
    def execute(self):
        self.output('Render %s' % self.__target)
        import mako.template, mako.lookup
        import mako.runtime
        import sys
        path = str(self.__template.path(absolute=True))
        previous = sys.path
        sys.path = sys.path[:]
        modules = set(sys.modules)
        for source in self.__hooks.keys():
            for hook in self.__hooks[source]:
                hook(self.__content, source)
        try:
            sys.path = [str(path) for path in self.__pythonpath] + sys.path
            with open(path, 'r') as tpl, \
                 tempfile.NamedTemporaryFile(mode = 'w') as content:
                line_number = 1

                def print_line_number():
                    if isinstance(self.__target,
                                  (drake.cxx.Source, drake.cxx.Header)):
                        print('# %d "%s"' % (line_number, path), file=content)

                print_line_number()
                for line in tpl:
                    print(line, file=content, end='')
                    if Renderer.mako_re.search(line): print_line_number()
                    line_number += 1
                content.flush()
                lookup = mako.lookup.TemplateLookup(directories=self.__lookup)
                tpl = mako.template.Template(filename=content.name,
                                             lookup=lookup)
                with drake.WritePermissions(self.__target):
                    with open(str(self.__target.path()), 'w') as f:
                        ctx = mako.runtime.Context(f, **self.__content)
                        tpl.render_context(ctx)
                    import shutil
                    shutil.copymode(str(self.__template.path()),
                                    str(self.__target.path()))
                    if self.__post_process:
                        self.__post_process(self.__target)
                return True
        finally:
            # Restore path.
            sys.path = previous
            # Unload modules to avoid side effects.
            for added in set(sys.modules) - modules:
                del sys.modules[added]