SpiecsEngine
 
Loading...
Searching...
No Matches
Build.py
Go to the documentation of this file.
1'''
2@files Build.py.
3@brief Build Spices Solution.
4@author Spices.
5'''
6
7import subprocess
8import argparse
9import os
10
11'''
12@brief vswhere path.
13'''
14vswhere_path : str = r"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
15
17
18 '''
19 @brief Find MSBuild path.
20 @return Returns MSBuild path.
21 '''
22
23 global vswhere_path
24
25 result = subprocess.run([
26 vswhere_path,
27 "-latest",
28 "-products",
29 "*",
30 "-requires",
31 "Microsoft.Component.MSBuild",
32 "-find",
33 "MSBuild\**\Bin\MSBuild.exe"],
34 capture_output = True,
35 text = True
36 )
37
38 if result.returncode == 0 and result.stdout:
39 return result.stdout.strip()
40 else:
41 raise Exception("Could not find MSBuild")
42
43def main():
44
45 '''
46 @brief Build Spices Solution with configuration.
47 '''
48
49 parser = argparse.ArgumentParser(description='Build Spices Solution')
50 parser.add_argument('--target' , type=str, required=True, help='target solution, e.g. C:/')
51 parser.add_argument('--configuration', type=str, required=True, help='target solution build configuration, e.g. C:/')
52 parser.add_argument('--platform' , type=str, required=True, help='target solution build platform, e.g. C:/')
53 args = parser.parse_args()
54
55 if not os.path.isfile(args.target):
56 raise Exception('Invalid argument for --target: {}'.format(args.target))
57
58 msbuild_path = find_msbuild()
59 solution_path = args.target
60
61 # Solution Build Command
62 build_command = [
63 msbuild_path,
64 solution_path,
65 "/p:Configuration=" + args.configuration,
66 "/p:Platform=" + args.platform,
67 "/v:m" # Set minimal detail level
68 ]
69
70 # Execute Build
71 process = subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
72
73 # Output Build result
74 try:
75 for line in process.stdout:
76 print(line, end='')
77 except KeyboardInterrupt:
78 print("\nBuild interrupted by user.")
79 process.terminate()
80 process.wait()
81 return
82
83 # Wait for Build
84 process.wait()
85
86 if process.returncode == 0:
87 print("Build Succeed")
88 else:
89 print("Build Failed, Error Code:", process.returncode)
90
91if __name__ == '__main__':
92 main()
main()
Definition Build.py:43
find_msbuild()
Definition Build.py:16