1
1
module fpm_backend_output
2
2
use iso_fortran_env, only: stdout= >output_unit
3
3
use fpm_filesystem, only: basename
4
- use fpm_targets, only: build_target_t
4
+ use fpm_targets, only: build_target_ptr
5
5
use fpm_backend_console, only: console_t
6
6
use M_attr, only: attr, attr_mode
7
7
implicit none
8
8
9
+ type build_progress_t
10
+
11
+ type (console_t) :: console
12
+
13
+ integer :: n_complete
14
+
15
+ integer :: n_target
16
+
17
+ logical :: plain_mode = .true.
18
+
19
+ integer , allocatable :: output_lines(:)
20
+
21
+ type (build_target_ptr), pointer :: target_queue(:)
22
+
23
+ contains
24
+ procedure :: init = > output_init
25
+ procedure :: compiling_status = > output_status_compiling
26
+ procedure :: completed_status = > output_status_complete
27
+ procedure :: success = > output_progress_success
28
+
29
+ end type build_progress_t
9
30
10
31
contains
11
32
12
- subroutine output_init (plain_mode )
33
+ subroutine output_init (progress ,target_queue ,plain_mode )
34
+ class(build_progress_t), intent (out ) :: progress
35
+ type (build_target_ptr), intent (in ), target :: target_queue(:)
13
36
logical , intent (in ), optional :: plain_mode
14
37
15
38
if (plain_mode) then
@@ -18,80 +41,114 @@ subroutine output_init(plain_mode)
18
41
call attr_mode(' color' )
19
42
end if
20
43
44
+ call progress% console% init(plain_mode)
45
+
46
+ progress% n_target = size (target_queue,1 )
47
+ progress% target_queue = > target_queue
48
+ progress% plain_mode = plain_mode
49
+
50
+ allocate (progress% output_lines(progress% n_target))
51
+
21
52
end subroutine output_init
22
53
23
- subroutine output_status_compiling (console , line , target )
24
- type (console_t), intent (inout ), target :: console
25
- integer , intent (inout ) :: line
26
- type (build_target_t), intent (in ) :: target
54
+ subroutine output_status_compiling (progress , queue_index )
55
+ class(build_progress_t), intent (inout ) :: progress
56
+ integer , intent (in ) :: queue_index
27
57
28
58
character (:), allocatable :: target_name
29
59
character (100 ) :: output_string
60
+ character (100 ) :: overall_progress
30
61
31
- if (allocated (target % source)) then
32
- target_name = basename(target % source% file_name)
33
- else
34
- target_name = basename(target % output_file)
35
- end if
62
+ associate(target = >progress% target_queue(queue_index)% ptr)
63
+
64
+ if (allocated (target % source)) then
65
+ target_name = basename(target % source% file_name)
66
+ else
67
+ target_name = basename(target % output_file)
68
+ end if
69
+
70
+ write (overall_progress,' (A,I4,A)' ) ' [' ,100 * progress% n_complete/ progress% n_target,' %]'
71
+
72
+ if (progress% plain_mode) then
73
+
74
+ ! $omp critical
75
+ write (* ,' (A8,A30)' ) trim (overall_progress),target_name
76
+ ! $omp end critical
36
77
37
- write (output_string, ' (A,T40,A,A) ' ) target_name,attr( ' <yellow>compiling...</yellow> ' )
78
+ else
38
79
39
- line = console% write_line(trim (output_string))
80
+ write (output_string,' (A,T40,A,A)' ) target_name,attr(' <yellow>compiling...</yellow>' )
81
+ call progress% console% write_line(trim (output_string),progress% output_lines(queue_index))
82
+
83
+ call progress% console% write_line(trim (overall_progress)// ' Compiling...' ,advance= .false. )
84
+
85
+ end if
86
+
87
+ end associate
40
88
41
89
end subroutine output_status_compiling
42
90
43
- subroutine output_status_complete ( console , line , target , build_stat , n_complete )
44
- type (console_t), intent ( inout ), target :: console
45
- integer , intent (in ) :: line
46
- type (build_target_t) , intent (in ) :: target
91
+
92
+ subroutine output_status_complete ( progress , queue_index , build_stat )
93
+ class(build_progress_t) , intent (inout ) :: progress
94
+ integer , intent (in ) :: queue_index
47
95
integer , intent (in ) :: build_stat
48
- integer , intent (inout ) :: n_complete
49
96
50
97
character (:), allocatable :: target_name
51
98
character (100 ) :: output_string
52
-
53
- if (allocated (target % source)) then
54
- target_name = basename(target % source% file_name)
55
- else
56
- target_name = basename(target % output_file)
57
- end if
58
-
59
- if (build_stat == 0 ) then
60
- write (output_string,' (A,T40,A,A)' ) target_name,attr(' <green>done.</green>' )
61
- else
62
- write (output_string,' (A,T40,A,A)' ) target_name,attr(' <red>failed.</red>' )
63
- end if
64
-
65
- call console% update_line(line,trim (output_string))
99
+ character (100 ) :: overall_progress
66
100
67
101
! $omp critical
68
- n_complete = n_complete + 1
102
+ progress % n_complete = progress % n_complete + 1
69
103
! $omp end critical
70
104
71
- end subroutine output_status_complete
105
+ associate( target = >progress % target_queue(queue_index) % ptr)
72
106
73
- subroutine output_progress (n_complete , total , plain_mode )
74
- integer , intent (in ) :: n_complete, total
75
- logical :: plain_mode
107
+ if (allocated (target % source)) then
108
+ target_name = basename(target % source% file_name)
109
+ else
110
+ target_name = basename(target % output_file)
111
+ end if
76
112
77
- character (:), allocatable :: advance
113
+ if (build_stat == 0 ) then
114
+ write (output_string,' (A,T40,A,A)' ) target_name,attr(' <green>done.</green>' )
115
+ else
116
+ write (output_string,' (A,T40,A,A)' ) target_name,attr(' <red>failed.</red>' )
117
+ end if
78
118
79
- if (plain_mode) then
80
- advance = " yes"
81
- else
82
- advance = " no"
83
- end if
119
+ write (overall_progress,' (A,I4,A)' ) ' [' ,100 * progress% n_complete/ progress% n_target,' %] '
84
120
85
- ! $omp critical
86
- write (* ,' (A,I4,A,A)' ,advance= advance) ' [' ,100 * n_complete/ total,' %] Compiling project...'
87
- ! $omp end critical
121
+ if (progress% plain_mode) then
122
+
123
+ ! $omp critical
124
+ write (* ,' (A8,A30,A7)' ) trim (overall_progress),target_name, ' done.'
125
+ ! $omp end critical
126
+
127
+ else
88
128
89
- end subroutine output_progress
129
+ call progress % console % update_line(progress % output_lines(queue_index), trim (output_string))
90
130
91
- subroutine output_progress_complete ( )
131
+ call progress % console % write_line( trim (overall_progress) // ' Compiling... ' ,advance = .false. )
92
132
93
- write (* ,' (A)' ) char (27 )// " [2K" // char (27 )// " [1G" // attr(' <green>[100%] Project compiled successfully.</green>' )
133
+ end if
134
+
135
+ end associate
136
+
137
+ end subroutine output_status_complete
138
+
139
+ subroutine output_progress_success (progress )
140
+ class(build_progress_t), intent (inout ) :: progress
141
+
142
+ if (progress% plain_mode) then
143
+
144
+ write (* ,' (A)' ) attr(' <green>[100%] Project compiled successfully.</green>' )
145
+
146
+ else
147
+
148
+ write (* ,' (A)' ) progress% console% LINE_RESET// attr(' <green>[100%] Project compiled successfully.</green>' )
149
+
150
+ end if
94
151
95
- end subroutine output_progress_complete
152
+ end subroutine output_progress_success
96
153
97
154
end module fpm_backend_output
0 commit comments