-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathSCsub
151 lines (127 loc) · 6.04 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
#!/usr/bin/env python
import re
import gdre_icon_builder
import shutil
from subprocess import Popen, PIPE
Import("env")
Import("env_modules")
etcpak_dir = "#thirdparty/etcpak/"
mmp3thirdparty_dir = "#thirdparty/minimp3/"
liboggthirdparty_dir = "#thirdparty/libogg/"
webpthirdparty_dir = "#thirdparty/libwebp/"
env_gdsdecomp = env_modules.Clone()
# Append the include path to include the current directory
# This is a hack for tests, since the test headers get built from tests/test_main.cpp,
# and the headers that our tests pull in are relative to the current directory.
# TODO: Figure out a way to not have to do this
env.Append(CPPPATH=["#modules/gdsdecomp/"])
env_gdsdecomp.Append(CPPPATH=["#modules/gdsdecomp/"])
env_gdsdecomp.Append(CPPPATH=["#thirdparty/thorsvg/"])
env_gdsdecomp["BUILDERS"]["MakeGDREIconsBuilder"] = Builder(
action=env_gdsdecomp.Run(gdre_icon_builder.make_gdre_icons_action),
suffix=".h",
src_suffix=".svg",
)
icon_sources = Glob("icons/*.svg")
env_gdsdecomp.Alias(
"gdre_icons",
[env_gdsdecomp.MakeGDREIconsBuilder("editor/gdre_icons.gen.h", icon_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/gdre_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()
env_gdsdecomp.Prepend(CPPPATH=[etcpak_dir])
if env["builtin_libogg"]:
env_gdsdecomp.Prepend(CPPPATH=[liboggthirdparty_dir])
if env["builtin_libvorbis"]:
env_gdsdecomp.Prepend(CPPPATH=["#thirdparty/libvorbis"])
# Treat minimp3 headers as system headers to avoid raising warnings. Not supported on MSVC.
if not env.msvc:
env_gdsdecomp.Append(CPPFLAGS=["-isystem", Dir(mmp3thirdparty_dir).path])
else:
env_gdsdecomp.Prepend(CPPPATH=[mmp3thirdparty_dir])
if env["builtin_libwebp"]:
env_gdsdecomp.Prepend(CPPPATH=[webpthirdparty_dir, webpthirdparty_dir + "src/"])
env_gdsdecomp.add_source_files(env.modules_sources, "*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "bytecode/*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "compat/*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "editor/*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "exporters/*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "utility/*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "external/tga/*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "external/etcpak-decompress/*.cpp")
env_gdsdecomp.add_source_files(env.modules_sources, "module_etc_decompress/*.cpp")