SCons: Format buildsystem files with psf/black

Configured for a max line length of 120 characters.

psf/black is very opinionated and purposely doesn't leave much room for
configuration. The output is mostly OK so that should be fine for us,
but some things worth noting:

- Manually wrapped strings will be reflowed, so by using a line length
  of 120 for the sake of preserving readability for our long command
  calls, it also means that some manually wrapped strings are back on
  the same line and should be manually merged again.

- Code generators using string concatenation extensively look awful,
  since black puts each operand on a single line. We need to refactor
  these generators to use more pythonic string formatting, for which
  many options are available (`%`, `format` or f-strings).

- CI checks and a pre-commit hook will be added to ensure that future
  buildsystem changes are well-formatted.
This commit is contained in:
Rémi Verschelde 2020-03-30 08:28:32 +02:00
parent 0168709978
commit cd4e46ee65
198 changed files with 4216 additions and 3446 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
Import('env')
Import('env_modules')
Import("env")
Import("env_modules")
env_gdnative = env_modules.Clone()
env_gdnative.add_source_files(env.modules_sources, "gdnative.cpp")
@ -12,9 +12,9 @@ env_gdnative.add_source_files(env.modules_sources, "nativescript/*.cpp")
env_gdnative.add_source_files(env.modules_sources, "gdnative_library_singleton_editor.cpp")
env_gdnative.add_source_files(env.modules_sources, "gdnative_library_editor_plugin.cpp")
env_gdnative.Prepend(CPPPATH=['#modules/gdnative/include/'])
env_gdnative.Prepend(CPPPATH=["#modules/gdnative/include/"])
Export('env_gdnative')
Export("env_gdnative")
SConscript("net/SCsub")
SConscript("arvr/SCsub")
@ -25,8 +25,11 @@ SConscript("videodecoder/SCsub")
from platform_methods import run_in_subprocess
import gdnative_builders
_, gensource = env_gdnative.CommandNoCache(['include/gdnative_api_struct.gen.h', 'gdnative_api_struct.gen.cpp'],
'gdnative_api.json', run_in_subprocess(gdnative_builders.build_gdnative_api_struct))
_, gensource = env_gdnative.CommandNoCache(
["include/gdnative_api_struct.gen.h", "gdnative_api_struct.gen.cpp"],
"gdnative_api.json",
run_in_subprocess(gdnative_builders.build_gdnative_api_struct),
)
env_gdnative.add_source_files(env.modules_sources, [gensource])
env.use_ptrcall = True

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
Import('env')
Import('env_gdnative')
Import("env")
Import("env_gdnative")
env_gdnative.add_source_files(env.modules_sources, '*.cpp')
env_gdnative.add_source_files(env.modules_sources, "*.cpp")

View file

@ -1,5 +1,6 @@
def can_build(env, platform):
return True
return True
def configure(env):
pass
pass

View file

@ -1,9 +1,11 @@
def can_build(env, platform):
return True
def configure(env):
env.use_ptrcall = True
def get_doc_classes():
return [
"@NativeScript",
@ -20,5 +22,6 @@ def get_doc_classes():
"WebRTCDataChannelGDNative",
]
def get_doc_path():
return "doc_classes"

View file

