From e64753cd89fc527f6927cbb0d796db25e1b8c40c Mon Sep 17 00:00:00 2001 From: minhqdao Date: Thu, 22 Jun 2023 13:54:02 +0700 Subject: [PATCH 1/6] Throw error when both --skip and --all were specified, rename clean_call to clean_all, clean up code --- src/fpm.f90 | 2 +- src/fpm_command_line.f90 | 23 +++++++++++++++++------ test/cli_test/cli_test.f90 | 3 +-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 50d39a8842..67a71f5e3a 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -687,7 +687,7 @@ subroutine cmd_clean(settings) if (is_dir('build')) then ! Remove the entire build directory - if (settings%clean_call) then + if (settings%clean_all) then call os_delete_dir(os_is_unix(), 'build'); return end if diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 306b79a535..427b7b36b2 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -113,7 +113,7 @@ module fpm_command_line type, extends(fpm_cmd_settings) :: fpm_clean_settings logical :: clean_skip = .false. - logical :: clean_call = .false. + logical :: clean_all = .false. end type type, extends(fpm_build_settings) :: fpm_publish_settings @@ -606,11 +606,22 @@ subroutine get_command_line_settings(cmd_settings) & ' --skip' // & & ' --all', & help_clean, version_text) - allocate(fpm_clean_settings :: cmd_settings) - call get_current_directory(working_dir, error) - cmd_settings=fpm_clean_settings( & - & clean_skip=lget('skip'), & - & clean_call=lget('all')) + + block + logical :: skip, clean_all + + skip = lget('skip') + clean_all = lget('all') + + if (all([skip, clean_all])) then + call fpm_stop(6, 'Do not specify both --skip and --all options on the clean subcommand.') + end if + + allocate(fpm_clean_settings :: cmd_settings) + cmd_settings=fpm_clean_settings( & + & clean_skip=skip, & + & clean_all=clean_all) + end block case('publish') call set_args(common_args // compiler_args //'& diff --git a/test/cli_test/cli_test.f90 b/test/cli_test/cli_test.f90 index f5336b62ca..2ba146729a 100644 --- a/test/cli_test/cli_test.f90 +++ b/test/cli_test/cli_test.f90 @@ -264,7 +264,7 @@ subroutine parse() if (allocated(settings%args)) act_args=settings%args type is (fpm_clean_settings) act_c_s=settings%clean_skip - act_c_a=settings%clean_call + act_c_a=settings%clean_all type is (fpm_install_settings) type is (fpm_publish_settings) act_show_v=settings%show_package_version @@ -275,7 +275,6 @@ subroutine parse() open(file='_test_cli',newunit=lun,delim='quote') write(lun,nml=act_cli,delim='quote') -!!write(*,nml=act_cli) close(unit=lun) end subroutine parse From ae27097707d1e7f9b856e76f93689d0175c2cc71 Mon Sep 17 00:00:00 2001 From: minhqdao Date: Thu, 22 Jun 2023 14:47:05 +0700 Subject: [PATCH 2/6] Add option for clearing the registry cache --- src/fpm.f90 | 15 ++++++++++++--- src/fpm_command_line.f90 | 7 +++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 67a71f5e3a..c6deada198 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -26,6 +26,7 @@ module fpm & stderr => error_unit use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer use fpm_environment, only: os_is_unix +use fpm_settings, only: fpm_global_settings, get_global_settings implicit none private @@ -684,15 +685,23 @@ subroutine cmd_clean(settings) class(fpm_clean_settings), intent(in) :: settings character :: user_response + type(fpm_global_settings) :: global_settings + type(error_t), allocatable :: error + + ! Clear registry cache + if (settings%registry_cache) then + call get_global_settings(global_settings, error) + if (allocated(error)) return + + call os_delete_dir(os_is_unix(), global_settings%registry_settings%cache_path) + end if if (is_dir('build')) then ! Remove the entire build directory if (settings%clean_all) then call os_delete_dir(os_is_unix(), 'build'); return - end if - ! Remove the build directory but skip dependencies - if (settings%clean_skip) then + else if (settings%clean_skip) then call delete_skip(os_is_unix()); return end if diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 427b7b36b2..5efede34f6 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -114,6 +114,7 @@ module fpm_command_line type, extends(fpm_cmd_settings) :: fpm_clean_settings logical :: clean_skip = .false. logical :: clean_all = .false. + logical :: registry_cache = .false. end type type, extends(fpm_build_settings) :: fpm_publish_settings @@ -603,6 +604,7 @@ subroutine get_command_line_settings(cmd_settings) case('clean') call set_args(common_args // & + & ' --registry-cache' // & & ' --skip' // & & ' --all', & help_clean, version_text) @@ -618,8 +620,9 @@ subroutine get_command_line_settings(cmd_settings) end if allocate(fpm_clean_settings :: cmd_settings) - cmd_settings=fpm_clean_settings( & - & clean_skip=skip, & + cmd_settings = fpm_clean_settings( & + & registry_cache=lget('registry-cache'), & + & clean_skip=skip, & & clean_all=clean_all) end block From cc2a5684c51b90cffa2787380f692c8f956a308a Mon Sep 17 00:00:00 2001 From: minhqdao Date: Thu, 22 Jun 2023 14:55:27 +0700 Subject: [PATCH 3/6] Add test --- test/cli_test/cli_test.f90 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/cli_test/cli_test.f90 b/test/cli_test/cli_test.f90 index 2ba146729a..975b80812b 100644 --- a/test/cli_test/cli_test.f90 +++ b/test/cli_test/cli_test.f90 @@ -29,6 +29,7 @@ program main logical :: w_t,act_w_t ; namelist/act_cli/act_w_t logical :: c_s,act_c_s ; namelist/act_cli/act_c_s logical :: c_a,act_c_a ; namelist/act_cli/act_c_a +logical :: reg_c,act_reg_c ; namelist/act_cli/act_reg_c logical :: show_v,act_show_v ; namelist/act_cli/act_show_v logical :: show_u_d,act_show_u_d; namelist/act_cli/act_show_u_d logical :: dry_run,act_dry_run ; namelist/act_cli/act_dry_run @@ -36,7 +37,7 @@ program main character(len=:), allocatable :: profile,act_profile ; namelist/act_cli/act_profile character(len=:), allocatable :: args,act_args ; namelist/act_cli/act_args -namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_u_d,dry_run,token +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 integer :: lun logical,allocatable :: tally(:) logical,allocatable :: subtally(:) @@ -75,6 +76,7 @@ program main 'CMD="clean", NAME=, ARGS="",', & 'CMD="clean --skip", C_S=T, NAME=, ARGS="",', & 'CMD="clean --all", C_A=T, NAME=, ARGS="",', & +'CMD="clean --registry-cache", REG_C=T, NAME=, ARGS="",', & 'CMD="publish --token abc --show-package-version", SHOW_V=T, NAME=, token="abc",ARGS="",', & 'CMD="publish --token abc --show-upload-data", SHOW_U_D=T, NAME=, token="abc",ARGS="",', & 'CMD="publish --token abc --dry-run", DRY_RUN=T, NAME=, token="abc",ARGS="",', & @@ -111,6 +113,7 @@ program main w_t=.false. ! --test c_s=.false. ! --skip c_a=.false. ! --all + reg_c=.false. ! --registry-cache show_v=.false. ! --show-package-version show_u_d=.false. ! --show-upload-data dry_run=.false. ! --dry-run @@ -134,6 +137,7 @@ program main act_w_t=.false. act_c_s=.false. act_c_a=.false. + act_reg_c=.false. act_show_v=.false. act_show_u_d=.false. act_dry_run=.false. @@ -148,6 +152,9 @@ program main subtally=[logical ::] call test_test('NAME',all(act_name==name)) call test_test('PROFILE',act_profile==profile) + call test_test('SKIP',act_c_s.eqv.c_s) + call test_test('ALL',act_c_a.eqv.c_a) + call test_test('REGISTRY-CACHE',act_reg_c.eqv.reg_c) call test_test('WITH_EXPECTED',act_w_e.eqv.w_e) call test_test('WITH_TESTED',act_w_t.eqv.w_t) call test_test('WITH_TEST',act_w_t.eqv.w_t) @@ -241,6 +248,7 @@ subroutine parse() act_w_t=.false. act_c_s=.false. act_c_a=.false. +act_reg_c=.false. act_show_v=.false. act_show_u_d=.false. act_dry_run=.false. @@ -265,6 +273,7 @@ subroutine parse() type is (fpm_clean_settings) act_c_s=settings%clean_skip act_c_a=settings%clean_all + act_reg_c=settings%registry_cache type is (fpm_install_settings) type is (fpm_publish_settings) act_show_v=settings%show_package_version From 56da54f8d0155d107c3f86498814985036b9b45e Mon Sep 17 00:00:00 2001 From: minhqdao Date: Thu, 22 Jun 2023 15:28:42 +0700 Subject: [PATCH 4/6] Add to fpm clean --- src/fpm.f90 | 3 ++- src/fpm_command_line.f90 | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index c6deada198..9aff72443b 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -679,7 +679,8 @@ subroutine delete_skip(is_unix) end do end subroutine delete_skip -!> Delete the build directory including or excluding dependencies. +!> Delete the build directory including or excluding dependencies. Can be used +!> to clear the registry cache. subroutine cmd_clean(settings) !> Settings for the clean command. class(fpm_clean_settings), intent(in) :: settings diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90 index 5efede34f6..cf98d3f624 100644 --- a/src/fpm_command_line.f90 +++ b/src/fpm_command_line.f90 @@ -764,7 +764,7 @@ subroutine set_help() ' [--list] [--compiler COMPILER_NAME] [-- ARGS] ', & ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & - ' clean [--skip] [--all] ', & + ' clean [--skip] [--all] [--registry-cache] ', & ' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', & ' [--dry-run] [--verbose] ', & ' '] @@ -889,7 +889,7 @@ subroutine set_help() ' list [--list] ', & ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', & ' [options] ', & - ' clean [--skip] [--all] ', & + ' clean [--skip] [--all] [--registry-cache] ', & ' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', & ' [--dry-run] [--verbose] ', & ' ', & @@ -901,12 +901,15 @@ subroutine set_help() help_text_flag, & ' --list List candidates instead of building or running them. On ', & ' the fpm(1) command this shows a brief list of subcommands.', & - ' --runner CMD Provides a command to prefix program execution paths. ', & + ' --runner CMD Provides a command to prefix program execution paths. ', & ' -- ARGS Arguments to pass to executables. ', & ' --skip Delete directories in the build/ directory without ', & - ' prompting, but skip dependencies. ', & + ' prompting, but skip dependencies. Cannot be used together ', & + ' with --all. ', & ' --all Delete directories in the build/ directory without ', & - ' prompting, including dependencies. ', & + ' prompting, including dependencies. Cannot be used together', & + ' with --skip. ', & + ' --registry-cache Delete registry cache. ', & ' ', & 'VALID FOR ALL SUBCOMMANDS ', & ' --help Show help text and exit ', & @@ -1364,10 +1367,12 @@ subroutine set_help() 'DESCRIPTION', & ' Prompts the user to confirm deletion of the build. If affirmative,', & ' directories in the build/ directory are deleted, except dependencies.', & + ' Use the --registry-cache option to delete the registry cache.', & '', & 'OPTIONS', & - ' --skip delete the build without prompting but skip dependencies.', & - ' --all delete the build without prompting including dependencies.', & + ' --skip Delete the build without prompting but skip dependencies.', & + ' --all Delete the build without prompting including dependencies.', & + ' --registry-cache Delete registry cache.', & '' ] help_publish=[character(len=80) :: & 'NAME', & From f83762ad842659cf923488819c003bf736422796 Mon Sep 17 00:00:00 2001 From: minhqdao Date: Thu, 22 Jun 2023 15:55:15 +0700 Subject: [PATCH 5/6] Check allocation status before allocating --- src/fpm_settings.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpm_settings.f90 b/src/fpm_settings.f90 index fe4b0748fa..a11abb8565 100644 --- a/src/fpm_settings.f90 +++ b/src/fpm_settings.f90 @@ -113,7 +113,7 @@ subroutine get_global_settings(global_settings, error) subroutine use_default_registry_settings(global_settings) type(fpm_global_settings), intent(inout) :: global_settings - allocate (global_settings%registry_settings) + if (.not. allocated(global_settings%registry_settings)) allocate (global_settings%registry_settings) global_settings%registry_settings%url = official_registry_base_url global_settings%registry_settings%cache_path = join_path(global_settings%path_to_config_folder_or_empty(), & & 'dependencies') From 78746653f35d8426e2ebfc8d91a7964c92eb5272 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Sat, 23 Mar 2024 12:55:04 +0530 Subject: [PATCH 6/6] check --- src/fpm.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpm.f90 b/src/fpm.f90 index 9aff72443b..d5c6e0d0a1 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -691,7 +691,7 @@ subroutine cmd_clean(settings) ! Clear registry cache if (settings%registry_cache) then - call get_global_settings(global_settings, error) + call get_global_settings(global_settings, error) if (allocated(error)) return call os_delete_dir(os_is_unix(), global_settings%registry_settings%cache_path)