From 4fed4fecf69afde1840564869ca11996a46c6a8b Mon Sep 17 00:00:00 2001 From: Takuya ASADA Date: Thu, 21 Feb 2019 11:49:26 +0000 Subject: [PATCH] reloc/python3: archive rpm build script in the relocatable package, build rpm using the script Since we archive rpm/deb build script on relocatable package and build rpm/deb using the script, so align python relocatable package too. Also added SCYLLA-RELOCATABLE-FILE, SCYLLA-RELEASE-FILE and SCYLLA-VERSION-FILE since these files are required for relocatable package. --- dist/redhat/python3/build_rpm.sh | 55 +++++++++++++------ reloc/python3/build_rpm.sh | 42 ++++++++++++++ scripts/create-relocatable-package-python3.py | 5 ++ 3 files changed, 84 insertions(+), 18 deletions(-) create mode 100755 reloc/python3/build_rpm.sh diff --git a/dist/redhat/python3/build_rpm.sh b/dist/redhat/python3/build_rpm.sh index 3cbd53a04c..c12eaec917 100755 --- a/dist/redhat/python3/build_rpm.sh +++ b/dist/redhat/python3/build_rpm.sh @@ -22,50 +22,69 @@ print_usage() { echo "${0} --reloc-pkg build/release/scylla-python3-package.tar.gz" echo " --reloc-pkg specify relocatable package path" - echo " --rpmbuild specify directory to use for building rpms" exit 1 } RELOC_PKG= -RPMBUILD= while [ $# -gt 0 ]; do case "$1" in "--reloc-pkg") RELOC_PKG="$2" shift 2 ;; - "--rpmbuild") - RPMBUILD="$2" - shift 2 - ;; *) print_usage ;; esac done +is_redhat_variant() { + [ -f /etc/redhat-release ] +} +pkg_install() { + if is_redhat_variant; then + sudo yum install -y $1 + else + echo "Requires to install following command: $1" + exit 1 + fi +} + + +if [ ! -e SCYLLA-RELOCATABLE-FILE ]; then + echo "do not directly execute build_rpm.sh, use reloc/build_rpm.sh instead." + exit 1 +fi + if [ -z "$RELOC_PKG" ]; then print_usage exit 1 fi - -if [ -z "$RPMBUILD" ]; then - print_usage - exit 1 -fi - if [ ! -f "$RELOC_PKG" ]; then - echo "${RELOC_PKG} not found." + echo "$RELOC_PKG is not found." exit 1 fi + +if [ ! -f /usr/bin/rpmbuild ]; then + pkg_install rpm-build +fi +if [ ! -f /usr/bin/git ]; then + pkg_install git +fi +if [ ! -f /usr/bin/pystache ]; then + if is_redhat_variant; then + sudo yum install -y python2-pystache || sudo yum install -y pystache + elif is_debian_variant; then + sudo apt-get install -y python2-pystache + fi +fi + RELOC_PKG_BASENAME=$(basename "$RELOC_PKG") -RPMBUILD=$(readlink -f "$RPMBUILD") -SPEC=$(dirname $(readlink -f "$0")) - +RPMBUILD=$(readlink -f ../) mkdir -p "$RPMBUILD"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} -PYVER=$(python3 -V | cut -d' ' -f2) +PYVER=$(python3 -V | cut -d' ' -f2) ln -fv "$RELOC_PKG" "$RPMBUILD"/SOURCES/ -pystache "$SPEC"/python.spec.mustache "{ \"version\": \"${PYVER}\", \"reloc_pkg\": \"${RELOC_PKG_BASENAME}\", \"name\": \"scylla-python3\", \"target\": \"/opt/scylladb/python3\" }" > "$RPMBUILD"/SPECS/python.spec +pystache dist/redhat/python3/python.spec.mustache "{ \"version\": \"${PYVER}\", \"reloc_pkg\": \"${RELOC_PKG_BASENAME}\", \"name\": \"scylla-python3\", \"target\": \"/opt/scylladb/python3\" }" > "$RPMBUILD"/SPECS/python.spec rpmbuild --nodebuginfo -ba --define "_build_id_links none" --define "_topdir ${RPMBUILD}" --define "dist .el7" "$RPMBUILD"/SPECS/python.spec diff --git a/reloc/python3/build_rpm.sh b/reloc/python3/build_rpm.sh new file mode 100755 index 0000000000..e4e62fde10 --- /dev/null +++ b/reloc/python3/build_rpm.sh @@ -0,0 +1,42 @@ +#!/bin/bash -e + +. /etc/os-release +print_usage() { + echo "build_rpm.sh --reloc-pkg build/release/scylla-python3-package.tar.gz" + echo " --reloc-pkg specify relocatable package path" + echo " --builddir specify rpmbuild directory" + exit 1 +} +RELOC_PKG=build/release/scylla-python3-package.tar.gz +BUILDDIR=build/redhat +OPTS="" +while [ $# -gt 0 ]; do + case "$1" in + "--reloc-pkg") + OPTS="$OPTS $1 $(readlink -f $2)" + RELOC_PKG=$2 + shift 2 + ;; + "--builddir") + builddir="$2" + shift 2 + ;; + *) + print_usage + ;; + esac +done + +if [ ! -e $RELOC_PKG ]; then + echo "$RELOC_PKG does not exist." + echo "Run ./reloc/python3/build_reloc.sh first." + exit 1 +fi +RELOC_PKG=$(readlink -f $RELOC_PKG) +if [[ ! $OPTS =~ --reloc-pkg ]]; then + OPTS="$OPTS --reloc-pkg $RELOC_PKG" +fi +mkdir -p $BUILDDIR/scylla-python3-package +tar -C $BUILDDIR/scylla-python3-package -xpf $RELOC_PKG SCYLLA-*-FILE dist/redhat/python3 +cd $BUILDDIR/scylla-python3-package +exec ./dist/redhat/python3/build_rpm.sh $OPTS diff --git a/scripts/create-relocatable-package-python3.py b/scripts/create-relocatable-package-python3.py index b8667d2c9b..591f766237 100755 --- a/scripts/create-relocatable-package-python3.py +++ b/scripts/create-relocatable-package-python3.py @@ -228,6 +228,11 @@ packages= ["python3"] + args.modules file_list = generate_file_list(dependencies(packages)) ar = tarfile.open(args.output, mode='w|gz') +pathlib.Path('build/SCYLLA-RELOCATABLE-FILE').touch() +ar.add('build/SCYLLA-RELOCATABLE-FILE', arcname='SCYLLA-RELOCATABLE-FILE') +ar.add('dist/redhat/python3') +ar.add('build/SCYLLA-RELEASE-FILE', arcname='SCYLLA-RELEASE-FILE') +ar.add('build/SCYLLA-VERSION-FILE', arcname='SCYLLA-VERSION-FILE') for f in file_list: copy_file_to_python_env(ar, f)