generated from nosoop/NinjaBuild-SMPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
137 lines (111 loc) · 4.22 KB
/
configure.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python
# plugin names, relative to `scripting/`
plugins = [
'brave_double_jump.sp',
'ff2r_arm.sp',
'ff2r_difficulty_reward.sp',
'ff2r_dynamic_behavior.sp',
'ff2r_playanimation.sp',
'ff2r_rage_sniper.sp',
'ff2r_ragemodel.sp',
'ff2r_tauntkillmods.sp',
'ff2r_tfcondition.sp'
]
# files to copy to builddir, relative to root
# plugin names from previous list will be copied automatically
copy_files = [
'gamedata/ff2r.sandy.txt',
'translations/ff2r_doublejump.phrases.txt'
]
# additional directories for sourcepawn include lookup
# `scripting/include` is explicitly included
include_dirs = [
'third_party/submodules',
'third_party/vendored'
]
# required version of spcomp (presumably pinned to SM version)
spcomp_min_version = (1, 11)
########################
# build.ninja script generation below.
import contextlib
import misc.ninja_syntax as ninja_syntax
import misc.spcomp_util
import os
import sys
import argparse
import platform
import shlex
import shutil
import subprocess
parser = argparse.ArgumentParser('Configures the project.')
parser.add_argument('--spcomp-dir',
help = 'Directory with the SourcePawn compiler. Will check PATH if not specified.')
args = parser.parse_args()
print("""Checking for SourcePawn compiler...""")
spcomp = shutil.which('spcomp', path = args.spcomp_dir)
if 'x86_64' in platform.machine():
# Use 64-bit spcomp if architecture supports it
spcomp = shutil.which('spcomp64', path = args.spcomp_dir) or spcomp
if not spcomp:
raise FileNotFoundError('Could not find SourcePawn compiler.')
available_version = misc.spcomp_util.extract_version(spcomp)
version_string = '.'.join(map(str, available_version))
print('Found SourcePawn compiler version', version_string, 'at', os.path.abspath(spcomp))
if spcomp_min_version > available_version:
raise ValueError("Failed to meet required compiler version "
+ '.'.join(map(str, spcomp_min_version)))
# properly handle quoting within params
if platform.system() == "Windows":
arg_list = subprocess.list2cmdline
else:
arg_list = shlex.join
with contextlib.closing(ninja_syntax.Writer(open('build.ninja', 'wt'))) as build:
build.comment('This file is used to build SourceMod plugins with ninja.')
build.comment('The file is automatically generated by configure.py')
build.newline()
vars = {
'configure_args': arg_list(sys.argv[1:]),
'root': '.',
'builddir': 'build',
'spcomp': spcomp,
'spcflags': [ '-i${root}/scripting/include', '-h', '-v0' ]
}
vars['spcflags'] += ('-i{}'.format(d) for d in include_dirs)
for key, value in vars.items():
build.variable(key, value)
build.newline()
build.comment("""Regenerate build files if build script changes.""")
build.rule('configure',
command = sys.executable + ' ${root}/configure.py ${configure_args}',
description = 'Reconfiguring build', generator = 1)
build.build('build.ninja', 'configure',
implicit = [ '${root}/configure.py', '${root}/misc/ninja_syntax.py' ])
build.newline()
build.rule('spcomp', deps = 'msvc',
command = '"${spcomp}" ${in} ${spcflags} -o ${out}',
description = 'Compiling ${out}')
build.newline()
# Platform-specific copy instructions
if platform.system() == "Windows":
build.rule('copy', command = 'cmd /c copy ${in} ${out} > NUL',
description = 'Copying ${out}')
elif platform.system() == "Linux":
build.rule('copy', command = 'cp ${in} ${out}', description = 'Copying ${out}')
build.newline()
build.comment("""Compile plugins specified in `plugins` list""")
for plugin in plugins:
smx_plugin = os.path.splitext(plugin)[0] + '.smx'
sp_file = os.path.normpath(os.path.join('$root', 'scripting', plugin))
smx_file = os.path.normpath(os.path.join('$builddir', 'plugins', smx_plugin))
build.build(smx_file, 'spcomp', sp_file)
build.newline()
build.comment("""Copy plugin sources to build output""")
for plugin in plugins:
sp_file = os.path.normpath(os.path.join('$root', 'scripting', plugin))
dist_sp = os.path.normpath(os.path.join('$builddir', 'scripting', plugin))
build.build(dist_sp, 'copy', sp_file)
build.newline()
build.comment("""Copy other files from source tree""")
for filepath in copy_files:
build.build(os.path.normpath(os.path.join('$builddir', filepath)), 'copy',
os.path.normpath(os.path.join('$root', filepath)))