Ejemplo n.º 1
0
def DriverMain(module, argv):
    # TODO(robertm): this is ugly - try to get rid of this
    if '--pnacl-driver-verbose' in argv:
        Log.IncreaseVerbosity()
        env.set('LOG_VERBOSE', '1')

    # driver_path has the form: /foo/bar/pnacl_root/newlib/bin/pnacl-clang
    driver_path = pathtools.abspath(pathtools.normalize(argv[0]))
    driver_bin = pathtools.dirname(driver_path)
    script_name = pathtools.basename(driver_path)
    env.set('SCRIPT_NAME', script_name)
    env.set('DRIVER_PATH', driver_path)
    env.set('DRIVER_BIN', driver_bin)

    Log.SetScriptName(script_name)

    ReadConfig()

    if IsWindowsPython():
        SetupCygwinLibs()

    # skip tool name
    argv = argv[1:]

    # Handle help info
    if ('--help' in argv or '-h' in argv or '-help' in argv
            or '--help-full' in argv):
        help_func = getattr(module, 'get_help', None)
        if not help_func:
            Log.Fatal(HelpNotAvailable())
        helpstr = help_func(argv)
        print helpstr
        return 0

    return module.main(argv)
Ejemplo n.º 2
0
def MakeSelUniversalScriptForLD(ld_flags, llc_outputs, files, outfile):
    """ Return sel_universal script text for invoking LD.nexe with the
  given ld_flags, llc_outputs (which are treated specially), and
  other input files (for native libraries). The output will be written
  to outfile.  """
    script = []

    # Open the output file.
    script.append('readwrite_file nexefile %s' % outfile)

    files_to_map = list(files)
    # Create a reverse-service mapping for each input file and add it to
    # the sel universal script.
    for f in files_to_map:
        basename = pathtools.basename(f)
        # If we are using the dummy shim, map it with the filename of the real
        # shim, so the baked-in commandline will work.
        if basename == 'libpnacl_irt_shim_dummy.a':
            basename = 'libpnacl_irt_shim.a'
        script.append('reverse_service_add_manifest_mapping files/%s %s' %
                      (basename, f))

    modules = len(llc_outputs)
    script.extend([
        'readonly_file objfile%d %s' % (i, f)
        for i, f in zip(range(modules), llc_outputs)
    ])
    script.append('rpc RunWithSplit i(%d) ' % modules +
                  ' '.join(['h(objfile%s)' % m for m in range(modules)] +
                           ['h(invalid)'
                            for x in range(modules, 16)]) + ' h(nexefile) *')
    script.append('echo "ld complete"')
    script.append('')
    return '\n'.join(script)
Ejemplo n.º 3
0
def MakeSelUniversalScriptForLD(ld_flags,
                                llc_outputs,
                                files,
                                outfile):
  """ Return sel_universal script text for invoking LD.nexe with the
  given ld_flags, llc_outputs (which are treated specially), and
  other input files (for native libraries). The output will be written
  to outfile.  """
  script = []

  # Open the output file.
  script.append('readwrite_file nexefile %s' % outfile)

  files_to_map = list(files)
  # Create a reverse-service mapping for each input file and add it to
  # the sel universal script.
  for f in files_to_map:
    basename = pathtools.basename(f)
    # If we are using the dummy shim, map it with the filename of the real
    # shim, so the baked-in commandline will work.
    if basename == 'libpnacl_irt_shim_dummy.a':
      basename = 'libpnacl_irt_shim.a'
    script.append('reverse_service_add_manifest_mapping files/%s %s' %
                  (basename, f))

  modules = len(llc_outputs)
  script.extend(['readonly_file objfile%d %s' % (i, f)
                 for i, f in zip(range(modules), llc_outputs)])
  script.append('rpc RunWithSplit i(%d) ' % modules +
                ' '.join(['h(objfile%s)' % m for m in range(modules)] +
                         ['h(invalid)' for x in range(modules, 16)]) +
                ' h(nexefile) *')
  script.append('echo "ld complete"')
  script.append('')
  return '\n'.join(script)
Ejemplo n.º 4
0
def FindBaseToolchain():
    """ Find toolchain/OS_ARCH directory """
    base_dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain')
    if base_dir is None:
        Log.Fatal("Unable to find 'toolchain' directory")
    toolchain_dir = os.path.join(base_dir,
                                 '%s_%s' % (GetOSName(), GetArchNameShort()))
    return shell.escape(toolchain_dir)
