From 5609cc54dde836d3d96878f131bd721db398d1b7 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 23 Jun 2021 23:04:06 +0100 Subject: Add --compiler argument to g-ir-scanner We currently use the `CC` environment variable to find the C compiler to use internally in g-ir-scanner. Build systems might wish to store the compiler detected during the build configuration, and then pass that compiler to g-ir-scanner at the time of build, avoiding to put things into the environment. One possible solution is to have a command line argument that lets us specify the C compiler, with the same semantics as the `CC` environment variable. --- giscanner/ccompiler.py | 8 ++++---- giscanner/scannermain.py | 4 ++++ giscanner/sourcescanner.py | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py index cb97e76f..a6be9ee6 100644 --- a/giscanner/ccompiler.py +++ b/giscanner/ccompiler.py @@ -124,9 +124,10 @@ class CCompiler(object): compiler_name != 'mingw32': raise SystemExit('Specified Compiler \'%s\' is unsupported.' % compiler_name) else: - # XXX: Is it common practice to use a non-Unix compiler - # class instance on non-Windows on platforms g-i supports? - compiler_name = distutils.ccompiler.get_default_compiler() + if compiler_name is None: + # XXX: Is it common practice to use a non-Unix compiler + # class instance on non-Windows on platforms g-i supports? + compiler_name = distutils.ccompiler.get_default_compiler() # Now, create the distutils ccompiler instance based on the info we have. if compiler_name == 'msvc': @@ -135,7 +136,6 @@ class CCompiler(object): # implementation from . import msvccompiler self.compiler = msvccompiler.get_msvc_compiler() - else: self.compiler = distutils.ccompiler.new_compiler(compiler=compiler_name) customize_compiler(self.compiler) diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 957ba0b7..ad2618b9 100644 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -214,6 +214,9 @@ match the namespace prefix.""") parser.add_option("", "--filelist", action="store", dest="filelist", default=[], help="file containing headers and sources to be scanned") + parser.add_option("", "--compiler", + action="store", dest="compiler", default=None, + help="the C compiler to use internally") group = get_preprocessor_option_group(parser) parser.add_option_group(group) @@ -455,6 +458,7 @@ def create_source_scanner(options, args): # Run the preprocessor, tokenize and construct simple # objects representing the raw C symbols ss = SourceScanner() + ss.set_compiler(options.compiler) ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines, diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py index 09f90441..9d567aee 100644 --- a/giscanner/sourcescanner.py +++ b/giscanner/sourcescanner.py @@ -231,6 +231,7 @@ class SourceScanner(object): self._scanner = CSourceScanner() self._filenames = [] self._cpp_options = [] + self._compiler = None # Public API @@ -244,6 +245,9 @@ class SourceScanner(object): if opt not in self._cpp_options: self._cpp_options.append(opt) + def set_compiler(self, compiler): + self._compiler = compiler + def parse_files(self, filenames): for filename in filenames: # self._scanner expects file names to be canonicalized and symlinks to be resolved @@ -290,7 +294,7 @@ class SourceScanner(object): defines = ['__GI_SCANNER__'] undefs = [] - cc = CCompiler() + cc = CCompiler(compiler_name=self._compiler) tmp_fd_cpp, tmp_name_cpp = tempfile.mkstemp(prefix='g-ir-cpp-', suffix='.c', -- cgit v1.2.1