1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
9 def get_build_requires(spec, bconds_with, bconds_without):
10 cond_rx = re.compile(r"%\{(\!\?|\?\!|\?)([a-zA-Z0-9_+]+)\s*:([^%\{\}]*)\}")
15 if macros.has_key(m.group(2)):
18 if not macros.has_key(m.group(2)):
23 l = cond_rx.sub(expand_one, l)
24 if len(l) > 1000: break
28 macro_rx = re.compile(r"%\{([a-zA-Z0-9_+]+)\}")
31 if macros.has_key(m.group(1)):
32 return string.strip(macros[m.group(1)])
34 return m.group(0) # don't change
37 l = macro_rx.sub(expand_one, l)
38 if len(l) > 1000: break
40 return expand_conds(l)
42 simple_br_rx = re.compile(r"^BuildRequires\s*:\s*([^\s]+)", re.I)
43 bcond_rx = re.compile(r"^%bcond_(with|without)\s+([^\s]+)")
44 version_rx = re.compile(r"^Version\s*:\s*([^\s]+)", re.I)
45 release_rx = re.compile(r"^Release\s*:\s*([^\s]+)", re.I)
46 name_rx = re.compile(r"^Name\s*:\s*([^\s]+)", re.I)
47 define_rx = re.compile(r"^\%define\s+([a-zA-Z0-9_+]+)\s+(.*)", re.I)
48 any_br_rx = re.compile(r"BuildRequires", re.I)
52 macros["_with_%s" % b] = 1
53 for b in bconds_without:
54 macros["_without_%s" % b] = 1
56 macros["__perl"] = "/usr/bin/perl"
57 macros["_bindir"] = "/usr/bin"
58 macros["_sbindir"] = "/usr/sbin"
59 macros["kgcc_package"] = "gcc"
64 for l in xreadlines.xreadlines(f):
66 if l == "%changelog": break
69 m = bcond_rx.search(l)
72 if m.group(1) == "with":
73 if macros.has_key("_with_%s" % bcond):
74 macros["with_%s" % bcond] = 1
76 if not macros.has_key("_without_%s" % bcond):
77 macros["with_%s" % bcond] = 1
80 # name,version,release
81 m = version_rx.search(l)
82 if m: macros["version"] = m.group(1)
83 m = release_rx.search(l)
84 if m: macros["release"] = m.group(1)
86 if m: macros["name"] = m.group(1)
89 m = define_rx.search(l)
90 if m: macros[m.group(1)] = m.group(2)
93 if any_br_rx.search(l):
95 m = simple_br_rx.search(l)
97 build_req.append(m.group(1))
99 if l <> "" and l[0] <> '#':
100 msg("spec error (%s): %s\n" % (spec, l))