diff options
author | Michael Hirsch, Ph.D <scivision@users.noreply.github.com> | 2019-04-05 11:15:48 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-04-05 23:50:22 +0300 |
commit | d6be7822a0a7391c9d2a22c053cd4fc61b5a71e4 (patch) | |
tree | 98f3ddd8fce5e6d83e5ef79721dc62d639ebede9 /mesonbuild | |
parent | 42a04f7e230d3b8d4f5c46ffccf01ca7dfb94ef2 (diff) | |
download | meson-d6be7822a0a7391c9d2a22c053cd4fc61b5a71e4.zip meson-d6be7822a0a7391c9d2a22c053cd4fc61b5a71e4.tar.gz meson-d6be7822a0a7391c9d2a22c053cd4fc61b5a71e4.tar.bz2 |
BUGFIX: don't crash Meson on bad existing exe file for Fortran sanity check
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/compilers/fortran.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 5afbb3d..e747a35 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -76,18 +76,27 @@ class FortranCompiler(Compiler): def get_soname_args(self, *args): return CCompiler.get_soname_args(self, *args) - def sanity_check(self, work_dir, environment): - source_name = os.path.join(work_dir, 'sanitycheckf.f90') - binary_name = os.path.join(work_dir, 'sanitycheckf') - with open(source_name, 'w') as ofile: - ofile.write('print *, "Fortran compilation is working."; end') + def sanity_check(self, work_dir: Path, environment): + """ + Check to be sure a minimal program can compile and execute + with this compiler & platform. + """ + work_dir = Path(work_dir) + source_name = work_dir / 'sanitycheckf.f90' + binary_name = work_dir / 'sanitycheckf' + if binary_name.is_file(): + binary_name.unlink() + + source_name.write_text('print *, "Fortran compilation is working."; end') + if environment.is_cross_build() and not self.is_cross: for_machine = MachineChoice.BUILD else: for_machine = MachineChoice.HOST extra_flags = environment.coredata.get_external_args(for_machine, self.language) extra_flags += environment.coredata.get_external_link_args(for_machine, self.language) - pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name]) + # %% build the test executable + pc = subprocess.Popen(self.exelist + extra_flags + [str(source_name), '-o', str(binary_name)]) pc.wait() if pc.returncode != 0: raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string()) @@ -95,12 +104,16 @@ class FortranCompiler(Compiler): if self.exe_wrapper is None: # Can't check if the binaries run so we have to assume they do return - cmdlist = self.exe_wrapper + [binary_name] + cmdlist = self.exe_wrapper + [str(binary_name)] else: - cmdlist = [binary_name] - pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - pe.wait() - if pe.returncode != 0: + cmdlist = [str(binary_name)] + # %% Run the test executable + try: + pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + pe.wait() + if pe.returncode != 0: + raise EnvironmentException('Executables created by Fortran compiler %s are not runnable.' % self.name_string()) + except OSError: raise EnvironmentException('Executables created by Fortran compiler %s are not runnable.' % self.name_string()) def get_std_warn_args(self, level): |