nsprpub/build/win32/pgomerge.py

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 #!/usr/bin/python
     2 # This Source Code Form is subject to the terms of the Mozilla Public
     3 # License, v. 2.0. If a copy of the MPL was not distributed with this
     4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6 # Usage: pgomerge.py <binary basename> <dist/bin>
     7 # Gathers .pgc files from dist/bin and merges them into
     8 # $PWD/$basename.pgd using pgomgr, then deletes them.
     9 # No errors if any of these files don't exist.
    11 import sys, os, os.path, subprocess
    12 if not sys.platform == "win32":
    13     raise Exception("This script was only meant for Windows.")
    15 def MergePGOFiles(basename, pgddir, pgcdir):
    16   """Merge pgc files produced from an instrumented binary
    17      into the pgd file for the second pass of profile-guided optimization
    18      with MSVC.  |basename| is the name of the DLL or EXE without the
    19      extension.  |pgddir| is the path that contains <basename>.pgd
    20      (should be the objdir it was built in).  |pgcdir| is the path
    21      containing basename!N.pgc files, which is probably dist/bin.
    22      Calls pgomgr to merge each pgc file into the pgd, then deletes
    23      the pgc files."""
    24   if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir):
    25     return
    26   pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
    27   if not os.path.isfile(pgdfile):
    28     return
    29   for file in os.listdir(pgcdir):
    30     if file.startswith(basename+"!") and file.endswith(".pgc"):
    31       try:
    32         pgcfile = os.path.normpath(os.path.join(pgcdir, file))
    33         subprocess.call(['pgomgr', '-merge',
    34                          pgcfile,
    35                          pgdfile])
    36         os.remove(pgcfile)
    37       except OSError:
    38         pass
    40 if __name__ == '__main__':
    41   if len(sys.argv) != 3:
    42       print >>sys.stderr, "Usage: pgomerge.py <binary basename> <dist/bin>"
    43       sys.exit(1)
    44   MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])

mercurial