Skip to content

Dependency management #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fpm/app/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ program main
fpm_build_settings, &
fpm_run_settings, &
fpm_test_settings, &
fpm_update_settings, &
fpm_install_settings, &
get_command_line_settings
use fpm, only: cmd_build, cmd_install, cmd_run
use fpm_cmd_new, only: cmd_new
use fpm_cmd_update, only: cmd_update

implicit none

Expand All @@ -25,6 +27,8 @@ program main
call cmd_run(settings,test=.false.)
type is (fpm_test_settings)
call cmd_run(settings,test=.true.)
type is (fpm_update_settings)
call cmd_update(settings)
type is (fpm_install_settings)
call cmd_install(settings)
end select
Expand Down
1 change: 1 addition & 0 deletions fpm/src/fpm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module fpm
FPM_SCOPE_DEP, FPM_SCOPE_APP, FPM_SCOPE_TEST, &
FPM_TARGET_EXECUTABLE

use fpm_dependency, only : update_dep_lock, dependency_walker_t
use fpm_sources, only: add_executable_sources, add_sources_from_dir
use fpm_targets, only: targets_from_sources, resolve_module_dependencies
use fpm_manifest, only : get_package_data, package_config_t
Expand Down
109 changes: 109 additions & 0 deletions fpm/src/fpm/cmd/update.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
!> Implementation of the fpm-update command.
module fpm_cmd_update
use, intrinsic :: iso_fortran_env, only : output_unit
use fpm_command_line, only : fpm_update_settings
use fpm_constants, only : fpm_manifest_file, fpm_build_dir, fpm_dependency_dir
use fpm_error, only : error_t, fatal_error
use fpm_filesystem, only : join_path, exists, mkdir
use fpm_git, only : git_target_t
use fpm_manifest, only : get_package_data, package_config_t, &
executable_config_t, dependency_config_t
use fpm_toml, only : toml_table, toml_parse, toml_serializer, toml_error, &
toml_key, add_table, set_value, get_value
use fpm_dependency, only : update_dep_lock, dependency_walker_t, &
new_dependency_walker, check_update_deps
implicit none
private
public :: cmd_update


contains

!> Entry point for the fpm-update command
subroutine cmd_update(settings)
!> Representation of the command line options for this command
type(fpm_update_settings), intent(in) :: settings

type(toml_table), allocatable :: table
type(package_config_t) :: package
type(dependency_walker_t) :: config
type(error_t), allocatable :: error
integer :: ii

call get_package_data(package, fpm_manifest_file, error, apply_defaults=.true.)
call handle_error(error)

if (.not.exists(fpm_build_dir)) then
call mkdir(fpm_build_dir)
end if

if (settings%fetch_only) then
config = new_dependency_walker(&
prefix=join_path(fpm_build_dir, fpm_dependency_dir), &
verbosity=merge(2, 1, settings%verbose))
else
config = new_dependency_walker(&
prefix=join_path(fpm_build_dir, fpm_dependency_dir), &
update=settings%name, &
update_all=size(settings%name) == 0, &
verbosity=merge(2, 1, settings%verbose))
end if

call update_dep_lock(config, table, package, error)
call handle_error(error)

call check_update_deps(config, table, error)
call handle_error(error)

call report_dependencies(config, table)

end subroutine cmd_update

subroutine report_dependencies(config, table)
!> Instance of the dependency handler
class(dependency_walker_t), intent(in) :: config
!> Table to collect all dependencies
type(toml_table), intent(inout) :: table

integer :: ii, unused
character(len=:), allocatable :: version, path
type(toml_key), allocatable :: list(:)
type(toml_table), pointer :: dep
logical :: required

call table%get_keys(list)

unused = 0
do ii = 1, size(list)
call get_value(table, list(ii)%key, dep)
call get_value(dep, "required", required, .false.)
call get_value(dep, "version", version)
call get_value(dep, "path", path)
if (.not.required) unused = unused + 1
if (config%verbosity > 1) then
write(config%unit, '("#", *(1x, a:))', advance='no') &
list(ii)%key, "version", version, "at", path
if (.not.required) then
write(config%unit, '(*(1x, a:))', advance='no') "(unused)"
end if
write(config%unit, '(a))')
end if
end do
if (unused > 0 .and. config%verbosity > 0) then
write(config%unit, '("#", 1x, i0, *(1x, a:))') &
unused, "unused dependencies present"
end if

end subroutine report_dependencies

!> Error handling for this command
subroutine handle_error(error)
!> Potential error
type(error_t), intent(in), optional :: error
if (present(error)) then
print '(a)', error%message
error stop 1
end if
end subroutine handle_error

end module fpm_cmd_update
17 changes: 17 additions & 0 deletions fpm/src/fpm/constants.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module fpm_constants
implicit none
public

!> Name of the project's manifest file
character(len=*), parameter :: fpm_manifest_file = "fpm.toml"

!> Name of the build directory
character(len=*), parameter :: fpm_build_dir = "build"

!> Name of the dependency subdirectory
character(len=*), parameter :: fpm_dependency_dir = "dependencies"

!> Name of the dependency lock file
character(len=*), parameter :: fpm_lock_file = "cache.toml"

end module fpm_constants
Loading