1 | #!/usr/bin/env python2.4 |
---|
2 | import sys |
---|
3 | sys.path.append(sys.argv[2]+ "/lib/python") |
---|
4 | import debian_linux.gencontrol |
---|
5 | from debian_linux.config import * |
---|
6 | from debian_linux.debian import * |
---|
7 | |
---|
8 | class gencontrol(debian_linux.gencontrol.gencontrol): |
---|
9 | makefile_targets = ('binary-arch', 'build', 'setup') |
---|
10 | |
---|
11 | def __init__(self): |
---|
12 | super(gencontrol, self).__init__() |
---|
13 | self.process_changelog(read_changelog()) |
---|
14 | |
---|
15 | def do_main_setup(self, vars, makeflags, extra): |
---|
16 | makeflags.update({ |
---|
17 | 'MAJOR': self.version['xen']['major'], |
---|
18 | 'VERSION': self.version['xen']['version'], |
---|
19 | 'SHORT_VERSION': self.version['xen']['short_version'], |
---|
20 | 'EXTRAVERSION': self.version['xen']['extraversion'], |
---|
21 | 'ABINAME': self.abiname, |
---|
22 | }) |
---|
23 | |
---|
24 | def do_main_packages(self, packages, extra): |
---|
25 | packages.extend(self.process_packages(self.templates["control.main"], self.vars)) |
---|
26 | |
---|
27 | def do_arch_setup(self, vars, makeflags, arch, extra): |
---|
28 | for i in ( |
---|
29 | ('xen-arch', 'XEN_ARCH'), |
---|
30 | ): |
---|
31 | if vars.has_key(i[0]): |
---|
32 | makeflags[i[1]] = vars[i[0]] |
---|
33 | |
---|
34 | def do_arch_packages(self, packages, makefile, arch, vars, makeflags, extra): |
---|
35 | utils = self.templates["control.utils"] |
---|
36 | packages_utils = self.process_packages(utils, vars) |
---|
37 | |
---|
38 | for package in packages_utils: |
---|
39 | name = package['Package'] |
---|
40 | if packages.has_key(name): |
---|
41 | package = packages.get(name) |
---|
42 | package['Architecture'].append(arch) |
---|
43 | else: |
---|
44 | package['Architecture'] = [arch] |
---|
45 | packages.append(package) |
---|
46 | |
---|
47 | package_utils_name = packages_utils[0]['Package'] |
---|
48 | |
---|
49 | for i in ('postinst', 'prerm'): |
---|
50 | j = self.substitute(self.templates["xen-utils.%s" % i], vars) |
---|
51 | file("debian/%s.%s" % (package_utils_name, i), 'w').write(j) |
---|
52 | |
---|
53 | cmds_binary_arch = [] |
---|
54 | cmds_binary_arch.append(("$(MAKE) -f debian/rules.real binary-arch-arch %s" % makeflags)) |
---|
55 | cmds_build = [] |
---|
56 | cmds_build.append(("$(MAKE) -f debian/rules.real build-arch %s" % makeflags,)) |
---|
57 | cmds_setup = [] |
---|
58 | cmds_setup.append(("$(MAKE) -f debian/rules.real setup-arch %s" % makeflags,)) |
---|
59 | makefile.append(("binary-arch-%s-real:" % arch, cmds_binary_arch)) |
---|
60 | makefile.append(("build-%s-real:" % arch, cmds_build)) |
---|
61 | makefile.append(("setup-%s-real:" % arch, cmds_setup)) |
---|
62 | |
---|
63 | def do_subarch_makefile(self, makefile, arch, subarch, makeflags, extra): |
---|
64 | pass |
---|
65 | |
---|
66 | def do_flavour_setup(self, vars, makeflags, arch, subarch, flavour, extra): |
---|
67 | for i in ( |
---|
68 | ('config', 'CONFIG'), |
---|
69 | ): |
---|
70 | if vars.has_key(i[0]): |
---|
71 | makeflags[i[1]] = vars[i[0]] |
---|
72 | |
---|
73 | def do_flavour_makefile(self, makefile, arch, subarch, flavour, makeflags, extra): |
---|
74 | for i in self.makefile_targets: |
---|
75 | makefile.append("%s-%s:: %s-%s-%s" % (i, arch, i, arch, flavour)) |
---|
76 | makefile.append("%s-%s-%s:: %s-%s-%s-real" % (i, arch, flavour, i, arch, flavour)) |
---|
77 | |
---|
78 | def do_flavour_packages(self, packages, makefile, arch, subarch, flavour, vars, makeflags, extra): |
---|
79 | hypervisor = self.templates["control.hypervisor"] |
---|
80 | |
---|
81 | if not vars.has_key('desc'): |
---|
82 | vars['desc'] = '' |
---|
83 | |
---|
84 | packages_own = [] |
---|
85 | packages_own.extend(self.process_packages(hypervisor, vars)) |
---|
86 | |
---|
87 | for package in packages_own: |
---|
88 | name = package['Package'] |
---|
89 | if packages.has_key(name): |
---|
90 | package = packages.get(name) |
---|
91 | package['Architecture'].append(arch) |
---|
92 | else: |
---|
93 | package['Architecture'] = [arch] |
---|
94 | packages.append(package) |
---|
95 | |
---|
96 | package_name = packages_own[0]['Package'] |
---|
97 | |
---|
98 | for i in ('postinst', 'postrm'): |
---|
99 | j = self.substitute(self.templates["xen-hypervisor.%s" % i], vars) |
---|
100 | file("debian/%s.%s" % (package_name, i), 'w').write(j) |
---|
101 | |
---|
102 | cmds_binary_arch = [] |
---|
103 | cmds_binary_arch.append(("$(MAKE) -f debian/rules.real binary-arch-flavour %s" % makeflags,)) |
---|
104 | cmds_build = [] |
---|
105 | cmds_build.append(("$(MAKE) -f debian/rules.real build-flavour %s" % makeflags,)) |
---|
106 | cmds_setup = [] |
---|
107 | cmds_setup.append(("$(MAKE) -f debian/rules.real setup-flavour %s" % makeflags,)) |
---|
108 | makefile.append(("binary-arch-%s-%s-real:" % (arch, flavour), cmds_binary_arch)) |
---|
109 | makefile.append(("build-%s-%s-real:" % (arch, flavour), cmds_build)) |
---|
110 | makefile.append(("setup-%s-%s-real:" % (arch, flavour), cmds_setup)) |
---|
111 | makefile.append(("source-%s-%s-real:" % (arch, flavour))) |
---|
112 | |
---|
113 | def process_changelog(self, changelog): |
---|
114 | self.version = changelog[0]['Version'] |
---|
115 | self.version['xen'] = parse_version_xen(self.version['complete']) |
---|
116 | self.abiname = '-%s' % self.config['abi',]['abiname'] |
---|
117 | self.vars = { |
---|
118 | 'major': self.version['xen']['major'], |
---|
119 | 'version': self.version['xen']['version'], |
---|
120 | 'short_version': self.version['xen']['short_version'], |
---|
121 | 'abiname': self.abiname, |
---|
122 | } |
---|
123 | |
---|
124 | def parse_version_xen(version): |
---|
125 | version_re = ur""" |
---|
126 | ^ |
---|
127 | (?P<source> |
---|
128 | (?P<upstream> |
---|
129 | (?P<version> |
---|
130 | (?P<major>\d+\.\d+) |
---|
131 | ( |
---|
132 | ( |
---|
133 | (?P<minor>\.\d+) |
---|
134 | ( |
---|
135 | (-\d+) |
---|
136 | | |
---|
137 | (~rc\d+) |
---|
138 | ) |
---|
139 | ) |
---|
140 | | |
---|
141 | (?P<unstable>-unstable) |
---|
142 | ) |
---|
143 | ) |
---|
144 | (?: |
---|
145 | \+hg |
---|
146 | (?P<hg_rev> |
---|
147 | \d+ |
---|
148 | ) |
---|
149 | )? |
---|
150 | ) |
---|
151 | - |
---|
152 | (?P<debian>[^-]+) |
---|
153 | ) |
---|
154 | $ |
---|
155 | """ |
---|
156 | match = re.match(version_re, version, re.X) |
---|
157 | if match is None: |
---|
158 | raise ValueError |
---|
159 | ret = match.groupdict() |
---|
160 | if ret['unstable'] is not None: |
---|
161 | ret['major'] = 'unstable' |
---|
162 | ret['short_version'] = ret['version'] |
---|
163 | ret['extraversion'] = ret['unstable'] |
---|
164 | else: |
---|
165 | ret['version'] = ret['major'] + ret['minor'] |
---|
166 | ret['short_version'] = ret['major'] |
---|
167 | ret['extraversion'] = ret['minor'] |
---|
168 | del ret['unstable'] |
---|
169 | return ret |
---|
170 | |
---|
171 | if __name__ == '__main__': |
---|
172 | gencontrol()() |
---|