Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Unified Diff: pylib/gyp/msvs_emulation.py

Issue 10407108: ninja windows: support precompiled headers (Closed) Base URL: https://gyp.googlecode.com/svn/trunk
Patch Set: try from svn Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pylib/gyp/generator/ninja.py ('k') | pylib/gyp/xcode_emulation.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/msvs_emulation.py
===================================================================
--- pylib/gyp/msvs_emulation.py (revision 1396)
+++ pylib/gyp/msvs_emulation.py (working copy)
@@ -143,6 +143,8 @@
('msvs_settings', dict),
('msvs_system_include_dirs', list),
('msvs_disabled_warnings', list),
+ ('msvs_precompiled_header', str),
+ ('msvs_precompiled_source', str),
]
configs = spec['configurations']
for field, default in supported_fields:
@@ -275,13 +277,31 @@
cflags = filter(lambda x: not x.startswith('/MP'), cflags)
return cflags
+ def GetPrecompiledHeader(self, config, gyp_to_build_path):
+ """Returns an object that handles the generation of precompiled header
+ build steps."""
+ return _PchHelper(self, config, gyp_to_build_path)
+
+ def _GetPchFlags(self, config, extension):
+ """Get the flags to be added to the cflags for precompiled header support.
+ """
+ # The PCH is only built once by a particular source file. Usage of PCH must
+ # only be for the same language (i.e. C vs. C++), so only include the pch
+ # flags when the language matches.
+ if self.msvs_precompiled_header[config]:
+ source_ext = os.path.splitext(self.msvs_precompiled_source[config])[1]
+ if _LanguageMatchesForPch(source_ext, extension):
+ pch = os.path.split(self.msvs_precompiled_header[config])[1]
+ return ['/Yu' + pch, '/FI' + pch, '/Fp${pchprefix}.' + pch + '.pch']
+ return []
+
def GetCflagsC(self, config):
"""Returns the flags that need to be added to .c compilations."""
- return []
+ return self._GetPchFlags(config, '.c')
def GetCflagsCC(self, config):
"""Returns the flags that need to be added to .cc compilations."""
- return ['/TP']
+ return ['/TP'] + self._GetPchFlags(config, '.cc')
def _GetAdditionalLibraryDirectories(self, root, config, gyp_to_build_path):
"""Get and normalize the list of paths in AdditionalLibraryDirectories
@@ -438,6 +458,63 @@
flags = ['/char', 'signed', '/env', 'win32', '/Oicf']
return outdir, output, variables, flags
+
+def _LanguageMatchesForPch(source_ext, pch_source_ext):
+ c_exts = ('.c',)
+ cc_exts = ('.cc', '.cxx', '.cpp')
+ return ((source_ext in c_exts and pch_source_ext in c_exts) or
+ (source_ext in cc_exts and pch_source_ext in cc_exts))
+
+class PrecompiledHeader(object):
+ """Helper to generate dependencies and build rules to handle generation of
+ precompiled headers. Interface matches the GCH handler in xcode_emulation.py.
+ """
+ def __init__(self, settings, config, gyp_to_build_path):
+ self.settings = settings
+ self.config = config
+ self.gyp_to_build_path = gyp_to_build_path
+
+ def _PchHeader(self):
+ """Get the header that will appear in an #include line for all source
+ files."""
+ return os.path.split(self.settings.msvs_precompiled_header[self.config])[1]
+
+ def _PchSource(self):
+ """Get the source file that is built once to compile the pch data."""
+ return self.gyp_to_build_path(
+ self.settings.msvs_precompiled_source[self.config])
+
+ def _PchOutput(self):
+ """Get the name of the output of the compiled pch data."""
+ return '${pchprefix}.' + self._PchHeader() + '.pch'
+
+ def GetObjDependencies(self, sources, objs):
+ """Given a list of sources files and the corresponding object files,
+ returns a list of the pch files that should be depended upon. The
+ additional wrapping in the return value is for interface compatability
+ with make.py on Mac, and xcode_emulation.py."""
+ if not self._PchHeader():
+ return []
+ source = self._PchSource()
+ assert source
+ pch_ext = os.path.splitext(self._PchSource())[1]
+ for source in sources:
+ if _LanguageMatchesForPch(os.path.splitext(source)[1], pch_ext):
+ return [(None, None, self._PchOutput())]
+ return []
+
+ def GetPchBuildCommands(self):
+ """Returns [(path_to_pch, language_flag, language, header)].
+ |path_to_gch| and |header| are relative to the build directory."""
+ header = self._PchHeader()
+ source = self._PchSource()
+ if not source or not header:
+ return []
+ ext = os.path.splitext(source)[1]
+ lang = 'c' if ext == '.c' else 'cc'
+ return [(self._PchOutput(), '/Yc' + header, lang, source)]
+
+
vs_version = None
def GetVSVersion(generator_flags):
global vs_version
« no previous file with comments | « pylib/gyp/generator/ninja.py ('k') | pylib/gyp/xcode_emulation.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698