Skip to content

Commit

Permalink
Enter path to global config file via the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
minhqdao committed Jun 18, 2023
1 parent 4d7ba17 commit f3150e3
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 84 deletions.
30 changes: 15 additions & 15 deletions src/fpm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ subroutine build_model(model, settings, package, error)
integer :: i, j
type(package_config_t) :: dependency
character(len=:), allocatable :: manifest, lib_dir
character(len=:), allocatable :: version
logical :: has_cpp
logical :: duplicates_found
type(string_t) :: include_dir
Expand Down Expand Up @@ -75,7 +74,8 @@ subroutine build_model(model, settings, package, error)
if (allocated(error)) return

! Create dependencies
call new_dependency_tree(model%deps, cache=join_path("build", "cache.toml"))
call new_dependency_tree(model%deps, cache=join_path("build", "cache.toml"), &
& path_to_config=settings%path_to_config)

! Build and resolve model dependencies
call model%deps%add(package, error)
Expand Down Expand Up @@ -324,7 +324,7 @@ end subroutine check_modules_for_duplicates
subroutine check_module_names(model, error)
type(fpm_model_t), intent(in) :: model
type(error_t), allocatable, intent(out) :: error
integer :: i,j,k,l,m
integer :: k,l,m
logical :: valid,errors_found,enforce_this_file
type(string_t) :: package_name,module_name,package_prefix

Expand Down Expand Up @@ -621,13 +621,13 @@ subroutine cmd_run(settings,test)
contains
subroutine compact_list_all()
integer, parameter :: LINE_WIDTH = 80
integer :: i, j, nCol
j = 1
integer :: ii, jj, nCol
jj = 1
nCol = LINE_WIDTH/col_width
write(stderr,*) 'Available names:'
do i=1,size(targets)
do ii=1,size(targets)

exe_target => targets(i)%ptr
exe_target => targets(ii)%ptr

if (exe_target%target_type == FPM_TARGET_EXECUTABLE .and. &
allocated(exe_target%dependencies)) then
Expand All @@ -636,9 +636,9 @@ subroutine compact_list_all()

if (exe_source%unit_scope == run_scope) then

write(stderr,'(A)',advance=(merge("yes","no ",modulo(j,nCol)==0))) &
write(stderr,'(A)',advance=(merge("yes","no ",modulo(jj,nCol)==0))) &
& [character(len=col_width) :: basename(exe_target%output_file, suffix=.false.)]
j = j + 1
jj = jj + 1

end if
end if
Expand All @@ -648,14 +648,14 @@ end subroutine compact_list_all

subroutine compact_list()
integer, parameter :: LINE_WIDTH = 80
integer :: i, j, nCol
j = 1
integer :: ii, jj, nCol
jj = 1
nCol = LINE_WIDTH/col_width
write(stderr,*) 'Matched names:'
do i=1,size(executables)
write(stderr,'(A)',advance=(merge("yes","no ",modulo(j,nCol)==0))) &
& [character(len=col_width) :: basename(executables(i)%s, suffix=.false.)]
j = j + 1
do ii=1,size(executables)
write(stderr,'(A)',advance=(merge("yes","no ",modulo(jj,nCol)==0))) &
& [character(len=col_width) :: basename(executables(ii)%s, suffix=.false.)]
jj = jj + 1
enddo
write(stderr,*)
end subroutine compact_list
Expand Down
10 changes: 4 additions & 6 deletions src/fpm/cmd/update.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ subroutine cmd_update(settings)
call get_package_data(package, "fpm.toml", error, apply_defaults=.true.)
call handle_error(error)

if (.not.exists("build")) then
if (.not. exists("build")) then
call mkdir("build")
call filewrite(join_path("build", ".gitignore"),["*"])
end if

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

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

call deps%add(package, error)
call handle_error(error)
Expand Down
82 changes: 51 additions & 31 deletions src/fpm/dependency.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module fpm_dependency
use fpm_environment, only: get_os_type, OS_WINDOWS, os_is_unix
use fpm_error, only: error_t, fatal_error
use fpm_filesystem, only: exists, join_path, mkdir, canon_path, windows_path, list_files, is_dir, basename, &
os_delete_dir, get_temp_filename
os_delete_dir, get_temp_filename, parent_dir
use fpm_git, only: git_target_revision, git_target_default, git_revision, operator(==)
use fpm_manifest, only: package_config_t, dependency_config_t, get_package_data
use fpm_manifest_dependency, only: manifest_has_changed
Expand Down Expand Up @@ -123,7 +123,11 @@ module fpm_dependency
type(dependency_node_t), allocatable :: dep(:)
!> Cache file
character(len=:), allocatable :: cache
!> Custom path to the global config file
character(len=:), allocatable :: path_to_config

contains

!> Overload procedure to add new dependencies to the tree
generic :: add => add_project, add_project_dependencies, add_dependencies, &
add_dependency, add_dependency_node
Expand Down Expand Up @@ -183,24 +187,24 @@ module fpm_dependency
contains

!> Create a new dependency tree
subroutine new_dependency_tree(self, verbosity, cache)
subroutine new_dependency_tree(self, verbosity, cache, path_to_config)
!> Instance of the dependency tree
type(dependency_tree_t), intent(out) :: self
!> Verbosity of printout
integer, intent(in), optional :: verbosity
!> Name of the cache file
character(len=*), intent(in), optional :: cache
!> Path to the global config file.
character(len=*), intent(in), optional :: path_to_config

call resize(self%dep)
self%dep_dir = join_path("build", "dependencies")

