11#!/usr/bin/env python
2+ import os
3+ 4+ 5+ def normalize_path (val , env ):
6+ return val if os .path .isabs (val ) else os .path .join (env .Dir ("#" ).abspath , val )
7+ 8+ 9+ def validate_parent_dir (key , val , env ):
10+ if not os .path .isdir (normalize_path (os .path .dirname (val ), env )):
11+ raise UserError ("'%s' is not a directory: %s" % (key , os .path .dirname (val )))
12+ 213
314libname = "EXTENSION-NAME"
415
5- env = SConscript ("godot-cpp/SConstruct" )
16+ localEnv = Environment (tools = ["default" ], PLATFORM = "" )
17+ 18+ customs = ["custom.py" ]
19+ customs = [os .path .abspath (path ) for path in customs ]
20+ 21+ opts = Variables (customs , ARGUMENTS )
22+ opts .Add (
23+ BoolVariable (
24+ key = "compiledb" ,
25+ help = "Generate compilation DB (`compile_commands.json`) for external tools" ,
26+ default = localEnv .get ("compiledb" , False ),
27+ )
28+ )
29+ opts .Add (
30+ PathVariable (
31+ key = "compiledb_file" ,
32+ help = "Path to a custom `compile_commands.json` file" ,
33+ default = localEnv .get ("compiledb_file" , "compile_commands.json" ),
34+ validator = validate_parent_dir ,
35+ )
36+ )
37+ opts .Update (localEnv )
38+ 39+ Help (opts .GenerateHelpText (localEnv ))
40+ 41+ env = localEnv .Clone ()
42+ env ["compiledb" ] = False
43+ 44+ env .Tool ("compilation_db" )
45+ compilation_db = env .CompilationDatabase (
46+ normalize_path (localEnv ["compiledb_file" ], localEnv )
47+ )
48+ env .Alias ("compiledb" , compilation_db )
49+ 50+ env = SConscript ("godot-cpp/SConstruct" , {"env" : env , "customs" : customs })
651
752env .Append (CPPPATH = ["src/" ])
853sources = Glob ("src/*.cpp" )
1964 source = sources ,
2065 )
2166
22- Default (library )
67+ default_args = [library ]
68+ if localEnv .get ("compiledb" , False ):
69+ default_args += [compilation_db ]
70+ Default (* default_args )
0 commit comments