Skip to content

Commit a8b1672

Browse files
author
Vano
committed
working configure script, verbose output
1 parent 2a6aa4d commit a8b1672

File tree

3 files changed

+64
-46
lines changed

3 files changed

+64
-46
lines changed

configure_script.py

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,53 @@
1-
import sys
2-
argv = sys.argv[1:]
3-
4-
print(argv)
5-
exit(1)
6-
try:
7-
library_name = argv[0].replace('-', '_')
8-
cpp_path = argv[1]
9-
h_path = argv[2]
10-
gdext_path = argv[3]
11-
except:
12-
ABOUT = \
13-
"""
14-
ERROR: Not enough arguments.
15-
Needed arguments (<argument> - example):
16-
17-
<library_name> (`my_library_name`)
18-
<cpp_file_path> (`src/register_types.cpp`)
19-
<header_file_path> (`include/register_types.h`)
20-
<gdextension_file_path> (`project/my_library.gdextension`)
21-
"""
22-
print(ABOUT, file=sys.stderr)
23-
exit(1)
24-
25-
print(f"Configuring '{gdext_path}' ...")
26-
open(gdext_path, 'w').write(
27-
SCRIPTS_GDEXTENSION_IN.replace('@LIBRARY_NAME@', library_name))
28-
29-
print(f"Configuring '{cpp_path}' ...")
30-
open(cpp_path, 'w').write(
31-
REGISTER_TYPES_CPP_IN.replace('@LIBRARY_NAME@', library_name))
32-
33-
print(f"Configuring '{h_path}' ...")
34-
open(h_path, 'w').write(
35-
REGISTER_TYPES_H_IN.replace('@LIBRARY_NAME@', library_name))
36-
37-
print("Files configured.")
38-
exit(0)
1+
@PY_EMBED_TEMPLATE_FILES@
2+
3+
import os, sys
4+
argv = sys.argv[1:]
5+
6+
try:
7+
library_name = argv[0].replace('-', '_')
8+
cpp_path = argv[1]
9+
h_path = argv[2]
10+
gdext_path = argv[3]
11+
except:
12+
ABOUT = \
13+
'''
14+
ERROR: Not enough arguments.
15+
Needed arguments (<argument> - example):
16+
17+
<library_name> (`my_library_name`)
18+
<cpp_file_path> (`src/register_types.cpp`)
19+
<header_file_path> (`include/register_types.h`)
20+
<gdextension_file_path> (`project/my_library.gdextension`)
21+
'''
22+
print(ABOUT, file=sys.stderr)
23+
exit(1)
24+
25+
prompt = f'''These files will be affected:
26+
{'(New) ' if not os.path.exists(gdext_path) else '(Override)'} {gdext_path}
27+
{'(New) ' if not os.path.exists(cpp_path) else '(Override)'} {cpp_path}
28+
{'(New) ' if not os.path.exists(h_path) else '(Override)'} {h_path}
29+
'''
30+
print(prompt)
31+
while True:
32+
inp = input('Are you sure? (Y/N) ')
33+
if inp == '':
34+
continue
35+
if inp not in 'yY':
36+
print('No changes, exiting...')
37+
exit(1)
38+
break
39+
40+
print(f"Configuring '{gdext_path}' ...")
41+
open(gdext_path, 'w').write(
42+
SCRIPTS_GDEXTENSION_IN.replace('@LIBRARY_NAME@', library_name))
43+
44+
print(f"Configuring '{cpp_path}' ...")
45+
open(cpp_path, 'w').write(
46+
REGISTER_TYPES_CPP_IN.replace('@LIBRARY_NAME@', library_name))
47+
48+
print(f"Configuring '{h_path}' ...")
49+
open(h_path, 'w').write(
50+
REGISTER_TYPES_H_IN.replace('@LIBRARY_NAME@', library_name))
51+
52+
print("Files configured.")
53+
exit(0)

generate.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ def embed_cmake(var_name, body):
4343
CPPSCRIPT_DEFS_H = open('src/cppscript_defs.h').read()
4444
CPPSCRIPT_BINDINGS_H = open('src/cppscript_bindings.h').read()
4545

46+
PY_CONFIGURE_SCRIPT = replace(PY_CONFIGURE_SCRIPT, [
47+
('@PY_EMBED_TEMPLATE_FILES@',
48+
embed_py("REGISTER_TYPES_CPP_IN", REGISTER_TYPES_CPP_IN) + \
49+
' ' + embed_py("REGISTER_TYPES_H_IN", REGISTER_TYPES_H_IN) + \
50+
' ' + embed_py("SCRIPTS_GDEXTENSION_IN", SCRIPTS_GDEXTENSION_IN))
51+
52+
]
53+
)
54+
4655
open(os.path.join(path, 'godot_cppscript.py'), 'w').write(
4756
replace(TEMPLATE_SCONS, [
48-
('@PY_EMBED_TEMPLATE_FILES@',
49-
' ' + embed_py("REGISTER_TYPES_CPP_IN", REGISTER_TYPES_CPP_IN) + \
50-
' ' + embed_py("REGISTER_TYPES_H_IN", REGISTER_TYPES_H_IN) + \
51-
' ' + embed_py("SCRIPTS_GDEXTENSION_IN", SCRIPTS_GDEXTENSION_IN)),
5257
('@PY_CONFIGURE_SCRIPT@',
53-
' ' + PY_CONFIGURE_SCRIPT.replace('\n', '\n ')),
58+
PY_CONFIGURE_SCRIPT),
5459
('@PY_EMBED_SRC_FILES@',
5560
embed_py("CPPSCRIPT_DEFS_H", CPPSCRIPT_DEFS_H) + \
5661
embed_py("CPPSCRIPT_BINDINGS_H", CPPSCRIPT_BINDINGS_H)),
@@ -69,7 +74,7 @@ def embed_cmake(var_name, body):
6974
open(os.path.join(path, 'godot_cppscript.cmake'), 'w').write(
7075
replace(CMAKE_MODULE, [
7176
('@CMAKE_EMBED_CONFIGURE_SCRIPT@',
72-
embed_cmake('PY_CONFIGURE_SCRIPT', PY_CONFIGURE_SCRIPT)),
77+
embed_cmake('PY_CONFIGURE_SCRIPT', PY_CONFIGURE_SCRIPT.replace('\n ', '\n')[4:])),
7378
('@CMAKE_EMBED_SRC_FILES@',
7479
embed_cmake("CPPSCRIPT_DEFS_H", CPPSCRIPT_DEFS_H) + \
7580
embed_cmake("CPPSCRIPT_BINDINGS_H", CPPSCRIPT_BINDINGS_H) + \

template_scons.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
if __name__ == '__main__':
66
# Ran as configure script
77

8-
@PY_EMBED_TEMPLATE_FILES@
9-
108
@PY_CONFIGURE_SCRIPT@
119

1210
@PY_EMBED_SRC_FILES@

0 commit comments

Comments
 (0)