godot_tools_build.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Build GodotTools solution
  2. import os
  3. from SCons.Script import Dir
  4. def build_godot_tools(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, 'editor/GodotTools/GodotTools.sln')
  8. build_config = 'Debug' if env['target'] == 'debug' else 'Release'
  9. from . solution_builder import build_solution, nuget_restore
  10. nuget_restore(env, solution_path)
  11. build_solution(env, solution_path, build_config)
  12. # Copy targets
  13. solution_dir = os.path.abspath(os.path.join(solution_path, os.pardir))
  14. src_dir = os.path.join(solution_dir, 'GodotTools', 'bin', build_config)
  15. dst_dir = os.path.abspath(os.path.join(str(target[0]), os.pardir))
  16. if not os.path.isdir(dst_dir):
  17. assert not os.path.isfile(dst_dir)
  18. os.makedirs(dst_dir)
  19. def copy_target(target_path):
  20. from shutil import copy
  21. filename = os.path.basename(target_path)
  22. copy(os.path.join(src_dir, filename), target_path)
  23. for scons_target in target:
  24. copy_target(str(scons_target))
  25. def build_godot_tools_project_editor(source, target, env):
  26. # source and target elements are of type SCons.Node.FS.File, hence why we convert them to str
  27. module_dir = env['module_dir']
  28. project_name = 'GodotTools.ProjectEditor'
  29. csproj_dir = os.path.join(module_dir, 'editor/GodotTools', project_name)
  30. csproj_path = os.path.join(csproj_dir, project_name + '.csproj')
  31. build_config = 'Debug' if env['target'] == 'debug' else 'Release'
  32. from . solution_builder import build_solution, nuget_restore
  33. # Make sure to restore NuGet packages in the project directory for the project to find it
  34. nuget_restore(env, os.path.join(csproj_dir, 'packages.config'), '-PackagesDirectory',
  35. os.path.join(csproj_dir, 'packages'))
  36. build_solution(env, csproj_path, build_config)
  37. # Copy targets
  38. src_dir = os.path.join(csproj_dir, 'bin', build_config)
  39. dst_dir = os.path.abspath(os.path.join(str(target[0]), os.pardir))
  40. if not os.path.isdir(dst_dir):
  41. assert not os.path.isfile(dst_dir)
  42. os.makedirs(dst_dir)
  43. def copy_target(target_path):
  44. from shutil import copy
  45. filename = os.path.basename(target_path)
  46. copy(os.path.join(src_dir, filename), target_path)
  47. for scons_target in target:
  48. copy_target(str(scons_target))
  49. def build(env_mono, api_sln_cmd):
  50. assert env_mono['tools']
  51. output_dir = Dir('#bin').abspath
  52. editor_tools_dir = os.path.join(output_dir, 'GodotSharp', 'Tools')
  53. target_filenames = [
  54. 'GodotTools.dll', 'GodotTools.IdeConnection.dll', 'GodotTools.BuildLogger.dll',
  55. 'GodotTools.ProjectEditor.dll', 'DotNet.Glob.dll', 'GodotTools.Core.dll'
  56. ]
  57. if env_mono['target'] == 'debug':
  58. target_filenames += [
  59. 'GodotTools.pdb', 'GodotTools.IdeConnection.pdb', 'GodotTools.BuildLogger.pdb',
  60. 'GodotTools.ProjectEditor.pdb', 'GodotTools.Core.pdb'
  61. ]
  62. targets = [os.path.join(editor_tools_dir, filename) for filename in target_filenames]
  63. cmd = env_mono.CommandNoCache(targets, api_sln_cmd, build_godot_tools, module_dir=os.getcwd())
  64. env_mono.AlwaysBuild(cmd)
  65. def build_project_editor_only(env_mono):
  66. assert env_mono['tools']
  67. output_dir = Dir('#bin').abspath
  68. editor_tools_dir = os.path.join(output_dir, 'GodotSharp', 'Tools')
  69. target_filenames = ['GodotTools.ProjectEditor.dll', 'DotNet.Glob.dll', 'GodotTools.Core.dll']
  70. if env_mono['target'] == 'debug':
  71. target_filenames += ['GodotTools.ProjectEditor.pdb', 'GodotTools.Core.pdb']
  72. targets = [os.path.join(editor_tools_dir, filename) for filename in target_filenames]
  73. cmd = env_mono.CommandNoCache(targets, [], build_godot_tools_project_editor, module_dir=os.getcwd())
  74. env_mono.AlwaysBuild(cmd)