Skip to content

Dependency handling #266

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

Merged
merged 5 commits into from
Dec 10, 2020
Merged
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 @@ -6,9 +6,11 @@ program main
fpm_run_settings, &
fpm_test_settings, &
fpm_install_settings, &
fpm_update_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 @@ -27,6 +29,8 @@ program main
call cmd_run(settings,test=.true.)
type is (fpm_install_settings)
call cmd_install(settings)
type is (fpm_update_settings)
call cmd_update(settings)
end select

end program main
2 changes: 1 addition & 1 deletion fpm/fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ copyright = "2020 fpm contributors"
[dependencies]
[dependencies.toml-f]
git = "https://github.com/toml-f/toml-f"
tag = "v0.2.1"
rev = "2f5eaba864ff630ba0c3791126a3f811b6e437f3"

[dependencies.M_CLI2]
git = "https://github.com/urbanjost/M_CLI2.git"
Expand Down
153 changes: 28 additions & 125 deletions fpm/src/fpm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module fpm
use fpm_backend, only: build_package
use fpm_command_line, only: fpm_build_settings, fpm_new_settings, &
fpm_run_settings, fpm_install_settings, fpm_test_settings
use fpm_dependency, only : new_dependency_tree
use fpm_environment, only: run
use fpm_filesystem, only: is_dir, join_path, number_of_rows, list_files, exists, basename
use fpm_model, only: fpm_model_t, srcfile_t, build_target_t, &
Expand All @@ -29,125 +30,6 @@ module fpm
contains


recursive subroutine add_libsources_from_package(sources,link_libraries,package_list,package, &
package_root,dev_depends,error)
! Discover library sources in a package, recursively including dependencies
!
type(srcfile_t), allocatable, intent(inout), target :: sources(:)
type(string_t), allocatable, intent(inout) :: link_libraries(:)
type(string_t), allocatable, intent(inout) :: package_list(:)
type(package_config_t), intent(in) :: package
character(*), intent(in) :: package_root
logical, intent(in) :: dev_depends
type(error_t), allocatable, intent(out) :: error

! Add package library sources
if (allocated(package%library)) then

call add_sources_from_dir(sources, join_path(package_root,package%library%source_dir), &
FPM_SCOPE_LIB, error=error)

if (allocated(error)) then
return
end if

end if

! Add library sources from dependencies
if (allocated(package%dependency)) then

call add_dependencies(package%dependency)

if (allocated(error)) then
return
end if

end if

! Add library sources from dev-dependencies
if (dev_depends .and. allocated(package%dev_dependency)) then

call add_dependencies(package%dev_dependency)

if (allocated(error)) then
return
end if

end if

contains

subroutine add_dependencies(dependency_list)
type(dependency_config_t), intent(in) :: dependency_list(:)

integer :: i
type(string_t) :: dep_name
type(package_config_t) :: dependency

character(:), allocatable :: dependency_path

do i=1,size(dependency_list)

if (dependency_list(i)%name .in. package_list) then
cycle
end if

if (allocated(dependency_list(i)%git)) then

dependency_path = join_path('build','dependencies',dependency_list(i)%name)

if (.not.exists(join_path(dependency_path,'fpm.toml'))) then
call dependency_list(i)%git%checkout(dependency_path, error)
if (allocated(error)) return
end if

else if (allocated(dependency_list(i)%path)) then

dependency_path = join_path(package_root,dependency_list(i)%path)

end if

call get_package_data(dependency, &
join_path(dependency_path,"fpm.toml"), error)

if (allocated(error)) then
error%message = 'Error while parsing manifest for dependency package at:'//&
new_line('a')//join_path(dependency_path,"fpm.toml")//&
new_line('a')//error%message
return
end if

if (.not.allocated(dependency%library) .and. &
exists(join_path(dependency_path,"src"))) then
allocate(dependency%library)
dependency%library%source_dir = "src"
end if


