SCsub 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/usr/bin/env python
  2. Import('env')
  3. env.editor_sources = []
  4. from compat import encode_utf8, byte_to_str, open_utf8
  5. def make_certs_header(target, source, env):
  6. src = source[0].srcnode().abspath
  7. dst = target[0].srcnode().abspath
  8. f = open(src, "rb")
  9. g = open_utf8(dst, "w")
  10. buf = f.read()
  11. decomp_size = len(buf)
  12. import zlib
  13. buf = zlib.compress(buf)
  14. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  15. g.write("#ifndef _CERTS_RAW_H\n")
  16. g.write("#define _CERTS_RAW_H\n")
  17. g.write("static const int _certs_compressed_size=" + str(len(buf)) + ";\n")
  18. g.write("static const int _certs_uncompressed_size=" + str(decomp_size) + ";\n")
  19. g.write("static const unsigned char _certs_compressed[]={\n")
  20. for i in range(len(buf)):
  21. g.write(byte_to_str(buf[i]) + ",\n")
  22. g.write("};\n")
  23. g.write("#endif")
  24. def make_doc_header(target, source, env):
  25. src = source[0].srcnode().abspath
  26. dst = target[0].srcnode().abspath
  27. f = open_utf8(src, "r")
  28. g = open_utf8(dst, "w")
  29. # Note: As long as we simply read the contents of `f` and immediately call
  30. # `zlib.compress` on the result, we could open `f` as binary file and store
  31. # the result in `buf` without passing it through `encode_utf8`. However if
  32. # we ever perform any string operations on the result (as in Godot 3)
  33. # we need the UTF8 decoding/encoding step, so it seems more future proof
  34. # to do it this way.
  35. buf = encode_utf8(f.read())
  36. decomp_size = len(buf)
  37. import zlib
  38. buf = zlib.compress(buf)
  39. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  40. g.write("#ifndef _DOC_DATA_RAW_H\n")
  41. g.write("#define _DOC_DATA_RAW_H\n")
  42. g.write("static const int _doc_data_compressed_size=" + str(len(buf)) + ";\n")
  43. g.write("static const int _doc_data_uncompressed_size=" + str(decomp_size) + ";\n")
  44. g.write("static const unsigned char _doc_data_compressed[]={\n")
  45. for i in range(len(buf)):
  46. g.write(byte_to_str(buf[i]) + ",\n")
  47. g.write("};\n")
  48. g.write("#endif")
  49. def make_fonts_header(target, source, env):
  50. dst = target[0].srcnode().abspath
  51. g = open_utf8(dst, "w")
  52. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  53. g.write("#ifndef _EDITOR_FONTS_H\n")
  54. g.write("#define _EDITOR_FONTS_H\n")
  55. # saving uncompressed, since freetype will reference from memory pointer
  56. xl_names = []
  57. for i in range(len(source)):
  58. f = open(source[i].srcnode().abspath, "rb")
  59. buf = f.read()
  60. import os.path
  61. name = os.path.splitext(os.path.basename(source[i].srcnode().abspath))[0]
  62. g.write("static const int _font_" + name + "_size=" + str(len(buf)) + ";\n")
  63. g.write("static const unsigned char _font_" + name + "[]={\n")
  64. for i in range(len(buf)):
  65. g.write(byte_to_str(buf[i]) + ",\n")
  66. g.write("};\n")
  67. g.write("#endif")
  68. def make_translations_header(target, source, env):
  69. dst = target[0].srcnode().abspath
  70. g = open_utf8(dst, "w")
  71. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  72. g.write("#ifndef _EDITOR_TRANSLATIONS_H\n")
  73. g.write("#define _EDITOR_TRANSLATIONS_H\n")
  74. import zlib
  75. import os.path
  76. paths = [node.srcnode().abspath for node in source]
  77. sorted_paths = sorted(paths, key=lambda path: os.path.splitext(os.path.basename(path))[0])
  78. xl_names = []
  79. for i in range(len(sorted_paths)):
  80. f = open(sorted_paths[i], "rb")
  81. buf = f.read()
  82. decomp_size = len(buf)
  83. buf = zlib.compress(buf)
  84. name = os.path.splitext(os.path.basename(sorted_paths[i]))[0]
  85. #g.write("static const int _translation_"+name+"_compressed_size="+str(len(buf))+";\n")
  86. #g.write("static const int _translation_"+name+"_uncompressed_size="+str(decomp_size)+";\n")
  87. g.write("static const unsigned char _translation_" + name + "_compressed[]={\n")
  88. for i in range(len(buf)):
  89. g.write(byte_to_str(buf[i]) + ",\n")
  90. g.write("};\n")
  91. xl_names.append([name, len(buf), str(decomp_size)])
  92. g.write("struct EditorTranslationList {\n")
  93. g.write("\tconst char* lang;\n")
  94. g.write("\tint comp_size;\n")
  95. g.write("\tint uncomp_size;\n")
  96. g.write("\tconst unsigned char* data;\n")
  97. g.write("};\n\n")
  98. g.write("static EditorTranslationList _editor_translations[]={\n")
  99. for x in xl_names:
  100. g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ",_translation_" + x[0] + "_compressed},\n")
  101. g.write("\t{NULL,0,0,NULL}\n")
  102. g.write("};\n")
  103. g.write("#endif")
  104. def make_authors_header(target, source, env):
  105. src = source[0].srcnode().abspath
  106. dst = target[0].srcnode().abspath
  107. f = open_utf8(src, "r")
  108. g = open_utf8(dst, "w")
  109. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  110. g.write("#ifndef _EDITOR_AUTHORS_H\n")
  111. g.write("#define _EDITOR_AUTHORS_H\n")
  112. g.write("static const char *dev_names[] = {\n")
  113. name_count = -1
  114. for line in f:
  115. if name_count >= 0:
  116. if line.startswith(" "):
  117. g.write("\t\"" + line.strip() + "\",\n")
  118. name_count += 1
  119. elif line.strip() == "## Developers":
  120. name_count = 0
  121. g.write("\t0\n")
  122. g.write("};\n")
  123. g.write("#define AUTHORS_COUNT " + str(name_count) + "\n")
  124. g.write("#endif\n")
  125. if (env["tools"] == "yes"):
  126. # Register exporters
  127. reg_exporters_inc = '#include "register_exporters.h"\n'
  128. reg_exporters = 'void register_exporters() {\n'
  129. for e in env.platform_exporters:
  130. env.editor_sources.append("#platform/" + e + "/export/export.cpp")
  131. reg_exporters += '\tregister_' + e + '_exporter();\n'
  132. reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n'
  133. reg_exporters += '}\n'
  134. f = open_utf8("register_exporters.gen.cpp", "w")
  135. f.write(reg_exporters_inc)
  136. f.write(reg_exporters)
  137. f.close()
  138. # API documentation
  139. env.Depends("#editor/doc_data_compressed.gen.h", "#doc/base/classes.xml")
  140. env.CommandNoCache("#editor/doc_data_compressed.gen.h", "#doc/base/classes.xml", make_doc_header)
  141. # Certificates
  142. env.Depends("#editor/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt")
  143. env.CommandNoCache("#editor/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt", make_certs_header)
  144. import glob
  145. path = env.Dir('.').abspath
  146. # Translations
  147. tlist = glob.glob(path + "/translations/*.po")
  148. env.Depends('#editor/translations.gen.h', tlist)
  149. env.CommandNoCache('#editor/translations.gen.h', tlist, make_translations_header)
  150. # Fonts
  151. flist = glob.glob(path + "/../thirdparty/fonts/*.ttf")
  152. flist.append(glob.glob(path + "/../thirdparty/fonts/*.otf"))
  153. env.Depends('#editor/builtin_fonts.gen.h', flist)
  154. env.CommandNoCache('#editor/builtin_fonts.gen.h', flist, make_fonts_header)
  155. # Authors
  156. env.Depends('#editor/authors.gen.h', "../AUTHORS.md")
  157. env.CommandNoCache('#editor/authors.gen.h', "../AUTHORS.md", make_authors_header)
  158. env.add_source_files(env.editor_sources, "*.cpp")
  159. SConscript('collada/SCsub')
  160. SConscript('doc/SCsub')
  161. SConscript('fileserver/SCsub')
  162. SConscript('icons/SCsub')
  163. SConscript('io_plugins/SCsub')
  164. SConscript('plugins/SCsub')
  165. lib = env.add_library("editor", env.editor_sources)
  166. env.Prepend(LIBS=[lib])
  167. Export('env')