@ -8,209 +8,249 @@ from platform_methods import subprocess_main
def _spaced(e):
return e if e[-1] == '*' else e + ' '
return e if e[-1] == "*" else e + " "
def _build_gdnative_api_struct_header(api):
out = [
'/* THIS FILE IS GENERATED DO NOT EDIT */',
'#ifndef GODOT_GDNATIVE_API_STRUCT_H',
'#define GODOT_GDNATIVE_API_STRUCT_H',
'',
'#include <gdnative/gdnative.h>',
'#include <android/godot_android.h>',
'#include <arvr/godot_arvr.h>',
'#include <nativescript/godot_nativescript.h>',
'#include <net/godot_net.h>',
'#include <pluginscript/godot_pluginscript.h>',
'#include <videodecoder/godot_videodecoder.h>',
'',
'#ifdef __cplusplus',
"/* THIS FILE IS GENERATED DO NOT EDIT */",
"#ifndef GODOT_GDNATIVE_API_STRUCT_H",
"#define GODOT_GDNATIVE_API_STRUCT_H",
"",
"#include <gdnative/gdnative.h>",
"#include <android/godot_android.h>",
"#include <arvr/godot_arvr.h>",
"#include <nativescript/godot_nativescript.h>",
"#include <net/godot_net.h>",
"#include <pluginscript/godot_pluginscript.h>",
"#include <videodecoder/godot_videodecoder.h>",
"",
"#ifdef __cplusplus",
'extern "C" {',
'#endif',
'',
'enum GDNATIVE_API_TYPES {',
'\tGDNATIVE_' + api['core']['type'] + ','
"#endif",
"",
"enum GDNATIVE_API_TYPES {",
"\tGDNATIVE_" + api["core"]["type"] + ",",
]
for ext in api['extensions']:
out += ['\tGDNATIVE_EXT_' + ext['type'] + ',']
for ext in api["extensions"]:
out += ["\tGDNATIVE_EXT_" + ext["type"] + ","]
out += ['};', '']
out += ["};", ""]
def generate_extension_struct(name, ext, include_version=True):
ret_val = []
if ext['next']:
ret_val += generate_extension_struct(name, ext['next'])
if ext["next"]:
ret_val += generate_extension_struct(name, ext["next"])
ret_val += [
'typedef struct godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct {',
'\tunsigned int type;',
'\tgodot_gdnative_api_version version;',
'\tconst godot_gdnative_api_struct *next;'
"typedef struct godot_gdnative_ext_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_api_struct {",
"\tunsigned int type;",
"\tgodot_gdnative_api_version version;",
"\tconst godot_gdnative_api_struct *next;",
]
for funcdef in ext['api']:
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
ret_val.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
for funcdef in ext["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
ret_val.append("\t%s(*%s)(%s);" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
ret_val += ['} godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct;', '']
ret_val += [
"} godot_gdnative_ext_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_api_struct;",
"",
]
return ret_val
def generate_core_extension_struct(core):
ret_val = []
if core['next']:
ret_val += generate_core_extension_struct(core['next'])
if core["next"]:
ret_val += generate_core_extension_struct(core["next"])
ret_val += [
'typedef struct godot_gdnative_core_' + ('{0}_{1}'.format(core['version']['major'], core['version']['minor'])) + '_api_struct {',
'\tunsigned int type;',
'\tgodot_gdnative_api_version version;',
'\tconst godot_gdnative_api_struct *next;',
"typedef struct godot_gdnative_core_"
+ ("{0}_{1}".format(core["version"]["major"], core["version"]["minor"]))
+ "_api_struct {",
"\tunsigned int type;",
"\tgodot_gdnative_api_version version;",
"\tconst godot_gdnative_api_struct *next;",
]
for funcdef in core['api']:
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
ret_val.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
for funcdef in core["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
ret_val.append("\t%s(*%s)(%s);" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
ret_val += ['} godot_gdnative_core_' + '{0}_{1}'.format(core['version']['major'], core['version']['minor']) + '_api_struct;', '']
ret_val += [
"} godot_gdnative_core_"
+ "{0}_{1}".format(core["version"]["major"], core["version"]["minor"])
+ "_api_struct;",
"",
]
return ret_val
for ext in api['extensions']:
name = ext['name']
for ext in api["extensions"]:
name = ext["name"]
out += generate_extension_struct(name, ext, False)
if api['core']['next']:
out += generate_core_extension_struct(api['core']['next'])
if api["core"]["next"]:
out += generate_core_extension_struct(api["core"]["next"])
out += [
'typedef struct godot_gdnative_core_api_struct {',
'\tunsigned int type;',
'\tgodot_gdnative_api_version version;',
'\tconst godot_gdnative_api_struct *next;',
'\tunsigned int num_extensions;',
'\tconst godot_gdnative_api_struct **extensions;',
"typedef struct godot_gdnative_core_api_struct {",
"\tunsigned int type;",
"\tgodot_gdnative_api_version version;",
"\tconst godot_gdnative_api_struct *next;",
"\tunsigned int num_extensions;",
"\tconst godot_gdnative_api_struct **extensions;",
]
for funcdef in api['core']['api']:
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
for funcdef in api["core"]["api"]:
args = ", ".join(["%s%s" % (_spaced(t), n) for t, n in funcdef["arguments"]])
out.append("\t%s(*%s)(%s);" % (_spaced(funcdef["return_type"]), funcdef["name"], args))
out += [
'} godot_gdnative_core_api_struct;',
'',
'#ifdef __cplusplus',
'}',
'#endif',
'',
'#endif // GODOT_GDNATIVE_API_STRUCT_H',
''
"} godot_gdnative_core_api_struct;",
"",
"#ifdef __cplusplus",
"}",
"#endif",
"",
"#endif // GODOT_GDNATIVE_API_STRUCT_H",
"",
]
return '\n'.join(out)
return "\n".join(out)
def _build_gdnative_api_struct_source(api):
out = [
'/* THIS FILE IS GENERATED DO NOT EDIT */',
'',
'#include <gdnative_api_struct.gen.h>',
''
]
out = ["/* THIS FILE IS GENERATED DO NOT EDIT */", "", "#include <gdnative_api_struct.gen.h>", ""]
def get_extension_struct_name(name, ext, include_version=True):
return 'godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct'
return (
"godot_gdnative_ext_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_api_struct"
)
def get_extension_struct_instance_name(name, ext, include_version=True):
return 'api_extension_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_struct'
return (
"api_extension_"
+ name
+ ("" if not include_version else ("_{0}_{1}".format(ext["version"]["major"], ext["version"]["minor"])))
+ "_struct"
)
def get_extension_struct_definition(name, ext, include_version=True):
ret_val = []
if ext['next']:
ret_val += get_extension_struct_definition(name, ext['next'])
if ext["next"]:
ret_val += get_extension_struct_definition(name, ext["next"])
ret_val += [
'extern const ' + get_extension_struct_name(name, ext, include_version) + ' ' + get_extension_struct_instance_name(name, ext, include_version) + ' = {',
'\tGDNATIVE_EXT_' + ext['type'] + ',',
'\t{' + str(ext['version']['major']) + ', ' + str(ext['version']['minor']) + '},',
'\t' + ('NULL' if not ext['next'] else ('(const godot_gdnative_api_struct *)&' + get_extension_struct_instance_name(name, ext['next']))) + ','
"extern const "
+ get_extension_struct_name(name, ext, include_version)
+ " "
+ get_extension_struct_instance_name(name, ext, include_version)
+ " = {",
"\tGDNATIVE_EXT_" + ext["type"] + ",",
"\t{" + str(ext["version"]["major"]) + ", " + str(ext["version"]["minor"]) + "},",
"\t"
+ (
"NULL"
if not ext["next"]
else ("(const godot_gdnative_api_struct *)&" + get_extension_struct_instance_name(name, ext["next"]))
)
+ ",",
]
for funcdef in ext['api']:
ret_val.append('\t%s,' % funcdef['name'])
for funcdef in ext["api"]:
ret_val.append("\t%s," % funcdef["name"])
ret_val += ['};\n']
ret_val += ["};\n"]
return ret_val
def get_core_struct_definition(core):
ret_val = []
if core['next']:
ret_val += get_core_struct_definition(core['next'])
if core["next"]:
ret_val += get_core_struct_definition(core["next"])
ret_val += [
'extern const godot_gdnative_core_' + ('{0}_{1}_api_struct api_{0}_{1}'.format(core['version']['major'], core['version']['minor'])) + ' = {',
'\tGDNATIVE_' + core['type'] + ',',
'\t{' + str(core['version']['major']) + ', ' + str(core['version']['minor']) + '},',
'\t' + ('NULL' if not core['next'] else ('(const godot_gdnative_api_struct *)& api_{0}_{1}'.format(core['next']['version']['major'], core['next']['version']['minor']))) + ','
"extern const godot_gdnative_core_"
+ ("{0}_{1}_api_struct api_{0}_{1}".format(core["version"]["major"], core["version"]["minor"]))
+ " = {",
"\tGDNATIVE_" + core["type"] + ",",
"\t{" + str(core["version"]["major"]) + ", " + str(core["version"]["minor"]) + "},",
"\t"
+ (
"NULL"
if not core["next"]
else (
"(const godot_gdnative_api_struct *)& api_{0}_{1}".format(
core["next"]["version"]["major"], core["next"]["version"]["minor"]
)
)
)
+ ",",
]
for funcdef in core['api']:
ret_val.append('\t%s,' % funcdef['name'])
for funcdef in core["api"]:
ret_val.append("\t%s," % funcdef["name"])
ret_val += ['};\n']
ret_val += ["};\n"]
return ret_val
for ext in api['extensions']:
name = ext['name']
for ext in api["extensions"]:
name = ext["name"]
out += get_extension_struct_definition(name, ext, False)
out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']
out += ["", "const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {"]
for ext in api['extensions']:
name = ext['name']
out += ['\t(godot_gdnative_api_struct *)&api_extension_' + name + '_struct,']
for ext in api["extensions"]:
name = ext["name"]
out += ["\t(godot_gdnative_api_struct *)&api_extension_" + name + "_struct,"]
out += ['};\n']
out += ["};\n"]
if api['core']['next']:
out += get_core_struct_definition(api['core']['next'])
if api["core"]["next"]:
out += get_core_struct_definition(api["core"]["next"])
out += [
'extern const godot_gdnative_core_api_struct api_struct = {',
'\tGDNATIVE_' + api['core']['type'] + ',',
'\t{' + str(api['core']['version']['major']) + ', ' + str(api['core']['version']['minor']) + '},',
'\t(const godot_gdnative_api_struct *)&api_1_1,',
'\t' + str(len(api['extensions'])) + ',',
'\tgdnative_extensions_pointers,',
"extern const godot_gdnative_core_api_struct api_struct = {",
"\tGDNATIVE_" + api["core"]["type"] + ",",
"\t{" + str(api["core"]["version"]["major"]) + ", " + str(api["core"]["version"]["minor"]) + "},",
"\t(const godot_gdnative_api_struct *)&api_1_1,",
"\t" + str(len(api["extensions"])) + ",",
"\tgdnative_extensions_pointers,",
]
for funcdef in api['core']['api']:
out.append('\t%s,' % funcdef['name'])
out.append('};\n')
for funcdef in api["core"]["api"]:
out.append("\t%s," % funcdef["name"])
out.append("};\n")
return '\n'.join(out)
return "\n".join(out)
def build_gdnative_api_struct(target, source, env):
with open(source[0], 'r') as fd:
with open(source[0], "r") as fd:
api = json.load(fd)
header, source = target
with open(header, 'w') as fd:
with open(header, "w") as fd:
fd.write(_build_gdnative_api_struct_header(api))
with open(source, 'w') as fd:
with open(source, "w") as fd:
fd.write(_build_gdnative_api_struct_source(api))
if __name__ == '__main__':
if __name__ == "__main__":
subprocess_main(globals())

View file

@ -1,9 +1,9 @@
#!/usr/bin/env python
Import('env')
Import('env_gdnative')
Import("env")
Import("env_gdnative")
env_gdnative.add_source_files(env.modules_sources, '*.cpp')
env_gdnative.add_source_files(env.modules_sources, "*.cpp")
if "platform" in env and env["platform"] in ["linuxbsd", "iphone"]:
env.Append(LINKFLAGS=["-rdynamic"])

View file

@ -1,13 +1,12 @@
#!/usr/bin/env python
Import('env')
Import('env_gdnative')
Import("env")
Import("env_gdnative")
env_net = env_gdnative.Clone()
has_webrtc = env_net["module_webrtc_enabled"]
if has_webrtc:
env_net.Append(CPPDEFINES=['WEBRTC_GDNATIVE_ENABLED'])
env_net.add_source_files(env.modules_sources, '*.cpp')
env_net.Append(CPPDEFINES=["WEBRTC_GDNATIVE_ENABLED"])
env_net.add_source_files(env.modules_sources, "*.cpp")

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
Import('env')
Import('env_gdnative')
Import("env")
Import("env_gdnative")
env_gdnative.add_source_files(env.modules_sources, '*.cpp')
env_gdnative.add_source_files(env.modules_sources, "*.cpp")

View file

@ -1,9 +1,9 @@
#!/usr/bin/env python
Import('env')
Import('env_modules')
Import("env")
Import("env_modules")
env_vsdecoder_gdnative = env_modules.Clone()
env_vsdecoder_gdnative.Prepend(CPPPATH=['#modules/gdnative/include/'])
env_vsdecoder_gdnative.add_source_files(env.modules_sources, '*.cpp')
env_vsdecoder_gdnative.Prepend(CPPPATH=["#modules/gdnative/include/"])
env_vsdecoder_gdnative.add_source_files(env.modules_sources, "*.cpp")