aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <proyvind@moondrake.org>2016-05-30 20:11:53 +0200
committerPer Øyvind Karlsen <proyvind@moondrake.org>2016-05-30 20:11:53 +0200
commitc379f051d3b45e306f628f0764ab781f20e0f8f4 (patch)
tree9959a862cfa24ccd2b86ed47889412ab83d861ed /MgaRepo
parent459ff0c8929e14f9051245dc26ec234667d2ef94 (diff)
downloadmgarepo-c379f051d3b45e306f628f0764ab781f20e0f8f4.tar
mgarepo-c379f051d3b45e306f628f0764ab781f20e0f8f4.tar.gz
mgarepo-c379f051d3b45e306f628f0764ab781f20e0f8f4.tar.bz2
mgarepo-c379f051d3b45e306f628f0764ab781f20e0f8f4.tar.xz
mgarepo-c379f051d3b45e306f628f0764ab781f20e0f8f4.zip
add support for optionally installing build depedencies by default
Diffstat (limited to 'MgaRepo')
-rw-r--r--MgaRepo/commands/buildrpm.py2
-rw-r--r--MgaRepo/rpmutil.py30
2 files changed, 29 insertions, 3 deletions
diff --git a/MgaRepo/commands/buildrpm.py b/MgaRepo/commands/buildrpm.py
index 76fa41e..421ece0 100644
--- a/MgaRepo/commands/buildrpm.py
+++ b/MgaRepo/commands/buildrpm.py
@@ -11,6 +11,7 @@ Builds the binary RPM(s) (.rpm) file(s) of a given package.
Options:
-bX Build stage option, where X is stage, default is -bb
+ -I Don't automatically try install missing build dependencies
-l Disable rpmlint check of packages built
-P USER Define the RPM packager information to USER
-q Quiet build output
@@ -21,6 +22,7 @@ Options:
def parse_options():
parser = OptionParser(HELP)
parser.add_option("-b", dest="build_cmd", default="a")
+ parser.add_option("-I", dest="installdeps", action="store_false", default=True)
parser.add_option("-l", dest="rpmlint", action="store_false", default=True)
parser.add_option("-P", dest="packager", default="")
parser.add_option("-q", "--quiet", dest="verbose", action="store_false", default=True)
diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py
index 05f453d..e9a2df9 100644
--- a/MgaRepo/rpmutil.py
+++ b/MgaRepo/rpmutil.py
@@ -378,7 +378,8 @@ def build_rpm(build_cmd="b",
verbose=True,
rpmlint=True,
short_circuit=False,
- packager = "",
+ packager = None,
+ installdeps = True,
macros = []):
top = os.getcwd()
topdir = "_topdir %s" % top
@@ -408,7 +409,7 @@ def build_rpm(build_cmd="b",
rpmdefs.append(("--define", "_build_pkgcheck_set %{_bindir}/rpmlint"))
rpmbuild = config.get("helper", "rpmbuild", "rpmbuild")
- args = [rpmbuild, "-b"+build_cmd, spec]
+ args = [rpmbuild, spec]
if short_circuit:
args.append("--short-circuit")
for pair in rpmdefs:
@@ -416,7 +417,30 @@ def build_rpm(build_cmd="b",
for pair in macros:
args.extend(("--define", "%s %s" % pair))
os.environ["LC_ALL"] = "C"
- execcmd(*args, show=verbose)
+ # First check whether dependencies are satisfied
+ status, output = execcmd(*args + ["--nobuild"], show=verbose, collecterr=True, noerror=True)
+ if status:
+ if "error: Failed build dependencies:" in output:
+ if not installdeps:
+ raise Error("Automatic installation of dependencies disabled,"
+ "aborting...")
+ else:
+ if verbose:
+ print("Installing missing build dependencies")
+ if os.getuid() != 0:
+ print("Trying to obtain privileges for urpmi:")
+ sudocheck = ["sudo", "-l", "urpmi"]
+ status, output = execcmd(*sudocheck, collecter=True, noerror=True)
+ if status:
+ raise Error("%s\nFailed! Cannot proceed without, aborting..."
+ % output.splitlines()[-1])
+ urpmi = ["sudo", "urpmi"]
+ else:
+ urpmi = ["urpmi"]
+ cmd = urpmi + ["--auto", "--buildrequires", "--no-recommends", spec]
+ status, output = execcmd(*cmd, show=verbose, collecter=True, noerror=True)
+
+ status, output = execcmd(*args + ["-b"+build_cmd], show=verbose)
def create_package(pkgdirurl, log="", verbose=0):
svn = detectVCS(pkgdirurl)