Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
godot-cpp/build_profile.py at master · godotengine/godot-cpp · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
godotengine
godot-cpp
Repository navigation
Code
Issues
292
(292)
Pull requests
61
(61)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
godot-cpp
/
build_profile.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
181 lines (151 loc) · 5.49 KB
master
Breadcrumbs
godot-cpp
/
build_profile.py
Copy path
Top
File metadata and controls
Code
Blame
181 lines (151 loc) · 5.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
json
import
sys
def
parse_build_profile
(
profile_filepath
,
api
):
if
profile_filepath
==
""
:
return
{}
with
open
(
profile_filepath
,
encoding
=
"utf-8"
)
as
profile_file
:
profile
=
json
.
load
(
profile_file
)
api_dict
=
{}
parents
=
{}
children
=
{}
for
engine_class
in
api
[
"classes"
]:
api_dict
[
engine_class
[
"name"
]]
=
engine_class
parent
=
engine_class
.
get
(
"inherits"
,
""
)
child
=
engine_class
[
"name"
]
parents
[
child
]
=
parent
if
parent
==
""
:
continue
children
[
parent
]
=
children
.
get
(
parent
, [])
children
[
parent
].
append
(
child
)
included
=
[]
front
=
list
(
profile
.
get
(
"enabled_classes"
, []))
if
front
:
# These must always be included
front
.
append
(
"WorkerThreadPool"
)
front
.
append
(
"ClassDB"
)
front
.
append
(
"ClassDBSingleton"
)
# In src/classes/low_level.cpp
front
.
append
(
"FileAccess"
)
front
.
append
(
"Image"
)
front
.
append
(
"XMLParser"
)
while
front
:
cls
=
front
.
pop
()
if
cls
in
included
:
continue
included
.
append
(
cls
)
parent
=
parents
.
get
(
cls
,
""
)
if
parent
:
front
.
append
(
parent
)
excluded
=
[]
front
=
list
(
profile
.
get
(
"disabled_classes"
, []))
while
front
:
cls
=
front
.
pop
()
if
cls
in
excluded
:
continue
excluded
.
append
(
cls
)
front
+=
children
.
get
(
cls
, [])
if
included
and
excluded
:
print
(
"WARNING: Cannot specify both 'enabled_classes' and 'disabled_classes' in build profile. 'disabled_classes' will be ignored."
)
return
{
"enabled_classes"
:
included
,
"disabled_classes"
:
excluded
,
}
def
generate_trimmed_api
(
source_api_filepath
,
profile_filepath
):
with
open
(
source_api_filepath
,
encoding
=
"utf-8"
)
as
api_file
:
api
=
json
.
load
(
api_file
)
if
profile_filepath
==
""
:
return
api
build_profile
=
parse_build_profile
(
profile_filepath
,
api
)
engine_classes
=
{}
for
class_api
in
api
[
"classes"
]:
engine_classes
[
class_api
[
"name"
]]
=
class_api
[
"is_refcounted"
]
for
native_struct
in
api
[
"native_structures"
]:
if
native_struct
[
"name"
]
==
"ObjectID"
:
continue
engine_classes
[
native_struct
[
"name"
]]
=
False
classes
=
[]
for
class_api
in
api
[
"classes"
]:
if
not
is_class_included
(
class_api
[
"name"
],
build_profile
):
continue
if
"methods"
in
class_api
:
methods
=
[]
for
method
in
class_api
[
"methods"
]:
if
not
is_method_included
(
method
,
build_profile
,
engine_classes
):
continue
methods
.
append
(
method
)
class_api
[
"methods"
]
=
methods
classes
.
append
(
class_api
)
api
[
"classes"
]
=
classes
return
api
def
is_class_included
(
class_name
,
build_profile
):
"""
Check if an engine class should be included.
This removes classes according to a build profile of enabled or disabled classes.
"""
included
=
build_profile
.
get
(
"enabled_classes"
, [])
excluded
=
build_profile
.
get
(
"disabled_classes"
, [])
if
included
:
return
class_name
in
included
if
excluded
:
return
class_name
not
in
excluded
return
True
def
is_method_included
(
method
,
build_profile
,
engine_classes
):
"""
Check if an engine class method should be included.
This removes methods according to a build profile of enabled or disabled classes.
"""
included
=
build_profile
.
get
(
"enabled_classes"
, [])
excluded
=
build_profile
.
get
(
"disabled_classes"
, [])
ref_cls
=
set
()
rtype
=
get_base_type
(
method
.
get
(
"return_value"
, {}).
get
(
"type"
,
""
))
args
=
[
get_base_type
(
a
[
"type"
])
for
a
in
method
.
get
(
"arguments"
, [])]
if
rtype
in
engine_classes
:
ref_cls
.
add
(
rtype
)
elif
is_enum
(
rtype
)
and
get_enum_class
(
rtype
)
in
engine_classes
:
ref_cls
.
add
(
get_enum_class
(
rtype
))
for
arg
in
args
:
if
arg
in
engine_classes
:
ref_cls
.
add
(
arg
)
elif
is_enum
(
arg
)
and
get_enum_class
(
arg
)
in
engine_classes
:
ref_cls
.
add
(
get_enum_class
(
arg
))
for
acls
in
ref_cls
:
if
len
(
included
)
>
0
and
acls
not
in
included
:
return
False
elif
len
(
excluded
)
>
0
and
acls
in
excluded
:
return
False
return
True
def
is_enum
(
type_name
):
return
type_name
.
startswith
(
"enum::"
)
or
type_name
.
startswith
(
"bitfield::"
)
def
get_enum_class
(
enum_name
:
str
):
if
"."
in
enum_name
:
if
is_bitfield
(
enum_name
):
return
enum_name
.
replace
(
"bitfield::"
,
""
).
split
(
"."
)[
0
]
else
:
return
enum_name
.
replace
(
"enum::"
,
""
).
split
(
"."
)[
0
]
else
:
return
"GlobalConstants"
def
get_base_type
(
type_name
):
if
type_name
.
startswith
(
"const "
):
type_name
=
type_name
[
6
:]
if
type_name
.
endswith
(
"*"
):
type_name
=
type_name
[:
-
1
]
if
type_name
.
startswith
(
"typedarray::"
):
type_name
=
type_name
.
replace
(
"typedarray::"
,
""
)
return
type_name
def
is_bitfield
(
type_name
):
return
type_name
.
startswith
(
"bitfield::"
)
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
<
3
or
len
(
sys
.
argv
)
>
4
:
print
(
"Usage: %s BUILD_PROFILE INPUT_JSON [OUTPUT_JSON]"
%
(
sys
.
argv
[
0
]))
sys
.
exit
(
1
)
profile
=
sys
.
argv
[
1
]
infile
=
sys
.
argv
[
2
]
outfile
=
sys
.
argv
[
3
]
if
len
(
sys
.
argv
)
>
3
else
""
api
=
generate_trimmed_api
(
infile
,
profile
)
if
outfile
:
with
open
(
outfile
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
json
.
dump
(
api
,
f
)
else
:
json
.
dump
(
api
,
sys
.
stdout
)
You can’t perform that action at this time.