| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 09:44:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | verbose = False | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 22:56:35 +02: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 21:51:20 +01:00
										 |  |  |     import os.path | 
					
						
							|  |  |  |     import sys | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:09:49 +02:00
										 |  |  |     hint_dirs = [] | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if sys.platform == "darwin": | 
					
						
							| 
									
										
										
										
											2020-05-09 17:09:49 +02:00
										 |  |  |         hint_dirs[:0] = [ | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |             "/Library/Frameworks/Mono.framework/Versions/Current/bin", | 
					
						
							|  |  |  |             "/usr/local/var/homebrew/linked/mono/bin", | 
					
						
							| 
									
										
										
										
											2020-05-09 17:09:49 +02:00
										 |  |  |         ] | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for hint_dir in hint_dirs: | 
					
						
							| 
									
										
										
										
											2020-05-09 17:09:49 +02:00
										 |  |  |         hint_path = os.path.join(hint_dir, "msbuild") | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  |         if os.path.isfile(hint_path): | 
					
						
							|  |  |  |             return hint_path | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         elif os.path.isfile(hint_path + ".exe"): | 
					
						
							|  |  |  |             return hint_path + ".exe" | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     for hint_dir in os.environ["PATH"].split(os.pathsep): | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  |         hint_dir = hint_dir.strip('"') | 
					
						
							| 
									
										
										
										
											2020-05-09 17:09:49 +02:00
										 |  |  |         hint_path = os.path.join(hint_dir, "msbuild") | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  |         if os.path.isfile(hint_path) and os.access(hint_path, os.X_OK): | 
					
						
							|  |  |  |             return hint_path | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         if os.path.isfile(hint_path + ".exe") and os.access(hint_path + ".exe", os.X_OK): | 
					
						
							|  |  |  |             return hint_path + ".exe" | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def find_msbuild_windows(env): | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     from .mono_reg_utils import find_mono_root_dir, find_msbuild_tools_path_reg | 
					
						
							| 
									
										
										
										
											2019-05-20 18:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     mono_root = env["mono_prefix"] or find_mono_root_dir(env["bits"]) | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if not mono_root: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         raise RuntimeError("Cannot find mono root directory") | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     mono_bin_dir = os.path.join(mono_root, "bin") | 
					
						
							|  |  |  |     msbuild_mono = os.path.join(mono_bin_dir, "msbuild.bat") | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-09 16:48:53 +02:00
										 |  |  |     msbuild_tools_path = find_msbuild_tools_path_reg() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if msbuild_tools_path: | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         return (os.path.join(msbuild_tools_path, "MSBuild.exe"), {}) | 
					
						
							| 
									
										
										
										
											2019-07-09 16:48:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01: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 08:28:32 +02: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 21:51:20 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-07-10 13:19:52 +02:00
										 |  |  |         return (msbuild_mono, mono_msbuild_env) | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 09:44:53 +02:00
										 |  |  | def run_command(command, args, env_override=None, name=None): | 
					
						
							|  |  |  |     def cmd_args_to_str(cmd_args): | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |         return " ".join([arg if not " " in arg else '"%s"' % arg for arg in cmd_args]) | 
					
						
							| 
									
										
										
										
											2019-07-03 09:44:53 +02: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 21:51:20 +01:00
										 |  |  |     import subprocess | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 09:44:53 +02: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 22:56:35 +02:00
										 |  |  | def build_solution(env, solution_path, build_config, extra_msbuild_args=[]): | 
					
						
							| 
									
										
										
										
											2019-07-03 09:44:53 +02:00
										 |  |  |     global verbose | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     verbose = env["verbose"] | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     msbuild_env = os.environ.copy() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Needed when running from Developer Command Prompt for VS | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     if "PLATFORM" in msbuild_env: | 
					
						
							|  |  |  |         del msbuild_env["PLATFORM"] | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 22:56:35 +02:00
										 |  |  |     msbuild_args = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dotnet_cli = find_dotnet_cli() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if dotnet_cli: | 
					
						
							|  |  |  |         msbuild_path = dotnet_cli | 
					
						
							|  |  |  |         msbuild_args += ["msbuild"]  # `dotnet msbuild` command | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2020-05-10 22:56:35 +02: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 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     print("MSBuild path: " + msbuild_path) | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Build solution | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-25 23:44:28 +02:00
										 |  |  |     msbuild_args += [solution_path, "/restore", "/t:Build", "/p:Configuration=" + build_config] | 
					
						
							| 
									
										
										
										
											2019-07-03 09:44:53 +02:00
										 |  |  |     msbuild_args += extra_msbuild_args | 
					
						
							| 
									
										
										
										
											2019-03-01 21:51:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:28:32 +02:00
										 |  |  |     run_command(msbuild_path, msbuild_args, env_override=msbuild_env, name="msbuild") |