]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - PLD_Builder/get_br.py
start migrating to python 3: use print function
[projects/pld-builder.new.git] / PLD_Builder / get_br.py
CommitLineData
dfff8bd5
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
fe8cf8f9
JR
3from __future__ import print_function
4
b03a96bc
MM
5import re
6import string
7import xreadlines
8from util import *
9
10
11def get_build_requires(spec, bconds_with, bconds_without):
dfff8bd5 12 cond_rx = re.compile(r"%\{(\!\?|\?\!|\?)([a-zA-Z0-9_+]+)\s*:([^%\{\}]*)\}")
e6376553 13
dfff8bd5
MM
14 def expand_conds(l):
15 def expand_one(m):
16 if m.group(1) == "?":
17 if macros.has_key(m.group(2)):
18 return m.group(3)
19 else:
20 if not macros.has_key(m.group(2)):
21 return m.group(3)
22 return ""
e6376553 23
dfff8bd5
MM
24 for i in range(10):
25 l = cond_rx.sub(expand_one, l)
26 if len(l) > 1000: break
b03a96bc 27
dfff8bd5 28 return l
b03a96bc 29
dfff8bd5
MM
30 macro_rx = re.compile(r"%\{([a-zA-Z0-9_+]+)\}")
31 def expand_macros(l):
32 def expand_one(m):
33 if macros.has_key(m.group(1)):
34 return string.strip(macros[m.group(1)])
35 else:
36 return m.group(0) # don't change
e6376553 37
dfff8bd5
MM
38 for i in range(10):
39 l = macro_rx.sub(expand_one, l)
40 if len(l) > 1000: break
e6376553 41
dfff8bd5 42 return expand_conds(l)
e6376553 43
dfff8bd5
MM
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)
e6376553 51
dfff8bd5
MM
52 macros = {}
53 for b in bconds_with:
54 macros["_with_%s" % b] = 1
55 for b in bconds_without:
56 macros["_without_%s" % b] = 1
57
58 macros["__perl"] = "/usr/bin/perl"
59 macros["_bindir"] = "/usr/bin"
60 macros["_sbindir"] = "/usr/sbin"
61 macros["kgcc_package"] = "gcc"
b03a96bc 62
dfff8bd5 63 build_req = []
e6376553 64
dfff8bd5
MM
65 f = open(spec)
66 for l in xreadlines.xreadlines(f):
67 l = string.strip(l)
68 if l == "%changelog": break
e6376553 69
dfff8bd5
MM
70 # %bcond_with..
71 m = bcond_rx.search(l)
72 if m:
73 bcond = m.group(2)
74 if m.group(1) == "with":
e6376553 75 if macros.has_key("_with_%s" % bcond):
dfff8bd5
MM
76 macros["with_%s" % bcond] = 1
77 else:
e6376553 78 if not macros.has_key("_without_%s" % bcond):
dfff8bd5
MM
79 macros["with_%s" % bcond] = 1
80 continue
e6376553 81
dfff8bd5
MM
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)
87 m = name_rx.search(l)
88 if m: macros["name"] = m.group(1)
89
90 # %define
91 m = define_rx.search(l)
92 if m: macros[m.group(1)] = m.group(2)
e6376553 93
dfff8bd5
MM
94 # *BuildRequires*
95 if any_br_rx.search(l):
96 l = expand_macros(l)
97 m = simple_br_rx.search(l)
98 if m:
99 build_req.append(m.group(1))
100 else:
101 if l <> "" and l[0] <> '#':
102 msg("spec error (%s): %s\n" % (spec, l))
b03a96bc 103
dfff8bd5 104 for x in build_req:
fe8cf8f9 105 print(x)
This page took 3.17471 seconds and 4 git commands to generate.