diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index a8be2b036..c0cd0bcd7 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -19,6 +19,7 @@ import subprocess import functools import itertools from pathlib import Path +from typing import List from .. import mlog from .. import coredata @@ -456,7 +457,7 @@ class CCompiler(Compiler): return self.compiles(code, env, extra_args=extra_args, dependencies=dependencies, mode='link') - def run(self, code, env, *, extra_args=None, dependencies=None): + def run(self, code: str, env, *, extra_args=None, dependencies=None): if self.is_cross and self.exe_wrapper is None: raise CrossNoRunException('Can not run test applications in this cross environment.') with self._build_wrapper(code, env, extra_args, dependencies, mode='link', want_output=True) as p: @@ -978,7 +979,7 @@ class CCompiler(Compiler): return [f.as_posix()] @staticmethod - def _get_file_from_list(files): + def _get_file_from_list(files: List[str]) -> str: for f in files: if os.path.isfile(f): return f diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index b1f3cc244..97e2b9444 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1795,7 +1795,7 @@ class ArmclangCompiler: EnvironmentException('armlink version string not found') # Using the regular expression from environment.search_version, # which is used for searching compiler version - version_regex = '(? List[str]: + return CCompiler._get_file_from_list(files) class GnuFortranCompiler(GnuCompiler, FortranCompiler): def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs): diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index d8530206b..ad279be5d 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -321,7 +321,7 @@ def search_version(text): # This regex is reaching magic levels. If it ever needs # to be updated, do not complexify but convert to something # saner instead. - version_regex = '(?error_unit +use iso_c_binding, only: c_int, c_char, c_null_char, c_ptr +use gzip, only: gzopen, gzwrite, gzclose + +implicit none + +character(kind=c_char,len=*), parameter :: path = c_char_"test.gz"//c_null_char +character(kind=c_char,len=*), parameter :: mode = c_char_"wb9"//c_null_char +integer(c_int), parameter :: buffer_size = 512 + +type(c_ptr) :: file +character(kind=c_char, len=buffer_size) :: buffer +integer(c_int) :: ret +integer :: i + +! open file +file = gzopen(path, mode) + +! fill buffer with data +do i=1,buffer_size/4 + write(buffer(4*(i-1)+1:4*i), '(i3.3, a)') i, new_line('') +end do +ret = gzwrite(file, buffer, buffer_size) +if (ret /= buffer_size) then + write(stderr,'(a, i3, a, i3, a)') 'Error: ', ret, ' / ', buffer_size, & + ' bytes written.' + stop 1 +end if + +! close file +ret = gzclose(file) +if (ret /= 0) then + write(stderr,*) 'Error: failure to close file with error code ', ret + stop 1 +end if + +end program diff --git a/test cases/fortran/4 self dependency/selfdep.f90 b/test cases/fortran/4 self dependency/selfdep.f90 index a27283283..1a7135300 100644 --- a/test cases/fortran/4 self dependency/selfdep.f90 +++ b/test cases/fortran/4 self dependency/selfdep.f90 @@ -1,11 +1,18 @@ -MODULE Circle - REAL, PARAMETER :: Pi = 3.1415927 +MODULE geom + +type :: circle + REAL :: Pi = 4.*atan(1.) REAL :: radius -END MODULE Circle +end type circle +END MODULE geom PROGRAM prog -use Circle +use geom, only : circle IMPLICIT NONE +type(circle) :: ell + +ell%radius = 3. + END PROGRAM prog diff --git a/test cases/fortran/5 static/main.f90 b/test cases/fortran/5 static/main.f90 index dc6454cf1..6d878cb47 100644 --- a/test cases/fortran/5 static/main.f90 +++ b/test cases/fortran/5 static/main.f90 @@ -1,6 +1,6 @@ -program hello - use static_hello - implicit none - call static_say_hello() -end program hello +use static_hello +implicit none + +call static_say_hello() +end program diff --git a/test cases/fortran/5 static/static_hello.f90 b/test cases/fortran/5 static/static_hello.f90 index 63415b08b..5407560d7 100644 --- a/test cases/fortran/5 static/static_hello.f90 +++ b/test cases/fortran/5 static/static_hello.f90 @@ -1,17 +1,17 @@ module static_hello - implicit none +implicit none - private - public :: static_say_hello +private +public :: static_say_hello - interface static_say_hello - module procedure say_hello - end interface static_say_hello +interface static_say_hello + module procedure say_hello +end interface static_say_hello contains - subroutine say_hello - print *, "Static library called." - end subroutine say_hello +subroutine say_hello + print *, "Static library called." +end subroutine say_hello end module static_hello diff --git a/test cases/fortran/6 dynamic/dynamic.f90 b/test cases/fortran/6 dynamic/dynamic.f90 index e78a40690..6a1f3590f 100644 --- a/test cases/fortran/6 dynamic/dynamic.f90 +++ b/test cases/fortran/6 dynamic/dynamic.f90 @@ -1,17 +1,17 @@ module dynamic - implicit none +implicit none - private - public :: hello +private +public :: hello - interface hello - module procedure say - end interface hello +interface hello + module procedure say +end interface hello contains - subroutine say - print *, "Hello, hello..." - end subroutine say +subroutine say + print *, "Hello from shared library." +end subroutine say end module dynamic diff --git a/test cases/fortran/6 dynamic/main.f90 b/test cases/fortran/6 dynamic/main.f90 index cb3a53fe6..fc48bcb15 100644 --- a/test cases/fortran/6 dynamic/main.f90 +++ b/test cases/fortran/6 dynamic/main.f90 @@ -1,6 +1,5 @@ -program main - use dynamic - implicit none +use dynamic, only: hello +implicit none - call hello() -end program main +call hello() +end program diff --git a/test cases/fortran/8 module names/mod1.f90 b/test cases/fortran/8 module names/mod1.f90 index 69cc9003d..29cd9f443 100644 --- a/test cases/fortran/8 module names/mod1.f90 +++ b/test cases/fortran/8 module names/mod1.f90 @@ -1,6 +1,6 @@ module MyMod1 - implicit none +implicit none - integer, parameter :: myModVal1 = 1 +integer, parameter :: myModVal1 = 1 end module MyMod1 diff --git a/test cases/fortran/8 module names/mod2.f90 b/test cases/fortran/8 module names/mod2.f90 index 971df443e..2087750de 100644 --- a/test cases/fortran/8 module names/mod2.f90 +++ b/test cases/fortran/8 module names/mod2.f90 @@ -1,6 +1,6 @@ module mymod2 - implicit none +implicit none - integer, parameter :: myModVal2 = 2 +integer, parameter :: myModVal2 = 2 end module mymod2 diff --git a/test cases/fortran/8 module names/test.f90 b/test cases/fortran/8 module names/test.f90 index ff5a54577..28847fb5f 100644 --- a/test cases/fortran/8 module names/test.f90 +++ b/test cases/fortran/8 module names/test.f90 @@ -1,7 +1,8 @@ -program test - use mymod1 - use MyMod2 +use mymod1 +use MyMod2 - integer, parameter :: testVar = myModVal1 + myModVal2 +implicit none -end program test +integer, parameter :: testVar = myModVal1 + myModVal2 + +end program diff --git a/test cases/fortran/9 cpp/fortran.f b/test cases/fortran/9 cpp/fortran.f index e69466932..255872c91 100644 --- a/test cases/fortran/9 cpp/fortran.f +++ b/test cases/fortran/9 cpp/fortran.f @@ -1,5 +1,11 @@ function fortran() bind(C) - use, intrinsic :: iso_c_binding - real(kind=c_double) :: fortran - fortran = 2.0**rand(1) + use, intrinsic :: iso_c_binding, only: dp=>c_double + implicit none + + real(dp) :: r, fortran + + call random_number(r) + + fortran = 2._dp**r + end function fortran diff --git a/test cases/fortran/9 cpp/meson.build b/test cases/fortran/9 cpp/meson.build index 93037aa1b..21a7449c7 100644 --- a/test cases/fortran/9 cpp/meson.build +++ b/test cases/fortran/9 cpp/meson.build @@ -15,7 +15,7 @@ endif e = executable( 'cppfort', ['main.cpp', 'fortran.f'], - dependencies : [link_with], + dependencies : link_with, ) test('C++ FORTRAN', e)