Beispiel #1
0
    def __init__(self, inputs, output):
        inputs = [pathtools.abspath(i) for i in inputs]
        output = pathtools.abspath(output)

        self.TempBase = output + '---linked'
        self.OutputDir = pathtools.dirname(output)

        # TODO(pdox): Figure out if there's a less confusing way
        #             to simplify the intermediate filename in this case.
        #if len(inputs) == 1:
        #  # There's only one input file, don't bother adding the source name.
        #  TempMap[inputs[0]] = output + '---'
        #  return

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

        while True:
            # Find conflicts
            ConflictMap = dict()
            Conflicts = set()
            for (f, [n, path]) in self.TempMap.iteritems():
                candidate = output + '---' + '_'.join(path[-n:]) + '---'
                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
        NewMap = dict()
        for (f, [n, path]) in self.TempMap.iteritems():
            candidate = output + '---' + '_'.join(path[-n:]) + '---'
            NewMap[f] = candidate
        self.TempMap = NewMap
        return
Beispiel #2
0
  def __init__(self, inputs, output):
    inputs = [ pathtools.abspath(i) for i in inputs ]
    output = pathtools.abspath(output)

    self.TempBase = output + '---linked'
    self.OutputDir = pathtools.dirname(output)

    # TODO(pdox): Figure out if there's a less confusing way
    #             to simplify the intermediate filename in this case.
    #if len(inputs) == 1:
    #  # There's only one input file, don't bother adding the source name.
    #  TempMap[inputs[0]] = output + '---'
    #  return

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

    while True:
      # Find conflicts
      ConflictMap = dict()
      Conflicts = set()
      for (f, [n, path]) in self.TempMap.iteritems():
        candidate = output + '---' + '_'.join(path[-n:]) + '---'
        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
    NewMap = dict()
    for (f, [n, path]) in self.TempMap.iteritems():
      candidate = output + '---' + '_'.join(path[-n:]) + '---'
      NewMap[f] = candidate
    self.TempMap = NewMap
    return
  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
    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
Beispiel #5
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)
 def TempNameForInput(self, input, imtype):
   fullpath = pathtools.abspath(input)
   # If input is already a temporary name, just add an extension
   if fullpath.startswith(self.TempBase):
     temp = fullpath + '.' + imtype
   else:
     # Source file
     temp = self.TempMap[fullpath] + '.' + imtype
   TempFiles.add(temp)
   return temp
 def TempNameForInput(self, input, imtype):
     fullpath = pathtools.abspath(input)
     # If input is already a temporary name, just add an extension
     if fullpath.startswith(self.TempBase):
         temp = fullpath + '.' + imtype
     else:
         # Source file
         temp = self.TempMap[fullpath] + '.' + imtype
     TempFiles.add(temp)
     return temp
Beispiel #8
0
def GetThinArchiveData(archive_filename, member, strtab_data):
  # Get member's filename (relative to the archive) and open the member
  # ourselves to check the data.
  member_filename = GetMemberFilename(member, strtab_data)
  member_filename = pathtools.join(
      pathtools.dirname(pathtools.abspath(archive_filename)),
      member_filename)
  member_fp = driver_log.DriverOpen(member_filename, 'rb')
  data = member_fp.read(member.size)
  member_fp.close()
  return data
Beispiel #9
0
def GetThinArchiveData(archive_filename, member, strtab_data):
    # Get member's filename (relative to the archive) and open the member
    # ourselves to check the data.
    member_filename = GetMemberFilename(member, strtab_data)
    member_filename = pathtools.join(
        pathtools.dirname(pathtools.abspath(archive_filename)),
        member_filename)
    member_fp = driver_log.DriverOpen(member_filename, 'rb')
    data = member_fp.read(member.size)
    member_fp.close()
    return data
Beispiel #10
0
  def TempNameForInput(self, input, imtype):
    fullpath = pathtools.abspath(input)
    # If input is already a temporary name, just change the extension
    if fullpath.startswith(self.TempBase):
      temp = self.TempBase + '.' + imtype
    else:
      # Source file
      temp = self.TempMap[fullpath] + '.' + imtype

    temp = self.ValidatePathLength(temp, imtype)
    TempFiles.add(temp)
    return temp
Beispiel #11
0
  def TempNameForInput(self, input, imtype):
    fullpath = pathtools.abspath(input)
    # If input is already a temporary name, just change the extension
    if fullpath.startswith(self.TempBase):
      temp = self.TempBase + '.' + imtype
    else:
      # Source file
      temp = self.TempMap[fullpath] + '.' + imtype

    if not env.getbool('SAVE_TEMPS'):
      TempFiles.add(temp)
    return temp
Beispiel #12
0
  def TempNameForInput(self, input, imtype):
    fullpath = pathtools.abspath(input)
    # If input is already a temporary name, just change the extension
    if fullpath.startswith(self.TempBase):
      temp = self.TempBase + '.' + imtype
    else:
      # Source file
      temp = self.TempMap[fullpath] + '.' + imtype

    if not env.getbool('SAVE_TEMPS'):
      TempFiles.add(temp)
    return temp
Beispiel #13
0
    def TempNameForInput(self, input, imtype):
        fullpath = pathtools.abspath(input)
        # If input is already a temporary name, just change the extension
        if fullpath.startswith(self.TempBase):
            temp = self.TempBase + '.' + imtype
        else:
            # Source file
            temp = self.TempMap[fullpath] + '.' + imtype

        temp = self.ValidatePathLength(temp, imtype)
        TempFiles.add(temp)
        return temp
Beispiel #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)
 def add(self, path):
   path = pathtools.abspath(path)
   self.files.append(path)
 def add(self, path):
   if env.getbool('SAVE_TEMPS'):
     return
   path = pathtools.abspath(path)
   self.files.append(path)
Beispiel #17
0
 def add(self, path):
     if env.getbool('SAVE_TEMPS'):
         return
     path = pathtools.abspath(path)
     self.files.append(path)
Beispiel #18
0
 def add(self, path):
     path = pathtools.abspath(path)
     self.files.append(path)