-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild_plugin.py
82 lines (71 loc) · 2.79 KB
/
build_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os, sys
from contextlib import contextmanager, suppress
#================================================================
# # About
# Plugin build script.
#
# # Arguments
# [1] BUILD_DIR - Location of the build folder.
# [2] PROJECT_DIR - Directory containing vcxproj file.
# [3] PLATFORM_TOOLSET - Toolset to compile the plugin with.
# [4] F4SE_REVISION - Which commit of F4SE to use for compilation.
#================================================================
#===================
# Configuration
#===================
# Get arguments
if len(sys.argv) > 3:
BUILD_DIR = sys.argv[1]
PROJECT_DIR = sys.argv[2]
PLATFORM_TOOLSET = sys.argv[3]
F4SE_REVISION = sys.argv[4]
else:
print('FATAL: Invalid arguments.')
sys.exit(1)
F4SE_REPO = 'https://github.com/osvein/f4se-mirror.git'
# Location of files generated by build tools
BUILD_PROJECT = os.path.join(PROJECT_DIR, 'build.vcxproj')
BUILD_SOLUTION = os.path.join(BUILD_DIR , 'build.sln')
#===================
# Utilities
#===================
@contextmanager
def cd(newdir):
prevdir = os.getcwd()
os.chdir(newdir)
try:
yield
finally:
os.chdir(prevdir)
#===================
# Build
#===================
# Fetch F4SE
if not os.path.exists('{}/f4se'.format(BUILD_DIR)):
os.system('git clone {} {}/f4se'.format(F4SE_REPO, BUILD_DIR))
with cd('{}/f4se'.format(BUILD_DIR)):
os.system('git checkout {}'.format(F4SE_REVISION))
f4se_dir = os.path.abspath('{}/f4se/src/f4se'.format(BUILD_DIR)).replace('\\', '/')
src_dir = os.path.abspath('{}/f4se/src'.format(BUILD_DIR)).replace('\\', '/')
# Run build tools
BUILD_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
prepOK = 0 # exit code 0 == success
prepOK |= os.system('python {}/patch_f4se.py "{}"'.format(BUILD_TOOLS_DIR, f4se_dir))
prepOK |= os.system('python {}/update_project_references.py "{}" "{}" "{}"'.format(BUILD_TOOLS_DIR, PROJECT_DIR, f4se_dir, BUILD_PROJECT))
prepOK |= os.system('python {}/make_solution.py "{}" "{}"'.format(BUILD_TOOLS_DIR, PROJECT_DIR, BUILD_SOLUTION))
# Build project
buildOK = 1 # exit code 1 == failed
if prepOK == 0:
os.environ['INCLUDE'] = '{};{};{}'.format(f4se_dir, src_dir, os.environ['INCLUDE'])
buildOK = os.system('msbuild {} /p:PlatformToolset={} /p:UseEnv=true /p:Configuration=Release'.format(BUILD_DIR, PLATFORM_TOOLSET))
# Clean files generated by build tools
with suppress(FileNotFoundError):
os.remove(BUILD_PROJECT)
os.remove(BUILD_SOLUTION)
# Package plugin
if os.path.exists('dist'):
PLUGIN_LOCATION_PATTERN = '{}/x64/Release/*.dll'.format(BUILD_DIR)
DIST_DIR = 'dist'
packageOK = os.system('python {}/package_plugin.py "{}" "{}" "{}" "{}"'.format(BUILD_TOOLS_DIR, PLUGIN_LOCATION_PATTERN, DIST_DIR, BUILD_DIR, PROJECT_DIR))
# Report result
sys.exit(buildOK)