-
Notifications
You must be signed in to change notification settings - Fork 3
/
wlancaf-merge.py
264 lines (244 loc) · 9.82 KB
/
wlancaf-merge.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Copyright (C) 2019 Adek Maulana
#
# A simple script to add/update QCACLD or PRIMA into/for your,
# Android kernel source. *only qcacld-3.0 and prima were supported.
from __future__ import print_function
import psutil
import signal
from argparse import ArgumentParser
from os import listdir
from os.path import isdir, exists, join
from subprocess import PIPE, Popen, CalledProcessError
def subprocess_run(cmd):
subproc = Popen(cmd, stdout=PIPE, stderr=PIPE,
shell=True, universal_newlines=True)
subproc.wait()
talk = subproc.communicate()
exitCode = subproc.returncode
if exitCode != 0:
print('An error was detected while running the subprocess:\n'
'exit code: %d\n'
'stdout: %s\n'
'stderr: %s' % (exitCode, talk[0], talk[1]))
raise CalledProcessError(exitCode, cmd)
return talk
def kill_subprocess(parent_pid, sig=signal.SIGTERM):
try:
parent = psutil.Process(parent_pid)
except psutil.NoSuchProcess:
return
children = parent.children(recursive=True)
for process in children:
process.send_signal(sig)
def git_env():
cmd = 'git --version | cut -d " " -f3 | head -n1 | tr -d "\n"'
talk = subprocess_run(cmd)
version = talk[0].strip().split('.')
major_version = int(version[0])
sub_version = int(version[1])
if major_version >= 2 and sub_version >= 9:
extra_cmd = '--allow-unrelated-histories'
else:
extra_cmd = ''
return extra_cmd
def parameters():
param = ArgumentParser(description='Wlan CAF driver updater/initial'
'merging into Android kernel source', )
param.add_argument('-W', '--wlan', choices=['qcacld', 'prima'],
help='Your WLAN driver type either qcacld/prima.',
required=True)
param.add_argument('-I', '--init', choices=['update', 'initial'],
help='Choose wether to update or initial merging.',
required=True)
param.add_argument('-T', '--tag', help='Your CAF tag you want to merge.',
required=True)
params = vars(param.parse_args())
wlan_type = params['wlan']
merge_type = params['init']
tag = params['tag']
return wlan_type, merge_type, tag
def repo():
wlan_type, merge_type, tag = parameters()
staging = 'drivers/staging'
if wlan_type == 'qcacld':
repo_url = {
'fw-api': ('https://source.codeaurora.org/'
'quic/la/platform/vendor/qcom-opensource/wlan/fw-api/'),
'qca-wifi-host-cmn': ('https://source.codeaurora.org/'
'quic/la/platform/vendor/qcom-opensource/'
'wlan/qca-wifi-host-cmn/'),
'qcacld-3.0': ('https://source.codeaurora.org/'
'quic/la/platform/vendor/qcom-opensource/wlan/'
'qcacld-3.0')
}
subdir = ['fw-api', 'qca-wifi-host-cmn', 'qcacld-3.0']
elif wlan_type == 'prima':
repo_url = ('https://source.codeaurora.org/'
'quic/la/platform/vendor/qcom-opensource/wlan/prima/')
subdir = 'prima'
return repo_url, staging, subdir
def check():
wlan_type, merge_type, tag = parameters()
repo_url, staging, subdir = repo()
if wlan_type == 'qcacld' and merge_type == 'initial':
for subdirs in subdir:
if isdir(join(staging, subdirs)):
if listdir(join(staging, subdirs)):
print('%s exist and not empty' % subdirs)
continue
else:
if subdirs == 'qcacld-3.0' and not listdir(
join(staging, 'fw-api')
) and not listdir(
join(staging, 'qca-wifi-host-cmn')
) and not listdir(join(staging, 'qcacld-3.0')):
return True
else:
return True
else:
raise OSError(
'you might want to use --init initial, '
'because those 3 are exists, '
'\nor one of them is exist and not empty.'
)
elif wlan_type == 'qcacld' and merge_type == 'update':
for subdirs in subdir:
if isdir(join(staging, subdirs)):
if not listdir(join(staging, subdirs)):
print('%s exist and empty' % subdirs)
continue
else:
if subdirs == 'qcacld-3.0' and listdir(
join(staging, 'fw-api')
) and listdir(
join(staging, 'qca-wifi-host-cmn')
) and listdir(join(staging, 'qcacld-3.0')):
return True
else:
continue
else:
raise OSError(
'you might want to use --init update, '
'because those 3 are not exists.'
'\nor exists but one of them has an empty folder.'
)
elif wlan_type == 'prima' and merge_type == 'initial':
if isdir(join(staging, subdir)):
if listdir(join(staging, subdir)):
raise OSError(
'you might want to use --init update, '
'\nbecause prima is exist and it is not empty.'
)
else:
return True
else:
return True
elif wlan_type == 'prima' and merge_type == 'update':
if isdir(join(staging, subdir)):
if listdir(join(staging, subdir)):
return True
else:
raise OSError(
'folder prima exist, but it is just an empty folder.'
)
else:
raise OSError(
'you might want to use --init initial, '
'because prima is not exist.'
)
def merge():
wlan_type, merge_type, tag = parameters()
repo_url, staging, subdir = repo()
extra_cmd = git_env()
if wlan_type == 'qcacld' and merge_type == 'initial':
for repos in repo_url:
print("fetching %s with tag '%s'" % (repos, tag))
cmd = 'git fetch %s %s' % (repo_url[repos], tag)
talk = subprocess_run(cmd)
while True:
cmds = [
'git merge -s ours --no-commit %s FETCH_HEAD' % extra_cmd,
('git read-tree --prefix=drivers/staging/%s '
'-u FETCH_HEAD' % repos),
('git commit -m "%s: Merge init tag \'%s\' into '
'`git rev-parse --abbrev-ref HEAD`"' % (repos, tag))
]
for cmd in cmds:
talk = subprocess_run(cmd)
if cmd == cmds[0]:
print('merging %s into kernel source...' % repos)
if cmd == cmds[2]:
print('committing changes...')
print('\n' + talk[0])
break
elif wlan_type == 'qcacld' and merge_type == 'update':
for repos in repo_url:
print("fetching %s with tag '%s'" % (repos, tag))
cmd = 'git fetch %s %s' % (repo_url[repos], tag)
talk = subprocess_run(cmd)
while True:
print('merging %s into kernel source and committing changes...'
% repos)
cmd = ('git merge -X subtree=drivers/staging/%s '
'--edit -m "%s: Merge tag \'%s\' into '
'`git rev-parse --abbrev-ref HEAD`" '
'FETCH_HEAD --no-edit'
% (repos, repos, tag))
talk = subprocess_run(cmd)
print('\n' + talk[0])
break
elif wlan_type == 'prima' and merge_type == 'initial':
cmds = [
'git fetch %s %s' % (repo_url, tag),
'git merge -s ours --no-commit %s FETCH_HEAD' % extra_cmd,
('git read-tree --prefix=drivers/staging/%s '
'-u FETCH_HEAD' % wlan_type),
('git commit -m "%s: Merge init tag \'%s\' into '
'`git rev-parse --abbrev-ref HEAD`"' % (wlan_type, tag))
]
for cmd in cmds:
talk = subprocess_run(cmd)
if cmd == cmds[0]:
print("fetching %s with tag '%s'" % (wlan_type, tag))
if cmd == cmds[1]:
print('merging %s into kernel source...' % wlan_type)
if cmd == cmds[3]:
print('committing changes...')
else:
print('\n' + talk[0])
elif wlan_type == 'prima' and merge_type == 'update':
cmds = [
'git fetch %s %s' % (repo_url, tag),
('git merge -X subtree=drivers/staging/%s '
'--edit -m "%s: Merge tag \'%s\' into '
'`git rev-parse --abbrev-ref HEAD`" FETCH_HEAD --no-edit'
% (wlan_type, wlan_type, tag))
]
for cmd in cmds:
talk = subprocess_run(cmd)
if cmd == cmds[0]:
print("fetching %s with tag '%s'" % (wlan_type, tag))
if cmd == cmds[1]:
print('merging %s into kernel source and committing changes...'
% wlan_type)
else:
print('\n' + talk[0])
return True
def main():
wlan_type, merge_type, tag = parameters()
repo_url, staging, subdir = repo()
if not exists('Makefile'):
raise OSError(
'Please, run this script inside your root kernel source.'
)
if not exists('drivers/staging'):
raise OSError(
"staging folder can't be found, "
'are you sure running it inside kernel source?'
)
if check() is True:
merge()
parameters()
main()