Skip to content

Commit d2009f1

Browse files
authored
Merge branch 'main' into backend-output
2 parents 6cd53f7 + 57b5636 commit d2009f1

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/fpm_filesystem.F90

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ module fpm_filesystem
66
OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
77
OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD
88
use fpm_environment, only: separator, get_env, os_is_unix
9-
use fpm_strings, only: f_string, replace, string_t, split, notabs
9+
use fpm_strings, only: f_string, replace, string_t, split, notabs, str_begins_with_str
1010
use iso_c_binding, only: c_char, c_ptr, c_int, c_null_char, c_associated, c_f_pointer
1111
use fpm_error, only : fpm_stop
1212
implicit none
1313
private
1414
public :: basename, canon_path, dirname, is_dir, join_path, number_of_rows, list_files, env_variable, &
1515
mkdir, exists, get_temp_filename, windows_path, unix_path, getline, delete_file
1616
public :: fileopen, fileclose, filewrite, warnwrite, parent_dir
17+
public :: is_hidden_file
1718
public :: read_lines, read_lines_expanded
1819
public :: which, run, LINE_BUFFER_LEN
1920

@@ -250,6 +251,15 @@ logical function is_dir(dir)
250251

251252
end function is_dir
252253

254+
!> test if a file is hidden
255+
logical function is_hidden_file(file_basename) result(r)
256+
character(*), intent(in) :: file_basename
257+
if (len(file_basename) <= 2) then
258+
r = .false.
259+
else
260+
r = str_begins_with_str(file_basename, '.')
261+
end if
262+
end function is_hidden_file
253263

254264
!> Construct path by joining strings with os file separator
255265
function join_path(a1,a2,a3,a4,a5) result(path)

src/fpm_sources.f90

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module fpm_sources
77
use fpm_error, only: error_t
88
use fpm_model, only: srcfile_t, FPM_UNIT_PROGRAM
9-
use fpm_filesystem, only: basename, canon_path, dirname, join_path, list_files
9+
use fpm_filesystem, only: basename, canon_path, dirname, join_path, list_files, is_hidden_file
1010
use fpm_strings, only: lower, str_ends_with, string_t, operator(.in.)
1111
use fpm_source_parsing, only: parse_f_source, parse_c_source
1212
use fpm_manifest_executable, only: executable_config_t
@@ -81,9 +81,10 @@ subroutine add_sources_from_dir(sources,directory,scope,with_executables,recurse
8181
allocate(existing_src_files(0))
8282
end if
8383

84-
is_source = [(.not.(canon_path(file_names(i)%s) .in. existing_src_files) .and. &
85-
(str_ends_with(lower(file_names(i)%s), fortran_suffixes) .or. &
86-
str_ends_with(lower(file_names(i)%s),[".c",".h"]) ),i=1,size(file_names))]
84+
is_source = [(.not.(is_hidden_file(basename(file_names(i)%s))) .and. &
85+
.not.(canon_path(file_names(i)%s) .in. existing_src_files) .and. &
86+
(str_ends_with(lower(file_names(i)%s), fortran_suffixes) .or. &
87+
str_ends_with(lower(file_names(i)%s),[".c",".h"]) ),i=1,size(file_names))]
8788
src_file_names = pack(file_names,is_source)
8889

8990
allocate(dir_sources(size(src_file_names)))

src/fpm_strings.f90

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module fpm_strings
3939
implicit none
4040

4141
private
42-
public :: f_string, lower, split, str_ends_with, string_t
42+
public :: f_string, lower, split, str_ends_with, string_t, str_begins_with_str
4343
public :: to_fortran_name, is_fortran_name
4444
public :: string_array_contains, string_cat, len_trim, operator(.in.), fnv_1a
4545
public :: replace, resize, str, join, glob
@@ -115,6 +115,19 @@ pure logical function str_ends_with_any(s, e) result(r)
115115

116116
end function str_ends_with_any
117117

118+
!> test if a CHARACTER string begins with a specified prefix
119+
pure logical function str_begins_with_str(s, e) result(r)
120+
character(*), intent(in) :: s, e
121+
integer :: n1, n2
122+
n1 = 1
123+
n2 = 1 + len(e)-1
124+
if (n2 > len(s)) then
125+
r = .false.
126+
else
127+
r = (s(n1:n2) == e)
128+
end if
129+
end function str_begins_with_str
130+
118131
!> return Fortran character variable when given a C-like array of
119132
!! single characters terminated with a C_NULL_CHAR character
120133
function f_string(c_string)

0 commit comments

Comments
 (0)