SCsub 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. Import("env")
  4. env.editor_sources = []
  5. import glob
  6. import os
  7. import editor_builders
  8. import methods
  9. if env.editor_build:
  10. # Generate doc data paths
  11. def doc_data_class_path_builder(target, source, env):
  12. paths = dict(sorted(source[0].read().items()))
  13. data = "\n".join([f'\t{{"{key}", "{value}"}},' for key, value in paths.items()])
  14. with methods.generated_wrapper(target) as file:
  15. file.write(
  16. f"""\
  17. static const int _doc_data_class_path_count = {len(paths)};
  18. struct _DocDataClassPath {{
  19. const char *name;
  20. const char *path;
  21. }};
  22. static const _DocDataClassPath _doc_data_class_paths[{len(env.doc_class_path) + 1}] = {{
  23. {data}
  24. {{nullptr, nullptr}},
  25. }};
  26. """
  27. )
  28. env.CommandNoCache("doc_data_class_path.gen.h", env.Value(env.doc_class_path), env.Run(doc_data_class_path_builder))
  29. # Register exporters
  30. def register_exporters_builder(target, source, env):
  31. platforms = source[0].read()
  32. exp_inc = "\n".join([f'#include "platform/{p}/export/export.h"' for p in platforms])
  33. exp_reg = "\n".join([f"\tregister_{p}_exporter();" for p in platforms])
  34. exp_type = "\n".join([f"\tregister_{p}_exporter_types();" for p in platforms])
  35. with methods.generated_wrapper(target) as file:
  36. file.write(
  37. f"""\
  38. #include "register_exporters.h"
  39. {exp_inc}
  40. void register_exporters() {{
  41. {exp_reg}
  42. }}
  43. void register_exporter_types() {{
  44. {exp_type}
  45. }}
  46. """
  47. )
  48. gen_exporters = env.CommandNoCache(
  49. "register_exporters.gen.cpp", env.Value(env.platform_exporters), env.Run(register_exporters_builder)
  50. )
  51. for e in env.platform_exporters:
  52. # Add all .cpp files in export folder
  53. env.add_source_files(env.editor_sources, f"../platform/{e}/export/*.cpp")
  54. # Core API documentation.
  55. docs = []
  56. docs += Glob("#doc/classes/*.xml")
  57. # Module API documentation.
  58. module_dirs = []
  59. for d in env.doc_class_path.values():
  60. if d not in module_dirs:
  61. module_dirs.append(d)
  62. for d in module_dirs:
  63. if not os.path.isabs(d):
  64. docs += Glob("#" + d + "/*.xml") # Built-in.
  65. else:
  66. docs += Glob(d + "/*.xml") # Custom.
  67. docs = sorted(docs)
  68. env.Depends("#editor/doc_data_compressed.gen.h", docs)
  69. env.CommandNoCache(
  70. "#editor/doc_data_compressed.gen.h",
  71. docs,
  72. env.Run(editor_builders.make_doc_header),
  73. )
  74. # Editor interface and class reference translations incur a significant size
  75. # cost for the editor binary (see godot-proposals#3421).
  76. # To limit it, we only include translations with a high enough completion
  77. # ratio (20% for the editor UI, 10% for the class reference).
  78. # Generated with `make include-list` for each resource.
  79. # Editor translations
  80. tlist = glob.glob(env.Dir("#editor/translations/editor").abspath + "/*.po")
  81. env.Depends("#editor/editor_translations.gen.h", tlist)
  82. env.CommandNoCache(
  83. "#editor/editor_translations.gen.h",
  84. tlist,
  85. env.Run(editor_builders.make_editor_translations_header),
  86. )
  87. # Property translations
  88. tlist = glob.glob(env.Dir("#editor/translations/properties").abspath + "/*.po")
  89. env.Depends("#editor/property_translations.gen.h", tlist)
  90. env.CommandNoCache(
  91. "#editor/property_translations.gen.h",
  92. tlist,
  93. env.Run(editor_builders.make_property_translations_header),
  94. )
  95. # Documentation translations
  96. tlist = glob.glob(env.Dir("#doc/translations").abspath + "/*.po")
  97. env.Depends("#editor/doc_translations.gen.h", tlist)
  98. env.CommandNoCache(
  99. "#editor/doc_translations.gen.h",
  100. tlist,
  101. env.Run(editor_builders.make_doc_translations_header),
  102. )
  103. # Extractable translations
  104. tlist = glob.glob(env.Dir("#editor/translations/extractable").abspath + "/*.po")
  105. tlist.extend(glob.glob(env.Dir("#editor/translations/extractable").abspath + "/extractable.pot"))
  106. env.Depends("#editor/extractable_translations.gen.h", tlist)
  107. env.CommandNoCache(
  108. "#editor/extractable_translations.gen.h",
  109. tlist,
  110. env.Run(editor_builders.make_extractable_translations_header),
  111. )
  112. env.add_source_files(env.editor_sources, "*.cpp")
  113. env.add_source_files(env.editor_sources, gen_exporters)
  114. SConscript("debugger/SCsub")
  115. SConscript("export/SCsub")
  116. SConscript("gui/SCsub")
  117. SConscript("icons/SCsub")
  118. SConscript("import/SCsub")
  119. SConscript("plugins/SCsub")
  120. SConscript("project_manager/SCsub")
  121. SConscript("themes/SCsub")
  122. lib = env.add_library("editor", env.editor_sources)
  123. env.Prepend(LIBS=[lib])