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