diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2021-06-23 23:04:06 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gmail.com> | 2022-02-12 15:45:01 +0000 |
commit | 698a53859ae6cbdf351e0299d4d31227731bd706 (patch) | |
tree | 2c7c05c4dad305f4d37c1ec35dffe708496b3452 /giscanner | |
parent | e9956657be16c102a57443e474a5206756e40548 (diff) | |
download | gobject-introspection-698a53859ae6cbdf351e0299d4d31227731bd706.tar.gz |
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.
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/ccompiler.py | 8 | ||||
-rw-r--r-- | giscanner/scannermain.py | 4 | ||||
-rw-r--r-- | 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 576f78ac..64575557 100644 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -217,6 +217,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) @@ -458,6 +461,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', |