Skip to content

Commit 22ea5a6

Browse files
committed
Add: support for remote git dependencies
1 parent 5027275 commit 22ea5a6

File tree

2 files changed

+84
-35
lines changed

2 files changed

+84
-35
lines changed

fpm/src/fpm.f90

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ recursive subroutine add_libsources_from_package(sources,package_list,package, &
5353
! Add library sources from dependencies
5454
if (allocated(package%dependency)) then
5555

56-
call add_local_dependencies(package%dependency)
56+
call add_dependencies(package%dependency)
5757

5858
if (allocated(error)) then
5959
return
@@ -64,7 +64,7 @@ recursive subroutine add_libsources_from_package(sources,package_list,package, &
6464
! Add library sources from dev-dependencies
6565
if (dev_depends .and. allocated(package%dev_dependency)) then
6666

67-
call add_local_dependencies(package%dev_dependency)
67+
call add_dependencies(package%dev_dependency)
6868

6969
if (allocated(error)) then
7070
return
@@ -74,13 +74,15 @@ recursive subroutine add_libsources_from_package(sources,package_list,package, &
7474

7575
contains
7676

77-
subroutine add_local_dependencies(dependency_list)
77+
subroutine add_dependencies(dependency_list)
7878
type(dependency_t) :: dependency_list(:)
7979

8080
integer :: i
8181
type(string_t) :: dep_name
8282
type(package_t) :: dependency
8383

84+
character(:), allocatable :: dependency_path
85+
8486
do i=1,size(dependency_list)
8587

8688
if (dependency_list(i)%name .in. package_list) then
@@ -89,49 +91,53 @@ subroutine add_local_dependencies(dependency_list)
8991

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

92-
call fatal_error(error,'Remote dependencies not implemented')
93-
return
94+
dependency_path = join_path('build','dependencies',dependency_list(i)%name)
9495

95-
end if
96-
97-
if (allocated(dependency_list(i)%path)) then
96+
if (.not.exists(join_path(dependency_path,'fpm.toml'))) then
97+
call dependency_list(i)%git%checkout(dependency_path, error)
98+
if (allocated(error)) return
99+
end if
98100

99-
call get_package_data(dependency, &
100-
join_path(package_root,dependency_list(i)%path,"fpm.toml"), error)
101+
else if (allocated(dependency_list(i)%path)) then
102+
103+
dependency_path = join_path(package_root,dependency_list(i)%path)
101104

102-
if (allocated(error)) then
103-
error%message = 'Error while parsing manifest for dependency package at:'//&
104-
new_line('a')//join_path(package_root,dependency_list(i)%path,"fpm.toml")//&
105-
new_line('a')//error%message
106-
return
107-
end if
105+
end if
108106

109-
if (.not.allocated(dependency%library) .and. &
110-
exists(join_path(package_root,dependency_list(i)%path,"src"))) then
111-
allocate(dependency%library)
112-
dependency%library%source_dir = "src"
113-
end if
107+
call get_package_data(dependency, &
108+
join_path(dependency_path,"fpm.toml"), error)
114109

115-
116-
call add_libsources_from_package(sources,package_list,dependency, &
117-
package_root=join_path(package_root,dependency_list(i)%path), &
118-
dev_depends=dev_depends, error=error)
119-
120-
if (allocated(error)) then
121-
error%message = 'Error while processing sources for dependency package "'//&
122-
new_line('a')//dependency%name//'"'//&
123-
new_line('a')//error%message
124-
return
125-
end if
110+
if (allocated(error)) then
111+
error%message = 'Error while parsing manifest for dependency package at:'//&
112+
new_line('a')//join_path(dependency_path,"fpm.toml")//&
113+
new_line('a')//error%message
114+
return
115+
end if
126116

127-
dep_name%s = dependency_list(i)%name
128-
package_list = [package_list, dep_name]
117+
if (.not.allocated(dependency%library) .and. &
118+
exists(join_path(dependency_path,"src"))) then
119+
allocate(dependency%library)
120+
dependency%library%source_dir = "src"
121+
end if
129122

123+
124+
call add_libsources_from_package(sources,package_list,dependency, &
125+
package_root=dependency_path, &
126+
dev_depends=dev_depends, error=error)
127+
128+
if (allocated(error)) then
129+
error%message = 'Error while processing sources for dependency package "'//&
130+
new_line('a')//dependency%name//'"'//&
131+
new_line('a')//error%message
132+
return
130133
end if
131134

135+
dep_name%s = dependency_list(i)%name
136+
package_list = [package_list, dep_name]
137+
132138
end do
133139

134-
end subroutine add_local_dependencies
140+
end subroutine add_dependencies
135141

136142
end subroutine add_libsources_from_package
137143

fpm/src/fpm/git.f90

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
!> Implementation for interacting with git repositories.
22
module fpm_git
3+
use fpm_error, only: error_t, fatal_error
34
implicit none
45

56
public :: git_target_t
@@ -43,6 +44,9 @@ module fpm_git
4344

4445
contains
4546

47+
!> Fetch and checkout in local directory
48+
procedure :: checkout
49+
4650
!> Show information on instance
4751
procedure :: info
4852

@@ -124,6 +128,45 @@ function git_target_tag(url, tag) result(self)
124128
end function git_target_tag
125129

126130

131+
subroutine checkout(self,local_path, error)
132+
133+
!> Instance of the git target
134+
class(git_target_t), intent(in) :: self
135+
136+
!> Local path to checkout in
137+
character(*), intent(in) :: local_path
138+
139+
!> Error
140+
type(error_t), allocatable, intent(out) :: error
141+
142+
!> Stat for execute_command_line
143+
integer :: stat
144+
145+
call execute_command_line("git init "//local_path, exitstat=stat)
146+
147+
if (stat /= 0) then
148+
call fatal_error(error,'Error while initiating git repository for remote dependency')
149+
return
150+
end if
151+
152+
call execute_command_line("git -C "//local_path//" fetch "//self%url//&
153+
" "//self%object, exitstat=stat)
154+
155+
if (stat /= 0) then
156+
call fatal_error(error,'Error while fetching git repository for remote dependency')
157+
return
158+
end if
159+
160+
call execute_command_line("git -C "//local_path//" checkout -qf FETCH_HEAD", exitstat=stat)
161+
162+
if (stat /= 0) then
163+
call fatal_error(error,'Error while checking out git repository for remote dependency')
164+
return
165+
end if
166+
167+
end subroutine checkout
168+
169+
127170
!> Show information on git target
128171
subroutine info(self, unit, verbosity)
129172

0 commit comments

Comments
 (0)