From 30d730f51fea587574a922f8763f3c7988198029 Mon Sep 17 00:00:00 2001 From: Laurence Kedward Date: Mon, 22 Nov 2021 16:11:26 +0000 Subject: Update: backend with verbose argument --- src/fpm.f90 | 4 ++-- src/fpm/cmd/install.f90 | 2 +- src/fpm_backend.f90 | 23 ++++++++++++++++++----- src/isatty.c | 13 +++++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/isatty.c (limited to 'src') diff --git a/src/fpm.f90 b/src/fpm.f90 index 6084a11..0fec0ed 100644 --- a/src/fpm.f90 +++ b/src/fpm.f90 @@ -284,7 +284,7 @@ if(settings%list)then else if (settings%show_model) then call show_model(model) else - call build_package(targets,model) + call build_package(targets,model,verbose=settings%verbose) endif end subroutine cmd_build @@ -415,7 +415,7 @@ subroutine cmd_run(settings,test) end if - call build_package(targets,model) + call build_package(targets,model,verbose=settings%verbose) if (settings%list) then call compact_list() diff --git a/src/fpm/cmd/install.f90 b/src/fpm/cmd/install.f90 index 099a0e5..46f24a7 100644 --- a/src/fpm/cmd/install.f90 +++ b/src/fpm/cmd/install.f90 @@ -54,7 +54,7 @@ contains end if if (.not.settings%no_rebuild) then - call build_package(targets,model) + call build_package(targets,model,verbose=settings%verbose) end if call new_installer(installer, prefix=settings%prefix, & diff --git a/src/fpm_backend.f90 b/src/fpm_backend.f90 index e0c6d73..731763f 100644 --- a/src/fpm_backend.f90 +++ b/src/fpm_backend.f90 @@ -40,12 +40,20 @@ implicit none private public :: build_package, sort_target, schedule_targets +interface + function c_isatty() bind(C, name = 'c_isatty') + use, intrinsic :: iso_c_binding, only: c_int + integer(c_int) :: c_isatty + end function +end interface + contains !> Top-level routine to build package described by `model` -subroutine build_package(targets,model) +subroutine build_package(targets,model,verbose) type(build_target_ptr), intent(inout) :: targets(:) type(fpm_model_t), intent(in) :: model + logical, intent(in) :: verbose integer :: i, j type(build_target_ptr), allocatable :: queue(:) @@ -54,6 +62,8 @@ subroutine build_package(targets,model) type(string_t), allocatable :: build_dirs(:) type(string_t) :: temp + logical :: plain_output + ! Need to make output directory for include (mod) files allocate(build_dirs(0)) do i = 1, size(targets) @@ -65,7 +75,7 @@ subroutine build_package(targets,model) end do do i = 1, size(build_dirs) - call mkdir(build_dirs(i)%s) + call mkdir(build_dirs(i)%s,verbose) end do ! Perform depth-first topological sort of targets @@ -83,6 +93,8 @@ subroutine build_package(targets,model) stat(:) = 0 build_failed = .false. + ! Set output mode + plain_output = (.not.(c_isatty()==1)) .or. verbose ! Loop over parallel schedule regions do i=1,size(schedule_ptr)-1 @@ -95,7 +107,7 @@ subroutine build_package(targets,model) skip_current = build_failed if (.not.skip_current) then - call build_target(model,queue(j)%ptr,stat(j)) + call build_target(model,queue(j)%ptr,verbose,stat(j)) end if ! Set global flag if this target failed to build @@ -261,16 +273,17 @@ end subroutine schedule_targets !> !> If successful, also caches the source file digest to disk. !> -subroutine build_target(model,target,stat) +subroutine build_target(model,target,verbose,stat) type(fpm_model_t), intent(in) :: model type(build_target_t), intent(in), target :: target + logical, intent(in) :: verbose integer, intent(out) :: stat integer :: fh !$omp critical if (.not.exists(dirname(target%output_file))) then - call mkdir(dirname(target%output_file)) + call mkdir(dirname(target%output_file),verbose) end if !$omp end critical diff --git a/src/isatty.c b/src/isatty.c new file mode 100644 index 0000000..bd0f74a --- /dev/null +++ b/src/isatty.c @@ -0,0 +1,13 @@ +#include //for isatty() +#include //for fileno() + +int c_isatty(void) +{ + + if (isatty(fileno(stdin))){ + return 1; + } else { + return 0; + } + +} \ No newline at end of file -- cgit v1.2.3