Ejemplo n.º 5
0
def FindBaseToolchain():
  """ Find toolchain/OS_ARCH directory """
  base_dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain')
  if base_dir is None:
    Log.Fatal("Unable to find 'toolchain' directory")
  toolchain_dir = os.path.join(
      base_dir,
      '%s_%s' % (GetOSName(), GetArchNameShort())
  )
  return shell.escape(toolchain_dir)
Ejemplo n.º 6
0
def DefaultOutputName(filename, outtype):
    if outtype in ('pp', 'dis'): return '-'  # stdout

    base = pathtools.basename(filename)
    base = RemoveExtension(base)
    if outtype in ('po'): return base + '.o'

    assert (outtype in ExtensionMap.values())
    assert (not IsSourceType(outtype))

    return base + '.' + outtype
Ejemplo n.º 7
0
def DefaultOutputName(filename, outtype):
  if outtype in ('pp','dis'): return '-' # stdout

  base = pathtools.basename(filename)
  base = RemoveExtension(base)
  if outtype in ('po'): return base + '.o'

  assert(outtype in ExtensionMap.values())
  assert(not IsSourceType(outtype))

  return base + '.' + outtype
Ejemplo n.º 8
0
def DefaultOutputName(filename, outtype):
  # For pre-processor mode, just print to stdout.
  if outtype in ('pp'): return '-'

  base = pathtools.basename(filename)
  base = RemoveExtension(base)
  if outtype in ('po'): return base + '.o'

  assert(outtype in filetype.ExtensionMap.values())
  assert(not filetype.IsSourceType(outtype))

  return base + '.' + outtype
Ejemplo n.º 9
0
def DefaultOutputName(filename, outtype):
  # For pre-processor mode, just print to stdout.
  if outtype in ('pp'): return '-'

  base = pathtools.basename(filename)
  base = RemoveExtension(base)
  if outtype in ('po'): return base + '.o'

  assert(outtype in filetype.ExtensionMap.values())
  assert(not filetype.IsSourceType(outtype))

  return base + '.' + outtype
Ejemplo n.º 10
0
  def __init__(self, inputs, output):
    self.TempBase = tempfile.mkdtemp()
    inputs = [ pathtools.abspath(i) for i in inputs ]
    output = pathtools.basename(output)

    TempFiles.add(self.TempBase)

    self.Output = output + '---linked'


    # Build the initial mapping
    self.TempMap = dict()
    for f in inputs:
      if f.startswith('-'):
        continue
      path = PathSplit(f)
      self.TempMap[f] = [1, path]

    def MangledName(path):
      return output + '---' + '_'.join(path[-n:]) + '---'

    while True:
      # Find conflicts
      ConflictMap = dict()
      Conflicts = set()
      for (f, [n, path]) in self.TempMap.iteritems():
        candidate = pathtools.abspath(MangledName(path))
        if candidate in ConflictMap:
          Conflicts.add(ConflictMap[candidate])
          Conflicts.add(f)
        else:
          ConflictMap[candidate] = f

      if len(Conflicts) == 0:
        break

      # Resolve conflicts
      for f in Conflicts:
        n = self.TempMap[f][0]
        if n+1 > len(self.TempMap[f][1]):
          Log.Fatal('Unable to resolve naming conflicts')
        self.TempMap[f][0] = n+1

    # Clean up the map and put the paths in tempdir
    NewMap = dict()
    for (f, [n, path]) in self.TempMap.iteritems():
      NewMap[f] = os.path.join(self.TempBase, MangledName(path))
    self.TempMap = NewMap
    return
Ejemplo n.º 11
0
def FindBasePNaCl():
  """ Find the base directory of the PNaCl toolchain """
  # The bin/ directory is one of:
  # <base>/bin if <base> is /path/to/pnacl_translator
  # <base>/newlib/bin or <base>/glibc/bin otherwise
  bindir = env.getone('DRIVER_BIN')

  # If this is a translator dir, use pnacl_translator
  translator_dir = FindBaseDir(
      lambda cur: pathtools.basename(cur) == 'pnacl_translator')
  if translator_dir is not None:
    return shell.escape(translator_dir)
  # Else use ../..
  basedir = pathtools.dirname(pathtools.dirname(bindir))
  return shell.escape(basedir)
