Skip to content

Commit 6bf8c23

Browse files
authored
Merge pull request #949 from fortran-lang/clean-registry-cache
Clear registry cache using `fpm clean --registry-cache`
2 parents 5bb77c0 + 7874665 commit 6bf8c23

File tree

4 files changed

+59
-22
lines changed

4 files changed

+59
-22
lines changed

src/fpm.f90

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module fpm
2727
& stderr => error_unit
2828
use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer
2929
use fpm_environment, only: os_is_unix
30+
use fpm_settings, only: fpm_global_settings, get_global_settings
3031

3132
implicit none
3233
private
@@ -698,21 +699,30 @@ subroutine delete_skip(is_unix)
698699
end do
699700
end subroutine delete_skip
700701

701-
!> Delete the build directory including or excluding dependencies.
702+
!> Delete the build directory including or excluding dependencies. Can be used
703+
!> to clear the registry cache.
702704
subroutine cmd_clean(settings)
703705
!> Settings for the clean command.
704706
class(fpm_clean_settings), intent(in) :: settings
705707

706708
character :: user_response
709+
type(fpm_global_settings) :: global_settings
710+
type(error_t), allocatable :: error
711+
712+
! Clear registry cache
713+
if (settings%registry_cache) then
714+
call get_global_settings(global_settings, error)
715+
if (allocated(error)) return
716+
717+
call os_delete_dir(os_is_unix(), global_settings%registry_settings%cache_path)
718+
end if
707719

708720
if (is_dir('build')) then
709721
! Remove the entire build directory
710-
if (settings%clean_call) then
722+
if (settings%clean_all) then
711723
call os_delete_dir(os_is_unix(), 'build'); return
712-
end if
713-
714724
! Remove the build directory but skip dependencies
715-
if (settings%clean_skip) then
725+
else if (settings%clean_skip) then
716726
call delete_skip(os_is_unix()); return
717727
end if
718728

src/fpm_command_line.f90

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ module fpm_command_line
126126

127127
type, extends(fpm_cmd_settings) :: fpm_clean_settings
128128
logical :: clean_skip = .false.
129-
logical :: clean_call = .false.
129+
logical :: clean_all = .false.
130+
logical :: registry_cache = .false.
130131
end type
131132

132133
type, extends(fpm_build_settings) :: fpm_publish_settings
@@ -676,14 +677,27 @@ subroutine get_command_line_settings(cmd_settings)
676677

677678
case('clean')
678679
call set_args(common_args // &
680+
& ' --registry-cache' // &
679681
& ' --skip' // &
680682
& ' --all', &
681683
help_clean, version_text)
682-
allocate(fpm_clean_settings :: cmd_settings)
683-
call get_current_directory(working_dir, error)
684-
cmd_settings=fpm_clean_settings( &
685-
& clean_skip=lget('skip'), &
686-
& clean_call=lget('all'))
684+
685+
block
686+
logical :: skip, clean_all
687+
688+
skip = lget('skip')
689+
clean_all = lget('all')
690+
691+
if (all([skip, clean_all])) then
692+
call fpm_stop(6, 'Do not specify both --skip and --all options on the clean subcommand.')
693+
end if
694+
695+
allocate(fpm_clean_settings :: cmd_settings)
696+
cmd_settings = fpm_clean_settings( &
697+
& registry_cache=lget('registry-cache'), &
698+
& clean_skip=skip, &
699+
& clean_all=clean_all)
700+
end block
687701

