-
Notifications
You must be signed in to change notification settings - Fork 7
/
configure.py
128 lines (103 loc) · 4.16 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
#!/usr/bin/python
# plugin names, relative to `scripting/`
plugins = [
"tf_econ_data.sp",
]
# files to copy to builddir, relative to root
# plugin names from previous list will be copied automatically
copy_files = [
"gamedata/tf2.econ_data.txt",
"scripting/include/tf_econ_data.inc",
"scripting/tf_econ_data/attached_particle_systems.sp",
"scripting/tf_econ_data/attribute_definition.sp",
"scripting/tf_econ_data/equip_regions.sp",
"scripting/tf_econ_data/item_definition.sp",
"scripting/tf_econ_data/keyvalues.sp",
"scripting/tf_econ_data/loadout_slot.sp",
"scripting/tf_econ_data/paintkit_definition.sp",
"scripting/tf_econ_data/quality_definition.sp",
"scripting/tf_econ_data/rarity_definition.sp",
]
# additional directories for sourcepawn include lookup
include_dirs = [
'${root}/scripting/include'
]
# required version of spcomp (presumably pinned to SM version)
spcomp_min_version = (1, 9)
########################
# 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 shutil
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)))
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': sys.argv[1:],
'root': '.',
'builddir': 'build',
'spcomp': spcomp,
'spcflags': [ '-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)))