godot/modules/mono/SCsub

122 lines
4.7 KiB
Plaintext
Raw Normal View History

2017-10-02 21:24:00 +00:00
#!/usr/bin/env python
Import('env')
from compat import byte_to_str
2017-10-02 21:24:00 +00:00
def make_cs_files_header(src, dst):
with open(dst, 'w') as header:
2017-10-02 21:24:00 +00:00
header.write('/* This is an automatically generated file; DO NOT EDIT! OK THX */\n')
header.write('#ifndef _CS_FILES_DATA_H\n')
header.write('#define _CS_FILES_DATA_H\n\n')
header.write('#include "map.h"\n')
header.write('#include "ustring.h"\n')
inserted_files = ''
import os
for file in os.listdir(src):
if file.endswith('.cs'):
with open(os.path.join(src, file), 'rb') as f:
buf = f.read()
decomp_size = len(buf)
import zlib
buf = zlib.compress(buf)
name = os.path.splitext(file)[0]
header.write('\nstatic const int _cs_' + name + '_compressed_size = ' + str(len(buf)) + ';\n')
header.write('static const int _cs_' + name + '_uncompressed_size = ' + str(decomp_size) + ';\n')
header.write('static const unsigned char _cs_' + name + '_compressed[] = { ')
for i, buf_idx in enumerate(range(len(buf))):
if i > 0:
header.write(', ')
header.write(byte_to_str(buf[buf_idx]))
2017-10-02 21:24:00 +00:00
inserted_files += '\tr_files.insert(\"' + file + '\", ' \
'CompressedFile(_cs_' + name + '_compressed_size, ' \
'_cs_' + name + '_uncompressed_size, ' \
'_cs_' + name + '_compressed));\n'
header.write(' };\n')
header.write('\nstruct CompressedFile\n' '{\n'
'\tint compressed_size;\n' '\tint uncompressed_size;\n' '\tconst unsigned char* data;\n'
'\n\tCompressedFile(int p_comp_size, int p_uncomp_size, const unsigned char* p_data)\n'
'\t{\n' '\t\tcompressed_size = p_comp_size;\n' '\t\tuncompressed_size = p_uncomp_size;\n'
'\t\tdata = p_data;\n' '\t}\n' '\n\tCompressedFile() {}\n' '};\n'
'\nvoid get_compressed_files(Map<String, CompressedFile>& r_files)\n' '{\n' + inserted_files + '}\n'
)
header.write('#endif // _CS_FILES_DATA_H')
env.add_source_files(env.modules_sources, '*.cpp')
env.add_source_files(env.modules_sources, 'mono_gd/*.cpp')
env.add_source_files(env.modules_sources, 'utils/*.cpp')
if env['tools']:
env.add_source_files(env.modules_sources, 'editor/*.cpp')
make_cs_files_header('glue/cs_files', 'glue/cs_compressed.gen.h')
vars = Variables()
vars.Add(BoolVariable('mono_glue', 'Build with the mono glue sources', True))
vars.Update(env)
# Glue sources
if env['mono_glue']:
env.add_source_files(env.modules_sources, 'glue/*.cpp')
else:
env.Append(CPPDEFINES = [ 'MONO_GLUE_DISABLED' ])
if ARGUMENTS.get('yolo_copy', False):
env.Append(CPPDEFINES = [ 'YOLO_COPY' ])
# Build GodotSharpTools solution
import os
import subprocess
import mono_reg_utils as monoreg
def mono_build_solution(source, target, env):
if os.name == 'nt':
msbuild_tools_path = monoreg.find_msbuild_tools_path_reg()
if not msbuild_tools_path:
raise RuntimeError('Cannot find MSBuild Tools Path in the registry')
msbuild_path = os.path.join(msbuild_tools_path, 'MSBuild.exe')
else:
msbuild_path = 'msbuild'
output_path = os.path.abspath(os.path.join(str(target[0]), os.pardir))
msbuild_args = [
msbuild_path,
os.path.abspath(str(source[0])),
'/p:Configuration=Release',
'/p:OutputPath=' + output_path
]
msbuild_env = os.environ.copy()
# Needed when running from Developer Command Prompt for VS
if 'PLATFORM' in msbuild_env:
del msbuild_env['PLATFORM']
msbuild_alt_paths = [ 'xbuild' ]
while True:
try:
subprocess.check_call(msbuild_args, env = msbuild_env)
break
except subprocess.CalledProcessError:
raise RuntimeError('GodotSharpTools build failed')
except OSError:
if os.name != 'nt':
if not msbuild_alt_paths:
raise RuntimeError('Could not find commands msbuild or xbuild')
# Try xbuild
msbuild_args[0] = msbuild_alt_paths.pop(0)
else:
raise RuntimeError('Could not find command MSBuild.exe')
mono_sln_builder = Builder(action = mono_build_solution)
env.Append(BUILDERS = { 'MonoBuildSolution' : mono_sln_builder })
env.MonoBuildSolution(
os.path.join(Dir('#bin').abspath, 'GodotSharpTools.dll'),
'editor/GodotSharpTools/GodotSharpTools.sln'
)