688702
case('publish')
689703
call set_args(common_args // compiler_args //'&
@@ -823,7 +837,7 @@ subroutine set_help()
823837
' [--list] [--compiler COMPILER_NAME] [-- ARGS] ', &
824838
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', &
825839
' [options] ', &
826-
' clean [--skip] [--all] ', &
840+
' clean [--skip] [--all] [--registry-cache] ', &
827841
' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', &
828842
' [--dry-run] [--verbose] ', &
829843
' ']
@@ -952,7 +966,7 @@ subroutine set_help()
952966
' list [--list] ', &
953967
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', &
954968
' [options] ', &
955-
' clean [--skip] [--all] ', &
969+
' clean [--skip] [--all] [--registry-cache] ', &
956970
' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', &
957971
' [--dry-run] [--verbose] ', &
958972
' ', &
@@ -964,12 +978,15 @@ subroutine set_help()
964978
help_text_flag, &
965979
' --list List candidates instead of building or running them. On ', &
966980
' the fpm(1) command this shows a brief list of subcommands.', &
967-
' --runner CMD Provides a command to prefix program execution paths. ', &
981+
' --runner CMD Provides a command to prefix program execution paths. ', &
968982
' -- ARGS Arguments to pass to executables. ', &
969983
' --skip Delete directories in the build/ directory without ', &
970-
' prompting, but skip dependencies. ', &
984+
' prompting, but skip dependencies. Cannot be used together ', &
985+
' with --all. ', &
971986
' --all Delete directories in the build/ directory without ', &
972-
' prompting, including dependencies. ', &
987+
' prompting, including dependencies. Cannot be used together', &
988+
' with --skip. ', &
989+
' --registry-cache Delete registry cache. ', &
973990
' ', &
974991
'VALID FOR ALL SUBCOMMANDS ', &
975992
' --help Show help text and exit ', &
@@ -1433,10 +1450,12 @@ subroutine set_help()
14331450
'DESCRIPTION', &
14341451
' Prompts the user to confirm deletion of the build. If affirmative,', &
14351452
' directories in the build/ directory are deleted, except dependencies.', &
1453+
' Use the --registry-cache option to delete the registry cache.', &
14361454
'', &
14371455
'OPTIONS', &
1438-
' --skip delete the build without prompting but skip dependencies.', &
1439-
' --all delete the build without prompting including dependencies.', &
1456+
' --skip Delete the build without prompting but skip dependencies.', &
1457+
' --all Delete the build without prompting including dependencies.', &
1458+
' --registry-cache Delete registry cache.', &
14401459
'' ]
14411460
help_publish=[character(len=80) :: &
14421461
'NAME', &

src/fpm_settings.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ subroutine get_global_settings(global_settings, error)
113113
subroutine use_default_registry_settings(global_settings)
114114
type(fpm_global_settings), intent(inout) :: global_settings
115115

116-
allocate (global_settings%registry_settings)
116+
if (.not. allocated(global_settings%registry_settings)) allocate (global_settings%registry_settings)
117117
global_settings%registry_settings%url = official_registry_base_url
118118
global_settings%registry_settings%cache_path = join_path(global_settings%path_to_config_folder_or_empty(), &
119119
& 'dependencies')

test/cli_test/cli_test.f90

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ program main
2929
logical :: w_t,act_w_t ; namelist/act_cli/act_w_t
3030
logical :: c_s,act_c_s ; namelist/act_cli/act_c_s
3131
logical :: c_a,act_c_a ; namelist/act_cli/act_c_a
32+
logical :: reg_c,act_reg_c ; namelist/act_cli/act_reg_c
3233
logical :: show_v,act_show_v ; namelist/act_cli/act_show_v
3334
logical :: show_u_d,act_show_u_d; namelist/act_cli/act_show_u_d
3435
logical :: dry_run,act_dry_run ; namelist/act_cli/act_dry_run
3536
character(len=:), allocatable :: token, act_token ; namelist/act_cli/act_token
3637

3738
character(len=:), allocatable :: profile,act_profile ; namelist/act_cli/act_profile
3839
character(len=:), allocatable :: args,act_args ; namelist/act_cli/act_args
39-
namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_u_d,dry_run,token
40+
namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,reg_c,name,profile,args,show_v,show_u_d,dry_run,token
4041
integer :: lun
4142
logical,allocatable :: tally(:)
4243
logical,allocatable :: subtally(:)
@@ -75,6 +76,7 @@ program main
7576
'CMD="clean", NAME=, ARGS="",', &
7677
'CMD="clean --skip", C_S=T, NAME=, ARGS="",', &
7778
'CMD="clean --all", C_A=T, NAME=, ARGS="",', &
79+
'CMD="clean --registry-cache", REG_C=T, NAME=, ARGS="",', &
7880
'CMD="publish --token abc --show-package-version", SHOW_V=T, NAME=, token="abc",ARGS="",', &
7981
'CMD="publish --token abc --show-upload-data", SHOW_U_D=T, NAME=, token="abc",ARGS="",', &
8082
'CMD="publish --token abc --dry-run", DRY_RUN=T, NAME=, token="abc",ARGS="",', &
@@ -111,6 +113,7 @@ program main
111113
w_t=.false. ! --test
112114
c_s=.false. ! --skip
113115
c_a=.false. ! --all
116+
reg_c=.false. ! --registry-cache
114117
show_v=.false. ! --show-package-version
115118
show_u_d=.false. ! --show-upload-data
116119
dry_run=.false. ! --dry-run
@@ -134,6 +137,7 @@ program main
134137
act_w_t=.false.
135138
act_c_s=.false.
136139
act_c_a=.false.
140+
act_reg_c=.false.
137141
act_show_v=.false.
138142
act_show_u_d=.false.
139143
act_dry_run=.false.
@@ -148,6 +152,9 @@ program main
148152
subtally=[logical ::]
149153
call test_test('NAME',all(act_name==name))
150154
call test_test('PROFILE',act_profile==profile)
155+
call test_test('SKIP',act_c_s.eqv.c_s)
156+
call test_test('ALL',act_c_a.eqv.c_a)
157+
call test_test('REGISTRY-CACHE',act_reg_c.eqv.reg_c)
151158
call test_test('WITH_EXPECTED',act_w_e.eqv.w_e)
152159
call test_test('WITH_TESTED',act_w_t.eqv.w_t)
153160
call test_test('WITH_TEST',act_w_t.eqv.w_t)
@@ -241,6 +248,7 @@ subroutine parse()
241248
act_w_t=.false.
242249
act_c_s=.false.
243250
act_c_a=.false.
251+
act_reg_c=.false.
244252
act_show_v=.false.
245253
act_show_u_d=.false.
246254
act_dry_run=.false.
@@ -264,7 +272,8 @@ subroutine parse()
264272
if (allocated(settings%args)) act_args=settings%args
265273
type is (fpm_clean_settings)
266274
act_c_s=settings%clean_skip
267-
act_c_a=settings%clean_call
275+
act_c_a=settings%clean_all
276+
act_reg_c=settings%registry_cache
268277
type is (fpm_install_settings)
269278
type is (fpm_publish_settings)
270279
act_show_v=settings%show_package_version
@@ -275,7 +284,6 @@ subroutine parse()
275284

276285
open(file='_test_cli',newunit=lun,delim='quote')
277286
write(lun,nml=act_cli,delim='quote')
278-
!!write(*,nml=act_cli)
279287
close(unit=lun)
280288

281289
end subroutine parse

0 commit comments

Comments
 (0)