Back to index

enigmail  1.4.3
pgomerge.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # Usage: pgomerge.py <binary basename> <dist/bin>
00003 # Gathers .pgc files from dist/bin and merges them into
00004 # $PWD/$basename.pgd using pgomgr, then deletes them.
00005 # No errors if any of these files don't exist.
00006 
00007 import sys, os, os.path, subprocess
00008 if not sys.platform == "win32":
00009     raise Exception("This script was only meant for Windows.")
00010 
00011 def MergePGOFiles(basename, pgddir, pgcdir):
00012   """Merge pgc files produced from an instrumented binary
00013      into the pgd file for the second pass of profile-guided optimization
00014      with MSVC.  |basename| is the name of the DLL or EXE without the
00015      extension.  |pgddir| is the path that contains <basename>.pgd
00016      (should be the objdir it was built in).  |pgcdir| is the path
00017      containing basename!N.pgc files, which is probably dist/bin.
00018      Calls pgomgr to merge each pgc file into the pgd, then deletes
00019      the pgc files."""
00020   if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir):
00021     return
00022   pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
00023   if not os.path.isfile(pgdfile):
00024     return
00025   for file in os.listdir(pgcdir):
00026     if file.startswith(basename+"!") and file.endswith(".pgc"):
00027       try:
00028         pgcfile = os.path.normpath(os.path.join(pgcdir, file))
00029         subprocess.call(['pgomgr', '-merge',
00030                          pgcfile,
00031                          pgdfile])
00032         os.remove(pgcfile)
00033       except OSError:
00034         pass
00035 
00036 if __name__ == '__main__':
00037   if len(sys.argv) != 3:
00038       print >>sys.stderr, "Usage: pgomerge.py <binary basename> <dist/bin>"
00039       sys.exit(1)
00040   MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])