-
Notifications
You must be signed in to change notification settings - Fork 11
/
configure.py
145 lines (115 loc) · 4.72 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
138
139
140
141
142
143
144
145
#!/usr/bin/python
# plugin names, relative to `scripting/`
plugins = [
'cwx.sp',
'cwx_equip_commands.sp',
]
# files to copy to builddir, relative to root
# plugin names from previous list will be copied automatically
copy_files = [
"configs/cwx/example_items.txt",
"gamedata/tf2.custom_weapons_x.txt",
"scripting/include/cwx.inc",
"scripting/cwx/item_config.sp",
"scripting/cwx/item_entity.sp",
"scripting/cwx/item_export.sp",
"scripting/cwx/loadout_entries.sp",
"scripting/cwx/loadout_radio_menu.sp",
"translations/cwx.phrases.txt",
]
# additional directories for sourcepawn include lookup
# `scripting/include` is explicitly included
include_dirs = [
'${builddir}/generated_code',
'third_party/include_submodules',
'third_party/vendored'
]
# required version of spcomp (presumably pinned to SM version)
spcomp_min_version = (1, 10)
########################
# 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()
spcomp = misc.spcomp_util.locate_compiler(args.spcomp_dir)
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 = {
'python': sys.executable,
'configure_args': 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 = '${python} ${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()
if os.path.exists('.git'):
# regenerate dyndep whenever .git/HEAD changes
# update dyndep file to point to our new HEAD ref
build.rule('versioning',
command = '${python} ${root}/misc/autoversion.py dyndep ${out}',
description = "Determining current git HEAD ref")
version_dyndep, *_ = build.build('${builddir}/generated_code/autoversioning/version.inc.dd', 'versioning', implicit = '.git/HEAD')
build.newline()
# regenerate versioning whenever our HEAD ref changes
build.rule('autoversion',
command = '${python} ${root}/misc/autoversion.py include ${out}',
description = "Building automatic version include")
version_include = build.build('${builddir}/generated_code/autoversioning/version.inc', 'autoversion',
implicit = version_dyndep, dyndep = version_dyndep)
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, implicit = version_include)
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)))