parameters: (pdb_filename, verbose=True, build_dir=None, toolchain_dir=None)
docstring: Update a pdb file with source information.
docstring_summary: Update a pdb file with source information.
docstring_tokens: Update a pdb file with source information .
function: def UpdatePDB(pdb_filename, verbose=True, build_dir=None, toolchain_dir=None):
    """Update a pdb file with source information."""
    dir_blacklist = { }
  
    if build_dir:
      # Blacklisting the build directory allows skipping the generated files, for
      # Chromium this makes the indexing ~10x faster.
      build_dir = (os.path.normpath(build_dir)).lower()
      for directory, _, _ in os.walk(build_dir):
        dir_blacklist[directory.lower()] = True
      dir_blacklist[build_dir.lower()] = True
  
    if toolchain_dir:
      # Blacklisting the directories from the toolchain as we don't have revision
      # info for them.
      toolchain_dir = (os.path.normpath(toolchain_dir)).lower()
      for directory, _, _ in os.walk(build_dir):
        dir_blacklist[directory.lower()] = True
      dir_blacklist[toolchain_dir.lower()] = True
  
    # Writes the header of the source index stream.
    #
    # Here's the description of the variables used in the SRC_* macros (those
    # variables have to be defined for every source file that we want to index):
    #   var1: The file path.
    #   var2: The name of the file without its path.
    #   var3: The revision or the hash of this file's repository.
    #   var4: The URL to this file.
    #   var5: (optional) The python method to call to decode this file, e.g. for
    #       a base64 encoded file this value should be 'base64.b64decode'.
    lines = [
      'SRCSRV: ini ------------------------------------------------',
      'VERSION=1',
      'INDEXVERSION=2',
      'VERCTRL=Subversion',
      'DATETIME=%s' % time.asctime(),
      'SRCSRV: variables ------------------------------------------',
      'SRC_EXTRACT_TARGET_DIR=%targ%\%fnbksl%(%var2%)\%var3%',
      'SRC_EXTRACT_TARGET=%SRC_EXTRACT_TARGET_DIR%\%fnfile%(%var1%)',
      'SRC_EXTRACT_CMD=cmd /c "mkdir "%SRC_EXTRACT_TARGET_DIR%" & python -c '
          '"import urllib2, base64;'
          'url = \\\"%var4%\\\";'
          'u = urllib2.urlopen(url);'
          'print %var5%(u.read());" > "%SRC_EXTRACT_TARGET%""',
      'SRCSRVTRG=%SRC_EXTRACT_TARGET%',
      'SRCSRVCMD=%SRC_EXTRACT_CMD%',
      'SRCSRV: source files ---------------------------------------',
    ]
  
    if ReadSourceStream(pdb_filename):
      raise Exception("PDB already has source indexing information!")
  
    filelist = ExtractSourceFiles(pdb_filename)
    number_of_files = len(filelist)
    indexed_files_total = 0
    while filelist:
      filename = next(iter(filelist))
      filedir = os.path.dirname(filename)
      if verbose:
        print "[%d / %d] Processing: %s" % (number_of_files - len(filelist),
            number_of_files, filename)
  
      # This directory is blacklisted, either because it's not part of a
      # repository, or from one we're not interested in indexing.
      if dir_blacklist.get(filedir, False):
        if verbose:
          print "  skipping, directory is blacklisted."
        filelist.remove(filename)
        continue
  
      # Skip the files that don't exist on the current machine.
      if not os.path.exists(filename):
        filelist.remove(filename)
        continue
  
      # Try to index the current file and all the ones coming from the same
      # repository.
      indexed_files = IndexFilesFromRepo(filename, filelist, lines)
      if not indexed_files:
        if not DirectoryIsUnderPublicVersionControl(filedir):
          dir_blacklist[filedir] = True
          if verbose:
            print "Adding %s to the blacklist." % filedir
        filelist.remove(filename)
        continue
  
      indexed_files_total += indexed_files
  
      if verbose:
        print "  %d files have been indexed." % indexed_files
  
    lines.append('SRCSRV: end ------------------------------------------------')
  
    WriteSourceStream(pdb_filename, '\r\n'.join(lines))
  
    if verbose:
      print "%d / %d files have been indexed." % (indexed_files_total,
                                                  number_of_files)
