From 8ff77c265094ba13d65a890adcf766569fd7f26a Mon Sep 17 00:00:00 2001 From: William Brown Date: Mon, 19 Feb 2018 14:59:45 +1000 Subject: [PATCH] Ticket 49570 - Make build commands easier to run and accessible Bug Description: Some of our contributing commands are pretty horrid: One of them is a nested shell script to work out build deps, and if you don't run it "just right" it won't work. Accesibility of our builds makes new contributions easier, and existing developers live easier. Fix Description: Add a wrapper "x.py", which is able to drive building the project in various forms. A "fresh" fedora system, would build like so: sudo ./x.py deps ./x.py config ./x.py make ./x.py test sudo ./x.py install sudo ./x.py pytest The development workflow would be: ./x.py make ./x.py test sudo ./x.py install sudo ./x.py pytest (Provided you don't change anything). Obviously, this doesn't interfer with existing work flows, but makes our contributor guide look really nice and simple :) https://pagure.io/389-ds-base/issue/49570 Author: wibrown Review by: ??? --- docker/389ds_poc/Dockerfile | 17 +++--- x.py | 144 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 10 deletions(-) create mode 100755 x.py diff --git a/docker/389ds_poc/Dockerfile b/docker/389ds_poc/Dockerfile index 95bea27d6..f58083315 100644 --- a/docker/389ds_poc/Dockerfile +++ b/docker/389ds_poc/Dockerfile @@ -6,34 +6,31 @@ # See LICENSE for details. # --- END COPYRIGHT BLOCK --- -FROM fedora:26 +FROM fedora:27 MAINTAINER 389-devel@lists.fedoraproject.org EXPOSE 389 636 ENV container docker RUN mkdir -p /usr/local/src -WORKDIR /usr/local/src ADD ./ /usr/local/src/389-ds-base +WORKDIR /usr/local/src/389-ds-base + RUN dnf upgrade -y && \ - dnf install --setopt=strict=False -y \ - @buildsys-build rpm-build make bzip2 git rsync \ - `grep -E "^(Build)?Requires" 389-ds-base/rpm/389-ds-base.spec.in | grep -v -E '(name|MODULE)' | awk '{ print $2 }' | sed 's/%{python3_pkgversion}/3/g' | grep -v "^/" | grep -v pkgversion | sort | uniq | tr '\n' ' '` && \ + ./x.py dep && \ dnf clean all - ### CHANGE THIS TO A ./configure and build that way. -RUN cd 389-ds-base && \ - PERL_ON=0 RUST_ON=1 make -f rpm.mk rpms +RUN PERL_ON=0 RUST_ON=1 make -f rpm.mk rpms -RUN dnf install -y 389-ds-base/dist/rpms/*389*.rpm && \ +RUN dnf install -y /usr/local/src/389-ds-base/dist/rpms/*389*.rpm && \ dnf clean all # Create the example setup inf. It's valid for containers! # Build the instance from the new installer tools. -RUN /usr/sbin/dscreate example > /root/ds-setup.inf && /usr/sbin/dscreate -v fromfile /root/ds-setup.inf --IsolemnlyswearthatIamuptonogood --containerised +RUN /usr/sbin/dscreate example > /root/ds-setup.inf && /usr/sbin/dscreate -v fromfile /root/ds-setup.inf --containerised # Finally add the volumes, they will inherit the contents of these directories. VOLUME /etc/dirsrv diff --git a/x.py b/x.py new file mode 100755 index 000000000..b4ab45eb1 --- /dev/null +++ b/x.py @@ -0,0 +1,144 @@ +#!/usr/bin/python3 + +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2018 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- + + +import sys +import subprocess +import os + +def _parse_spec_deps(spec_path, pyversion='3'): + lines = None + deps = [] + with open(spec_path) as f: + lines = f.readlines() + for line in lines: + if line.startswith('BuildRequires:') or line.startswith('Requires:'): + pkg_name = line.split(':')[1].strip().split(' ')[0] + pkg_name = pkg_name.replace("%{python3_pkgversion}", pyversion) + + # Now we have to clean up the pkg name + if "%{" in pkg_name or pkg_name == 'python3-lib389' or pkg_name == 'perl(': + continue + deps.append(pkg_name) + return deps + +def dependencies(): + if os.path.isfile('/etc/redhat-release'): + lines = None + with open('/etc/redhat-release') as f: + lines = f.read() + if 'Fedora' in lines: + subprocess.check_call( + """dnf install -y @buildsys-build make python3-setuptools rsync""", + shell=True) + # Get the deps from the RPM spec + # How can we make this path relative? + deps = _parse_spec_deps('./rpm/389-ds-base.spec.in') + deps_string = " ".join(deps) + subprocess.check_call( + """dnf install -y --setopt=strict=False %s""" % deps_string, + shell=True) + elif 'Centos' in lines: + subprocess.check_call( + """yum install -y @buildsys-build make epel-release""", + shell=True) + deps = _parse_spec_deps('./rpm/389-ds-base.spec.in', '34') + deps_string = " ".join(deps) + subprocess.check_call( + """yum install -y %s""" % deps_string, + shell=True) + else: + print('Unknown platform. Please report a bug to https://pagure.io/389-ds-base/ along with your "uname -a" output') + else: + print('Unknown platform. Please report a bug to https://pagure.io/389-ds-base/ along with your "uname -a" output') + +def configure(args=[]): + os.makedirs('./build_ds', exist_ok=True) + myenv = os.environ.copy() + subprocess.check_call([ + 'autoreconf', '-fiv' + ]) + if args == []: + args = ['--enable-debug', '--enable-cmocka', '--enable-asan'] + + try: + os.chdir('./build_ds') + config_cmd = ['../configure'] + args + subprocess.check_call(config_cmd, env=myenv) + finally: + os.chdir('../') + +MAKE_PREFIX = ['make', '-C', './build_ds'] + +def make(): + subprocess.check_call( + MAKE_PREFIX + ['-j8'] + ) + subprocess.check_call( + MAKE_PREFIX + ['lib389'] + ) + +def test(): + subprocess.check_call( + MAKE_PREFIX + ['check'] + ) + +def install(): + subprocess.check_call( + MAKE_PREFIX + ['install'] + ) + subprocess.check_call( + MAKE_PREFIX + ['lib389-install'] + ) + +def rpm(): + subprocess.check_call( + MAKE_PREFIX + ['rpms'] + ) + +def srpm(): + subprocess.check_call( + MAKE_PREFIX + ['srpm'] + ) + +def pytest(args): + myenv = os.environ.copy() + myenv['PYTHONPATH'] = './src/lib389' + if args == []: + args = ['dirsrvtests/tests/suites/', 'dirsrvtests/tests/tickets/'] + cmd = ['pytest-3'] + args + # Do we need to mess with environment here? + subprocess.check_call(cmd, env=myenv) + +def run_x(): + if len(sys.argv) == 1: + print('x.py []') + sys.exit(1) + elif sys.argv[1].startswith('d'): + dependencies() + elif sys.argv[1].startswith('c'): + configure(args = sys.argv[2:]) + elif sys.argv[1].startswith('i'): + install() + elif sys.argv[1].startswith('m'): + make() + elif sys.argv[1].startswith('t'): + test() + elif sys.argv[1].startswith('r'): + rpm() + elif sys.argv[1].startswith('s'): + srpm() + elif sys.argv[1].startswith('p'): + pytest(args = sys.argv[2:]) + +if __name__ == '__main__': + run_x() + + -- 2.14.3