diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2017-10-02 23:24:00 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2017-10-03 00:01:26 +0200 |
commit | e36fb95c50ce0cd0ab9621afe668332895712c2e (patch) | |
tree | 5f146ad19fa9364c66fae002b0210a6a967b5e6e /modules/mono/SCsub | |
parent | 29b44801b2e9693c5d19d3e4fbb708af367c4904 (diff) |
Added mono module
Diffstat (limited to 'modules/mono/SCsub')
-rw-r--r-- | modules/mono/SCsub | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/modules/mono/SCsub b/modules/mono/SCsub new file mode 100644 index 0000000000..0af2056c5c --- /dev/null +++ b/modules/mono/SCsub @@ -0,0 +1,120 @@ +#!/usr/bin/env python + +Import('env') + + +def make_cs_files_header(src, dst): + with open(dst, 'wb') as header: + 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(str(ord(buf[buf_idx]))) + 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' +) |