-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathdisable-burst-if-requested.py
More file actions
97 lines (72 loc) · 3.28 KB
/
disable-burst-if-requested.py
File metadata and controls
97 lines (72 loc) · 3.28 KB
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
# This file was used before for mobiles and Webgl but was removed (around end of January 2025). The file itself was left here for now in case we would need to use it.
# This Python script is used to manage Burst AOT (Ahead-Of-Time) compilation settings for Unity builds.
# An example usage would be "- python .yamato/disable-burst-if-requested.py --project-path {{ project.path }} --platform WebGL"
import argparse
import json
import os
args = None
platform_plugin_definition = None
def resolve_target(platform):
resolved_target = platform
if 'StandaloneWindows' in platform:
resolved_target = 'StandaloneWindows'
elif 'StandaloneLinux' in platform:
resolved_target = 'StandaloneLinux64'
return resolved_target
def create_config(settings_path, platform):
config_name = os.path.join(settings_path, 'BurstAotSettings_{}.json'.format(resolve_target(platform)))
monobehaviour = {
'm_Enabled': True,
'm_EditorHideFlags': 0,
'm_Name': "",
'm_EditorClassIdentifier': 'Unity.Burst.Editor:Unity.Burst.Editor:BurstPlatformAotSettings',
'DisableOptimisations': False,
'DisableSafetyChecks': True,
'DisableBurstCompilation': False
}
data = {'MonoBehaviour': monobehaviour}
with open(config_name, 'w') as f:
json.dump(data, f)
return config_name
def get_or_create_AOT_config(project_path, platform):
settings_path = os.path.join(project_path, 'ProjectSettings')
if not os.path.isdir(settings_path):
os.mkdir(settings_path)
config_names = [os.path.join(settings_path, filename) for filename in os.listdir(settings_path) if filename.startswith("BurstAotSettings_{}".format(resolve_target(platform)))]
if not config_names:
return [create_config(settings_path, platform)]
return config_names
def disable_AOT(project_path, platform):
config_names = get_or_create_AOT_config(project_path, platform)
for config_name in config_names:
set_AOT(config_name, True)
def enable_AOT(project_path, platform):
config_names = get_or_create_AOT_config(project_path, platform)
for config_name in config_names:
set_AOT(config_name, False)
def set_AOT(config_file, status):
config = None
with open(config_file, 'r') as f:
config = json.load(f)
assert config is not None, 'AOT settings not found; did the burst-enabled build finish successfully?'
config['MonoBehaviour']['DisableBurstCompilation'] = status
with open(config_file, 'w') as f:
json.dump(config, f)
def main():
enable_burst = os.environ.get('ENABLE_BURST_COMPILATION', 'true').strip().lower()
if enable_burst == 'true':
print('BURST COMPILATION: ENABLED')
elif enable_burst == 'false':
print('BURST COMPILATION: DISABLED')
disable_AOT(args.project_path, args.platform)
else:
sys.exit('BURST COMPILATION: unexpected value: {}'.format(enable_burst))
def parse_args():
global args
parser = argparse.ArgumentParser(description='This tool disables burst AOT compilation')
parser.add_argument('--project-path', help='Specify the location of the unity project.')
parser.add_argument('--platform', help="Platform to be used to run the build.")
args = parser.parse_args()
if __name__ == '__main__':
parse_args()
main()