Skip to content

Commit 5333702

Browse files
authored
Remove ENV_VARIABLE() as it duplicates the functionality of GET_ENV() (#942)
2 parents 210aafc + bf88610 commit 5333702

File tree

3 files changed

+16
-45
lines changed

3 files changed

+16
-45
lines changed

src/fpm_compiler.F90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
module fpm_compiler
2929
use,intrinsic :: iso_fortran_env, only: stderr=>error_unit
3030
use fpm_environment, only: &
31-
get_env, &
3231
get_os_type, &
3332
OS_LINUX, &
3433
OS_MACOS, &

src/fpm_filesystem.F90

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ module fpm_filesystem
1414
public :: basename, canon_path, dirname, is_dir, join_path, number_of_rows, list_files, get_local_prefix, &
1515
mkdir, exists, get_temp_filename, windows_path, unix_path, getline, delete_file, fileopen, fileclose, &
1616
filewrite, warnwrite, parent_dir, is_hidden_file, read_lines, read_lines_expanded, which, run, &
17-
os_delete_dir, is_absolute_path, env_variable, get_home, execute_and_read_output, &
18-
get_dos_path
17+
os_delete_dir, is_absolute_path, get_home, execute_and_read_output, get_dos_path
1918

2019
#ifndef FPM_BOOTSTRAP
2120
interface
@@ -53,32 +52,7 @@ end function c_is_dir
5352

5453
contains
5554

56-
57-
!> return value of environment variable
58-
subroutine env_variable(var, name)
59-
character(len=:), allocatable, intent(out) :: var
60-
character(len=*), intent(in) :: name
61-
integer :: length, stat
62-
63-
call get_environment_variable(name, length=length, status=stat)
64-
if (stat /= 0) return
65-
66-
allocate(character(len=length) :: var)
67-
68-
if (length > 0) then
69-
call get_environment_variable(name, var, status=stat)
70-
if (stat /= 0) then
71-
deallocate(var)
72-
return
73-
end if
74-
end if
75-
76-
end subroutine env_variable
77-
78-
79-
!> Extract filename from path with or without suffix.
80-
!>
81-
!> The suffix is included by default.
55+
!> Extract filename from path with/without suffix
8256
function basename(path,suffix) result (base)
8357

8458
character(*), intent(In) :: path
@@ -1079,15 +1053,15 @@ function get_local_prefix(os) result(prefix)
10791053
character(len=:), allocatable :: home
10801054

10811055
if (os_is_unix(os)) then
1082-
call env_variable(home, "HOME")
1083-
if (allocated(home)) then
1056+
home=get_env('HOME','')
1057+
if (home /= '' ) then
10841058
prefix = join_path(home, ".local")
10851059
else
10861060
prefix = default_prefix_unix
10871061
end if
10881062
else
1089-
call env_variable(home, "APPDATA")
1090-
if (allocated(home)) then
1063+
home=get_env('APPDATA','')
1064+
if (home /= '' ) then
10911065
prefix = join_path(home, "local")
10921066
else
10931067
prefix = default_prefix_win
@@ -1130,14 +1104,14 @@ subroutine get_home(home, error)
11301104
type(error_t), allocatable, intent(out) :: error
11311105

11321106
if (os_is_unix()) then
1133-
call env_variable(home, 'HOME')
1134-
if (.not. allocated(home)) then
1107+
home=get_env('HOME','')
1108+
if ( home == '' ) then
11351109
call fatal_error(error, "Couldn't retrieve 'HOME' variable")
11361110
return
11371111
end if
11381112
else
1139-
call env_variable(home, 'USERPROFILE')
1140-
if (.not. allocated(home)) then
1113+
home=get_env('USERPROFILE','')
1114+
if ( home == '' ) then
11411115
call fatal_error(error, "Couldn't retrieve '%USERPROFILE%' variable")
11421116
return
11431117
end if

test/fpm_test/test_os.f90

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module test_os
22
use testsuite, only: new_unittest, unittest_t, error_t, test_failed
3-
use fpm_filesystem, only: env_variable, join_path, mkdir, os_delete_dir, is_dir, get_local_prefix, get_home
4-
use fpm_environment, only: os_is_unix
3+
use fpm_filesystem, only: join_path, mkdir, os_delete_dir, is_dir, get_local_prefix, get_home
4+
use fpm_environment, only: os_is_unix, get_env
55
use fpm_os, only: get_absolute_path, get_absolute_path_by_cd, get_current_directory
66

77
implicit none
@@ -134,7 +134,7 @@ subroutine abs_path_nonexisting(error)
134134
subroutine abs_path_root(error)
135135
type(error_t), allocatable, intent(out) :: error
136136

137-
character(len=:), allocatable :: home_drive, home_path, result
137+
character(len=:), allocatable :: home_path, result
138138

139139
if (os_is_unix()) then
140140
call get_absolute_path('/', result, error)
@@ -144,8 +144,7 @@ subroutine abs_path_root(error)
144144
call test_failed(error, "Result '"//result//"' doesn't equal input value: '/'"); return
145145
end if
146146
else
147-
call env_variable(home_drive, 'HOMEDRIVE')
148-
home_path = home_drive//'\'
147+
home_path = get_env('HOMEDRIVE','') //'\'
149148

150149
call get_absolute_path(home_path, result, error)
151150
if (allocated(error)) return
@@ -177,7 +176,7 @@ subroutine abs_path_home(error)
177176
subroutine abs_path_cd_root(error)
178177
type(error_t), allocatable, intent(out) :: error
179178

180-
character(len=:), allocatable :: home_drive, home_path, current_dir_before, current_dir_after, result
179+
character(len=:), allocatable :: home_path, current_dir_before, current_dir_after, result
181180

182181
call get_current_directory(current_dir_before, error)
183182
if (allocated(error)) return
@@ -189,8 +188,7 @@ subroutine abs_path_cd_root(error)
189188
call test_failed(error, "Result '"//result//"' doesn't equal input value: '/'"); return
190189
end if
191190
else
192-
call env_variable(home_drive, 'HOMEDRIVE')
193-
home_path = home_drive//'\'
191+
home_path = get_env('HOMEDRIVE','')//'\'
194192

195193
call get_absolute_path_by_cd(home_path, result, error)
196194

0 commit comments

Comments
 (0)