summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2021-06-23 23:04:06 +0100
committerEmmanuele Bassi <ebassi@gmail.com>2021-07-29 16:18:20 +0000
commit5609cc54dde836d3d96878f131bd721db398d1b7 (patch)
tree407f8eefa78b773741740ec55c7c14f9780a9591
parentc691d9f03b93baddcd1f4e979a97e8d72a27d893 (diff)
downloadgobject-introspection-5609cc54dde836d3d96878f131bd721db398d1b7.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.
-rw-r--r--giscanner/ccompiler.py8
-rw-r--r--giscanner/scannermain.py4
-rw-r--r--giscanner/sourcescanner.py6
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',