call add_libsources_from_package(sources,link_libraries,package_list,dependency, &
package_root=dependency_path, &
dev_depends=.false., error=error)

if (allocated(error)) then
error%message = 'Error while processing sources for dependency package "'//&
new_line('a')//dependency%name//'"'//&
new_line('a')//error%message
return
end if

dep_name%s = dependency_list(i)%name
package_list = [package_list, dep_name]
if (allocated(dependency%build%link)) then
link_libraries = [link_libraries, dependency%build%link]
end if

end do

end subroutine add_dependencies

end subroutine add_libsources_from_package


subroutine build_model(model, settings, package, error)
! Constructs a valid fpm model from command line settings and toml manifest
!
Expand All @@ -158,6 +40,8 @@ subroutine build_model(model, settings, package, error)
type(string_t), allocatable :: package_list(:)

integer :: i
type(package_config_t) :: dependency
character(len=:), allocatable :: manifest, lib_dir

if(settings%verbose)then
write(*,*)'<INFO>BUILD_NAME:',settings%build_name
Expand All @@ -172,6 +56,10 @@ subroutine build_model(model, settings, package, error)
allocate(model%link_libraries(0))
end if

call new_dependency_tree(model%deps, cache=join_path("build", "cache.toml"))
call model%deps%add(package, error)
if (allocated(error)) return

allocate(package_list(1))
package_list(1)%s = package%name

Expand Down Expand Up @@ -228,12 +116,27 @@ subroutine build_model(model, settings, package, error)

endif

! Add library sources, including local dependencies
call add_libsources_from_package(model%sources,model%link_libraries,package_list,package, &
package_root='.',dev_depends=.true.,error=error)
if (allocated(error)) then
return
end if
do i = 1, model%deps%ndep
associate(dep => model%deps%dep(i))
manifest = join_path(dep%proj_dir, "fpm.toml")

call get_package_data(dependency, manifest, error, &
apply_defaults=.true.)
if (allocated(error)) exit

if (allocated(dependency%library)) then
lib_dir = join_path(dep%proj_dir, dependency%library%source_dir)
call add_sources_from_dir(model%sources, lib_dir, FPM_SCOPE_LIB, &
error=error)
if (allocated(error)) exit
end if

if (allocated(dependency%build%link)) then
model%link_libraries = [model%link_libraries, dependency%build%link]
end if
end associate
end do
if (allocated(error)) return

call targets_from_sources(model,model%sources)

Expand Down
68 changes: 68 additions & 0 deletions fpm/src/fpm/cmd/update.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module fpm_cmd_update
use fpm_command_line, only : fpm_update_settings
use fpm_dependency, only : dependency_tree_t, new_dependency_tree
use fpm_error, only : error_t
use fpm_filesystem, only : exists, mkdir, join_path, delete_file
use fpm_manifest, only : package_config_t, get_package_data
implicit none
private
public :: cmd_update

contains

!> Entry point for the update subcommand
subroutine cmd_update(settings)
!> Representation of the command line arguments
type(fpm_update_settings), intent(in) :: settings
type(package_config_t) :: package
type(dependency_tree_t) :: deps
type(error_t), allocatable :: error

integer :: ii
character(len=:), allocatable :: cache

call get_package_data(package, "fpm.toml", error, apply_defaults=.true.)
call handle_error(error)

if (.not.exists("build")) then
call mkdir("build")
end if

cache = join_path("build", "cache.toml")
if (settings%clean) then
call delete_file(cache)
end if

call new_dependency_tree(deps, cache=cache, &
verbosity=merge(2, 1, settings%verbose))

call deps%add(package, error)
call handle_error(error)

if (settings%fetch_only) return

if (size(settings%name) == 0) then
do ii = 1, deps%ndep
call deps%update(deps%dep(ii)%name, error)
call handle_error(error)
end do
else
do ii = 1, size(settings%name)
call deps%update(trim(settings%name(ii)), error)
call handle_error(error)
end do
end if

end subroutine cmd_update

!> 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
Loading