api_solution_build.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. depend_cmd = []
  37. for build_config in ['Debug', 'Release']:
  38. output_dir = Dir('#bin').abspath
  39. editor_api_dir = os.path.join(output_dir, 'GodotSharp', 'Api', build_config)
  40. targets = [os.path.join(editor_api_dir, filename) for filename in target_filenames]
  41. cmd = env_mono.CommandNoCache(targets, depend_cmd, build_api_solution,
  42. module_dir=os.getcwd(), solution_build_config=build_config)
  43. env_mono.AlwaysBuild(cmd)
  44. # Make the Release build of the API solution depend on the Debug build.
  45. # We do this in order to prevent SCons from building them in parallel,
  46. # which can freak out MSBuild. In many cases, one of the builds would
  47. # hang indefinitely requiring a key to be pressed for it to continue.
  48. depend_cmd = cmd
  49. return depend_cmd