44import os
55import sys
66from collections import OrderedDict
7- from typing import Dict , List , Optional , Any
7+ from typing import Dict , List , Any
88import yaml
99
1010
@@ -74,11 +74,12 @@ def get_module_test(module_dirname: str) -> Dict[str, Any]:
7474 return load_yaml (os .path .join (PHP_MODULE_PATH , module_dirname , "test.yml" ))
7575
7676
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 ]]:
7878 """Returns a list of PHP module directory names.
7979
8080 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.
8283 """
8384 modules = []
8485 with os .scandir (PHP_MODULE_PATH ) as it :
@@ -91,17 +92,18 @@ def get_modules(mod_name: Optional[str] = None) -> List[Dict[str, Any]]:
9192 # Convert list of deps into dict(dir, name, deps)
9293 items = []
9394 for module in modules :
94- if module ["deps" ]:
95+ if module ["deps" ] and not ignore_dependencies :
9596 deps = []
9697 for dep in module ["deps" ]:
9798 deps .append (get_el_by_name (modules , dep ))
9899 module ["deps" ] = deps
99100 items .append (module )
100101 else :
102+ module ["deps" ] = []
101103 items .append (module )
102104 # 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 ]
105107 return sorted (items , key = lambda item : item ["dir" ])
106108
107109
@@ -196,38 +198,53 @@ def write_group_vars(modules: List[str]) -> None:
196198# --------------------------------------------------------------------------------------------------
197199def print_help () -> None :
198200 """Show help screen."""
199- print ("Usage:" , os .path .basename (__file__ ), "[php-module] " )
201+ print ("Usage:" , os .path .basename (__file__ ), "[options] [PHP-EXT]... " )
200202 print (" " , os .path .basename (__file__ ), "-h, --help" )
201203 print ()
202204 print ("This script will generate the Ansible group_vars file: .ansible/group_vars/all/mods.yml" )
203205 print ("based on all the modules found in php_modules/ directory." )
204206 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." )
207213 print (" only be generated for this single module (and its dependencies)." )
208214 print (" This is useful if you want to test new modules and not build all" )
209215 print (" previous modules in the Dockerfile." )
210216 print ()
211217 print (" Note: You still need to generate the Dockerfiles via Ansible for" )
212218 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." )
213225
214226
215227def main (argv : List [str ]) -> None :
216228 """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 )
228245
229246 # Get modules in order of dependencies
230- modules = get_modules (single_module )
247+ modules = get_modules (selected_modules , ignore_dependencies )
231248 module_tree = get_module_dependency_tree (modules )
232249 names = resolve_module_dependency_tree (module_tree )
233250
0 commit comments