Ejemplo n.º 12
0
def FindBasePNaCl():
    """ Find the base directory of the PNaCl toolchain """
    # The bin/ directory is one of:
    # <base>/bin if <base> is /path/to/pnacl_translator
    # <base>/newlib/bin or <base>/glibc/bin otherwise
    bindir = env.getone('DRIVER_BIN')

    # If this is a translator dir, use pnacl_translator
    translator_dir = FindBaseDir(
        lambda cur: pathtools.basename(cur) == 'pnacl_translator')
    if translator_dir is not None:
        return shell.escape(translator_dir)
    # Else use ../..
    basedir = pathtools.dirname(pathtools.dirname(bindir))
    return shell.escape(basedir)
Ejemplo n.º 13
0
    def __init__(self, inputs, output):
        self.TempBase = tempfile.mkdtemp()
        inputs = [pathtools.abspath(i) for i in inputs]
        output = pathtools.basename(output)

        TempFiles.add(self.TempBase)

        self.Output = output + '---linked'

        # Build the initial mapping
        self.TempMap = dict()
        for f in inputs:
            if f.startswith('-'):
                continue
            path = PathSplit(f)
            self.TempMap[f] = [1, path]

        def MangledName(path):
            return output + '---' + '_'.join(path[-n:]) + '---'

        while True:
            # Find conflicts
            ConflictMap = dict()
            Conflicts = set()
            for (f, [n, path]) in self.TempMap.iteritems():
                candidate = pathtools.abspath(MangledName(path))
                if candidate in ConflictMap:
                    Conflicts.add(ConflictMap[candidate])
                    Conflicts.add(f)
                else:
                    ConflictMap[candidate] = f

            if len(Conflicts) == 0:
                break

            # Resolve conflicts
            for f in Conflicts:
                n = self.TempMap[f][0]
                if n + 1 > len(self.TempMap[f][1]):
                    Log.Fatal('Unable to resolve naming conflicts')
                self.TempMap[f][0] = n + 1

        # Clean up the map and put the paths in tempdir
        NewMap = dict()
        for (f, [n, path]) in self.TempMap.iteritems():
            NewMap[f] = os.path.join(self.TempBase, MangledName(path))
        self.TempMap = NewMap
        return
Ejemplo n.º 14
0
def DriverMain(module, argv):
  # TODO(robertm): this is ugly - try to get rid of this
  if '--pnacl-driver-verbose' in argv:
    Log.IncreaseVerbosity()
    env.set('LOG_VERBOSE', '1')

  # driver_path has the form: /foo/bar/pnacl_root/newlib/bin/pnacl-clang
  driver_path = pathtools.abspath(pathtools.normalize(argv[0]))
  driver_bin = pathtools.dirname(driver_path)
  script_name = pathtools.basename(driver_path)
  env.set('SCRIPT_NAME', script_name)
  env.set('DRIVER_PATH', driver_path)
  env.set('DRIVER_BIN', driver_bin)

  Log.SetScriptName(script_name)

  ReadConfig()

  if IsWindowsPython():
    SetupCygwinLibs()

  # skip tool name
  argv = argv[1:]

  # Handle help info
  if ('--help' in argv or
      '-h' in argv or
      '-help' in argv or
      '--help-full' in argv):
    help_func = getattr(module, 'get_help', None)
    if not help_func:
      Log.Fatal(HelpNotAvailable())
    helpstr = help_func(argv)
    print helpstr
    return 0

  return module.main(argv)
Ejemplo n.º 15
0
def FindBaseNaCl():
  """ Find native_client/ directory """
  dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'native_client')
  if dir is None:
    Log.Fatal("Unable to find 'native_client' directory")
  return shell.escape(dir)
Ejemplo n.º 16
0
def FindBaseNaCl():
  """ Find native_client/ directory """
  dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'native_client')
  if dir is None:
    Log.Fatal("Unable to find 'native_client' directory")
  return shell.escape(dir)
Ejemplo n.º 17
0
def FindBaseToolchain():
  """ Find toolchain/ directory """
  dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain')
  if dir is None:
    Log.Fatal("Unable to find 'toolchain' directory")
  return shell.escape(dir)
Ejemplo n.º 18
0
def FindBaseToolchain():
  """ Find toolchain/ directory """
  dir = FindBaseDir(lambda cur: pathtools.basename(cur) == 'toolchain')
  if dir is None:
    Log.Fatal("Unable to find 'toolchain' directory")
  return shell.escape(dir)