if (present(verbosity)) then
self%verbosity = verbosity
end if
if (present(verbosity)) self%verbosity = verbosity

if (present(cache)) then
self%cache = cache
end if
if (present(cache)) self%cache = cache

if (present(path_to_config)) self%path_to_config = path_to_config

end subroutine new_dependency_tree

Expand Down Expand Up @@ -311,15 +315,15 @@ subroutine add_project(self, package, error)

! After resolving all dependencies, check if we have cached ones to avoid updates
if (allocated(self%cache)) then
call new_dependency_tree(cached, verbosity=self%verbosity,cache=self%cache)
call new_dependency_tree(cached, verbosity=self%verbosity, cache=self%cache)
call cached%load(self%cache, error)
if (allocated(error)) return

! Skip root node
do id=2,cached%ndep
cached%dep(id)%cached = .true.
call self%add(cached%dep(id), error)
if (allocated(error)) return
do id = 2, cached%ndep
cached%dep(id)%cached = .true.
call self%add(cached%dep(id), error)
if (allocated(error)) return
end do
end if

Expand Down Expand Up @@ -443,13 +447,13 @@ subroutine add_dependency_node(self, dependency, error)
! the manifest has priority
if (dependency%cached) then
if (dependency_has_changed(dependency, self%dep(id), self%verbosity, self%unit)) then
if (self%verbosity>0) write (self%unit, out_fmt) "Dependency change detected:", dependency%name
self%dep(id)%update = .true.
if (self%verbosity > 0) write (self%unit, out_fmt) "Dependency change detected:", dependency%name
self%dep(id)%update = .true.
else
! Store the cached one
self%dep(id) = dependency
self%dep(id)%update = .false.
endif
! Store the cached one
self%dep(id) = dependency
self%dep(id)%update = .false.
end if
end if
else
! New dependency: add from scratch
Expand Down Expand Up @@ -498,7 +502,7 @@ subroutine update_dependency(self, name, error)

associate (dep => self%dep(id))
if (allocated(dep%git) .and. dep%update) then
if (self%verbosity>0) write (self%unit, out_fmt) "Update:", dep%name
if (self%verbosity > 0) write (self%unit, out_fmt) "Update:", dep%name
proj_dir = join_path(self%dep_dir, dep%name)
call dep%git%checkout(proj_dir, error)
if (allocated(error)) return
Expand Down Expand Up @@ -545,8 +549,24 @@ subroutine resolve_dependencies(self, root, error)
type(error_t), allocatable, intent(out) :: error

type(fpm_global_settings) :: global_settings
character(:), allocatable :: parent_directory
integer :: ii

! Register path to global config file if it was entered via the command line.
if (allocated(self%path_to_config)) then
if (len_trim(self%path_to_config) > 0) then
parent_directory = parent_dir(self%path_to_config)

if (len_trim(parent_directory) == 0) then
global_settings%path_to_config_folder = "."
else
global_settings%path_to_config_folder = parent_directory
end if

global_settings%config_file_name = basename(self%path_to_config)
end if
end if

call get_global_settings(global_settings, error)
if (allocated(error)) return

Expand Down Expand Up @@ -722,7 +742,7 @@ subroutine check_and_read_pkg_data(json, node, download_url, version, error)
character(:), allocatable :: version_key, version_str, error_message, namespace, name

namespace = ""
name = "UNNAMED_NODE"
name = "UNNAMED_NODE"
if (allocated(node%namespace)) namespace = node%namespace
if (allocated(node%name)) name = node%name

Expand Down Expand Up @@ -1199,27 +1219,27 @@ logical function dependency_has_changed(cached, manifest, verbosity, iunit) resu
!> may not have it
if (allocated(cached%version) .and. allocated(manifest%version)) then
if (cached%version /= manifest%version) then
if (verbosity>1) write(iunit,out_fmt) "VERSION has changed: "//cached%version%s()//" vs. "//manifest%version%s()
return
endif
if (verbosity > 1) write (iunit, out_fmt) "VERSION has changed: "//cached%version%s()//" vs. "//manifest%version%s()
return
end if
else
if (verbosity>1) write(iunit,out_fmt) "VERSION has changed presence "
if (verbosity > 1) write (iunit, out_fmt) "VERSION has changed presence "
end if
if (allocated(cached%revision) .and. allocated(manifest%revision)) then
if (cached%revision /= manifest%revision) then
if (verbosity>1) write(iunit,out_fmt) "REVISION has changed: "//cached%revision//" vs. "//manifest%revision
if (verbosity > 1) write (iunit, out_fmt) "REVISION has changed: "//cached%revision//" vs. "//manifest%revision
return
endif
end if
else
if (verbosity>1) write(iunit,out_fmt) "REVISION has changed presence "
if (verbosity > 1) write (iunit, out_fmt) "REVISION has changed presence "
end if
if (allocated(cached%proj_dir) .and. allocated(manifest%proj_dir)) then
if (cached%proj_dir /= manifest%proj_dir) then
if (verbosity>1) write(iunit,out_fmt) "PROJECT DIR has changed: "//cached%proj_dir//" vs. "//manifest%proj_dir
if (verbosity > 1) write (iunit, out_fmt) "PROJECT DIR has changed: "//cached%proj_dir//" vs. "//manifest%proj_dir
return
endif
end if
else
if (verbosity>1) write(iunit,out_fmt) "PROJECT DIR has changed presence "
if (verbosity > 1) write (iunit, out_fmt) "PROJECT DIR has changed presence "
end if

!> All checks passed: the two dependencies have no differences
Expand Down
Loading

0 comments on commit f3150e3

Please sign in to comment.