mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 07:53:26 +00:00
Add custom_modules
build option to compile external user modules
This patch adds ability to include external, user-defined C++ modules
to be compiled as part of Godot via `custom_modules` build option
which can be passed to `scons`.
```
scons platform=x11 tools=yes custom_modules="../project/modules"
```
Features:
- detects all available modules under `custom_modules` directory the
same way as it does for built-in modules (not recursive);
- works with both relative and absolute paths on the filesystem;
- multiple search paths can be specified as a comma-separated list.
Module custom documentation and editor icons collection and generation
process is adapted to work with absolute paths needed by such modules.
Also fixed doctool bug mixing absolute and relative paths respectively.
Implementation details:
- `env.module_list` is a dictionary now, which holds both module name as
key and either a relative or absolute path to a module as a value.
- `methods.detect_modules` is run twice: once for built-in modules, and
second for external modules, all combined later.
- `methods.detect_modules` was not doing what it says on the tin. It is
split into `detect_modules` which collects a list of available modules
and `write_modules` which generates `register_types` sources for each.
- whether a module is built-in or external is distinguished by relative
or absolute paths respectively. `custom_modules` scons converter
ensures that the path is absolute even if relative path is supplied,
including expanding user paths and symbolic links.
- treats the parent directory as if it was Godot's base directory, so
that there's no need to change include paths in cases where custom
modules are included as dependencies in other modules.
(cherry picked from commit a96f0e98d7
)
This commit is contained in:
parent
11d6c0f20d
commit
133997654c
6 changed files with 125 additions and 66 deletions
59
methods.py
59
methods.py
|
@ -130,31 +130,41 @@ def parse_cg_file(fname, uniforms, sizes, conditionals):
|
|||
fs.close()
|
||||
|
||||
|
||||
def detect_modules():
|
||||
def detect_modules(at_path):
|
||||
module_list = {} # name : path
|
||||
|
||||
module_list = []
|
||||
modules_glob = os.path.join(at_path, "*")
|
||||
files = glob.glob(modules_glob)
|
||||
files.sort() # so register_module_types does not change that often, and also plugins are registered in alphabetic order
|
||||
|
||||
for x in files:
|
||||
if not is_module(x):
|
||||
continue
|
||||
name = os.path.basename(x)
|
||||
path = x.replace("\\", "/") # win32
|
||||
module_list[name] = path
|
||||
|
||||
return module_list
|
||||
|
||||
|
||||
def is_module(path):
|
||||
return os.path.isdir(path) and os.path.exists(path + "/config.py")
|
||||
|
||||
|
||||
def write_modules(module_list):
|
||||
includes_cpp = ""
|
||||
register_cpp = ""
|
||||
unregister_cpp = ""
|
||||
|
||||
files = glob.glob("modules/*")
|
||||
files.sort() # so register_module_types does not change that often, and also plugins are registered in alphabetic order
|
||||
for x in files:
|
||||
if not os.path.isdir(x):
|
||||
continue
|
||||
if not os.path.exists(x + "/config.py"):
|
||||
continue
|
||||
x = x.replace("modules/", "") # rest of world
|
||||
x = x.replace("modules\\", "") # win32
|
||||
module_list.append(x)
|
||||
for name, path in module_list.items():
|
||||
try:
|
||||
with open("modules/" + x + "/register_types.h"):
|
||||
includes_cpp += '#include "modules/' + x + '/register_types.h"\n'
|
||||
register_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
|
||||
register_cpp += '\tregister_' + x + '_types();\n'
|
||||
with open(os.path.join(path, "register_types.h")):
|
||||
includes_cpp += '#include "' + path + '/register_types.h"\n'
|
||||
register_cpp += '#ifdef MODULE_' + name.upper() + '_ENABLED\n'
|
||||
register_cpp += '\tregister_' + name + '_types();\n'
|
||||
register_cpp += '#endif\n'
|
||||
unregister_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
|
||||
unregister_cpp += '\tunregister_' + x + '_types();\n'
|
||||
unregister_cpp += '#ifdef MODULE_' + name.upper() + '_ENABLED\n'
|
||||
unregister_cpp += '\tunregister_' + name + '_types();\n'
|
||||
unregister_cpp += '#endif\n'
|
||||
except IOError:
|
||||
pass
|
||||
|
@ -178,7 +188,18 @@ void unregister_module_types() {
|
|||
with open("modules/register_module_types.gen.cpp", "w") as f:
|
||||
f.write(modules_cpp)
|
||||
|
||||
return module_list
|
||||
|
||||
def convert_custom_modules_path(path):
|
||||
if not path:
|
||||
return path
|
||||
err_msg = "Build option 'custom_modules' must %s"
|
||||
if not os.path.isdir(path):
|
||||
raise ValueError(err_msg % "point to an existing directory.")
|
||||
if os.path.realpath(path) == os.path.realpath("modules"):
|
||||
raise ValueError(err_msg % "be a directory other than built-in `modules` directory.")
|
||||
if is_module(path):
|
||||
raise ValueError(err_msg % "point to a directory with modules, not a single module.")
|
||||
return os.path.realpath(os.path.expanduser(path))
|
||||
|
||||
|
||||
def disable_module(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue