Skip to content

Commit

Permalink
ninja depscanner: handle C++ sources named capital C
Browse files Browse the repository at this point in the history
In commit 4ca9a16 we added unreliable
support (it warns you if you try it) for gcc-compatible treatment of
uppercase-C files being C++ instead of C. In order to handle it
correctly, we needed to evaluate can-compile by special-casing "C" to
avoid lowercasing it for comparisons.

This didn't cover all cases where we check if "C" is a C++ language
file. We also straight-up check the language of a file (rather than
working backwards to see if a C++ compiler can compile it) when doing
module scanning, and this needs to special-case "C" as well.

We also had one case where we only checked lowercase fortran extensions,
but not lowercase C++ extensions. While we are at it, use lowercase for
C++ as well, except the "C" special case.

Fixes #10629
  • Loading branch information
eli-schwartz authored and nirbheek committed Aug 8, 2022
1 parent 552e06b commit fadf7cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions mesonbuild/backend/ninjabackend.py
Expand Up @@ -975,7 +975,9 @@ def select_sources_to_scan(self, compiled_sources):
all_suffixes = set(compilers.lang_suffixes['cpp']) | set(compilers.lang_suffixes['fortran'])
selected_sources = []
for source in compiled_sources:
ext = os.path.splitext(source)[1][1:].lower()
ext = os.path.splitext(source)[1][1:]
if ext != 'C':
ext = ext.lower()
if ext in all_suffixes:
selected_sources.append(source)
return selected_sources
Expand Down Expand Up @@ -2706,7 +2708,9 @@ def add_dependency_scanner_entries_to_element(self, target, compiler, element, s
if not self.should_use_dyndeps_for_target(target):
return
extension = os.path.splitext(src.fname)[1][1:]
if not (extension.lower() in compilers.lang_suffixes['fortran'] or extension in compilers.lang_suffixes['cpp']):
if extension != 'C':
extension = extension.lower()
if not (extension in compilers.lang_suffixes['fortran'] or extension in compilers.lang_suffixes['cpp']):
return
dep_scan_file = self.get_dep_scan_file_for(target)
element.add_item('dyndep', dep_scan_file)
Expand Down
4 changes: 3 additions & 1 deletion mesonbuild/scripts/depscan.py
Expand Up @@ -51,7 +51,9 @@ def __init__(self, pickle_file: str, outfile: str, sources: T.List[str]):
self.sources_with_exports: T.List[str] = []

def scan_file(self, fname: str) -> None:
suffix = os.path.splitext(fname)[1][1:].lower()
suffix = os.path.splitext(fname)[1][1:]
if suffix != 'C':
suffix = suffix.lower()
if suffix in lang_suffixes['fortran']:
self.scan_fortran_file(fname)
elif suffix in lang_suffixes['cpp']:
Expand Down

0 comments on commit fadf7cc

Please sign in to comment.