4
4
import os
5
5
import sys
6
6
from collections import OrderedDict
7
- from typing import Dict , List , Optional , Any
7
+ from typing import Dict , List , Any
8
8
import yaml
9
9
10
10
@@ -74,11 +74,12 @@ def get_module_test(module_dirname: str) -> Dict[str, Any]:
74
74
return load_yaml (os .path .join (PHP_MODULE_PATH , module_dirname , "test.yml" ))
75
75
76
76
77
- def get_modules (mod_name : Optional [str ] = None ) -> List [Dict [str , Any ]]:
77
+ def get_modules (selected_modules : List [str ], ignore_dependencies : bool ) -> List [Dict [str , Any ]]:
78
78
"""Returns a list of PHP module directory names.
79
79
80
80
Args:
81
- mod_name: If specified, only get this module (and its dependencies).
81
+ selected_modules: If not empty, only gather specified modules (and its dependencies).
82
+ ignore_dependencies: If true, all dependent extensions will be ignored.
82
83
"""
83
84
modules = []
84
85
with os .scandir (PHP_MODULE_PATH ) as it :
@@ -91,17 +92,18 @@ def get_modules(mod_name: Optional[str] = None) -> List[Dict[str, Any]]:
91
92
# Convert list of deps into dict(dir, name, deps)
92
93
items = []
93
94
for module in modules :
94
- if module ["deps" ]:
95
+ if module ["deps" ] and not ignore_dependencies :
95
96
deps = []
96
97
for dep in module ["deps" ]:
97
98
deps .append (get_el_by_name (modules , dep ))
98
99
module ["deps" ] = deps
99
100
items .append (module )
100
101
else :
102
+ module ["deps" ] = []
101
103
items .append (module )
102
104
# Check if we only want to read a single module
103
- if mod_name :
104
- return [get_el_by_name (items , mod_name )]
105
+ if selected_modules :
106
+ return [get_el_by_name (items , mod_name ) for mod_name in selected_modules ]
105
107
return sorted (items , key = lambda item : item ["dir" ])
106
108
107
109
@@ -196,38 +198,53 @@ def write_group_vars(modules: List[str]) -> None:
196
198
# --------------------------------------------------------------------------------------------------
197
199
def print_help () -> None :
198
200
"""Show help screen."""
199
- print ("Usage:" , os .path .basename (__file__ ), "[php-module] " )
201
+ print ("Usage:" , os .path .basename (__file__ ), "[options] [PHP-EXT]... " )
200
202
print (" " , os .path .basename (__file__ ), "-h, --help" )
201
203
print ()
202
204
print ("This script will generate the Ansible group_vars file: .ansible/group_vars/all/mods.yml" )
203
205
print ("based on all the modules found in php_modules/ directory." )
204
206
print ()
205
- print ("Optional arguments:" )
206
- print (" [php-module] When specifying a name of a php-module, the group_vars file will" )
207
+ print ("Positional arguments:" )
208
+ print (" [PHP-EXT] Specify None, one or more PHP extensions to generate group_vars for." )
209
+ print (" When no PHP extension is specified (argument is omitted), group_vars" )
210
+ print (" for all extensions will be genrated." )
211
+ print (" When one or more PHP extension are specified, only group_vars for" )
212
+ print (" these extensions will be created." )
207
213
print (" only be generated for this single module (and its dependencies)." )
208
214
print (" This is useful if you want to test new modules and not build all" )
209
215
print (" previous modules in the Dockerfile." )
210
216
print ()
211
217
print (" Note: You still need to generate the Dockerfiles via Ansible for" )
212
218
print (" the changes to take effect, before building the image." )
219
+ print ("Optional arguments:" )
220
+ print (" -i Ignore dependent modules." )
221
+ print (" By default each exentions is checked for build dependencies of other" )
222
+ print (" extensions. For example many extensions build against libxml ext." )
223
+ print (" By specifying -i, those dependencies are not beeing added to" )
224
+ print (" ansible group_vars. Use at your own risk." )
213
225
214
226
215
227
def main (argv : List [str ]) -> None :
216
228
"""Main entrypoint."""
217
- if not (len (argv ) == 0 or len (argv ) == 1 ):
218
- print_help ()
219
- sys .exit (1 )
220
- if len (argv ) == 1 :
221
- if argv [0 ] == "--help" or argv [0 ] == "-h" :
222
- print_help ()
223
- sys .exit (0 )
224
-
225
- single_module = None
226
- if len (argv ) == 1 :
227
- single_module = argv [0 ]
229
+ ignore_dependencies = False
230
+ selected_modules = []
231
+ if len (argv ):
232
+ for arg in argv :
233
+ if arg in ("-h" , "--help" ):
234
+ print_help ()
235
+ sys .exit (0 )
236
+ for arg in argv :
237
+ if arg .startswith ("-" ) and arg != "-i" :
238
+ print ("Invalid argument:" , arg )
239
+ print ("Use -h or --help for help" )
240
+ sys .exit (1 )
241
+ if arg == "-i" :
242
+ ignore_dependencies = True
243
+ else :
244
+ selected_modules .append (arg )
228
245
229
246
# Get modules in order of dependencies
230
- modules = get_modules (single_module )
247
+ modules = get_modules (selected_modules , ignore_dependencies )
231
248
module_tree = get_module_dependency_tree (modules )
232
249
names = resolve_module_dependency_tree (module_tree )
233
250
0 commit comments