SCsub 4.6 KB

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