function_tokens: def UpdatePDB ( pdb_filename , verbose = True , build_dir = None , toolchain_dir = None ) : dir_blacklist = { } if build_dir : # Blacklisting the build directory allows skipping the generated files, for # Chromium this makes the indexing ~10x faster. build_dir = ( os . path . normpath ( build_dir ) ) . lower ( ) for directory , _ , _ in os . walk ( build_dir ) : dir_blacklist [ directory . lower ( ) ] = True dir_blacklist [ build_dir . lower ( ) ] = True if toolchain_dir : # Blacklisting the directories from the toolchain as we don't have revision # info for them. toolchain_dir = ( os . path . normpath ( toolchain_dir ) ) . lower ( ) for directory , _ , _ in os . walk ( build_dir ) : dir_blacklist [ directory . lower ( ) ] = True dir_blacklist [ toolchain_dir . lower ( ) ] = True # Writes the header of the source index stream. # # Here's the description of the variables used in the SRC_* macros (those # variables have to be defined for every source file that we want to index): #   var1: The file path. #   var2: The name of the file without its path. #   var3: The revision or the hash of this file's repository. #   var4: The URL to this file. #   var5: (optional) The python method to call to decode this file, e.g. for #       a base64 encoded file this value should be 'base64.b64decode'. lines = [ 'SRCSRV: ini ------------------------------------------------' , 'VERSION=1' , 'INDEXVERSION=2' , 'VERCTRL=Subversion' , 'DATETIME=%s' % time . asctime ( ) , 'SRCSRV: variables ------------------------------------------' , 'SRC_EXTRACT_TARGET_DIR=%targ%\%fnbksl%(%var2%)\%var3%' , 'SRC_EXTRACT_TARGET=%SRC_EXTRACT_TARGET_DIR%\%fnfile%(%var1%)' , 'SRC_EXTRACT_CMD=cmd /c "mkdir "%SRC_EXTRACT_TARGET_DIR%" & python -c ' '"import urllib2, base64;' 'url = \\\"%var4%\\\";' 'u = urllib2.urlopen(url);' 'print %var5%(u.read());" > "%SRC_EXTRACT_TARGET%""' , 'SRCSRVTRG=%SRC_EXTRACT_TARGET%' , 'SRCSRVCMD=%SRC_EXTRACT_CMD%' , 'SRCSRV: source files ---------------------------------------' , ] if ReadSourceStream ( pdb_filename ) : raise Exception ( "PDB already has source indexing information!" ) filelist = ExtractSourceFiles ( pdb_filename ) number_of_files = len ( filelist ) indexed_files_total = 0 while filelist : filename = next ( iter ( filelist ) ) filedir = os . path . dirname ( filename ) if verbose : print "[%d / %d] Processing: %s" % ( number_of_files - len ( filelist ) , number_of_files , filename ) # This directory is blacklisted, either because it's not part of a # repository, or from one we're not interested in indexing. if dir_blacklist . get ( filedir , False ) : if verbose : print "  skipping, directory is blacklisted." filelist . remove ( filename ) continue # Skip the files that don't exist on the current machine. if not os . path . exists ( filename ) : filelist . remove ( filename ) continue # Try to index the current file and all the ones coming from the same # repository. indexed_files = IndexFilesFromRepo ( filename , filelist , lines ) if not indexed_files : if not DirectoryIsUnderPublicVersionControl ( filedir ) : dir_blacklist [ filedir ] = True if verbose : print "Adding %s to the blacklist." % filedir filelist . remove ( filename ) continue indexed_files_total += indexed_files if verbose : print "  %d files have been indexed." % indexed_files lines . append ( 'SRCSRV: end ------------------------------------------------' ) WriteSourceStream ( pdb_filename , '\r\n' . join ( lines ) ) if verbose : print "%d / %d files have been indexed." % ( indexed_files_total , number_of_files )