Skip to content

Commit b1f5a06

Browse files
committed
Only preprocess current files
1 parent 77d1010 commit b1f5a06

File tree

2 files changed

+20
-39
lines changed

2 files changed

+20
-39
lines changed

fypp-gfortran.py

+18-37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import sys
23
import subprocess
34
from pathlib import Path
@@ -13,47 +14,27 @@
1314
output_dir.mkdir(parents=True)
1415

1516
# Get the filenames with .fypp extension and convert to string.
16-
filenames = [str(f) for f in Path(".").glob("**/*.fypp")]
17+
source_file = [arg for arg in args if arg.endswith(".fypp")]
18+
output_file = [arg for arg in args if arg.endswith(".o")]
19+
20+
if len(source_file) != len(output_file):
21+
subprocess.run(["gfortran"] + args, check=True)
22+
sys.exit(0)
23+
24+
source_file = source_file[0]
25+
output_file = output_file[0]
26+
preprocessed = output_file.replace(".o", ".f90")
1727

1828
# Filter out the macro definitions.
1929
macros = [arg for arg in args if arg.startswith("-D")]
2030

2131
# Filter out the include paths with -I prefix.
2232
include_paths = [arg for arg in args if arg.startswith("-I")]
2333

24-
# Declare preprocessed array.
25-
preprocessed = []
26-
27-
# Preprocess the .fypp files.
28-
for filename in filenames:
29-
30-
# Get the output filename only without extension and path.
31-
output_filename = Path(filename).stem
32-
33-
# Save the output_file to build directory.
34-
output_file = str(Path(output_dir, f"{output_filename}.f90"))
35-
36-
subprocess.run(
37-
[
38-
"fypp",
39-
filename,
40-
*include_paths,
41-
*macros,
42-
output_file,
43-
],
44-
)
45-
46-
# Append the output_file to preprocessed array.
47-
# Along with the path to store object files.
48-
# This will save the object files in preprocessed_files directory.
49-
preprocessed.append(f"-c {output_file} -o {str(Path(output_dir, f'{output_filename}.o'))}")
50-
51-
# Run gfortran for each preprocessed file.
52-
for file in preprocessed :
53-
file_args = file.split()
54-
subprocess.run(
55-
["gfortran"] + file_args,
56-
check=True,
57-
)
58-
59-
subprocess.run(["gfortran"] + args)
34+
subprocess.run(
35+
["fypp", "-n", source_file, preprocessed] + macros + include_paths,
36+
check=True
37+
)
38+
39+
args = [arg for arg in args if arg != source_file and not arg in macros] + [preprocessed]
40+
subprocess.run(["gfortran"] + args, check=True)

src/fpm_sources.f90

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module fpm_sources
1515
private
1616
public :: add_sources_from_dir, add_executable_sources
1717

18-
character(4), parameter :: fortran_suffixes(2) = [".f90", &
19-
".f "]
18+
character(5), parameter :: fortran_suffixes(3) = [".f90 ", ".fypp", &
19+
".f "]
2020

2121
contains
2222

0 commit comments

Comments
 (0)