subroutineload_external_projectprivate
subroutine load_external_project(p, s, url)
Add the modules in the modules.json of an external project at url, a path or a web address.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| p | type(project_t) | inout | the project | |
| s | type(settings_t) | in | the settings | |
| url | character(len=*) | in | where the project's documentation is |
Calls
- starts_with
- ends_with
- unique_tag
- make_directory
- run_command
- quoted_path
- quoted
- warn
- resolve_path
- remove_file
- read_external
- push_int
Source
Show the code
subroutine load_external_project(p, s, url)
type(project_t), intent(inout) :: p !! the project
type(settings_t), intent(in) :: s !! the settings
character(len=*), intent(in) :: url !! where the project's documentation is
type(json_core) :: json
type(json_value), pointer :: root, modules, item
character(len=:), allocatable :: path, base, fetched
character(len=32) :: tag
logical :: found, remote
integer :: k, n, id, status
remote = starts_with(url, 'http://') .or. starts_with(url, 'https://')
if (remote) then
base = url
if (.not. ends_with(base, '/')) base = base//'/'
call unique_tag(tag)
fetched = s%output_dir//'/.external-modules-'//trim(tag)//'.json'
call make_directory(s%output_dir, status)
call run_command('curl -fsSL -o '//quoted_path(fetched)//' '//quoted(base//'modules.json'), status)
path = fetched
if (status /= 0) then
call warn("Could not open external URL '"//url//"'")
return
end if
else
base = resolve_path(s%directory, url)//'/'
path = base//'modules.json'
end if
call json%initialize()
call json%load(path, root)
if (remote) then
call remove_file(fetched)
end if
if (json%failed()) then
call json%clear_exceptions()
call warn("Could not open external URL '"//url//"'")
return
end if
call json%get_child(root, 'modules', modules, found)
if (found) then
call json%info(modules, n_children=n)
do k = 1, n
call json%get_child(modules, k, item, found)
call read_external(p, json, item, base, 0, id)
if (id > 0) call push_int(p%modules, id)
end do
end if
call json%destroy(root)
if (remote) then
call remove_file(path)
end if
end subroutine load_external_project