From 502a0d52dbc9eb16a6b07f359c9bebc347448c16 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Sat, 20 Aug 2022 11:38:18 +0200 Subject: [PATCH] Only preprocess current files --- fypp-gfortran.py | 55 +++++++++++++++------------------------------ src/fpm_sources.f90 | 4 ++-- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/fypp-gfortran.py b/fypp-gfortran.py index f44625ff8d..08dee63f80 100755 --- a/fypp-gfortran.py +++ b/fypp-gfortran.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import sys import subprocess from pathlib import Path @@ -13,7 +14,16 @@ output_dir.mkdir(parents=True) # Get the filenames with .fypp extension and convert to string. -filenames = [str(f) for f in Path(".").glob("**/*.fypp")] +source_file = [arg for arg in args if arg.endswith(".fypp")] +output_file = [arg for arg in args if arg.endswith(".o")] + +if len(source_file) != len(output_file): + subprocess.run(["gfortran"] + args, check=True) + sys.exit(0) + +source_file = source_file[0] +output_file = output_file[0] +preprocessed = output_file.replace(".o", ".f90") # Filter out the macro definitions. macros = [arg for arg in args if arg.startswith("-D")] @@ -21,39 +31,10 @@ # Filter out the include paths with -I prefix. include_paths = [arg for arg in args if arg.startswith("-I")] -# Declare preprocessed array. -preprocessed = [] - -# Preprocess the .fypp files. -for filename in filenames: - - # Get the output filename only without extension and path. - output_filename = Path(filename).stem - - # Save the output_file to build directory. - output_file = str(Path(output_dir, f"{output_filename}.f90")) - - subprocess.run( - [ - "fypp", - filename, - *include_paths, - *macros, - output_file, - ], - ) - - # Append the output_file to preprocessed array. - # Along with the path to store object files. - # This will save the object files in preprocessed_files directory. - preprocessed.append(f"-c {output_file} -o {str(Path(output_dir, f'{output_filename}.o'))}") - -# Run gfortran for each preprocessed file. -for file in preprocessed : - file_args = file.split() - subprocess.run( - ["gfortran"] + file_args, - check=True, - ) - -subprocess.run(["gfortran"] + args) +subprocess.run( + ["fypp", "-n", source_file, preprocessed] + macros + include_paths, + check=True +) + +args = [arg for arg in args if arg != source_file and not arg in macros] + [preprocessed] +subprocess.run(["gfortran"] + args, check=True) diff --git a/src/fpm_sources.f90 b/src/fpm_sources.f90 index b821362c55..16586da9ef 100644 --- a/src/fpm_sources.f90 +++ b/src/fpm_sources.f90 @@ -15,8 +15,8 @@ module fpm_sources private public :: add_sources_from_dir, add_executable_sources -character(4), parameter :: fortran_suffixes(2) = [".f90", & - ".f "] +character(5), parameter :: fortran_suffixes(3) = [".f90 ", ".fypp", & + ".f "] character(4), parameter :: c_suffixes(4) = [".c ", ".h ", ".cpp", ".hpp"] contains