Skip to content
Snippets Groups Projects
Commit e5d8d6b2 authored by Simon McVittie's avatar Simon McVittie
Browse files

Install a script that builds the relocatable installation

parent 2eee2eb0
Branches
Tags
No related merge requests found
.*.sw?
/.mypy_cache
/_build/ /_build/
/libcapsule/ /libcapsule/
/libcapsule_*.dsc /libcapsule_*.dsc
......
...@@ -45,17 +45,18 @@ build:scout: ...@@ -45,17 +45,18 @@ build:scout:
meson \ meson \
${NULL+} ${NULL+}
meson --prefix="$(pwd)/_build/prefix" -Dpython=python3.5 _build meson \
--prefix="$(pwd)/_build/prefix" \
-Dpython=python3.5 \
-Dsrcdir=src \
_build
ninja -C _build ninja -C _build
meson test --verbose -C _build meson test --verbose -C _build
ninja -C _build install ninja -C _build install
rm -fr _build/relocatable-install rm -fr _build/relocatable-install
./build-relocatable-install.py \ _build/prefix/bin/pressure-vessel-build-relocatable-install \
--srcdir . \
--builddir _build \
--output _build/relocatable-install \ --output _build/relocatable-install \
--archive "$(pwd)/_build" \ --archive "$(pwd)/_build" \
--set-version "$(cat .tarball-version)" \
${NULL+} ${NULL+}
prove -v ./tests/relocatable-install.py :: \ prove -v ./tests/relocatable-install.py :: \
"$(pwd)/_build/relocatable-install" "$(pwd)/_build/relocatable-install"
......
...@@ -149,14 +149,12 @@ or available via apt-get. For example, you could do the build in a ...@@ -149,14 +149,12 @@ or available via apt-get. For example, you could do the build in a
SteamRT 1 'scout' SDK Docker image that has those packages already. SteamRT 1 'scout' SDK Docker image that has those packages already.
Then you can do: Then you can do:
meson --prefix="$(pwd)/_build/prefix" _build meson --prefix="$(pwd)/_build/prefix" -Dsrcdir=src _build
ninja -C _build ninja -C _build
meson test -v -C _build # optional meson test -v -C _build # optional
ninja -C _build install ninja -C _build install
rm -fr _build/relocatable-install rm -fr _build/relocatable-install
./build-relocatable-install.py \ _build/prefix/bin/pressure-vessel-build-relocatable-install \
--srcdir . \
--builddir _build \
--output _build/relocatable-install \ --output _build/relocatable-install \
--archive . --archive .
./tests/relocatable-install.py _build/relocatable-install # optional ./tests/relocatable-install.py _build/relocatable-install # optional
......
#!@sh@
exec "@python@" \
"${DESTDIR}@prefix@/@srcdir@/build-relocatable-install.py" \
--prefix "@prefix@" \
--srcdir "@srcdir@" \
--set-version "@version@" \
"$@"
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
import argparse import argparse
import glob import glob
import json
import os import os
import re import re
import shutil import shutil
...@@ -135,42 +134,30 @@ def main(): ...@@ -135,42 +134,30 @@ def main():
# type: () -> None # type: () -> None
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument('--destdir', default=os.getenv('DESTDIR'))
'--destdir', default=os.getenv('DESTDIR', ''))
parser.add_argument(
'--srcdir', default=os.getenv('MESON_SOURCE_ROOT', '.'))
parser.add_argument(
'--builddir', default=os.getenv('MESON_BUILD_ROOT', '_build'))
parser.add_argument('--prefix', default=None) parser.add_argument('--prefix', default=None)
parser.add_argument('--srcdir', default=None)
parser.add_argument('--output', '-o', default=None) parser.add_argument('--output', '-o', default=None)
parser.add_argument('--archive', default=None) parser.add_argument('--archive', default=None)
parser.add_argument('--set-version', dest='version', default='unknown') parser.add_argument('--set-version', dest='version', default=None)
args = parser.parse_args() args = parser.parse_args()
if args.destdir: if args.srcdir is None:
args.destdir = os.path.abspath(args.destdir) args.srcdir = os.path.dirname(__file__)
args.srcdir = os.path.abspath(args.srcdir) if args.prefix is None:
args.builddir = os.path.abspath(args.builddir) args.prefix = '/usr/lib/pressure-vessel/relocatable'
if args.archive is None: if not os.path.isabs(args.srcdir):
args.archive = args.builddir args.srcdir = os.path.join(args.prefix, args.srcdir)
else:
args.archive = os.path.abspath(args.archive)
if args.prefix is None: if args.destdir:
blob = subprocess.check_output([ args.prefix = args.destdir + args.prefix
'meson', 'introspect', args.builddir, '--buildoptions', args.srcdir = args.destdir + args.srcdir
], universal_newlines=True)
for opt in json.loads(blob): if args.version is None:
if opt['name'] == 'prefix': with open(os.path.join(args.srcdir, '.tarball-version')) as reader:
args.prefix = opt['value'] args.version = reader.read().strip()
break
else:
raise RuntimeError(
'Unable to determine installation prefix from Meson, '
'please specify --prefix'
)
with tempfile.TemporaryDirectory(prefix='pressure-vessel-') as tmpdir: with tempfile.TemporaryDirectory(prefix='pressure-vessel-') as tmpdir:
if args.output is None: if args.output is None:
...@@ -181,8 +168,6 @@ def main(): ...@@ -181,8 +168,6 @@ def main():
if os.path.exists(installation): if os.path.exists(installation):
raise RuntimeError('--output directory must not already exist') raise RuntimeError('--output directory must not already exist')
destdir_prefix = args.destdir + args.prefix
os.makedirs(os.path.join(installation, 'bin'), exist_ok=True) os.makedirs(os.path.join(installation, 'bin'), exist_ok=True)
os.makedirs(os.path.join(installation, 'metadata'), exist_ok=True) os.makedirs(os.path.join(installation, 'metadata'), exist_ok=True)
...@@ -194,13 +179,13 @@ def main(): ...@@ -194,13 +179,13 @@ def main():
for script in SCRIPTS: for script in SCRIPTS:
install_exe( install_exe(
os.path.join(destdir_prefix, 'bin', script), os.path.join(args.prefix, 'bin', script),
os.path.join(installation, 'bin'), os.path.join(installation, 'bin'),
) )
for exe in EXECUTABLES: for exe in EXECUTABLES:
install_exe( install_exe(
os.path.join(destdir_prefix, 'bin', exe), os.path.join(args.prefix, 'bin', exe),
os.path.join(installation, 'bin'), os.path.join(installation, 'bin'),
) )
...@@ -430,82 +415,33 @@ def main(): ...@@ -430,82 +415,33 @@ def main():
exist_ok=True, exist_ok=True,
) )
for src_tar in ( tar = subprocess.Popen([
os.path.join( 'tar',
args.srcdir, '-C', args.srcdir,
'..', '--exclude=.*.sw?',
'pressure-vessel_{}.orig.tar.xz'.format(args.version), '--exclude=./.git',
), '--exclude=./.mypy_cache',
os.path.join( '--exclude=./_build',
args.builddir, '--exclude=./debian',
'meson-dist/pressure-vessel-{}.tar.gz'.format( '--exclude=./relocatable-install',
args.version, '-cf-',
), '.',
), ], stdout=subprocess.PIPE)
os.path.join( subprocess.check_call([
args.srcdir, 'tar',
'pressure-vessel-{}.tar.xz'.format(args.version), '-C', os.path.join(
installation,
'sources',
'pressure-vessel',
), ),
): '-xvf-',
if os.path.exists(src_tar): ], stdin=tar.stdout)
subprocess.check_call([
'tar',
'-C', os.path.join(
installation,
'sources',
'pressure-vessel',
),
'--strip-components=1',
'-xvf', src_tar,
])
break
else:
if os.path.exists('/usr/bin/git'):
git_archive = subprocess.Popen([
'git', 'archive', '--format=tar', 'HEAD',
], cwd=args.srcdir, stdout=subprocess.PIPE)
subprocess.check_call([
'tar',
'-C', os.path.join(
installation,
'sources',
'pressure-vessel',
),
'-xvf-',
], stdin=git_archive.stdout)
if git_archive.wait() != 0:
raise subprocess.CalledProcessError(
returncode=git_archive.returncode,
cmd=git_archive.args,
)
else:
tar = subprocess.Popen([
'tar',
'-C', args.srcdir,
'--exclude=./.git',
'--exclude=./_build',
'--exclude=./relocatable-install',
'--exclude=./.mypy_cache',
'--exclude=.*.swp',
'-cf-',
'.',
], stdout=subprocess.PIPE)
subprocess.check_call([
'tar',
'-C', os.path.join(
installation,
'sources',
'pressure-vessel',
),
'-xvf-',
], stdin=tar.stdout)
if tar.wait() != 0: if tar.wait() != 0:
raise subprocess.CalledProcessError( raise subprocess.CalledProcessError(
returncode=git_archive.returncode, returncode=tar.returncode,
cmd=git_archive.args, cmd=tar.args,
) )
with open( with open(
os.path.join( os.path.join(
......
...@@ -109,17 +109,18 @@ pipeline { ...@@ -109,17 +109,18 @@ pipeline {
sh ''' sh '''
set -eu set -eu
cd src cd src
meson --prefix="$(pwd)/_build/prefix" -Dpython=python3.5 _build meson \
--prefix="$(pwd)/_build/prefix" \
-Dpython=python3.5 \
-Dsrcdir=src \
_build
ninja -C _build ninja -C _build
meson test --verbose -C _build meson test --verbose -C _build
ninja -C _build install ninja -C _build install
rm -fr ../relocatable-install rm -fr ../relocatable-install
./build-relocatable-install.py \ _build/prefix/bin/pressure-vessel-build-relocatable-install \
--srcdir . \
--builddir _build \
--output "${WORKSPACE}/relocatable-install" \ --output "${WORKSPACE}/relocatable-install" \
--archive "${WORKSPACE}" \ --archive "${WORKSPACE}" \
--set-version "$(cat .tarball-version)" \
${NULL+} ${NULL+}
prove -v ./tests/relocatable-install.py :: \ prove -v ./tests/relocatable-install.py :: \
"${WORKSPACE}/relocatable-install" "${WORKSPACE}/relocatable-install"
......
#!/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('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.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',
'--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:
...@@ -26,6 +26,7 @@ override_dh_auto_configure: ...@@ -26,6 +26,7 @@ override_dh_auto_configure:
meson _build \ meson _build \
--prefix=/usr/lib/pressure-vessel/relocatable \ --prefix=/usr/lib/pressure-vessel/relocatable \
-Dpython=/usr/bin/$$python \ -Dpython=/usr/bin/$$python \
-Dsrcdir=src \
-Dversion=$(DEB_VERSION) \ -Dversion=$(DEB_VERSION) \
$(NULL) $(NULL)
......
...@@ -179,4 +179,30 @@ executable( ...@@ -179,4 +179,30 @@ executable(
install_rpath : '${ORIGIN}/../' + get_option('libdir'), install_rpath : '${ORIGIN}/../' + get_option('libdir'),
) )
if get_option('srcdir') != ''
conf_data = configuration_data()
conf_data.set('prefix', get_option('prefix'))
conf_data.set('python', python.path())
conf_data.set('sh', sh.path())
conf_data.set('srcdir', get_option('srcdir'))
conf_data.set('version', version)
install_data(
configure_file(
input : 'build-relocatable-install.in',
output : 'pressure-vessel-build-relocatable-install',
configuration : conf_data,
),
install_dir : get_option('bindir'),
install_mode : 'rwxr-xr-x',
)
meson.add_install_script(
python.path(),
meson.current_source_dir() / 'copy-source-code.py',
'--srcdir', meson.current_source_dir(),
'--prefix', get_option('prefix'),
'--set-version', version,
get_option('srcdir'),
)
endif
# vim:set sw=2 sts=2 et: # vim:set sw=2 sts=2 et:
option('python', type : 'string', value : 'python3') option('python', type : 'string', value : 'python3')
option('srcdir', type : 'string', value : '')
option('version', type : 'string', value : 'auto') option('version', type : 'string', value : 'auto')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment