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
|
|
|
|
|
|
|
|
2020-05-10 20:56:35 +00:00
|
|
|
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():
|
2019-03-01 20:51:20 +00:00
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
2020-05-09 15:09:49 +00:00
|
|
|
hint_dirs = []
|
|
|
|
if sys.platform == "darwin":
|
|
|
|
hint_dirs[:0] = [
|
|
|
|
"/Library/Frameworks/Mono.framework/Versions/Current/bin",
|
|
|
|
"/usr/local/var/homebrew/linked/mono/bin",
|
|
|
|
]
|
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
|
|
|
|
elif os.path.isfile(hint_path + '.exe'):
|
|
|
|
return hint_path + '.exe'
|
|
|
|
|
|
|
|
for hint_dir in os.environ['PATH'].split(os.pathsep):
|
|
|
|
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
|
|
|
|
if os.path.isfile(hint_path + '.exe') and os.access(hint_path + '.exe', os.X_OK):
|
|
|
|
return hint_path + '.exe'
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def find_msbuild_windows(env):
|
2019-05-20 16:34:35 +00:00
|
|
|
from . mono_reg_utils import find_mono_root_dir, find_msbuild_tools_path_reg
|
|
|
|
|
|
|
|
mono_root = env['mono_prefix'] or find_mono_root_dir(env['bits'])
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
if not mono_root:
|
|
|
|
raise RuntimeError('Cannot find mono root directory')
|
|
|
|
|
|
|
|
mono_bin_dir = os.path.join(mono_root, 'bin')
|
|
|
|
msbuild_mono = os.path.join(mono_bin_dir, 'msbuild.bat')
|
|
|
|
|
2019-07-09 14:48:53 +00:00
|
|
|
msbuild_tools_path = find_msbuild_tools_path_reg()
|
|
|
|
|
|
|
|
if msbuild_tools_path:
|
2019-07-10 11:19:52 +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 = {
|
|
|
|
'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-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):
|
|
|
|
return ' '.join([arg if not ' ' in arg else '"%s"' % arg for arg in cmd_args])
|
|
|
|
|
|
|
|
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
|
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))
|
|
|
|
|
|
|
|
|
2020-05-10 20:56:35 +00:00
|
|
|
def build_solution(env, solution_path, build_config, extra_msbuild_args=[]):
|
2019-07-03 07:44:53 +00:00
|
|
|
global verbose
|
|
|
|
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
|
|
|
|
if 'PLATFORM' in msbuild_env:
|
|
|
|
del msbuild_env['PLATFORM']
|
|
|
|
|
2020-05-10 20:56:35 +00:00
|
|
|
msbuild_args = []
|
|
|
|
|
|
|
|
dotnet_cli = find_dotnet_cli()
|
|
|
|
|
|
|
|
if dotnet_cli:
|
|
|
|
msbuild_path = dotnet_cli
|
|
|
|
msbuild_args += ["msbuild"] # `dotnet msbuild` command
|
2019-03-01 20:51:20 +00:00
|
|
|
else:
|
2020-05-10 20:56:35 +00:00
|
|
|
# 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")
|
2019-03-01 20:51:20 +00:00
|
|
|
|
|
|
|
print('MSBuild path: ' + msbuild_path)
|
|
|
|
|
|
|
|
# Build solution
|
|
|
|
|
2020-05-10 20:56:35 +00:00
|
|
|
targets = ["Restore", "Build"]
|
2020-05-09 15:09:49 +00:00
|
|
|
|
2020-05-10 20:56:35 +00:00
|
|
|
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
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
run_command(msbuild_path, msbuild_args, env_override=msbuild_env, name='msbuild')
|