Newer
Older
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
#!/usr/bin/env python3
# Copyright © 2017-2019 Collabora Ltd.
#
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import argparse
import os
import subprocess
try:
import typing
except ImportError:
pass
else:
typing # silence pyflakes
def v_check_call(command, **kwargs):
print('# {}'.format(command))
subprocess.check_call(command, **kwargs)
def v_check_output(command, **kwargs):
print('# {}'.format(command))
return subprocess.check_output(command, **kwargs)
def main():
# type: () -> None
parser = argparse.ArgumentParser()
parser.add_argument(
'--destdir', default=os.getenv('DESTDIR', ''))
parser.add_argument(
'--srcdir', default=os.getenv('MESON_SOURCE_ROOT', '.'))
parser.add_argument('--set-version', default='0.0.0', dest='version')
parser.add_argument('--prefix', default='/usr')
parser.add_argument(
'--pressure-vessel-dir',
default='lib/pressure-vessel/relocatable',
dest='pv_dir',
)
parser.add_argument('output')
args = parser.parse_args()
args.srcdir = os.path.abspath(args.srcdir)
args.prefix = os.path.abspath(args.prefix)
if not os.path.isabs(args.output):
args.output = os.path.join(args.prefix, args.pv_dir, args.output)
if args.destdir:
args.destdir = os.path.abspath(args.destdir)
args.output = args.destdir + args.output
os.makedirs(os.path.join(args.output), exist_ok=True)
tar = subprocess.Popen([
'tar',
'-C', args.srcdir,
'--exclude=.*.sw?',
'--exclude=./.git',
'--exclude=./.mypy_cache',
'--exclude=./_build',
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
'--exclude=./debian',
'--exclude=./relocatable-install',
'-cf-',
'.',
], stdout=subprocess.PIPE)
subprocess.check_call([
'tar',
'-C', os.path.join(
args.output,
),
'-xvf-',
], stdin=tar.stdout)
if tar.wait() != 0:
raise subprocess.CalledProcessError(
returncode=tar.returncode,
cmd=tar.args,
)
with open(
os.path.join(
args.output,
'.tarball-version',
),
'w',
) as writer:
writer.write('{}\n'.format(args.version))
if __name__ == '__main__':
main()
# vim:set sw=4 sts=4 et: