| Index: tools/telemetry/telemetry/core/build_extension.py
|
| diff --git a/tools/telemetry/telemetry/core/build_extension.py b/tools/telemetry/telemetry/core/build_extension.py
|
| index 38a635fc4c24ce1423009e5b8725ae74308cfe03..201563923c13199024ae3ff662a8faff7b0ee1e5 100644
|
| --- a/tools/telemetry/telemetry/core/build_extension.py
|
| +++ b/tools/telemetry/telemetry/core/build_extension.py
|
| @@ -2,6 +2,10 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +import os
|
| +import sys
|
| +import tempfile
|
| +
|
|
|
| def _FixDistutilsMsvcCompiler():
|
| # To avoid runtime mismatch, distutils should use the compiler which was used
|
| @@ -12,8 +16,9 @@ def _FixDistutilsMsvcCompiler():
|
| for version in [msvc9compiler.get_build_version(), 9.0, 10.0, 11.0, 12.0]:
|
| msvc9compiler.VERSION = version
|
| try:
|
| - msvc9compiler.MSVCCompiler().initialize()
|
| - return
|
| + compiler = msvc9compiler.MSVCCompiler()
|
| + compiler.initialize()
|
| + return compiler
|
| except Exception:
|
| pass
|
| raise Exception('Could not initialize MSVC compiler for distutils.')
|
| @@ -22,8 +27,6 @@ def _FixDistutilsMsvcCompiler():
|
| def BuildExtension(sources, output_dir, extension_name):
|
| from distutils import log
|
| from distutils.core import Distribution, Extension
|
| - import os
|
| - import tempfile
|
|
|
| build_dir = tempfile.mkdtemp()
|
| # Source file paths must be relative to current path.
|
| @@ -52,9 +55,27 @@ def BuildExtension(sources, output_dir, extension_name):
|
|
|
|
|
| if __name__ == '__main__':
|
| - import sys
|
| - assert len(sys.argv) > 3, (
|
| - 'Usage: build.py source-files output-dir ext-name\n'
|
| - 'got: ' + str(sys.argv)
|
| - )
|
| - BuildExtension(sys.argv[1:-2], sys.argv[-2], sys.argv[-1])
|
| + from distutils import sysconfig
|
| +
|
| + if os.name == 'nt':
|
| + msvc_compiler = _FixDistutilsMsvcCompiler()
|
| + cflags = ' '.join(msvc_compiler.compile_options)
|
| + ldflags = ' '.join(msvc_compiler.ldflags_shared)
|
| + else:
|
| + cflags = sysconfig.get_config_var('CFLAGS')
|
| + ldflags = sysconfig.get_config_var('LDFLAGS')
|
| + # Remove redundant flag in C++ builds.
|
| + cflags = cflags.replace('-Wstrict-prototypes', '')
|
| +
|
| + cmd = sys.argv[1] if len(sys.argv) > 1 else ''
|
| + values = {
|
| + 'cflags': cflags,
|
| + 'ldflags': ldflags,
|
| + 'include_dirs': sysconfig.get_python_inc(),
|
| + }
|
| + try:
|
| + print values[cmd]
|
| + except KeyError:
|
| + print >> sys.stderr, 'Usage: %s (%s)' % (
|
| + sys.argv[0], '|'.join(values.keys()))
|
| + sys.exit(-1)
|
|
|