nsprpub/build/win32/pgomerge.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/build/win32/pgomerge.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +#!/usr/bin/python
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +# Usage: pgomerge.py <binary basename> <dist/bin>
    1.10 +# Gathers .pgc files from dist/bin and merges them into
    1.11 +# $PWD/$basename.pgd using pgomgr, then deletes them.
    1.12 +# No errors if any of these files don't exist.
    1.13 +
    1.14 +import sys, os, os.path, subprocess
    1.15 +if not sys.platform == "win32":
    1.16 +    raise Exception("This script was only meant for Windows.")
    1.17 +
    1.18 +def MergePGOFiles(basename, pgddir, pgcdir):
    1.19 +  """Merge pgc files produced from an instrumented binary
    1.20 +     into the pgd file for the second pass of profile-guided optimization
    1.21 +     with MSVC.  |basename| is the name of the DLL or EXE without the
    1.22 +     extension.  |pgddir| is the path that contains <basename>.pgd
    1.23 +     (should be the objdir it was built in).  |pgcdir| is the path
    1.24 +     containing basename!N.pgc files, which is probably dist/bin.
    1.25 +     Calls pgomgr to merge each pgc file into the pgd, then deletes
    1.26 +     the pgc files."""
    1.27 +  if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir):
    1.28 +    return
    1.29 +  pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
    1.30 +  if not os.path.isfile(pgdfile):
    1.31 +    return
    1.32 +  for file in os.listdir(pgcdir):
    1.33 +    if file.startswith(basename+"!") and file.endswith(".pgc"):
    1.34 +      try:
    1.35 +        pgcfile = os.path.normpath(os.path.join(pgcdir, file))
    1.36 +        subprocess.call(['pgomgr', '-merge',
    1.37 +                         pgcfile,
    1.38 +                         pgdfile])
    1.39 +        os.remove(pgcfile)
    1.40 +      except OSError:
    1.41 +        pass
    1.42 +
    1.43 +if __name__ == '__main__':
    1.44 +  if len(sys.argv) != 3:
    1.45 +      print >>sys.stderr, "Usage: pgomerge.py <binary basename> <dist/bin>"
    1.46 +      sys.exit(1)
    1.47 +  MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])

mercurial