Skip to content

Commit faced23

Browse files
refactor(get_archiver): extract to it's own function
1 parent 0ac5f5b commit faced23

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/fpm.f90

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module fpm
44
use fpm_command_line, only: fpm_build_settings, fpm_new_settings, &
55
fpm_run_settings, fpm_install_settings, fpm_test_settings
66
use fpm_dependency, only : new_dependency_tree
7-
use fpm_environment, only: get_os_type, run, OS_UNKNOWN, OS_WINDOWS
7+
use fpm_environment, only: get_archiver, run
88
use fpm_filesystem, only: is_dir, join_path, number_of_rows, list_files, exists, basename
99
use fpm_model, only: fpm_model_t, srcfile_t, show_model, &
1010
FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, &
@@ -62,22 +62,7 @@ subroutine build_model(model, settings, package, error)
6262
model%fortran_compiler = settings%compiler
6363
endif
6464

65-
associate(os_type => get_os_type())
66-
if (os_type /= OS_WINDOWS .and. os_type /= OS_UNKNOWN) then
67-
model%archiver = "ar -rs "
68-
else
69-
block
70-
integer :: estat
71-
72-
call execute_command_line("ar --version", exitstat=estat)
73-
if (estat /= 0) then
74-
model%archiver = "lib /OUT:"
75-
else
76-
model%archiver = "ar -rs "
77-
end if
78-
end block
79-
end if
80-
end associate
65+
model%archiver = get_archiver()
8166

8267
if (is_unknown_compiler(model%fortran_compiler)) then
8368
write(*, '(*(a:,1x))') &

src/fpm_environment.f90

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!> This module contains procedures that interact with the programming environment.
2-
!!
2+
!!
33
!! * [get_os_type] -- Determine the OS type
44
!! * [get_env] -- return the value of an environment variable
55
module fpm_environment
@@ -9,6 +9,7 @@ module fpm_environment
99
public :: os_is_unix
1010
public :: run
1111
public :: get_env
12+
public :: get_archiver
1213

1314
integer, parameter, public :: OS_UNKNOWN = 0
1415
integer, parameter, public :: OS_LINUX = 1
@@ -110,7 +111,7 @@ integer function get_os_type() result(r)
110111
end if
111112
end function get_os_type
112113

113-
!> Compare the output of [[get_os_type]] or the optional
114+
!> Compare the output of [[get_os_type]] or the optional
114115
!! passed INTEGER value to the value for OS_WINDOWS
115116
!! and return .TRUE. if they match and .FALSE. otherwise
116117
logical function os_is_unix(os) result(unix)
@@ -150,7 +151,7 @@ end subroutine run
150151
function get_env(NAME,DEFAULT) result(VALUE)
151152
implicit none
152153
!> name of environment variable to get the value of
153-
character(len=*),intent(in) :: NAME
154+
character(len=*),intent(in) :: NAME
154155
!> default value to return if the requested value is undefined or blank
155156
character(len=*),intent(in),optional :: DEFAULT
156157
!> the returned value
@@ -182,4 +183,24 @@ function get_env(NAME,DEFAULT) result(VALUE)
182183
if(VALUE.eq.''.and.present(DEFAULT))VALUE=DEFAULT
183184
end function get_env
184185

186+
function get_archiver() result(archiver)
187+
character(:), allocatable :: archiver
188+
189+
associate(os_type => get_os_type())
190+
if (os_type /= OS_WINDOWS .and. os_type /= OS_UNKNOWN) then
191+
archiver = "ar -rs "
192+
else
193+
block
194+
integer :: estat
195+
196+
call execute_command_line("ar --version", exitstat=estat)
197+
if (estat /= 0) then
198+
archiver = "lib /OUT:"
199+
else
200+
archiver = "ar -rs "
201+
end if
202+
end block
203+
end if
204+
end associate
205+
end function
185206
end module fpm_environment

0 commit comments

Comments
 (0)