Skip to content

Commit 9c363d8

Browse files
committed
fypp preprocessing at root using temp subfolders
1 parent 5979ae9 commit 9c363d8

File tree

3 files changed

+30
-49
lines changed

3 files changed

+30
-49
lines changed

ci/fypp_deployment.py renamed to config/fypp_deployment.py

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
11
import os
2-
import shutil
32
import fypp
43
import argparse
54
from joblib import Parallel, delayed
65

7-
def copy_folder_with_filter(source_folder, destination_folder, filter_list=None, filter_suffix=None):
8-
# Create destination folder if it doesn't exist
9-
if not os.path.exists(destination_folder):
10-
os.makedirs(destination_folder)
11-
12-
# Iterate over the files and folders in the source folder
13-
for item in os.listdir(source_folder):
14-
source_item = os.path.join(source_folder, item)
15-
destination_item = os.path.join(destination_folder, item)
16-
17-
# If it's a folder, recursively copy it
18-
if os.path.isdir(source_item):
19-
copy_folder_with_filter(source_item, destination_item, filter_list, filter_suffix)
20-
else:
21-
# If filter_list is provided, check if the filename is in the list to avoid it
22-
should_copy = False if filter_list and item in filter_list else True
23-
should_copy = False if filter_suffix and item.endswith(filter_suffix) else should_copy
24-
if should_copy:
25-
shutil.copy2(source_item, destination_item)
26-
276
def pre_process_toml(args):
287
"""
298
Pre-process the fpm.toml
@@ -93,7 +72,7 @@ def pre_process_fypp(args):
9372
kwd.append("-DPROJECT_VERSION_PATCH="+str(args.vpatch))
9473
if args.with_qp:
9574
kwd.append("-DWITH_QP=True")
96-
if args.with_xqp:
75+
if args.with_xdp:
9776
kwd.append("-DWITH_XDP=True")
9877

9978
optparser = fypp.get_option_parser()
@@ -103,25 +82,13 @@ def pre_process_fypp(args):
10382
tool = fypp.Fypp(options)
10483

10584
# Check destination folder for preprocessing. if not 'stdlib-fpm', it is assumed to be the root folder.
106-
in_place = False if args.destdir == 'stdlib-fpm' else True
107-
src = 'src' if in_place else 'stdlib-fpm'+os.sep+'src'
108-
test = 'test' if in_place else 'stdlib-fpm'+os.sep+'test'
109-
example = 'example' if in_place else 'stdlib-fpm'+os.sep+'example'
110-
if not in_place:
111-
copy_folder_with_filter('src', src,
112-
filter_list=['CMakeLists.txt',"f18estop.f90"])
113-
copy_folder_with_filter('test', test,
114-
filter_list=['CMakeLists.txt',"test_always_fail.f90",
115-
"test_always_skip.f90","test_hash_functions.f90"],
116-
filter_suffix='manual')
117-
copy_folder_with_filter('example',example,
118-
filter_list=['CMakeLists.txt'])
119-
shutil.copy2('ci'+os.sep+'fpm.toml', 'stdlib-fpm'+os.sep+'fpm.toml')
120-
shutil.copy2('VERSION', 'stdlib-fpm'+os.sep+'VERSION')
121-
shutil.copy2('LICENSE', 'stdlib-fpm'+os.sep+'LICENSE')
85+
if not os.path.exists('src'+os.sep+'temp'):
86+
os.makedirs('src'+os.sep+'temp')
87+
if not os.path.exists('test'+os.sep+'temp'):
88+
os.makedirs('test'+os.sep+'temp')
12289

12390
# Define the folders to search for *.fypp files
124-
folders = [src,test]
91+
folders = ['src','test']
12592
# Process all folders
12693
fypp_files = [os.path.join(root, file) for folder in folders
12794
for root, _, files in os.walk(folder)
@@ -130,13 +97,12 @@ def pre_process_fypp(args):
13097
def process_f(file):
13198
source_file = file
13299
root = os.path.dirname(file)
100+
if not os.path.exists(root+os.sep+'temp'):
101+
os.makedirs(root+os.sep+'temp')
133102
basename = os.path.splitext(os.path.basename(source_file))[0]
134103
sfx = 'f90' if basename not in C_PREPROCESSED else 'F90'
135-
target_file = root + os.sep + basename + '.' + sfx
104+
target_file = root+os.sep+'temp' + os.sep + basename + '.' + sfx
136105
tool.process_file(source_file, target_file)
137-
# if folder different from root
138-
if not in_place:
139-
os.remove(source_file)
140106

141107
Parallel(n_jobs=args.njob)(delayed(process_f)(f) for f in fypp_files)
142108

@@ -179,7 +145,7 @@ def fpm_build(args,unknown):
179145
parser.add_argument("--njob", type=int, default=4, help="Number of parallel jobs for preprocessing")
180146
parser.add_argument("--maxrank",type=int, default=7, help="Set the maximum allowed rank for arrays")
181147
parser.add_argument("--with_qp",type=bool, default=False, help="Include WITH_QP in the command")
182-
parser.add_argument("--with_xqp",type=bool, default=False, help="Include WITH_XDP in the command")
148+
parser.add_argument("--with_xdp",type=bool, default=False, help="Include WITH_XDP in the command")
183149

184150
parser.add_argument('--destdir', action='store', type=str, default='stdlib-fpm', help='destination directory for the fypp preprocessing.')
185151
# external libraries arguments
@@ -189,15 +155,15 @@ def fpm_build(args,unknown):
189155
args, unknown = parser.parse_known_args()
190156
#==========================================
191157
# read current manifest
158+
with open('VERSION', 'r') as file:
159+
version = file.read().split(".")
160+
vmajor, vminor, vpatch = [int(value) for value in version]
192161
import tomlkit
193-
with open('ci'+os.sep+'fpm.toml', 'r') as file:
162+
with open('fpm.toml', 'r') as file:
194163
manifest = tomlkit.parse(file.read())
195-
version = manifest['version'].split(".")
196-
if version != ['VERSION']:
197-
vmajor, vminor, vpatch = [int(value) for value in version]
198164
#==========================================
199165
# pre process the fpm manifest
200-
#pre_process_toml(args)
166+
# pre_process_toml(args)
201167
#==========================================
202168
# pre process the meta programming fypp files
203169
pre_process_fypp(args)
File renamed without changes.

fpm.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name = "stdlib"
2+
version = "VERSION"
3+
license = "MIT"
4+
author = "stdlib contributors"
5+
maintainer = "@fortran-lang/stdlib"
6+
copyright = "2019-2021 stdlib contributors"
7+
8+
[dev-dependencies]
9+
test-drive.git = "https://github.com/fortran-lang/test-drive"
10+
test-drive.tag = "v0.4.0"
11+
12+
[preprocess]
13+
[preprocess.cpp]
14+
suffixes = [".F90", ".f90"]
15+
macros = ["MAXRANK=7"]

0 commit comments

Comments
 (0)