forked from blueblur0730/modified-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.py
More file actions
194 lines (161 loc) · 7.1 KB
/
configure.py
File metadata and controls
194 lines (161 loc) · 7.1 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/python
# additional directories for sourcepawn include lookup. relative to root.
include_dirs = [
'personal_sourcepawn_library_env'
]
# copy the include files generated by our plugins into the build output
release_include_dirs = [
'include',
]
########################
# 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
import glob
# destination directory for sourcepawn files. relative to root.
destination_dir = [
os.path.relpath(d, '.') for d in glob.glob('source/*') if os.path.isdir(d)
]
parser = argparse.ArgumentParser('Configures the project.')
parser.add_argument('--spcomp-dir', type = str,
help = 'Directory with the SourcePawn compiler. Will check PATH if not specified.')
parser.add_argument('--no-source', action = 'store_true', default = False,
help = 'Do not copy the source file into the build result.')
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.')
# required version of spcomp (presumably pinned to SM version)
# spcomp_min_version = (1, 12)
# 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}', '-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 `destination_dir` list""")
for dest_dir in destination_dir:
dir = os.path.normpath(os.path.join(vars['root'], dest_dir, 'scripting'))
for root, dirs, files in os.walk(dir):
if not args.no_source:
for file in files:
# Copy all files
file_path = os.path.join(root, file)
dist_sp = os.path.normpath(os.path.join(vars['builddir'], file_path))
build.build(dist_sp, 'copy', file_path)
build.newline()
for subdir in dirs:
# Add this directory as an include path
root_subdir = os.path.join(root, subdir)
include_path = '-i {}'.format(root_subdir)
if include_path not in vars['spcflags']:
vars['spcflags'] += include_path
# Ignore if there's no source files.
if not os.path.isdir(dir):
continue
# Only process files in the top-level scripting directory
for file in os.listdir(dir):
file_path = os.path.join(dir, file)
if os.path.isfile(file_path):
if file.endswith('.sp'): # Only compile .sp files
smx_plugin = os.path.splitext(file)[0] + '.smx'
smx_file = os.path.normpath(os.path.join(vars['builddir'], dest_dir, 'plugins', smx_plugin))
build.build(smx_file, 'spcomp', file_path) # Compile SourcePawn files to SMX
build.newline()
build.newline()
build.comment("""Copy other files from source tree""")
for filepath in destination_dir:
dir_data = os.path.normpath(os.path.join(vars['root'], filepath, 'data'))
for root, subdir_data, files in os.walk(dir_data):
for file in files:
filepath_data = os.path.join(root, file)
dist_to_copy = os.path.normpath(os.path.join(vars['builddir'], filepath_data))
build.build(dist_to_copy, 'copy', os.path.normpath(os.path.join(vars['root'], filepath_data)))
build.newline()
dir_configs = os.path.normpath(os.path.join(vars['root'], filepath, 'configs'))
for root, subdir_configs, files in os.walk(dir_configs):
for file in files:
filepath_configs = os.path.join(root, file)
dist_to_copy = os.path.normpath(os.path.join(vars['builddir'], filepath_configs))
build.build(dist_to_copy, 'copy', os.path.normpath(os.path.join(vars['root'], filepath_configs)))
build.newline()
dir_gamedata = os.path.normpath(os.path.join(vars['root'], filepath, 'gamedata'))
for root, subdir_gamedata, files in os.walk(dir_gamedata):
for file in files:
filepath_gamedata = os.path.join(root, file)
dist_to_copy = os.path.normpath(os.path.join(vars['builddir'], filepath_gamedata))
build.build(dist_to_copy, 'copy', os.path.normpath(os.path.join(vars['root'], filepath_gamedata)))
build.newline()
dir_translations = os.path.normpath(os.path.join(vars['root'], filepath, 'translations'))
for root, subdir_translations, files in os.walk(dir_translations):
for file in files:
filepath_translations = os.path.join(root, file)
dist_to_copy = os.path.normpath(os.path.join(vars['builddir'], filepath_translations))
build.build(dist_to_copy, 'copy', os.path.normpath(os.path.join(vars['root'], filepath_translations)))
build.newline()
# Copy other files in destination directory, usually a readme.
for file in os.listdir(filepath):
file_path = os.path.join(filepath, file)
if os.path.isfile(file_path):
dist_to_copy = os.path.normpath(os.path.join(vars['builddir'], file_path))
build.build(dist_to_copy, 'copy', os.path.normpath(os.path.join(vars['root'], file_path)))
build.newline()
build.newline()
build.comment("""Copy include files to build output""")
for include_dir in release_include_dirs:
include_path = os.path.normpath(os.path.join(vars['root'], include_dir))
for root, dirs, files in os.walk(include_path):
for file in files:
file_path = os.path.join(root, file)
dist_to_copy = os.path.normpath(os.path.join(vars['builddir'], 'include', file))
build.build(dist_to_copy, 'copy', file_path)