OLD | NEW |
---|---|
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 This module helps emulate Visual Studio 2008 behavior on top of other | 6 This module helps emulate Visual Studio 2008 behavior on top of other |
7 build systems, primarily ninja. | 7 build systems, primarily ninja. |
8 """ | 8 """ |
9 | 9 |
10 import os | 10 import os |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 flags = ['/char', 'signed', '/env', 'win32', '/Oicf'] | 603 flags = ['/char', 'signed', '/env', 'win32', '/Oicf'] |
604 return outdir, output, variables, flags | 604 return outdir, output, variables, flags |
605 | 605 |
606 | 606 |
607 def _LanguageMatchesForPch(source_ext, pch_source_ext): | 607 def _LanguageMatchesForPch(source_ext, pch_source_ext): |
608 c_exts = ('.c',) | 608 c_exts = ('.c',) |
609 cc_exts = ('.cc', '.cxx', '.cpp') | 609 cc_exts = ('.cc', '.cxx', '.cpp') |
610 return ((source_ext in c_exts and pch_source_ext in c_exts) or | 610 return ((source_ext in c_exts and pch_source_ext in c_exts) or |
611 (source_ext in cc_exts and pch_source_ext in cc_exts)) | 611 (source_ext in cc_exts and pch_source_ext in cc_exts)) |
612 | 612 |
613 | |
613 class PrecompiledHeader(object): | 614 class PrecompiledHeader(object): |
614 """Helper to generate dependencies and build rules to handle generation of | 615 """Helper to generate dependencies and build rules to handle generation of |
615 precompiled headers. Interface matches the GCH handler in xcode_emulation.py. | 616 precompiled headers. Interface matches the GCH handler in xcode_emulation.py. |
616 """ | 617 """ |
617 def __init__(self, settings, config, gyp_to_build_path): | 618 def __init__( |
619 self, settings, config, gyp_to_build_path, gyp_to_unique_output, obj_ext): | |
618 self.settings = settings | 620 self.settings = settings |
619 self.config = config | 621 self.config = config |
620 self.gyp_to_build_path = gyp_to_build_path | 622 pch_source = self.settings.msvs_precompiled_source[self.config] |
623 self.pch_source = gyp_to_build_path(pch_source) | |
624 filename, _ = os.path.splitext(pch_source) | |
625 self.output_obj = gyp_to_unique_output(filename + obj_ext).lower() | |
621 | 626 |
622 def _PchHeader(self): | 627 def _PchHeader(self): |
623 """Get the header that will appear in an #include line for all source | 628 """Get the header that will appear in an #include line for all source |
624 files.""" | 629 files.""" |
625 return os.path.split(self.settings.msvs_precompiled_header[self.config])[1] | 630 return os.path.split(self.settings.msvs_precompiled_header[self.config])[1] |
626 | 631 |
627 def _PchSource(self): | |
628 """Get the source file that is built once to compile the pch data.""" | |
629 return self.gyp_to_build_path( | |
630 self.settings.msvs_precompiled_source[self.config]) | |
631 | |
632 def _PchOutput(self): | |
633 """Get the name of the output of the compiled pch data.""" | |
634 return '${pchprefix}.' + self._PchHeader() + '.pch' | |
635 | |
636 def GetObjDependencies(self, sources, objs): | 632 def GetObjDependencies(self, sources, objs): |
637 """Given a list of sources files and the corresponding object files, | 633 """Given a list of sources files and the corresponding object files, |
638 returns a list of the pch files that should be depended upon. The | 634 returns a list of the pch files that should be depended upon. The |
639 additional wrapping in the return value is for interface compatability | 635 additional wrapping in the return value is for interface compatability |
640 with make.py on Mac, and xcode_emulation.py.""" | 636 with make.py on Mac, and xcode_emulation.py.""" |
641 if not self._PchHeader(): | 637 if not self._PchHeader(): |
642 return [] | 638 return [] |
643 source = self._PchSource() | 639 pch_ext = os.path.splitext(self.pch_source)[1] |
644 assert source | |
645 pch_ext = os.path.splitext(self._PchSource())[1] | |
646 for source in sources: | 640 for source in sources: |
647 if _LanguageMatchesForPch(os.path.splitext(source)[1], pch_ext): | 641 if _LanguageMatchesForPch(os.path.splitext(source)[1], pch_ext): |
648 return [(None, None, self._PchOutput())] | 642 return [(None, None, self.output_obj)] |
649 return [] | 643 return [] |
650 | 644 |
651 def GetPchBuildCommands(self): | 645 def GetPchBuildCommands(self): |
652 """Returns [(path_to_pch, language_flag, language, header)]. | 646 """Not used on Windows as there are no additional build steps required |
653 |path_to_gch| and |header| are relative to the build directory.""" | 647 (instead, existing steps are modified in GetFlagsModifications below).""" |
654 header = self._PchHeader() | 648 return [] |
655 source = self._PchSource() | 649 |
656 if not source or not header: | 650 def GetFlagsModifications(self, input, output, implicit, command, |
Nico
2013/01/23 21:43:35
nit: input, output order in the parameters is the
| |
657 return [] | 651 cflags_c, cflags_cc, expand_special): |
658 ext = os.path.splitext(source)[1] | 652 """Get the modified cflags and implicit dependencies that should be used |
659 lang = 'c' if ext == '.c' else 'cc' | 653 for the pch compilation step.""" |
660 return [(self._PchOutput(), '/Yc' + header, lang, source)] | 654 if input == self.pch_source: |
655 pch_output = ['/Yc' + self._PchHeader()] | |
656 if command == 'cxx': | |
657 return ([('cflags_cc', map(expand_special, cflags_cc + pch_output))], | |
658 [], self.output_obj) | |
659 elif command == 'cc': | |
660 return ([('cflags_c', map(expand_special, cflags_c + pch_output))], | |
661 [], self.output_obj) | |
662 return [], implicit, output | |
661 | 663 |
662 | 664 |
663 vs_version = None | 665 vs_version = None |
664 def GetVSVersion(generator_flags): | 666 def GetVSVersion(generator_flags): |
665 global vs_version | 667 global vs_version |
666 if not vs_version: | 668 if not vs_version: |
667 vs_version = gyp.MSVSVersion.SelectVisualStudioVersion( | 669 vs_version = gyp.MSVSVersion.SelectVisualStudioVersion( |
668 generator_flags.get('msvs_version', 'auto')) | 670 generator_flags.get('msvs_version', 'auto')) |
669 return vs_version | 671 return vs_version |
670 | 672 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 so they're not surprised when the VS build fails.""" | 765 so they're not surprised when the VS build fails.""" |
764 if int(generator_flags.get('msvs_error_on_missing_sources', 0)): | 766 if int(generator_flags.get('msvs_error_on_missing_sources', 0)): |
765 no_specials = filter(lambda x: '$' not in x, sources) | 767 no_specials = filter(lambda x: '$' not in x, sources) |
766 relative = [os.path.join(build_dir, gyp_to_ninja(s)) for s in no_specials] | 768 relative = [os.path.join(build_dir, gyp_to_ninja(s)) for s in no_specials] |
767 missing = filter(lambda x: not os.path.exists(x), relative) | 769 missing = filter(lambda x: not os.path.exists(x), relative) |
768 if missing: | 770 if missing: |
769 # They'll look like out\Release\..\..\stuff\things.cc, so normalize the | 771 # They'll look like out\Release\..\..\stuff\things.cc, so normalize the |
770 # path for a slightly less crazy looking output. | 772 # path for a slightly less crazy looking output. |
771 cleaned_up = [os.path.normpath(x) for x in missing] | 773 cleaned_up = [os.path.normpath(x) for x in missing] |
772 raise Exception('Missing input files:\n%s' % '\n'.join(cleaned_up)) | 774 raise Exception('Missing input files:\n%s' % '\n'.join(cleaned_up)) |
OLD | NEW |