1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
3 from __future__ import print_function
11 def get_build_requires(spec, bconds_with, bconds_without):
12 cond_rx = re.compile(r"%\{(\!\?|\?\!|\?)([a-zA-Z0-9_+]+)\s*:([^%\{\}]*)\}")
17 if macros.has_key(m.group(2)):
20 if not macros.has_key(m.group(2)):
25 l = cond_rx.sub(expand_one, l)
26 if len(l) > 1000: break
30 macro_rx = re.compile(r"%\{([a-zA-Z0-9_+]+)\}")
33 if macros.has_key(m.group(1)):
34 return string.strip(macros[m.group(1)])
36 return m.group(0) # don't change
39 l = macro_rx.sub(expand_one, l)
40 if len(l) > 1000: break
42 return expand_conds(l)
44 simple_br_rx = re.compile(r"^BuildRequires\s*:\s*([^\s]+)", re.I)
45 bcond_rx = re.compile(r"^%bcond_(with|without)\s+([^\s]+)")
46 version_rx = re.compile(r"^Version\s*:\s*([^\s]+)", re.I)
47 release_rx = re.compile(r"^Release\s*:\s*([^\s]+)", re.I)
48 name_rx = re.compile(r"^Name\s*:\s*([^\s]+)", re.I)
49 define_rx = re.compile(r"^\%define\s+([a-zA-Z0-9_+]+)\s+(.*)", re.I)
50 any_br_rx = re.compile(r"BuildRequires", re.I)
54 macros["_with_%s" % b] = 1
55 for b in bconds_without:
56 macros["_without_%s" % b] = 1
58 macros["__perl"] = "/usr/bin/perl"
59 macros["_bindir"] = "/usr/bin"
60 macros["_sbindir"] = "/usr/sbin"
61 macros["kgcc_package"] = "gcc"
66 for l in xreadlines.xreadlines(f):
68 if l == "%changelog": break
71 m = bcond_rx.search(l)
74 if m.group(1) == "with":
75 if macros.has_key("_with_%s" % bcond):
76 macros["with_%s" % bcond] = 1
78 if not macros.has_key("_without_%s" % bcond):
79 macros["with_%s" % bcond] = 1
82 # name,version,release
83 m = version_rx.search(l)
84 if m: macros["version"] = m.group(1)
85 m = release_rx.search(l)
86 if m: macros["release"] = m.group(1)
88 if m: macros["name"] = m.group(1)
91 m = define_rx.search(l)
92 if m: macros[m.group(1)] = m.group(2)
95 if any_br_rx.search(l):
97 m = simple_br_rx.search(l)
99 build_req.append(m.group(1))
101 if l <> "" and l[0] <> '#':
102 msg("spec error (%s): %s\n" % (spec, l))