forked from Szwagi/cs2docker-autorestart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageScript
More file actions
128 lines (96 loc) · 3.88 KB
/
Copy pathPackageScript
File metadata and controls
128 lines (96 loc) · 3.88 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
# 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, sdk_name):
self.sdk_name = sdk_name
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.addBinFolder(cxx)
self.generateVDF()
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), 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))
)
packages = dict()
for sdk_target in MMSPlugin.sdk_targets:
sdk = sdk_target.sdk
cxx = sdk_target.cxx
packages[sdk["name"]] = SDKPackage(cxx, sdk["name"])
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]
packages[sdk_name].addBinary(task.binary)
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")