コード例 #1
0
  def Run(self, argv):
    """Runs the compiler using the passed clang/gcc style argument list.

    Args:
      argv: List of arguments

    Returns:
      The return code of the compilation.

    Raises:
      ValueError: if target architecture isn't specified
    """
    parser = msvc_tools.ArgParser(self, argv, GCCPATTERNS)
    if not parser.target_arch:
      raise ValueError('Must specify target architecture (-m32 or -m64)')

    return self.RunBinary('cl', parser.options, parser.target_arch, parser)
コード例 #2
0
    def Run(self, argv):
        """Runs the compiler using the passed clang/gcc style argument list.

    Args:
      argv: List of arguments

    Returns:
      The return code of the compilation.

    Raises:
      ValueError: if target architecture isn't specified
    """
        parser = msvc_tools.ArgParser(self, argv, GCCPATTERNS)

        compiler = 'cl'
        if parser.is_cuda_compilation:
            compiler = 'nvcc'
        return self.RunBinary(compiler, parser.options, parser)
コード例 #3
0
    def Run(self, argv):
        """Runs the compiler using the passed clang/gcc style argument list.

    Args:
      argv: List of arguments

    Returns:
      The return code of the compilation.

    Raises:
      ValueError: if target architecture isn't specified
    """
        parser = msvc_tools.ArgParser(self, argv, GCCPATTERNS)

        # Select runtime option
        # Find the last runtime option passed
        rt = None
        rt_idx = -1
        for i, opt in enumerate(reversed(parser.options)):
            if opt in ['/MT', '/MTd', '/MD', '/MDd']:
                if opt[-1] == 'd':
                    parser.enforce_debug_rt = True
                rt = opt[:3]
                rt_idx = len(parser.options) - i - 1
                break
        rt = rt or '/MT'  # Default to static runtime
        # Add debug if necessary
        if parser.enforce_debug_rt:
            rt += 'd'
        # Include runtime option
        if rt_idx >= 0:
            parser.options[rt_idx] = rt
        else:
            if parser.is_cuda_compilation:
                parser.options.append('--compiler-options="%s"' % rt)
            else:
                parser.options.append(rt)

        compiler = 'cl'
        if parser.is_cuda_compilation:
            compiler = 'nvcc'
        return self.RunBinary(compiler, parser.options, parser)
コード例 #4
0
  def Run(self, argv):
    """Runs the linker using the passed clang/gcc style argument list.

    Args:
      argv: List of arguments

    Returns:
      The return code of the link.

    Raises:
      ValueError: if target architecture or compile mode isn't specified
    """
    # For now assume we are building a library.
    tool = 'lib'
    default_args = ['/nologo']

    # Build argument list.
    parser = msvc_tools.ArgParser(self, argv, LINKPATTERNS)

    # Preprocessing arguments for linking whole archive libraries
    parser.WholeArchivePreprocess()

    # Find the output file name.
    name = ''
    for arg in parser.options:
      if '/OUT:' in arg:
        name = re.sub(r'^"|"$', '', arg[5:])
    if not name:
      raise msvc_tools.Error('No output file name specified!')
    # Check if the library is empty, which is what happens when we create header
    # or intermediate link-only libraries.
    if (len(parser.options) == 2 and parser.options[0].startswith('/OUT') and
        parser.options[1].startswith('/M')):
      # Just "touch" the library to create the file.
      with open(name, 'w'):
        os.utime(name, None)
    else:
      # If the output name ends in .lo, or .a, it is a library, otherwise
      # we need to use link to create an executable.
      if os.path.splitext(name)[1] not in ['.a', '.lo']:
        tool = 'link'

        if not parser.target_arch:
          raise ValueError('Must specify target architecture (-m32 or -m64)')

        # Append explicit machine type.
        if parser.target_arch == 'x64':
          default_args.append('/MACHINE:X64')
        else:
          default_args.append('/MACHINE:X86')

        # Args for buildng a console application. These must appear here since
        # blaze will not properly pass them to the linker.
        # /SUBSYSTEM:CONSOLE: Build a console application.
        default_args += ['/SUBSYSTEM:CONSOLE']
        # If there is no .o on the command line, then we need to add the
        # run-time library for the target. Without this the linker gives a
        # LNK4001 error and cannot find an entry point.
        for arg in parser.options:
          if arg.endswith('.o'):
            break
        else:
          if not parser.compilation_mode:
            raise ValueError('Must specify compilation mode '
                             '(-Xcompilation-mode={dbg,fastbuild,opt})')

          if parser.compilation_mode == 'dbg':
            default_args.insert(0, 'libcmtd.lib')
          else:
            default_args.insert(0, 'libcmt.lib')

      return self.RunBinary(tool, default_args + parser.options,
                            parser.target_arch, parser)
コード例 #5
0
ファイル: msvc_link.py プロジェクト: shaopengyuan/bazel
    def Run(self, argv):
        """Runs the linker using the passed clang/gcc style argument list.

    Args:
      argv: List of arguments

    Returns:
      The return code of the link.

    Raises:
      ValueError: if target architecture or compile mode isn't specified
    """
        # For now assume we are building a library.
        tool = 'lib'
        default_args = []

        # Build argument list.
        parser = msvc_tools.ArgParser(self, argv, LINKPATTERNS)

        # Preprocessing arguments for linking whole archive libraries
        parser.WholeArchivePreprocess()

        # Find the output file name.
        name = ''
        for arg in parser.options:
            if '/OUT:' in arg:
                name = re.sub(r'^"|"$', '', arg[5:])
        if not name:
            raise msvc_tools.Error('No output file name specified!')
        # Check if the library is empty, which is what happens when we create header
        # or intermediate link-only libraries.
        if (len(parser.options) == 2 and parser.options[0].startswith('/OUT')
                and parser.options[1].startswith('/M')):
            # Just "touch" the library to create the file.
            with open(name, 'w'):
                os.utime(name, None)
        else:
            # If the output name ends in .lo, or .a, it is a library, otherwise
            # we need to use link to create an executable.
            if os.path.splitext(name)[1] not in ['.a', '.lo']:
                tool = 'link'

                # If there is no .o on the command line, then we need to add the
                # run-time library for the target. Without this the linker gives a
                # LNK4001 error and cannot find an entry point.
                for arg in parser.options:
                    if arg.endswith('.o'):
                        break
                else:
                    if not parser.compilation_mode:
                        raise ValueError(
                            'Must specify compilation mode '
                            '(-Xcompilation-mode={dbg,fastbuild,opt})')

                    rtlib = 'libcmt%s.lib'
                    # attempt to choose the right runtime library if we can
                    for opt in reversed(parser.options):
                        if opt in ['/MT', '/MTd']:
                            rtlib = 'msvcrt%s.lib'
                            break
                    default_args.insert(
                        0, rtlib %
                        ('d' if parser.compilation_mode == 'dbg' else ''))

            return self.RunBinary(tool, default_args + parser.options, parser)