This repository was archived by the owner on Jan 30, 2025. It is now read-only.
forked from nikitalita/patchwork_editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCsub
218 lines (181 loc) · 8.31 KB
/
SCsub
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python
import os
import re
import shutil
from subprocess import Popen, PIPE, check_output
import glob
Import("env")
Import("env_modules")
MODULE_DIR = os.path.realpath(".")
EXTERNAL_DIR = os.path.join(MODULE_DIR, "external")
EXTERNAL_LIB_DIR = os.path.join(EXTERNAL_DIR, "lib")
env_patchwork_editor = env_modules.Clone()
env_patchwork_editor["disable_exceptions"] = False
env_patchwork_editor.Append(CPPPATH=["."])
env_patchwork_editor.Append(CPPPATH=["external/include"])
env.Append(LIBPATH=[EXTERNAL_LIB_DIR])
# icon stuff
# env_patchwork_editor.Append(CPPPATH=["#thirdparty/thorsvg/"])
# env_patchwork_editor["BUILDERS"]["MakeGDREIconsBuilder"] = Builder(
# action=env_patchwork_editor.Run(gdre_icon_builder.make_gdre_icons_action),
# suffix=".h",
# src_suffix=".svg",
# )
# icon_sources = Glob("icons/*.svg")
# env_patchwork_editor.Alias(
# "gdre_icons",
# [env_patchwork_editor.MakeGDREIconsBuilder("editor/gdre_icons.gen.h", icon_sources)],
# )
# automerge stuff
def get_sources(rel_path, filters=["*.h", "*.hpp", "*.cpp"]):
abs_path = os.path.join(MODULE_DIR, rel_path)
# check if abs_path exists
if not os.path.exists(abs_path):
raise Exception(
f"Path {abs_path} does not exist, please run `git submodule update --init --recursive` in the patchwork_editor directory"
)
sources = []
for suffix in filters:
globstr = os.path.join(abs_path, "**", suffix)
sources += glob.glob(globstr, recursive=True)
return [os.path.relpath(source, MODULE_DIR) for source in sources]
def cmake_builder(external_dir, source_dir, build_dir, libs, config_options=None):
output = bytes()
# get dev_build from env
dev_build = env["dev_build"] if "dev_build" in env else False
build_variant = "Debug" if dev_build else "Release"
print("BUILD VARIANT", build_variant)
Config_cmd = ["cmake", "-S", source_dir, "-B", build_dir , "-DCMAKE_BUILD_TYPE=" + build_variant]
if config_options:
Config_cmd += config_options
try:
if os.path.exists(build_dir):
shutil.rmtree(build_dir, ignore_errors=True)
output += check_output(["cmake", "-E", "make_directory", external_dir]) + b"\n"
output += check_output(["cmake", "-E", "make_directory", build_dir]) + b"\n"
output += check_output(Config_cmd) + b"\n"
output += check_output(["cmake", "--build", build_dir]) + b"\n"
# remove the old libs
for lib in libs:
lib_path = os.path.join(external_dir, lib)
if os.path.exists(lib_path):
os.remove(lib_path)
output += check_output(["cmake", "--install", build_dir, "--prefix", external_dir]) + b"\n"
except Exception as e:
# convert output to string
output = output.decode("utf-8")
print(f"Failed to build automerge-c: {e}")
print(f"Output: {output}")
exit(1)
# output = output.decode("utf-8")
# print(output)
def add_libs_to_env(module_obj, libs, sources):
for lib in libs:
env_patchwork_editor.Depends(lib, sources)
# get the basename of the library minus the extension
lib_name = os.path.basename(lib).split(".")[0]
full_lib_path = os.path.join(MODULE_DIR, lib)
env.Append(LIBS=[lib_name])
env.Depends(module_obj, libs)
PATCHWORK_RUST_PREFIX = "thirdparty/patchwork_rust"
PATCHWORK_RUST_DIR = os.path.join(MODULE_DIR, PATCHWORK_RUST_PREFIX)
PATCHWORK_RUST_BUILD_DIR = os.path.join(PATCHWORK_RUST_DIR, "build")
PATCHWORK_LIBS = ["external/lib/libpatchwork_rust.a", "external/lib/libpatchwork_rust_core.a"]
AUTOMERGE_CONFIG_OPTS = ["-DUTF32_INDEXING=true"]
def patchwork_rust_builder(target, source, env):
cmake_builder(EXTERNAL_DIR, PATCHWORK_RUST_DIR, PATCHWORK_RUST_BUILD_DIR, PATCHWORK_LIBS, AUTOMERGE_CONFIG_OPTS)
def build_patchwork_rust(module_obj):
SRC_SUFFIXES = ["*.h", "*.cpp", "*.rs", "*.txt"]
env_patchwork_editor["BUILDERS"]["PatchworkRustBuilder"] = Builder(
action=patchwork_rust_builder,
suffix=".a",
src_suffix=["*.h", "*.cpp", "*.rs", "*.txt"],
)
patchwork_rust_sources = get_sources(PATCHWORK_RUST_PREFIX, SRC_SUFFIXES)
env_patchwork_editor.Alias(
"patchworkrustlib",
[env_patchwork_editor.PatchworkRustBuilder(PATCHWORK_LIBS, patchwork_rust_sources)],
)
add_libs_to_env(module_obj, PATCHWORK_LIBS, patchwork_rust_sources)
def doproc(cmd):
# ensure that it doesn't print stderr to the terminal if print_err is False
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
(output, err) = process.communicate()
if not err:
return output.decode("utf-8").strip()
else:
return None
semver_regex = r"^[vV]?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
def write_version_header():
git = shutil.which("git")
version_info = "unknown"
is_tag = False
if git == None:
print("GDRE WARNING: cannot find git on path, unknown version will be saved in gdre_version.gen.h")
else:
# git describe --abbrev=6
version_info = doproc([git, "describe", "--tags", "--abbrev=6"])
if version_info is None:
print("GDRE WARNING: git failed to run, unknown version will be saved in gdre_version.gen.h")
version_info = "unknown"
else:
# git describe --exact-match --tags HEAD
res = doproc([git, "describe", "--exact-match", "--tags", "HEAD"])
if not res:
splits = version_info.split("-")
build_info = splits[-1]
build_num = splits[-2]
# everything but the last two elements
new_version_info = "-".join(splits[:-2])
semver_regex_match = re.match(semver_regex, new_version_info)
if semver_regex_match:
major = semver_regex_match.group("major")
minor = semver_regex_match.group("minor")
patch = semver_regex_match.group("patch")
prerelease_tag = semver_regex_match.group("prerelease")
build_metadata = semver_regex_match.group("buildmetadata")
else:
print("WARNING: version string does not match semver format")
splits = new_version_info.split(".")
if len(splits) < 3:
print("WARNING: version string is too short")
major = "0"
minor = "0"
patch = "0"
else:
major = splits[0]
minor = splits[1]
patch = splits[2]
prerelease_tag = ""
build_metadata = ""
dev_stuff = f"dev.{build_num}+{build_info}"
if prerelease_tag:
prerelease_name = prerelease_tag.split(".")[0]
prerelease_num = prerelease_tag.split(".")[-1]
if prerelease_num.isdigit():
prerelease_num = str(int(prerelease_num) + 1)
print("prerelease_num", prerelease_num)
prerelease_tag = f"{prerelease_name}.{prerelease_num}"
else:
prerelease_tag += ".1"
new_version_info = f"{major}.{minor}.{patch}-{prerelease_tag}+{dev_stuff.replace('+', '-')}"
else:
patch = str(int(patch) + 1) if patch.isdigit() else 0
new_version_info = f"{major}.{minor}.{patch}-{dev_stuff}"
version_info = new_version_info
else:
version_info = res
f = open("editor/patchwork_version.gen.h", "w")
# check if we're not on a tag
process = Popen([git, "status", "--porcelain"], stdout=PIPE)
# define GDRE_VERSION "dev-poc (for Godot 4.0)"
f.write('#define GDRE_VERSION "')
f.write(version_info)
f.write('"\n')
f.close()
write_version_header()
module_obj = []
env_patchwork_editor.add_source_files(module_obj, "*.cpp")
env_patchwork_editor.add_source_files(module_obj, "editor/*.cpp")
build_patchwork_rust(module_obj)
env.modules_sources += module_obj