diff options
-rw-r--r-- | fpm/src/fpm.f90 | 76 | ||||
-rw-r--r-- | fpm/src/fpm/git.f90 | 43 |
2 files changed, 84 insertions, 35 deletions
diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index 1c5275a..55b2baa 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -53,7 +53,7 @@ recursive subroutine add_libsources_from_package(sources,package_list,package, & ! Add library sources from dependencies if (allocated(package%dependency)) then - call add_local_dependencies(package%dependency) + call add_dependencies(package%dependency) if (allocated(error)) then return @@ -64,7 +64,7 @@ recursive subroutine add_libsources_from_package(sources,package_list,package, & ! Add library sources from dev-dependencies if (dev_depends .and. allocated(package%dev_dependency)) then - call add_local_dependencies(package%dev_dependency) + call add_dependencies(package%dev_dependency) if (allocated(error)) then return @@ -74,13 +74,15 @@ recursive subroutine add_libsources_from_package(sources,package_list,package, & contains - subroutine add_local_dependencies(dependency_list) + subroutine add_dependencies(dependency_list) type(dependency_t) :: dependency_list(:) integer :: i type(string_t) :: dep_name type(package_t) :: dependency + character(:), allocatable :: dependency_path + do i=1,size(dependency_list) if (dependency_list(i)%name .in. package_list) then @@ -89,49 +91,53 @@ recursive subroutine add_libsources_from_package(sources,package_list,package, & if (allocated(dependency_list(i)%git)) then - call fatal_error(error,'Remote dependencies not implemented') - return + dependency_path = join_path('build','dependencies',dependency_list(i)%name) - end if - - if (allocated(dependency_list(i)%path)) then + 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 - call get_package_data(dependency, & - join_path(package_root,dependency_list(i)%path,"fpm.toml"), error) + else if (allocated(dependency_list(i)%path)) then + + dependency_path = join_path(package_root,dependency_list(i)%path) - if (allocated(error)) then - error%message = 'Error while parsing manifest for dependency package at:'//& - new_line('a')//join_path(package_root,dependency_list(i)%path,"fpm.toml")//& - new_line('a')//error%message - return - end if + end if - if (.not.allocated(dependency%library) .and. & - exists(join_path(package_root,dependency_list(i)%path,"src"))) then - allocate(dependency%library) - dependency%library%source_dir = "src" - end if + call get_package_data(dependency, & + join_path(dependency_path,"fpm.toml"), error) - - call add_libsources_from_package(sources,package_list,dependency, & - package_root=join_path(package_root,dependency_list(i)%path), & - dev_depends=dev_depends, 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 + 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 - dep_name%s = dependency_list(i)%name - package_list = [package_list, dep_name] + 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,package_list,dependency, & + package_root=dependency_path, & + dev_depends=dev_depends, 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] + end do - end subroutine add_local_dependencies + end subroutine add_dependencies end subroutine add_libsources_from_package diff --git a/fpm/src/fpm/git.f90 b/fpm/src/fpm/git.f90 index 28ae867..f02d06f 100644 --- a/fpm/src/fpm/git.f90 +++ b/fpm/src/fpm/git.f90 @@ -1,5 +1,6 @@ !> Implementation for interacting with git repositories. module fpm_git + use fpm_error, only: error_t, fatal_error implicit none public :: git_target_t @@ -43,6 +44,9 @@ module fpm_git contains + !> Fetch and checkout in local directory + procedure :: checkout + !> Show information on instance procedure :: info @@ -124,6 +128,45 @@ contains end function git_target_tag + subroutine checkout(self,local_path, error) + + !> Instance of the git target + class(git_target_t), intent(in) :: self + + !> Local path to checkout in + character(*), intent(in) :: local_path + + !> Error + type(error_t), allocatable, intent(out) :: error + + !> Stat for execute_command_line + integer :: stat + + call execute_command_line("git init "//local_path, exitstat=stat) + + if (stat /= 0) then + call fatal_error(error,'Error while initiating git repository for remote dependency') + return + end if + + call execute_command_line("git -C "//local_path//" fetch "//self%url//& + " "//self%object, exitstat=stat) + + if (stat /= 0) then + call fatal_error(error,'Error while fetching git repository for remote dependency') + return + end if + + call execute_command_line("git -C "//local_path//" checkout -qf FETCH_HEAD", exitstat=stat) + + if (stat /= 0) then + call fatal_error(error,'Error while checking out git repository for remote dependency') + return + end if + + end subroutine checkout + + !> Show information on git target subroutine info(self, unit, verbosity) |