diff options
author | Andreas Haas <Hinsbart@users.noreply.github.com> | 2017-10-03 00:13:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-03 00:13:40 +0200 |
commit | b0194a33f65970948ef66819913bf3034a3a22e8 (patch) | |
tree | 35e21b53b10bbd525506bb5b72b7f89214e1234f /modules/mono/SCsub | |
parent | 5cd68abf8896fd86a33c048d6fece61c3cd3f8e5 (diff) | |
parent | d5caf71c3fcdeb422d1b0ea97a836fcdb57a8713 (diff) |
Merge pull request #11739 from neikeq/tengo-el-mono
Moved mono module here
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' +) |