-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSConstruct
153 lines (124 loc) · 4.98 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
import os
import shutil
import build_version
env = SConscript("godot-cpp/SConstruct")
lib_name = "libgddragonbones"
# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp") + Glob("register_types.cpp")
output_bin_folder = "./bin"
plugin_folder = "./demo/addons/gddragonbones"
plugin_bin_folder = f"{plugin_folder}/bin"
extension_file = "demo/addons/gddragonbones/gddragonbones.gdextension"
def add_sources_recursively(dir: str, glob_sources, exclude_folder: list = []):
for f in os.listdir(dir):
if f in exclude_folder:
continue
sub_dir = os.path.join(dir, f)
if os.path.isdir(sub_dir):
glob_sources += Glob(os.path.join(sub_dir, "*.cpp"))
add_sources_recursively(sub_dir, glob_sources, exclude_folder)
if env.debug_features:
env.Append(CPPDEFINES=["TOOLS_ENABLED"])
sources += Glob("src/editor/*.cpp")
add_sources_recursively("src/", sources, ["editor"])
if env["platform"] == "macos":
library = env.SharedLibrary(
f'{output_bin_folder}/{lib_name}.{env["platform"]}.{env["target"]}.framework/{lib_name}.{env["platform"]}.{env["target"]}',
source=sources,
)
elif env["platform"] == "ios":
if env["ios_simulator"]:
library = env.StaticLibrary(
f'{output_bin_folder}/{lib_name}.{env["platform"]}.{env["target"]}.simulator.a',
source=sources,
)
else:
library = env.StaticLibrary(
f'{output_bin_folder}/{lib_name}.{env["platform"]}.{env["target"]}.a',
source=sources,
)
else:
library = env.SharedLibrary(
f'{output_bin_folder}/{lib_name}{env["suffix"]}{env["SHLIBSUFFIX"]}',
source=sources,
)
platform = env["platform"]
compile_target = env["target"]
suffix = env["suffix"]
ios_simulator = env["ios_simulator"]
share_lib_suffix = env["SHLIBSUFFIX"]
def copy_file(from_path, to_path):
if not os.path.exists(os.path.dirname(to_path)):
os.makedirs(os.path.dirname(to_path))
shutil.copyfile(from_path, to_path)
def on_complete(target, source, env):
if platform == "macos":
copy_file(
f"{output_bin_folder}/{lib_name}.{platform}.{compile_target}.framework/{lib_name}.{platform}.{compile_target}",
f"{plugin_bin_folder}/{lib_name}.{platform}.{compile_target}.framework/{lib_name}.{platform}.{compile_target}".replace(
".dev.", "."
),
)
elif platform == "ios":
if ios_simulator:
copy_file(
f"{output_bin_folder}/{lib_name}.{platform}.{compile_target}.simulator.a",
f"{plugin_bin_folder}/{lib_name}.{platform}.{compile_target}.simulator.a".replace(
".dev.", "."
),
)
else:
copy_file(
f"{output_bin_folder}/{lib_name}.{platform}.{compile_target}.a",
f"{plugin_bin_folder}/{lib_name}.{platform}.{compile_target}.a".replace(
".dev.", "."
),
)
else:
copy_file(
f"{output_bin_folder}/{lib_name}{suffix}{share_lib_suffix}",
f"{plugin_bin_folder}/{lib_name}{suffix}{share_lib_suffix}".replace(
".dev.", "."
),
)
copied_readme_file_path = os.path.join(plugin_folder, "README.md")
copied_readme_zh_file_path = os.path.join(plugin_folder, "README.zh.md")
copy_file("README.md", copied_readme_file_path)
copy_file("README.zh.md", copied_readme_zh_file_path)
copy_file("LICENSE", os.path.join(plugin_folder, "LICENSE"))
# 替换 readme 中图片的路径
for fp in [copied_readme_file_path, copied_readme_zh_file_path]:
f = open(fp, "r", encoding="utf8")
lines = f.readlines()
f.close()
for i in range(len(lines)):
if lines[i].count("(demo/addons/gddragonbones/") > 0:
lines[i] = lines[i].replace("(demo/addons/gddragonbones/", "(")
f = open(fp, "w", encoding="utf8")
f.writelines(lines)
f.close()
# 更新.gdextension中的版本信息
f = open(extension_file, "r", encoding="utf8")
lines = f.readlines()
f.close()
for i in range(len(lines)):
if lines[i].startswith('version = "') and lines[i].endswith('"\n'):
lines[i] = f'version = "{build_version.version}"\n'
break
f = open(extension_file, "w", encoding="utf8")
f.writelines(lines)
f.close()
# Disable scons cache for source files
NoCache(sources)
complete_command = Command("complete", library, on_complete)
Depends(complete_command, library)
Default(complete_command)