-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPackageScript
More file actions
140 lines (103 loc) · 4.9 KB
/
PackageScript
File metadata and controls
140 lines (103 loc) · 4.9 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
# vim: set ts=2 sw=2 tw=99 noet ft=python:
import os
import glob
builder.SetBuildFolder('package')
class SDKPackage:
sdk_name = None
plugin_folder_path = None
plugin_folder = None
metamod_path = None
metamod = None
bin_path = None
bin = None
def __init__(self, cxx):
self.plugin_folder_path = os.path.join('addons', MMSPlugin.metadata['name'])
self.plugin_folder = builder.AddFolder(self.plugin_folder_path)
self.metamod_path = os.path.join('addons', 'metamod')
self.metamod = builder.AddFolder(self.metamod_path)
self.gamedata_folder_path = os.path.join('addons', MMSPlugin.metadata['name'], 'gamedata')
self.gamedata_folder = builder.AddFolder(self.gamedata_folder_path)
self.mode_folder_path = os.path.join('addons', MMSPlugin.metadata['name'], 'modes')
self.mode_folder = builder.AddFolder(self.mode_folder_path)
self.style_folder_path = os.path.join('addons', MMSPlugin.metadata['name'], 'styles')
self.style_folder = builder.AddFolder(self.style_folder_path)
self.translations_folder_path = os.path.join('addons', MMSPlugin.metadata['name'], 'translations')
self.translations_folder = builder.AddFolder(self.translations_folder_path)
self.addBinFolder(cxx)
self.generateVDF()
builder.AddCopy(os.path.join(builder.buildPath, '../gamedata', 'cs2surf-core.games.txt'), self.gamedata_folder)
for filename in os.listdir(os.path.join(builder.buildPath, '../cfg')):
builder.AddCopy(os.path.join(builder.buildPath, '../cfg', filename), builder.AddFolder('cfg'))
for filename in os.listdir(os.path.join(builder.buildPath, '../translations')):
builder.AddCopy(os.path.join(builder.buildPath, '../translations', filename), self.translations_folder)
def addBinFolder(self, cxx):
platform64_path_map = {
'windows': 'win64',
'linux': 'linuxsteamrt64',
'mac': 'osx64'
}
if cxx.target.arch == 'x86_64':
self.bin_path = os.path.join(self.plugin_folder_path, 'bin', platform64_path_map[cxx.target.platform])
else:
self.bin_path = os.path.join(self.plugin_folder_path, 'bin')
self.bin = builder.AddFolder(self.bin_path)
def generateVDF(self):
vdf_content = '"Metamod Plugin"\n'
vdf_content += '{\n'
vdf_content += f'\t"alias"\t"{MMSPlugin.metadata["alias"]}"\n'
vdf_content += f'\t"file"\t"{os.path.join(os.path.relpath(self.bin_path, self.sdk_name), MMSPlugin.metadata["name"])}"\n'
vdf_content += '}'
builder.AddOutputFile(os.path.join(self.metamod_path, f'{MMSPlugin.metadata["name"]}.vdf'), vdf_content.encode('utf8'))
def addBinary(self, binary):
(_, plugin_bin_name) = os.path.split(binary.path)
plugin_bin_ext = os.path.splitext(plugin_bin_name)[1]
builder.AddCopy(binary, os.path.join(self.bin_path, MMSPlugin.metadata['name'] + plugin_bin_ext))
# Adds file relative to plugin folder
def addFile(self, file_path, result_path = None):
if not os.path.isabs(file_path):
file_path = os.path.join(builder.sourcePath, file_path)
if result_path is None:
result_path = os.path.join(self.plugin_folder_path, os.path.basename(file_path))
else:
result_path = os.path.join(self.plugin_folder_path, result_path)
builder.AddFolder(os.path.dirname(result_path))
builder.AddCopy(file_path, result_path)
# Adds directory relative to plugins folder
def addFolder(self, folder_path, result_path = None, search_ext = '*', recursive = True):
if not os.path.isabs(folder_path):
folder_path = os.path.join(builder.sourcePath, folder_path)
if result_path is None:
result_path = os.path.join(self.plugin_folder_path, os.path.basename(folder_path))
search_param = f'*.{search_ext}'
if recursive:
search_param = os.path.join('**', search_param)
for file in glob.glob(os.path.join(folder_path, search_param), recursive = recursive):
self.addFile(file, os.path.join(result_path, os.path.relpath(file, folder_path)))
sdk_target = MMSPlugin.sdk_target
sdk = sdk_target.sdk
cxx = sdk_target.cxx
package = SDKPackage(cxx)
pdb_list = []
for task in MMSPlugin.binaries:
# Determine which sdk this binary belongs to since we encode it in its name
binary_filename = os.path.splitext(os.path.basename(task.binary.path))[0]
sdk_name = binary_filename.split('.')[-1]
package.addBinary(task.binary)
# Add custom stuff here
# Examples:
# package.addFolder('some_folder_with_files')
# package.addFile('configs/config.cfg', 'other/new_name_for_a_config.cfg')
if task.debug:
pdb_list.append(task.debug)
for task in MMSPlugin.mode_binaries:
builder.AddCopy(task.binary, package.mode_folder)
if task.debug:
pdb_list.append(task.debug)
for task in MMSPlugin.style_binaries:
builder.AddCopy(task.binary, package.style_folder)
if task.debug:
pdb_list.append(task.debug)
# Generate PDB info.
with open(os.path.join(builder.buildPath, 'pdblog.txt'), 'wt') as fp:
for line in pdb_list:
fp.write(line.path + '\n')