1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3 from __future__ import print_function
10 def get_build_requires(spec, bconds_with, bconds_without):
11 cond_rx = re.compile(r"%\{(\!\?|\?\!|\?)([a-zA-Z0-9_+]+)\s*:([^%\{\}]*)\}")
16 if m.group(2) in macros:
19 if not m.group(2) in macros:
24 l = cond_rx.sub(expand_one, l)
25 if len(l) > 1000: break
29 macro_rx = re.compile(r"%\{([a-zA-Z0-9_+]+)\}")
32 if m.group(1) in macros:
33 return macros[m.group(1)].strip()
35 return m.group(0) # don't change
38 l = macro_rx.sub(expand_one, l)
39 if len(l) > 1000: break
41 return expand_conds(l)
43 simple_br_rx = re.compile(r"^BuildRequires\s*:\s*([^\s]+)", re.I)
44 bcond_rx = re.compile(r"^%bcond_(with|without)\s+([^\s]+)")
45 version_rx = re.compile(r"^Version\s*:\s*([^\s]+)", re.I)
46 release_rx = re.compile(r"^Release\s*:\s*([^\s]+)", re.I)
47 name_rx = re.compile(r"^Name\s*:\s*([^\s]+)", re.I)
48 define_rx = re.compile(r"^\%define\s+([a-zA-Z0-9_+]+)\s+(.*)", re.I)
49 any_br_rx = re.compile(r"BuildRequires", re.I)
53 macros["_with_%s" % b] = 1
54 for b in bconds_without:
55 macros["_without_%s" % b] = 1
57 macros["__perl"] = "/usr/bin/perl"
58 macros["_bindir"] = "/usr/bin"
59 macros["_sbindir"] = "/usr/sbin"
60 macros["kgcc_package"] = "gcc"
67 if l == "%changelog": break
70 m = bcond_rx.search(l)
73 if m.group(1) == "with":
74 if "_with_%s" % bcond in macros:
75 macros["with_%s" % bcond] = 1
77 if not "_without_%s" % bcond in macros:
78 macros["with_%s" % bcond] = 1
81 # name,version,release
82 m = version_rx.search(l)
83 if m: macros["version"] = m.group(1)
84 m = release_rx.search(l)
85 if m: macros["release"] = m.group(1)
87 if m: macros["name"] = m.group(1)
90 m = define_rx.search(l)
91 if m: macros[m.group(1)] = m.group(2)
94 if any_br_rx.search(l):
96 m = simple_br_rx.search(l)
98 build_req.append(m.group(1))
100 if l <> "" and l[0] <> '#':
101 msg("spec error (%s): %s\n" % (spec, l))