2019-03-01 20:51:20 +00:00
|
|
|
import os
|
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
|
|
|
|
verbose = False
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def find_msbuild_unix(filename):
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
2020-05-09 15:09:49 +00:00
|
|
|
hint_dirs = []
|
2020-03-30 06:28:32 +00:00
|
|
|
if sys.platform == "darwin":
|
2020-05-09 15:09:49 +00:00
|
|
|
hint_dirs[:0] = [
|
2020-03-30 06:28:32 +00:00
|
|
|
"/Library/Frameworks/Mono.framework/Versions/Current/bin",
|
|
|
|
"/usr/local/var/homebrew/linked/mono/bin",
|
2020-05-09 15:09:49 +00:00
|
|
|
]
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
for hint_dir in hint_dirs:
|
2020-05-09 15:09:49 +00:00
|
|
|
hint_path = os.path.join(hint_dir, "msbuild")
|
2019-03-01 20:51:20 +00:00
|
|
|
if os.path.isfile(hint_path):
|
|
|
|
return hint_path
|
2020-03-30 06:28:32 +00:00
|
|
|
elif os.path.isfile(hint_path + ".exe"):
|
|
|
|
return hint_path + ".exe"
|
2019-03-01 20:51:20 +00:00
|
|
|
|
2020-03-30 06:28:32 +00:00
|
|
|
for hint_dir in os.environ["PATH"].split(os.pathsep):
|
2019-03-01 20:51:20 +00:00
|
|
|
hint_dir = hint_dir.strip('"')
|
2020-05-09 15:09:49 +00:00
|
|
|
hint_path = os.path.join(hint_dir, "msbuild")
|
2019-03-01 20:51:20 +00:00
|
|
|
if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK):
|
|
|
|
return hint_path
|
2020-03-30 06:28:32 +00:00
|
|
|
if os.path.isfile(hint_path + ".exe") and os.access(hint_path + ".exe", os.X_OK):
|
|
|
|
return hint_path + ".exe"
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def find_msbuild_windows(env):
|
2020-03-30 06:28:32 +00:00
|
|
|
from .mono_reg_utils import find_mono_root_dir, find_msbuild_tools_path_reg
|
2019-05-20 16:34:35 +00:00
|
|
|
|
2020-03-30 06:28:32 +00:00
|
|
|
mono_root = env["mono_prefix"] or find_mono_root_dir(env["bits"])
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
if not mono_root:
|
2020-03-30 06:28:32 +00:00
|
|
|
raise RuntimeError("Cannot find mono root directory")
|
2019-03-01 20:51:20 +00:00
|
|
|
|
2020-03-30 06:28:32 +00:00
|
|
|
mono_bin_dir = os.path.join(mono_root, "bin")
|
|
|
|
msbuild_mono = os.path.join(mono_bin_dir, "msbuild.bat")
|
2019-03-01 20:51:20 +00:00
|
|
|
|
2019-07-09 14:48:53 +00:00
|
|
|
msbuild_tools_path = find_msbuild_tools_path_reg()
|
|
|
|
|
|
|
|
if msbuild_tools_path:
|
2020-03-30 06:28:32 +00:00
|
|
|
return (os.path.join(msbuild_tools_path, "MSBuild.exe"), {})
|
2019-07-09 14:48:53 +00:00
|
|
|
|
2019-03-01 20:51:20 +00:00
|
|
|
if os.path.isfile(msbuild_mono):
|
|
|
|
# The (Csc/Vbc/Fsc)ToolExe environment variables are required when
|
|
|
|
# building with Mono's MSBuild. They must point to the batch files
|
|
|
|
# in Mono's bin directory to make sure they are executed with Mono.
|
|
|
|
mono_msbuild_env = {
|
2020-03-30 06:28:32 +00:00
|
|
|
"CscToolExe": os.path.join(mono_bin_dir, "csc.bat"),
|
|
|
|
"VbcToolExe": os.path.join(mono_bin_dir, "vbc.bat"),
|
|
|
|
"FscToolExe": os.path.join(mono_bin_dir, "fsharpc.bat"),
|
2019-03-01 20:51:20 +00:00
|
|
|
}
|
2019-07-10 11:19:52 +00:00
|
|
|
return (msbuild_mono, mono_msbuild_env)
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
def run_command(command, args, env_override=None, name=None):
|
|
|
|
def cmd_args_to_str(cmd_args):
|
2020-03-30 06:28:32 +00:00
|
|
|
return " ".join([arg if not " " in arg else '"%s"' % arg for arg in cmd_args])
|
2019-07-03 07:44:53 +00:00
|
|
|
|
|
|
|
args = [command] + args
|
|
|
|
|
|
|
|
if name is None:
|
|
|
|
name = os.path.basename(command)
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print("Running '%s': %s" % (name, cmd_args_to_str(args)))
|
|
|
|
|
2019-03-01 20:51:20 +00:00
|
|
|
import subprocess
|
2020-03-30 06:28:32 +00:00
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
try:
|
|
|
|
if env_override is None:
|
|
|
|
subprocess.check_call(args)
|
|
|
|
else:
|
|
|
|
subprocess.check_call(args, env=env_override)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
raise RuntimeError("'%s' exited with error code: %s" % (name, e.returncode))
|
|
|
|
|
|
|
|
|
|
|
|
def nuget_restore(env, *args):
|
|
|
|
global verbose
|
2020-03-30 06:28:32 +00:00
|
|
|
verbose = env["verbose"]
|
2019-07-03 07:44:53 +00:00
|
|
|
|
|
|
|
# Do NuGet restore
|
2020-03-30 06:28:32 +00:00
|
|
|
run_command(nuget_path, ["restore"] + list(args), name="nuget restore")
|
2019-07-03 07:44:53 +00:00
|
|
|
|
|
|
|
|
2020-05-09 15:09:49 +00:00
|
|
|
def build_solution(env, solution_path, build_config, extra_msbuild_args=[], restore=False):
|
2019-07-03 07:44:53 +00:00
|
|
|
global verbose
|
2020-03-30 06:28:32 +00:00
|
|
|
verbose = env["verbose"]
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
msbuild_env = os.environ.copy()
|
|
|
|
|
|
|
|
# Needed when running from Developer Command Prompt for VS
|
2020-03-30 06:28:32 +00:00
|
|
|
if "PLATFORM" in msbuild_env:
|
|
|
|
del msbuild_env["PLATFORM"]
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
# Find MSBuild
|
2020-03-30 06:28:32 +00:00
|
|
|
if os.name == "nt":
|
2019-03-01 20:51:20 +00:00
|
|
|
msbuild_info = find_msbuild_windows(env)
|
|
|
|
if msbuild_info is None:
|
2020-03-30 06:28:32 +00:00
|
|
|
raise RuntimeError("Cannot find MSBuild executable")
|
2019-03-01 20:51:20 +00:00
|
|
|
msbuild_path = msbuild_info[0]
|
2019-07-10 11:19:52 +00:00
|
|
|
msbuild_env.update(msbuild_info[1])
|
2019-03-01 20:51:20 +00:00
|
|
|
else:
|
2020-03-30 06:28:32 +00:00
|
|
|
msbuild_path = find_msbuild_unix("msbuild")
|
2019-03-01 20:51:20 +00:00
|
|
|
if msbuild_path is None:
|
2020-05-09 15:09:49 +00:00
|
|
|
raise RuntimeError("Cannot find MSBuild executable")
|
2019-03-01 20:51:20 +00:00
|
|
|
|
2020-03-30 06:28:32 +00:00
|
|
|
print("MSBuild path: " + msbuild_path)
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
# Build solution
|
|
|
|
|
2020-05-09 15:09:49 +00:00
|
|
|
targets = ["Build"]
|
|
|
|
if restore:
|
|
|
|
targets.insert(0, "Restore")
|
|
|
|
|
|
|
|
msbuild_args = [solution_path, "/t:%s" % ",".join(targets), "/p:Configuration=" + build_config]
|
2019-07-03 07:44:53 +00:00
|
|
|
msbuild_args += extra_msbuild_args
|
2019-03-01 20:51:20 +00:00
|
|
|
|
2020-03-30 06:28:32 +00:00
|
|
|
run_command(msbuild_path, msbuild_args, env_override=msbuild_env, name="msbuild")
|