2023-02-03 07:07:58 -08:00
|
|
|
#!/usr/bin/env python3
|
2020-04-05 10:49:14 -07:00
|
|
|
|
2020-04-06 21:33:07 -07:00
|
|
|
# Copyright (C) 2020 Zebediah Figura
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
#
|
2020-04-05 10:49:14 -07:00
|
|
|
|
2020-11-01 13:24:56 -08:00
|
|
|
import email.header, getopt, os, subprocess, sys
|
2020-04-06 21:33:07 -07:00
|
|
|
|
|
|
|
stagingdir = os.path.dirname(os.path.realpath(__file__)) + '/../'
|
|
|
|
patchdir = stagingdir + 'patches'
|
2020-04-05 10:49:14 -07:00
|
|
|
if 'DESTDIR' in os.environ:
|
|
|
|
winedir = os.environ['DESTDIR']
|
|
|
|
else:
|
|
|
|
winedir = '.'
|
|
|
|
backend = "patch"
|
2020-04-06 21:33:07 -07:00
|
|
|
force_autoconf = False
|
2020-04-05 10:49:14 -07:00
|
|
|
|
|
|
|
applied = []
|
|
|
|
|
2020-04-06 21:33:07 -07:00
|
|
|
patch_data = ''
|
|
|
|
|
2020-04-05 10:49:14 -07:00
|
|
|
def usage():
|
2023-02-03 07:07:58 -08:00
|
|
|
print('''
|
2020-04-07 08:10:11 -07:00
|
|
|
Usage: ./staging/patchinstall.py [options] [patchset ...]
|
2020-04-05 10:49:14 -07:00
|
|
|
|
2020-04-06 21:33:07 -07:00
|
|
|
Applies all Wine-Staging patch sets, or each specified patch set plus its
|
|
|
|
dependencies, to a Wine tree.
|
2020-04-05 10:49:14 -07:00
|
|
|
|
|
|
|
Options:
|
2020-04-06 21:33:07 -07:00
|
|
|
-h, --help print this message
|
|
|
|
-v, --version print version information
|
|
|
|
-a, --all apply all patches (except those excluded with -W)
|
|
|
|
-W, --exclude <patchset> exclude a patch
|
|
|
|
--no-autoconf do not run autoreconf and tools/make_requests
|
|
|
|
--force-autoconf run autoreconf and tools/make_requests after every patch
|
|
|
|
(ignored when not using git-am or git-am-C1 backends)
|
|
|
|
--backend=<backend> use the given backend to apply patches:
|
|
|
|
patch use the `gitapply.sh` tool (a wrapper around `patch`)
|
|
|
|
git-am use `git am`
|
|
|
|
git-am-C1 use `git am -C1`
|
|
|
|
git-apply use `git apply`
|
2020-04-07 08:10:11 -07:00
|
|
|
--ignore-missing automatically add dependencies, but do not fail
|
|
|
|
if they are missing or disabled
|
2020-11-01 13:24:56 -08:00
|
|
|
-r, --rebase-mode alias for --backend=git-am-C1 --no-autoconf
|
2020-04-07 08:10:11 -07:00
|
|
|
-d, --destdir=<path> install to <path> (defaults to current working directory)
|
2020-05-18 17:12:27 -07:00
|
|
|
--upstream-commit print the Wine commit hash and exit
|
2023-02-03 07:07:58 -08:00
|
|
|
''')
|
2020-04-05 10:49:14 -07:00
|
|
|
|
2020-04-06 21:33:07 -07:00
|
|
|
def run(*args, **kwargs):
|
2023-02-03 07:07:58 -08:00
|
|
|
print(' '.join(args[0]))
|
2020-04-06 21:33:07 -07:00
|
|
|
return subprocess.call(*args, **kwargs)
|
|
|
|
|
2020-04-05 10:49:14 -07:00
|
|
|
# return a patch to be shoved in patchlist below
|
|
|
|
def parse_def_file(name, path):
|
|
|
|
deps = []
|
|
|
|
if os.path.exists(path):
|
2020-04-06 21:33:07 -07:00
|
|
|
with open(path) as f:
|
|
|
|
for l in f.readlines():
|
2020-04-05 10:49:14 -07:00
|
|
|
if l.lower().startswith('depends: '):
|
|
|
|
deps.append(l.split(' ')[1].strip())
|
|
|
|
elif l.lower().strip() == 'disabled: true':
|
|
|
|
return None
|
|
|
|
return deps
|
|
|
|
|
|
|
|
def apply_patch(patch):
|
|
|
|
if backend == 'git-am':
|
2020-04-06 21:33:07 -07:00
|
|
|
return run(['git','-C',winedir,'am',patch])
|
2020-04-05 10:49:14 -07:00
|
|
|
elif backend == 'git-am-C1':
|
2020-04-06 21:33:07 -07:00
|
|
|
return run(['git','-C',winedir,'am','-C1',patch])
|
2020-04-05 10:49:14 -07:00
|
|
|
elif backend == 'patch':
|
|
|
|
with open(patch) as f:
|
2023-02-03 07:07:58 -08:00
|
|
|
print(patchdir+'/gitapply.sh <',patch)
|
2020-04-05 10:49:14 -07:00
|
|
|
return subprocess.call([patchdir+'/gitapply.sh'],stdin=f)
|
|
|
|
elif backend == 'git-apply':
|
2020-04-06 21:33:07 -07:00
|
|
|
return run(['git','-C',winedir,'apply','--index',patch])
|
|
|
|
|
|
|
|
def run_autoconf(patch):
|
|
|
|
if not force_autoconf: return
|
|
|
|
|
|
|
|
if backend != 'git-am' and backend != 'git-am-C1':
|
2023-02-03 07:07:58 -08:00
|
|
|
print('Warning: ignoring --force-autoconf for backend ',backend)
|
2020-04-06 21:33:07 -07:00
|
|
|
|
|
|
|
need_autoreconf = False
|
|
|
|
need_make_requests = False
|
|
|
|
|
|
|
|
with open(patch) as f:
|
|
|
|
for line in f.readlines():
|
|
|
|
line = line.strip()
|
|
|
|
if line == '--- a/configure.ac' or line == '--- a/aclocal.m4': need_autoreconf = True
|
|
|
|
elif line == '--- a/server/protocol.def': need_make_requests = True
|
|
|
|
|
|
|
|
if need_autoreconf:
|
|
|
|
run(['autoreconf','-f'], cwd=winedir)
|
|
|
|
if need_make_requests:
|
|
|
|
run(['./tools/make_requests'], cwd=winedir)
|
|
|
|
if need_autoreconf or need_make_requests:
|
|
|
|
run(['git','-C',winedir,'commit','-a','--amend','--no-edit'])
|
|
|
|
|
|
|
|
def add_patch_data(patch):
|
|
|
|
global patch_data
|
|
|
|
author = ''
|
|
|
|
subject = ''
|
|
|
|
with open(patch) as f:
|
|
|
|
for line in f.readlines():
|
|
|
|
header = email.header.decode_header(line)
|
|
|
|
if header[0][0] == 'From:':
|
|
|
|
author = header[1][0]
|
|
|
|
elif line[:5] == 'From:':
|
|
|
|
author = line[6:line.index('<')-1]
|
|
|
|
elif line[:8] == 'Subject:':
|
2020-04-07 08:10:11 -07:00
|
|
|
subject = line[9:]
|
2020-04-06 21:33:07 -07:00
|
|
|
if '[' in subject: subject = subject[subject.index(']') + 1:]
|
|
|
|
if author and subject: break
|
2020-04-08 07:42:34 -07:00
|
|
|
author = author.strip().strip('"').replace('\\','\\\\').replace('"','\\"')
|
|
|
|
subject = subject.strip().replace('\\','\\\\').replace('"','\\"')
|
2020-04-06 21:33:07 -07:00
|
|
|
patch_data += '+ {"%s", "%s", 1},\n' %(author, subject)
|
2020-04-05 10:49:14 -07:00
|
|
|
|
|
|
|
def apply_set(patchlist, name):
|
|
|
|
if name in applied:
|
|
|
|
return True
|
|
|
|
for dep in patchlist[name]:
|
2020-04-07 08:10:11 -07:00
|
|
|
if dep in patchlist and not apply_set(patchlist, dep):
|
2020-04-05 10:49:14 -07:00
|
|
|
return False
|
|
|
|
for patch in sorted(os.listdir(patchdir+'/'+name)):
|
2020-04-06 21:33:07 -07:00
|
|
|
if patch.endswith('.patch') and patch.startswith('0'):
|
|
|
|
patch_file = patchdir + '/' + name + '/' + patch
|
|
|
|
if apply_patch(patch_file):
|
2023-02-03 07:07:58 -08:00
|
|
|
print('Failed to apply patch %s/%s' %(name, patch))
|
2020-04-06 21:33:07 -07:00
|
|
|
return False
|
|
|
|
run_autoconf(patch_file)
|
|
|
|
add_patch_data(patch_file)
|
2020-04-05 10:49:14 -07:00
|
|
|
applied.append(name)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def add_patchset(patchlist, name):
|
|
|
|
path = patchdir + '/' + name
|
|
|
|
if os.path.isdir(path):
|
|
|
|
deps = parse_def_file(name, path + '/definition')
|
|
|
|
if deps == None:
|
2023-02-03 07:07:58 -08:00
|
|
|
print('Error: attempt to apply %s, but it is disabled.' %name)
|
2020-04-05 10:49:14 -07:00
|
|
|
sys.exit(1)
|
|
|
|
patchlist[name] = deps
|
|
|
|
for dep in deps: add_patchset(patchlist, dep)
|
|
|
|
|
|
|
|
def main():
|
2020-04-07 08:10:11 -07:00
|
|
|
global backend, force_autoconf, winedir
|
2020-04-05 10:49:14 -07:00
|
|
|
patchlist = {}
|
|
|
|
excluded = []
|
|
|
|
no_autoconf = False
|
2020-04-07 08:10:11 -07:00
|
|
|
ignore_missing = False
|
2020-04-05 10:49:14 -07:00
|
|
|
|
|
|
|
try:
|
2020-04-07 08:10:11 -07:00
|
|
|
opts, args = getopt.gnu_getopt(sys.argv[1:], 'ad:hrvW:', \
|
2020-04-06 21:33:07 -07:00
|
|
|
['all',
|
|
|
|
'backend=',
|
2020-04-07 08:10:11 -07:00
|
|
|
'destdir=',
|
2020-04-06 21:33:07 -07:00
|
|
|
'force-autoconf',
|
2020-04-07 08:10:11 -07:00
|
|
|
'ignore-missing',
|
2020-04-06 21:33:07 -07:00
|
|
|
'help',
|
|
|
|
'no-autoconf',
|
2020-05-18 17:12:27 -07:00
|
|
|
'upstream-commit',
|
2020-04-06 21:33:07 -07:00
|
|
|
'version'])
|
2020-04-05 10:49:14 -07:00
|
|
|
except getopt.GetoptError as err:
|
2023-02-03 07:07:58 -08:00
|
|
|
print(str(err))
|
2020-04-05 10:49:14 -07:00
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
for o, a in opts:
|
|
|
|
if o == '-h' or o == '--help':
|
|
|
|
usage()
|
|
|
|
sys.exit(0)
|
2020-04-06 21:33:07 -07:00
|
|
|
elif o == '-v' or o == '--version':
|
|
|
|
with open(stagingdir + 'staging/VERSION') as f:
|
2023-02-03 07:07:58 -08:00
|
|
|
print(f.read().rstrip())
|
|
|
|
print('wine-staging is distributed under the GNU LGPL 2.1.')
|
|
|
|
print('See individual files for copyright information.')
|
2020-04-06 21:33:07 -07:00
|
|
|
sys.exit(0)
|
2020-04-05 10:49:14 -07:00
|
|
|
elif o == '-r' or o == '--rebase-mode':
|
|
|
|
no_autoconf = True
|
|
|
|
backend = "git-am-C1"
|
2020-04-06 21:33:07 -07:00
|
|
|
elif o == '-W' or o == '--exclude':
|
2020-04-05 10:49:14 -07:00
|
|
|
excluded.append(a)
|
2020-04-06 21:33:07 -07:00
|
|
|
elif o == '-a' or o == '--all':
|
2020-04-05 10:49:14 -07:00
|
|
|
for name in os.listdir(patchdir):
|
|
|
|
path = patchdir + '/' + name
|
|
|
|
if os.path.isdir(path):
|
|
|
|
deps = parse_def_file(name, path + '/definition')
|
|
|
|
if deps != None: # it's not disabled
|
|
|
|
patchlist[name] = deps
|
2020-04-07 08:10:11 -07:00
|
|
|
elif o == '-d' or o == '--destdir':
|
|
|
|
winedir = a
|
2020-04-05 10:49:14 -07:00
|
|
|
elif o == '--backend':
|
|
|
|
backend = a
|
|
|
|
elif o == '--no-autoconf':
|
|
|
|
no_autoconf = True
|
2020-04-06 21:33:07 -07:00
|
|
|
elif o == '--force-autoconf':
|
|
|
|
force_autoconf = True
|
2020-04-07 08:10:11 -07:00
|
|
|
elif o == '--ignore-missing':
|
|
|
|
ignore_missing = True
|
2020-05-18 17:12:27 -07:00
|
|
|
elif o == '--upstream-commit':
|
|
|
|
with open(stagingdir + 'staging/upstream-commit') as f:
|
2023-02-03 07:07:58 -08:00
|
|
|
print(f.read().rstrip());
|
2020-05-18 17:12:27 -07:00
|
|
|
sys.exit(0)
|
2020-04-05 10:49:14 -07:00
|
|
|
|
|
|
|
for a in args: add_patchset(patchlist, a)
|
|
|
|
|
|
|
|
for p in excluded: del patchlist[p]
|
|
|
|
|
2020-04-07 08:10:11 -07:00
|
|
|
if not os.access(winedir + '/tools/make_requests', os.F_OK):
|
2023-02-03 07:07:58 -08:00
|
|
|
print("Target directory '%s' does not point to a Wine tree." %winedir)
|
2020-04-07 08:10:11 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
2020-04-05 10:49:14 -07:00
|
|
|
if not patchlist:
|
2023-02-03 07:07:58 -08:00
|
|
|
print('No patches specified, either use -a or specify one or more patch sets as arguments.')
|
2020-04-05 10:49:14 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Check that all of our dependencies exist
|
|
|
|
for p in patchlist:
|
|
|
|
deps = patchlist[p]
|
|
|
|
for d in deps:
|
|
|
|
if d not in patchlist:
|
2020-04-07 08:10:11 -07:00
|
|
|
if not ignore_missing:
|
2023-02-03 07:07:58 -08:00
|
|
|
print('Error: unknown or disabled dependency %s of %s.' %(d,p))
|
2020-04-07 08:10:11 -07:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2023-02-03 07:07:58 -08:00
|
|
|
print('Warning: unknown or disabled dependency %s of %s.' %(d,p))
|
2020-04-05 10:49:14 -07:00
|
|
|
|
|
|
|
# Now try to apply each patch
|
|
|
|
for p in sorted(patchlist.keys()):
|
|
|
|
# Try to apply it
|
|
|
|
if not apply_set(patchlist, p):
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-04-06 21:33:07 -07:00
|
|
|
if not no_autoconf and not force_autoconf:
|
|
|
|
run(['autoreconf','-f'],cwd=winedir)
|
|
|
|
run(['./tools/make_requests'],cwd=winedir)
|
2020-04-05 10:49:14 -07:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|