api_solution_build.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Build the Godot API solution
  2. import os
  3. from SCons.Script import Dir
  4. def build_api_solution(source, target, env):
  5. # source and target elements are of type SCons.Node.FS.File, hence why we convert them to str
  6. module_dir = env['module_dir']
  7. solution_path = os.path.join(module_dir, 'glue/Managed/Generated/GodotSharp.sln')
  8. if not os.path.isfile(solution_path):
  9. raise RuntimeError("Godot API solution not found. Did you forget to run '--generate-mono-glue'?")
  10. build_config = env['solution_build_config']
  11. extra_msbuild_args = ['/p:NoWarn=1591'] # Ignore missing documentation warnings
  12. from .solution_builder import build_solution
  13. build_solution(env, solution_path, build_config, extra_msbuild_args=extra_msbuild_args)
  14. # Copy targets
  15. core_src_dir = os.path.abspath(os.path.join(solution_path, os.pardir, 'GodotSharp', 'bin', build_config))
  16. editor_src_dir = os.path.abspath(os.path.join(solution_path, os.pardir, 'GodotSharpEditor', 'bin', build_config))
  17. dst_dir = os.path.abspath(os.path.join(str(target[0]), os.pardir))
  18. if not os.path.isdir(dst_dir):
  19. assert not os.path.isfile(dst_dir)
  20. os.makedirs(dst_dir)
  21. def copy_target(target_path):
  22. from shutil import copy
  23. filename = os.path.basename(target_path)
  24. src_path = os.path.join(core_src_dir, filename)
  25. if not os.path.isfile(src_path):
  26. src_path = os.path.join(editor_src_dir, filename)
  27. copy(src_path, target_path)
  28. for scons_target in target:
  29. copy_target(str(scons_target))
  30. def build(env_mono):
  31. assert env_mono['tools']
  32. target_filenames = [
  33. 'GodotSharp.dll', 'GodotSharp.pdb', 'GodotSharp.xml',
  34. 'GodotSharpEditor.dll', 'GodotSharpEditor.pdb', 'GodotSharpEditor.xml'
  35. ]
  36. for build_config in ['Debug', 'Release']:
  37. output_dir = Dir('#bin').abspath
  38. editor_api_dir = os.path.join(output_dir, 'GodotSharp', 'Api', build_config)
  39. targets = [os.path.join(editor_api_dir, filename) for filename in target_filenames]
  40. cmd = env_mono.CommandNoCache(targets, [], build_api_solution,
  41. module_dir=os.getcwd(), solution_build_config=build_config)
  42. env_mono.AlwaysBuild(cmd)