diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2015-03-10 13:15:52 +0800 |
---|---|---|
committer | Chun-wei Fan <fanchunwei@src.gnome.org> | 2015-07-30 11:01:01 +0800 |
commit | ad8fc51441b331c7db573201dd283a423081c042 (patch) | |
tree | f54c33c452d90e3c1b814b366e9072563236069c /giscanner/sourcescanner.py | |
parent | 0638f9f130fe080f945d07cde5cc01835a80553a (diff) | |
download | gobject-introspection-ad8fc51441b331c7db573201dd283a423081c042.tar.gz |
sourcescanner.py: Use Distutils for Preprocessing
Add a preprocess() function in ccompiler.py so that it will call the
preprocess() method of the distutils.ccompiler class, and make use of it
from sourcescanner.py.
As we would need to set up the options (include paths, macros, undefs) to
pass into the preprocessor (and later for the compiler), we have a new
private function that translates what we have from the rest of giscanner so
that it could be passed to distutils.ccompiler in a way that it
understands.
Also, as the MSVCCompiler classes in distutils do not provide a
preprocess() implementation, we provide our own so that we can use it when
preprocessing, via distutils, through subclassing MSVCCompiler.
https://bugzilla.gnome.org/show_bug.cgi?id=728313
Diffstat (limited to 'giscanner/sourcescanner.py')
-rw-r--r-- | giscanner/sourcescanner.py | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py index 9310cff2..e66ed7de 100644 --- a/giscanner/sourcescanner.py +++ b/giscanner/sourcescanner.py @@ -25,6 +25,7 @@ import tempfile from .libtoolimporter import LibtoolImporter from .message import Position +from .ccompiler import CCompiler with LibtoolImporter(None, None): if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ: @@ -282,6 +283,8 @@ class SourceScanner(object): defines = ['__GI_SCANNER__'] undefs = [] + cc = CCompiler() + tmp_fd_cpp, tmp_name_cpp = tempfile.mkstemp(prefix='g-ir-cpp-', suffix='.c') fp_cpp = os.fdopen(tmp_fd_cpp, 'w') self._write_preprocess_src(fp_cpp, defines, undefs, filenames) @@ -293,46 +296,9 @@ class SourceScanner(object): # so we want the name to match the output file name of the MSVC preprocessor tmpfile_output = tmpfile_basename + '.i' - cpp_args = os.environ.get('CC', 'cc').split() # support CC="ccache gcc" - - cpp_args += ['-E', '-C', '-I.'] - - # MSVC: The '-P' option makes the preprocessor output to a file, but we - # can't specify directly the name of the output file, so we use the - # MSVC-style preprocessor output file name for all builds for simplicity - # Define the following macros to silence many, many warnings - # in using the MSVC preprocessor during the parsing stage... - if 'cl.exe' in cpp_args or 'cl' in cpp_args: - cpp_args += ('-P', - '-D_USE_DECLSPECS_FOR_SAL', - '-D_CRT_SECURE_NO_WARNINGS', - '-D_CRT_NONSTDC_NO_WARNINGS', - '-DSAL_NO_ATTRIBUTE_DECLARATIONS') - - cpp_args += self._cpp_options - cpp_args += [tmp_name_cpp] - - # We expect the preprocessor to remove macros. If debugging is turned - # up high enough that won't happen, so strip these out. Bug #720504 - for flag in ['-g3', '-ggdb3', '-gstabs3', '-gcoff3', '-gxcoff3', '-gvms3']: - try: - cpp_args.remove(flag) - except ValueError: - pass - - proc = subprocess.Popen(cpp_args, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE) - - if 'cl.exe' not in cpp_args and'cl' not in cpp_args: - cpp_args += ['-o', tmpfile_output] - - proc = subprocess.Popen(cpp_args) - - assert proc, 'Proc was none' - proc.wait() - if proc.returncode != 0: - raise SystemExit('Error while processing the source.') + cc.preprocess(tmp_name_cpp, + tmpfile_output, + self._cpp_options) os.unlink(tmp_name_cpp) fp = open(tmpfile_output, 'r') |