Skip to content

Commit 5b109c9

Browse files
committed
correct missing argument for IntelClFortranCompiler
ifort passes all tests cleanup logic
1 parent 59e5ad6 commit 5b109c9

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ def generate_single_compile(self, target, src, is_generated=False, header_deps=N
21642164
# outdir argument instead.
21652165
# https://github.com/mesonbuild/meson/issues/1348
21662166
if not is_generated:
2167-
abs_src = os.path.join(build_dir, rel_src)
2167+
abs_src = Path(build_dir) / rel_src
21682168
extra_deps += self.get_fortran_deps(compiler, abs_src, target)
21692169
# Dependency hack. Remove once multiple outputs in Ninja is fixed:
21702170
# https://groups.google.com/forum/#!topic/ninja-build/j-2RfBIOd_8
@@ -2802,7 +2802,7 @@ def _scan_fortran_file_deps(src: Path, srcdir: Path, dirname: Path, tdeps, compi
28022802
# a common occurrence, which would lead to lots of
28032803
# distracting noise.
28042804
continue
2805-
srcfile = srcdir / tdeps[usename].fname
2805+
srcfile = srcdir / tdeps[usename].fname # type: Path
28062806
if not srcfile.is_file():
28072807
if srcfile.name != src.name: # generated source file
28082808
pass
@@ -2824,7 +2824,7 @@ def _scan_fortran_file_deps(src: Path, srcdir: Path, dirname: Path, tdeps, compi
28242824
ancestor_child = '_'.join(parents)
28252825
if ancestor_child not in tdeps:
28262826
raise MesonException("submodule {} relies on ancestor module {} that was not found.".format(submodmatch.group(2).lower(), ancestor_child.split('_')[0]))
2827-
submodsrcfile = srcdir / tdeps[ancestor_child].fname
2827+
submodsrcfile = srcdir / tdeps[ancestor_child].fname # type: Path
28282828
if not submodsrcfile.is_file():
28292829
if submodsrcfile.name != src.name: # generated source file
28302830
pass

mesonbuild/compilers/fortran.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ def sanity_check(self, work_dir: Path, environment):
6565
extra_flags = environment.coredata.get_external_args(self.for_machine, self.language)
6666
extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
6767
extra_flags += self.get_always_args()
68-
# %% build the test executable
69-
pc = subprocess.Popen(self.exelist + extra_flags + [str(source_name), '-o', str(binary_name)])
70-
pc.wait()
71-
if pc.returncode != 0:
68+
# %% build the test executable "sanitycheckf"
69+
# cwd=work_dir is necessary on Windows especially for Intel compilers to avoid error: cannot write on sanitycheckf.obj
70+
# this is a defect with how Windows handles files and ifort's object file-writing behavior vis concurrent ProcessPoolExecutor.
71+
# This simple workaround solves the issue.
72+
returncode = subprocess.run(self.exelist + extra_flags + [str(source_name), '-o', str(binary_name)],
73+
cwd=work_dir).returncode
74+
if returncode != 0:
7275
raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
7376
if self.is_cross:
7477
if self.exe_wrapper is None:
@@ -79,9 +82,8 @@ def sanity_check(self, work_dir: Path, environment):
7982
cmdlist = [str(binary_name)]
8083
# %% Run the test executable
8184
try:
82-
pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
83-
pe.wait()
84-
if pe.returncode != 0:
85+
returncode = subprocess.run(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
86+
if returncode != 0:
8587
raise EnvironmentException('Executables created by Fortran compiler %s are not runnable.' % self.name_string())
8688
except OSError:
8789
raise EnvironmentException('Executables created by Fortran compiler %s are not runnable.' % self.name_string())
@@ -271,8 +273,8 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
271273
'custom': [],
272274
}
273275

274-
def __init__(self, exelist, version, is_cross, target: str, exe_wrapper=None):
275-
FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
276+
def __init__(self, exelist, for_machine: MachineChoice, version, is_cross, target: str, exe_wrapper=None):
277+
FortranCompiler.__init__(self, exelist, for_machine, version, is_cross, exe_wrapper)
276278
IntelVisualStudioLikeCompiler.__init__(self, target)
277279

278280
default_warn_args = ['/warn:general', '/warn:truncated_source']

mesonbuild/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ def detect_cuda_compiler(self, for_machine):
854854
return cls(ccache + compiler, version, for_machine, exe_wrap)
855855
raise EnvironmentException('Could not find suitable CUDA compiler: "' + ' '.join(compilers) + '"')
856856

857-
def detect_fortran_compiler(self, for_machine):
857+
def detect_fortran_compiler(self, for_machine: MachineChoice):
858858
popen_exceptions = {}
859859
compilers, ccache, exe_wrap = self._get_compilers('fortran', for_machine)
860860
is_cross = not self.machines.matches_build_machine(for_machine)
@@ -901,7 +901,7 @@ def detect_fortran_compiler(self, for_machine):
901901
if 'Intel(R) Visual Fortran' in err:
902902
version = search_version(err)
903903
target = 'x86' if 'IA-32' in err else 'x86_64'
904-
return IntelClFortranCompiler(compiler, version, is_cross, target, exe_wrap)
904+
return IntelClFortranCompiler(compiler, version, for_machine, is_cross, target, exe_wrap)
905905

906906
if 'ifort (IFORT)' in out:
907907
return IntelFortranCompiler(compiler, version, for_machine, is_cross, exe_wrap, full_version=full_version)

mesonbuild/interpreter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from itertools import chain
4141
from pathlib import PurePath
4242
import functools
43-
import typing
43+
from typing import Sequence, List, Union, Optional, Iterator, Dict, Any
4444

4545
import importlib
4646

@@ -874,10 +874,10 @@ def __repr__(self):
874874
return r.format(self.__class__.__name__, h.get_id(), h.command)
875875

876876
class Test(InterpreterObject):
877-
def __init__(self, name: str, project: str, suite: typing.List[str], exe: build.Executable,
878-
depends: typing.List[typing.Union[build.CustomTarget, build.BuildTarget]],
879-
is_parallel: bool, cmd_args: typing.List[str], env: build.EnvironmentVariables,
880-
should_fail: bool, timeout: int, workdir: typing.Optional[str], protocol: str):
877+
def __init__(self, name: str, project: str, suite: List[str], exe: build.Executable,
878+
depends: List[Union[build.CustomTarget, build.BuildTarget]],
879+
is_parallel: bool, cmd_args: List[str], env: build.EnvironmentVariables,
880+
should_fail: bool, timeout: int, workdir: Optional[str], protocol: str):
881881
InterpreterObject.__init__(self)
882882
self.name = name
883883
self.suite = suite
@@ -2773,7 +2773,7 @@ def func_exception(self, node, args, kwargs):
27732773
self.validate_arguments(args, 0, [])
27742774
raise Exception()
27752775

2776-
def add_languages(self, args, required):
2776+
def add_languages(self, args: Sequence[str], required: bool) -> bool:
27772777
success = self.add_languages_for(args, required, MachineChoice.BUILD)
27782778
success &= self.add_languages_for(args, required, MachineChoice.HOST)
27792779
return success
@@ -3831,7 +3831,7 @@ def func_add_test_setup(self, node, args, kwargs):
38313831

38323832
# TODO make cross agnostic, just taking into account for_machine
38333833
# TODO PerMachine[T], Iterator[T]
3834-
def get_argdict_on_crossness(self, dicts_per_machine: PerMachine, kwargs) -> typing.Iterator:
3834+
def get_argdict_on_crossness(self, dicts_per_machine: PerMachine, kwargs) -> Iterator:
38353835
for_native = kwargs.get('native', not self.environment.is_cross_build())
38363836
if not isinstance(for_native, bool):
38373837
raise InterpreterException('Keyword native must be a boolean.')
@@ -4218,7 +4218,7 @@ def func_is_variable(self, node, args, kwargs):
42184218
return varname in self.variables
42194219

42204220
@staticmethod
4221-
def machine_from_native_kwarg(kwargs: typing.Dict[str, typing.Any]) -> MachineChoice:
4221+
def machine_from_native_kwarg(kwargs: Dict[str, Any]) -> MachineChoice:
42224222
native = kwargs.get('native', False)
42234223
if not isinstance(native, bool):
42244224
raise InvalidArguments('Argument to "native" must be a boolean.')

run_project_tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ def detect_tests_to_run(only: List[str]) -> List[Tuple[str, List[Path], bool]]:
600600
gathered_tests: list of tuple of str, list of pathlib.Path, bool
601601
tests to run
602602
"""
603+
604+
ninja_fortran_compiler = shutil.which('gfortran') or shutil.which('flang') or shutil.which('pgfortran') or (not mesonlib.is_windows() and shutil.which('ifort'))
605+
ninja_fortran = backend is Backend.ninja and ninja_fortran_compiler
606+
vs_fortran = mesonlib.is_windows() and backend is Backend.vs and shutil.which('ifort')
607+
skip_fortran = not(ninja_fortran or vs_fortran)
608+
603609
# Name, subdirectory, skip condition.
604610
all_tests = [
605611
('cmake', 'cmake', not shutil.which('cmake') or (os.environ.get('compiler') == 'msvc2015' and under_ci)),
@@ -621,7 +627,7 @@ def detect_tests_to_run(only: List[str]) -> List[Tuple[str, List[Path], bool]]:
621627
('d', 'd', backend is not Backend.ninja or not have_d_compiler()),
622628
('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or not have_objc_compiler()),
623629
('objective c++', 'objcpp', backend not in (Backend.ninja, Backend.xcode) or not have_objcpp_compiler()),
624-
('fortran', 'fortran', backend is not Backend.ninja or not shutil.which('gfortran')),
630+
('fortran', 'fortran', skip_fortran),
625631
('swift', 'swift', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('swiftc')),
626632
('cuda', 'cuda', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('nvcc')),
627633
('python3', 'python3', backend is not Backend.ninja),

0 commit comments

Comments
 (0)