summaryrefslogtreecommitdiff
path: root/modules/mono/build_scripts
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2020-05-10 22:56:35 +0200
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2020-05-11 08:17:37 +0200
commitdcf1dc4fe02bbebe86cb13168596a1d3d1d67371 (patch)
treebff86487cd7be808d00a0b7f68faf46917ffec37 /modules/mono/build_scripts
parent6a0473bcc23c096ef9ee929632a209761c2668f6 (diff)
C#: Support for building with the dotnet CLI
By adding a reference to the 'Microsoft.NETFramework.ReferenceAssemblies' nuget package, we can build projects targeting .NET Framework with the dotnet CLI. By referencing this package we also don't need to install Mono on Linux/macOS or .NET Framework on Windows, as the assemblies are taken from the package.
Diffstat (limited to 'modules/mono/build_scripts')
-rw-r--r--modules/mono/build_scripts/godot_tools_build.py2
-rw-r--r--modules/mono/build_scripts/solution_builder.py68
2 files changed, 45 insertions, 25 deletions
diff --git a/modules/mono/build_scripts/godot_tools_build.py b/modules/mono/build_scripts/godot_tools_build.py
index 8e77f3bb44..7391e8790d 100644
--- a/modules/mono/build_scripts/godot_tools_build.py
+++ b/modules/mono/build_scripts/godot_tools_build.py
@@ -15,7 +15,7 @@ def build_godot_tools(source, target, env):
from .solution_builder import build_solution
- build_solution(env, solution_path, build_config, restore=True)
+ build_solution(env, solution_path, build_config)
# No need to copy targets. The GodotTools csproj takes care of copying them.
diff --git a/modules/mono/build_scripts/solution_builder.py b/modules/mono/build_scripts/solution_builder.py
index e8ddb7114e..371819fd72 100644
--- a/modules/mono/build_scripts/solution_builder.py
+++ b/modules/mono/build_scripts/solution_builder.py
@@ -4,7 +4,29 @@ import os
verbose = False
-def find_msbuild_unix(filename):
+def find_dotnet_cli():
+ import os.path
+
+ if os.name == "nt":
+ windows_exts = os.environ["PATHEXT"]
+ windows_exts = windows_exts.split(os.pathsep) if windows_exts else []
+
+ for hint_dir in os.environ["PATH"].split(os.pathsep):
+ hint_dir = hint_dir.strip('"')
+ hint_path = os.path.join(hint_dir, "dotnet")
+ if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK):
+ return hint_path
+ if os.path.isfile(hint_path + ".exe") and os.access(hint_path + ".exe", os.X_OK):
+ return hint_path + ".exe"
+ else:
+ for hint_dir in os.environ["PATH"].split(os.pathsep):
+ hint_dir = hint_dir.strip('"')
+ hint_path = os.path.join(hint_dir, "dotnet")
+ if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK):
+ return hint_path
+
+
+def find_msbuild_unix():
import os.path
import sys
@@ -86,15 +108,7 @@ def run_command(command, args, env_override=None, name=None):
raise RuntimeError("'%s' exited with error code: %s" % (name, e.returncode))
-def nuget_restore(env, *args):
- global verbose
- verbose = env["verbose"]
-
- # Do NuGet restore
- run_command(nuget_path, ["restore"] + list(args), name="nuget restore")
-
-
-def build_solution(env, solution_path, build_config, extra_msbuild_args=[], restore=False):
+def build_solution(env, solution_path, build_config, extra_msbuild_args=[]):
global verbose
verbose = env["verbose"]
@@ -104,27 +118,33 @@ def build_solution(env, solution_path, build_config, extra_msbuild_args=[], rest
if "PLATFORM" in msbuild_env:
del msbuild_env["PLATFORM"]
- # Find MSBuild
- if os.name == "nt":
- msbuild_info = find_msbuild_windows(env)
- if msbuild_info is None:
- raise RuntimeError("Cannot find MSBuild executable")
- msbuild_path = msbuild_info[0]
- msbuild_env.update(msbuild_info[1])
+ msbuild_args = []
+
+ dotnet_cli = find_dotnet_cli()
+
+ if dotnet_cli:
+ msbuild_path = dotnet_cli
+ msbuild_args += ["msbuild"] # `dotnet msbuild` command
else:
- msbuild_path = find_msbuild_unix("msbuild")
- if msbuild_path is None:
- raise RuntimeError("Cannot find MSBuild executable")
+ # Find MSBuild
+ if os.name == "nt":
+ msbuild_info = find_msbuild_windows(env)
+ if msbuild_info is None:
+ raise RuntimeError("Cannot find MSBuild executable")
+ msbuild_path = msbuild_info[0]
+ msbuild_env.update(msbuild_info[1])
+ else:
+ msbuild_path = find_msbuild_unix()
+ if msbuild_path is None:
+ raise RuntimeError("Cannot find MSBuild executable")
print("MSBuild path: " + msbuild_path)
# Build solution
- targets = ["Build"]
- if restore:
- targets.insert(0, "Restore")
+ targets = ["Restore", "Build"]
- msbuild_args = [solution_path, "/t:%s" % ",".join(targets), "/p:Configuration=" + build_config]
+ msbuild_args += [solution_path, "/t:%s" % ",".join(targets), "/p:Configuration=" + build_config]
msbuild_args += extra_msbuild_args
run_command(msbuild_path, msbuild_args, env_override=msbuild_env, name="msbuild")