@@ -24,6 +24,7 @@ def __init__(
24
24
deps : list [str ],
25
25
libraries : list [str ],
26
26
library_dirs : list [Path ],
27
+ include_dirs : list [Path ],
27
28
object_files : list [Path ],
28
29
linker_args : list [str ],
29
30
c_args : list [str ],
@@ -38,12 +39,17 @@ def __init__(
38
39
self .deps = deps
39
40
self .libraries = libraries
40
41
self .library_dirs = library_dirs
42
+ if include_dirs is not None :
43
+ self .include_dirs = include_dirs
44
+ else :
45
+ self .include_dirs = []
41
46
self .substitutions = {}
42
47
self .objects = object_files
43
48
self .pipeline = [
44
49
self .initialize_template ,
45
50
self .sources_substitution ,
46
51
self .deps_substitution ,
52
+ self .include_substitution ,
47
53
self .libraries_substitution ,
48
54
]
49
55
self .build_type = build_type
@@ -67,13 +73,13 @@ def initialize_template(self) -> None:
67
73
def sources_substitution (self ) -> None :
68
74
indent = " " * 21
69
75
self .substitutions ["source_list" ] = f",\n { indent } " .join (
70
- [f"'{ source } '" for source in self .sources ]
76
+ [f"{ indent } '{ source } '" for source in self .sources ]
71
77
)
72
78
73
79
def deps_substitution (self ) -> None :
74
80
indent = " " * 21
75
81
self .substitutions ["dep_list" ] = f",\n { indent } " .join (
76
- [f"dependency('{ dep } ')" for dep in self .deps ]
82
+ [f"{ indent } dependency('{ dep } ')" for dep in self .deps ]
77
83
)
78
84
79
85
def libraries_substitution (self ) -> None :
@@ -93,10 +99,16 @@ def libraries_substitution(self) -> None:
93
99
94
100
indent = " " * 21
95
101
self .substitutions ["lib_list" ] = f"\n { indent } " .join (
96
- [f"{ lib } ," for lib in self .libraries ]
102
+ [f"{ indent } { lib } ," for lib in self .libraries ]
97
103
)
98
104
self .substitutions ["lib_dir_list" ] = f"\n { indent } " .join (
99
- [f"lib_dir_{ i } ," for i in range (len (self .library_dirs ))]
105
+ [f"{ indent } lib_dir_{ i } ," for i in range (len (self .library_dirs ))]
106
+ )
107
+
108
+ def include_substitution (self ) -> None :
109
+ indent = " " * 21
110
+ self .substitutions ["inc_list" ] = f",\n { indent } " .join (
111
+ [f"{ indent } '{ inc } '" for inc in self .include_dirs ]
100
112
)
101
113
102
114
def generate_meson_build (self ):
@@ -130,13 +142,6 @@ def _move_exec_to_root(self, build_dir: Path):
130
142
shutil .copy2 (path_object , dest_path )
131
143
os .remove (path_object )
132
144
133
- def _get_build_command (self ):
134
- return [
135
- "meson" ,
136
- "setup" ,
137
- self .meson_build_dir ,
138
- ]
139
-
140
145
def write_meson_build (self , build_dir : Path ) -> None :
141
146
"""Writes the meson build file at specified location"""
142
147
meson_template = MesonTemplate (
@@ -145,6 +150,7 @@ def write_meson_build(self, build_dir: Path) -> None:
145
150
self .dependencies ,
146
151
self .libraries ,
147
152
self .library_dirs ,
153
+ self .include_dirs ,
148
154
self .extra_objects ,
149
155
self .flib_flags ,
150
156
self .fc_flags ,
@@ -157,19 +163,14 @@ def write_meson_build(self, build_dir: Path) -> None:
157
163
meson_build_file .write_text (src )
158
164
return meson_build_file
159
165
166
+ def _run_subprocess_command (self , command , cwd ):
167
+ subprocess .run (command , cwd = cwd , check = True )
168
+
160
169
def run_meson (self , build_dir : Path ):
161
- completed_process = subprocess .run (self ._get_build_command (), cwd = build_dir )
162
- if completed_process .returncode != 0 :
163
- raise subprocess .CalledProcessError (
164
- completed_process .returncode , completed_process .args
165
- )
166
- completed_process = subprocess .run (
167
- ["meson" , "compile" , "-C" , self .meson_build_dir ], cwd = build_dir
168
- )
169
- if completed_process .returncode != 0 :
170
- raise subprocess .CalledProcessError (
171
- completed_process .returncode , completed_process .args
172
- )
170
+ setup_command = ["meson" , "setup" , self .meson_build_dir ]
171
+ self ._run_subprocess_command (setup_command , build_dir )
172
+ compile_command = ["meson" , "compile" , "-C" , self .meson_build_dir ]
173
+ self ._run_subprocess_command (compile_command , build_dir )
173
174
174
175
def compile (self ) -> None :
175
176
self .sources = _prepare_sources (self .modulename , self .sources , self .build_dir )
@@ -183,7 +184,8 @@ def _prepare_sources(mname, sources, bdir):
183
184
Path (bdir ).mkdir (parents = True , exist_ok = True )
184
185
# Copy sources
185
186
for source in sources :
186
- shutil .copy (source , bdir )
187
+ if Path (source ).exists () and Path (source ).is_file ():
188
+ shutil .copy (source , bdir )
187
189
generated_sources = [
188
190
Path (f"{ mname } module.c" ),
189
191
Path (f"{ mname } -f2pywrappers2.f90" ),
0 commit comments