Skip to content

Commit a559c12

Browse files
committed
wyphan's patches
1 parent 4eab3f1 commit a559c12

File tree

5 files changed

+170
-14
lines changed

5 files changed

+170
-14
lines changed

src/fpm/installer.f90

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ module fpm_installer
3131
integer :: verbosity = 1
3232
!> Command to copy objects into the installation prefix
3333
character(len=:), allocatable :: copy
34+
!> Command to move objects into the installation prefix
35+
character(len=:), allocatable :: move
3436
!> Cached operating system
3537
integer :: os
3638
contains
@@ -69,11 +71,18 @@ module fpm_installer
6971
!> Copy command on Windows platforms
7072
character(len=*), parameter :: default_copy_win = "copy"
7173

74+
!> Move command on Unix platforms
75+
character(len=*), parameter :: default_move_unix = "mv"
76+
77+
!> Move command on Windows platforms
78+
character(len=*), parameter :: default_move_win = "move"
79+
80+
7281
contains
7382

7483
!> Create a new instance of an installer
7584
subroutine new_installer(self, prefix, bindir, libdir, includedir, verbosity, &
76-
copy)
85+
copy, move)
7786
!> Instance of the installer
7887
type(installer_t), intent(out) :: self
7988
!> Path to installation directory
@@ -88,6 +97,8 @@ subroutine new_installer(self, prefix, bindir, libdir, includedir, verbosity, &
8897
integer, intent(in), optional :: verbosity
8998
!> Copy command
9099
character(len=*), intent(in), optional :: copy
100+
!> Move command
101+
character(len=*), intent(in), optional :: move
91102

92103
self%os = get_os_type()
93104

@@ -101,6 +112,16 @@ subroutine new_installer(self, prefix, bindir, libdir, includedir, verbosity, &
101112
end if
102113
end if
103114

115+
if (present(move)) then
116+
self%move = move
117+
else
118+
if (os_is_unix(self%os)) then
119+
self%move = default_move_unix
120+
else
121+
self%move = default_move_win
122+
end if
123+
end if
124+
104125
if (present(includedir)) then
105126
self%includedir = includedir
106127
else
@@ -238,7 +259,12 @@ subroutine install(self, source, destination, error)
238259
end if
239260
end if
240261

241-
call self%run(self%copy//' "'//source//'" "'//install_dest//'"', error)
262+
! move instead of copy if already installed
263+
if (exists(install_dest)) then
264+
call self%run(self%move//' "'//source//'" "'//install_dest//'"', error)
265+
else
266+
call self%run(self%copy//' "'//source//'" "'//install_dest//'"', error)
267+
end if
242268
if (allocated(error)) return
243269

244270
end subroutine install

src/fpm_command_line.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ subroutine set_help()
759759
' + help Alternate to the --help switch for displaying help text. ', &
760760
' + list Display brief descriptions of all subcommands. ', &
761761
' + install Install project. ', &
762-
' + clean Delete directories in the build/ directory, except ', &
762+
' + clean Delete directories in the "build/" directory, except ', &
763763
' dependencies. Prompts for confirmation to delete. ', &
764764
' ', &
765765
' Their syntax is ', &

src/fpm_filesystem.F90

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ subroutine mkdir(dir, echo)
369369

370370
if(present(echo))then
371371
echo_local=echo
372-
else
372+
else
373373
echo_local=.true.
374-
end if
374+
end if
375375

376376
if (is_dir(dir)) return
377377

@@ -929,15 +929,36 @@ subroutine run(cmd,echo,exitstat,verbose,redirect)
929929

930930
end subroutine run
931931

932-
!> delete dir using system os remove directory commands
933-
subroutine os_delete_dir(unix, dir)
932+
!> Delete directory using system OS remove directory commands
933+
subroutine os_delete_dir(unix, dir, echo)
934934
logical, intent(in) :: unix
935935
character(len=*), intent(in) :: dir
936+
logical, intent(in), optional :: echo
937+
938+
logical :: echo_local
939+
940+
if(present(echo))then
941+
echo_local=echo
942+
else
943+
echo_local=.true.
944+
end if
945+
936946
if (unix) then
937947
call run('rm -rf ' // dir, .false.)
948+
949+
if (echo_local) then
950+
write (*, '(" + ",2a)') 'rm -rf ' // dir
951+
end if
952+
938953
else
939954
call run('rmdir /s/q ' // dir, .false.)
955+
956+
if (echo_local) then
957+
write (*, '(" + ",2a)') 'rmdir /s/q ' // dir
958+
end if
959+
940960
end if
961+
941962
end subroutine os_delete_dir
942963

943964
end module fpm_filesystem

test/cli_test/cli_test.f90

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ program main
2727
integer :: i, ios
2828
logical :: w_e,act_w_e ; namelist/act_cli/act_w_e
2929
logical :: w_t,act_w_t ; namelist/act_cli/act_w_t
30+
logical :: c_s,act_c_s ; namelist/act_cli/act_c_s
31+
logical :: c_a,act_c_a ; namelist/act_cli/act_c_a
3032

3133
character(len=63) :: profile,act_profile ; namelist/act_cli/act_profile
3234
character(len=:),allocatable :: args,act_args ; namelist/act_cli/act_args
33-
namelist/expected/cmd,cstat,estat,w_e,w_t,name,profile,args
35+
namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args
3436
integer :: lun
3537
logical,allocatable :: tally(:)
3638
logical,allocatable :: subtally(:)
@@ -42,7 +44,7 @@ program main
4244
'CMD="new", ESTAT=1,', &
4345
!'CMD="new -unknown", ESTAT=2,', &
4446
'CMD="new my_project another yet_another -test", ESTAT=2,', &
45-
'CMD="new my_project --app", W_E=T, NAME="my_project",', &
47+
'CMD="new my_project --app", W_E=T, NAME="my_project",', &
4648
'CMD="new my_project --app --test", W_E=T,W_T=T, NAME="my_project",', &
4749
'CMD="new my_project --test", W_T=T, NAME="my_project",', &
4850
'CMD="new my_project", W_E=T,W_T=T, NAME="my_project",', &
@@ -64,7 +66,11 @@ program main
6466
&NAME="proj1","p2","project3",profile="release" ARGS="""arg1"" ""-x"" ""and a long one""", ', &
6567

6668
'CMD="build", NAME= profile="",ARGS="",', &
67-
'CMD="build --profile release", NAME= profile="release",ARGS="",', &
69+
'CMD="build --profile release", NAME= profile="release",ARGS="",', &
70+
71+
'CMD="clean", NAME= ARGS="",', &
72+
'CMD="clean --skip", C_S=T, NAME= ARGS="",', &
73+
'CMD="clean --all", C_A=T, NAME= ARGS="",', &
6874
' ' ]
6975
character(len=256) :: readme(3)
7076

@@ -95,6 +101,8 @@ program main
95101
profile="" ! --profile PROF
96102
w_e=.false. ! --app
97103
w_t=.false. ! --test
104+
c_s=.false. ! --skip
105+
c_a=.false. ! --all
98106
args=repeat(' ',132) ! -- ARGS
99107
cmd=repeat(' ',132) ! the command line arguments to test
100108
cstat=0 ! status values from EXECUTE_COMMAND_LINE()
@@ -112,6 +120,8 @@ program main
112120
act_profile=''
113121
act_w_e=.false.
114122
act_w_t=.false.
123+
act_c_s=.false.
124+
act_c_a=.false.
115125
act_args=repeat(' ',132)
116126
read(lun,nml=act_cli,iostat=ios,iomsg=message)
117127
if(ios.ne.0)then
@@ -193,9 +203,10 @@ subroutine parse()
193203
fpm_build_settings, &
194204
fpm_run_settings, &
195205
fpm_test_settings, &
206+
fpm_clean_settings, &
196207
fpm_install_settings, &
197208
get_command_line_settings
198-
use fpm, only: cmd_build, cmd_run
209+
use fpm, only: cmd_build, cmd_run, cmd_clean
199210
use fpm_cmd_install, only: cmd_install
200211
use fpm_cmd_new, only: cmd_new
201212
class(fpm_cmd_settings), allocatable :: cmd_settings
@@ -206,6 +217,8 @@ subroutine parse()
206217
act_args=''
207218
act_w_e=.false.
208219
act_w_t=.false.
220+
act_c_s=.false.
221+
act_c_a=.false.
209222
act_profile=''
210223

211224
select type(settings=>cmd_settings)
@@ -223,6 +236,9 @@ subroutine parse()
223236
act_profile=settings%profile
224237
act_name=settings%name
225238
act_args=settings%args
239+
type is (fpm_clean_settings)
240+
act_c_s=settings%clean_skip
241+
act_c_a=settings%clean_call
226242
type is (fpm_install_settings)
227243
end select
228244

test/fpm_test/test_filesystem.f90

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module test_filesystem
22
use testsuite, only : new_unittest, unittest_t, error_t, test_failed
3-
use fpm_filesystem, only: canon_path
3+
use fpm_filesystem, only: canon_path, is_dir, mkdir, os_delete_dir
4+
use fpm_environment, only: OS_WINDOWS, get_os_type, os_is_unix
45
implicit none
56
private
67

@@ -16,7 +17,8 @@ subroutine collect_filesystem(testsuite)
1617
type(unittest_t), allocatable, intent(out) :: testsuite(:)
1718

1819
testsuite = [ &
19-
& new_unittest("canon-path", test_canon_path) &
20+
& new_unittest("canon-path", test_canon_path), &
21+
& new_unittest("create-delete-directory", test_mkdir_rmdir) &
2022
]
2123

2224
end subroutine collect_filesystem
@@ -96,11 +98,102 @@ subroutine check_string(error, actual, expected)
9698

9799
if (actual /= expected) then
98100
call test_failed(error, &
99-
"Character value missmatch "//&
101+
"Character value mismatch "//&
100102
"expected '"//expected//"' but got '"//actual//"'")
101103
end if
102104

103105
end subroutine check_string
104106

105107

108+
subroutine test_mkdir_rmdir(error)
109+
110+
!> Error handling
111+
type(error_t), allocatable, intent(out) :: error
112+
113+
logical :: is_win
114+
115+
is_win = (get_os_type() == OS_WINDOWS)
116+
117+
if (is_win) then
118+
call check_mkdir(error, "tmpdir\subdir")
119+
else
120+
call check_mkdir(error, "tmpdir/subdir")
121+
end if
122+
if (allocated(error)) return
123+
124+
if (is_win) then
125+
call check_rmdir(error, "tmpdir\subdir")
126+
else
127+
call check_rmdir(error, "tmpdir/subdir")
128+
end if
129+
if (allocated(error)) return
130+
131+
call check_rmdir(error, "tmpdir")
132+
if (allocated(error)) return
133+
134+
end subroutine test_mkdir_rmdir
135+
136+
137+
!> Create a directory and verify its existence
138+
subroutine check_mkdir(error, path)
139+
140+
!> Error handling
141+
type(error_t), allocatable, intent(out) :: error
142+
143+
!> Directory path
144+
character(len=*), intent(in) :: path
145+
146+
logical :: stat
147+
148+
! Directory shouldn't exist before it's created
149+
stat = (is_dir(path) .eqv. .false.)
150+
if (.not. stat) then
151+
call test_failed(error, &
152+
"Directory path "//path//" already exists before its creation")
153+
end if
154+
155+
! Create directory
156+
call mkdir(path)
157+
158+
! Check that directory is indeed created
159+
stat = (is_dir(path) .eqv. .true.)
160+
if (.not. stat) then
161+
call test_failed(error, &
162+
"Directory path "//path//" cannot be created")
163+
end if
164+
165+
end subroutine check_mkdir
166+
167+
168+
!> Create a directory and verify its existence
169+
subroutine check_rmdir(error, path)
170+
171+
!> Error handling
172+
type(error_t), allocatable, intent(out) :: error
173+
174+
!> Directory path
175+
character(len=*), intent(in) :: path
176+
177+
logical :: stat
178+
179+
! Directory should exist before it's deleted
180+
stat = (is_dir(path) .eqv. .true.)
181+
if (.not. stat) then
182+
call test_failed(error, &
183+
"Directory path "//path//" doesn't exist before its deletion")
184+
end if
185+
186+
! Delete directory
187+
call os_delete_dir(os_is_unix(),path)
188+
189+
! Check that directory is indeed deleted
190+
stat = (is_dir(path) .eqv. .false.)
191+
if (.not. stat) then
192+
call test_failed(error, &
193+
"Directory path "//path//" cannot be deleted")
194+
end if
195+
196+
end subroutine check_rmdir
197+
198+
106199
end module test_filesystem

0 commit comments

Comments
 (0)