@@ -33,7 +33,26 @@ def validate_parent_dir(key, val, env):
3333 raise UserError ("'%s' is not a directory: %s" % (key , os .path .dirname (val )))
3434
3535
36- platforms = ("linux" , "macos" , "windows" , "android" , "ios" , "web" )
36+ def get_platform_tools_paths (env ):
37+ path = env .get ("custom_tools" , None )
38+ if path is None :
39+ return ["tools" ]
40+ return [normalize_path (path , env ), "tools" ]
41+
42+
43+ def get_custom_platforms (env ):
44+ path = env .get ("custom_tools" , None )
45+ if path is None :
46+ return []
47+ platforms = []
48+ for x in os .listdir (normalize_path (path , env )):
49+ if not x .endswith (".py" ):
50+ continue
51+ platforms .append (x .removesuffix (".py" ))
52+ return platforms
53+
54+
55+ platforms = ["linux" , "macos" , "windows" , "android" , "ios" , "web" ]
3756
3857# CPU architecture options.
3958architecture_array = [
@@ -82,12 +101,25 @@ def options(opts, env):
82101 else :
83102 raise ValueError ("Could not detect platform automatically, please specify with platform=<platform>" )
84103
104+ opts .Add (
105+ PathVariable (
106+ key = "custom_tools" ,
107+ help = "Path to directory containing custom tools" ,
108+ default = env .get ("custom_tools" , None ),
109+ validator = validate_dir ,
110+ )
111+ )
112+
113+ opts .Update (env )
114+
115+ custom_platforms = get_custom_platforms (env )
116+
85117 opts .Add (
86118 EnumVariable (
87119 key = "platform" ,
88120 help = "Target platform" ,
89121 default = env .get ("platform" , default_platform ),
90- allowed_values = platforms ,
122+ allowed_values = platforms + custom_platforms ,
91123 ignorecase = 2 ,
92124 )
93125 )
@@ -198,9 +230,9 @@ def options(opts, env):
198230 )
199231 )
200232
201- # Add platform options
202- for pl in platforms :
203- tool = Tool (pl , toolpath = [ "tools" ] )
233+ # Add platform options (custom tools can override platforms)
234+ for pl in sorted ( set ( platforms + custom_platforms )) :
235+ tool = Tool (pl , toolpath = get_platform_tools_paths ( env ) )
204236 if hasattr (tool , "options" ):
205237 tool .options (opts )
206238
@@ -259,7 +291,7 @@ def generate(env):
259291 if env ["use_hot_reload" ]:
260292 env .Append (CPPDEFINES = ["HOT_RELOAD_ENABLED" ])
261293
262- tool = Tool (env ["platform" ], toolpath = [ "tools" ] )
294+ tool = Tool (env ["platform" ], toolpath = get_platform_tools_paths ( env ) )
263295
264296 if tool is None or not tool .exists (env ):
265297 raise ValueError ("Required toolchain not found for platform " + env ["platform" ])
0 commit comments