Add armv6j_hardfp
[catalyst.git] / catalyst
1 #!/usr/bin/python -OO
2
3 # Maintained in full by:
4 # Andrew Gaffney <agaffney@gentoo.org>
5 # Chris Gianelloni <wolf31o2@wolf31o2.org>
6 # $Id$
7
8 import os, sys, getopt
9
10 # This assumes that our modules are in a sub-dir named "modules" in the
11 # directory that the main catalyst binary is in
12 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
13 sys.path.append(__selfpath__ + "/modules")
14
15 import catalyst
16 from catalyst.output import *
17 from catalyst.error import *
18 from catalyst.hash import hash_map
19
20 __maintainer__="Chris Gianelloni <wolf31o2@wolf31o2.org>"
21 __version__="2.99"
22
23 conf_values = {}
24 config = catalyst.config.config()
25
26 def usage():
27         print "Usage catalyst [options] [-C variable=value...] [ -s identifier]"
28         print " -a --clear-autoresume   clear autoresume flags"
29         print " -c --config     use specified configuration file"
30         print " -C --cli        catalyst commandline (MUST BE LAST OPTION)"
31         print " -d --debug      enable debugging"
32         print " -f --file       read specfile"
33         print " -F --fetchonly  fetch files only"
34         print " -h --help       print this help message"
35         print " -p --purge      clear tmp dirs,package cache and autoresume flags"
36         print " -P --purgeonly  clear tmp dirs,package cache and autoresume flags and exit"
37         print " -s --snapshot   generate a release snapshot"
38         print " -V --version    display version information"
39         print " -v --verbose    verbose output"
40         print
41         print "Usage examples:"
42         print
43         print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
44         print "catalyst -C target=snapshot version_stamp=my_date"
45         print
46         print "Using the snapshot option (-s, --snapshot) to build a release snapshot:"
47         print "catalyst -s 20071121"
48         print
49         print "Using the specfile option (-f, --file) to build a stage target:"
50         print "catalyst -f stage1-specfile.spec"
51
52 def show_version():
53         msg("Catalyst, version " + __version__)
54         msg("Copyright 2003-2008 Gentoo Foundation")
55         msg("Copyright 2008 various authors")
56         msg("Distributed under the GNU General Public License version 2.1")
57
58 def parse_config():
59         # search a couple of different areas for the main config file
60         myconf = {}
61
62         confdefaults = {
63                 "storedir": "/var/tmp/catalyst",
64                 "sharedir": "/usr/share/catalyst",
65                 "distdir": "/usr/portage/distfiles",
66                 "portdir": "/usr/portage",
67                 "options": "",
68                 "snapshot_cache": "/var/tmp/catalyst/snapshot_cache",
69                 "hash_function": "crc32"
70         }
71
72         # first, try the one passed (presumably from the cmdline)
73         if "config_file" in conf_values:
74                 if os.path.exists(conf_values["config_file"]):
75                         msg("Using command line specified Catalyst configuration file, " + conf_values["config_file"])
76                 else:
77                         die("specified configuration file " + conf_values["config_file"] + " does not exist")
78
79         # next, try the default location
80         elif os.path.exists("/etc/catalyst/catalyst.conf"):
81                 msg("Using default Catalyst configuration file, /etc/catalyst/catalyst.conf")
82                 conf_values["config_file"] = "/etc/catalyst/catalyst.conf"
83
84         # can't find a config file (we are screwed), so bail out
85         else:
86                 die("Could not find a suitable configuration file")
87
88         # Load the default config values into myconf
89         for x in confdefaults:
90                 msg("Setting " + x + " to default value '" + confdefaults[x] + "'")
91                 myconf[x] = confdefaults[x]
92
93         # now, try and parse the config file "config_file"
94         try:
95                 myconfig = catalyst.config.ConfigParser(conf_values["config_file"])
96                 myconf.update(myconfig.get_values())
97
98         except:
99                 die("Unable to parse configuration file, " + conf_values["config_file"])
100
101         # now, load up the values into conf_values so that we can use them
102         for x in confdefaults.keys():
103                 if x in myconf:
104                         msg("Setting " + x + " to config file value '" + myconf[x] + "'")
105                         conf_values[x] = myconf[x]
106                 else:
107                         msg("Setting " + x + " to default value '" + confdefaults[x] + "'")
108                         conf_values[x] = confdefaults[x]
109
110         options = (
111                 ("autoresume", "AUTORESUME", "Autoresuming support enabled."),
112                 ("ccache", "CCACHE", "Compiler cache support enabled."),
113                 ("clear-autoresume", "CLEAR_AUTORESUME", "Cleaning autoresume flags support enabled"),
114 #               ("compress", "COMPRESS", "Compression enabled."),
115                 ("distcc", "DISTCC", "Distcc support enabled."),
116                 ("icecream", "ICECREAM", "Icecream compiler cluster support enabled."),
117                 ("kerncache", "KERNCACHE", "Kernel cache support enabled."),
118                 ("pkgcache", "PKGCACHE", "Package cache support enabled."),
119                 ("purge", "PURGE", "Purge support enabled."),
120                 ("seedcache", "SEEDCACHE", "Seed cache support enabled."),
121                 ("snapcache", "SNAPCACHE", "Snapshot cache support enabled."),
122 #               ("tarball", "TARBALL", "Tarball creation enabled.")
123         )
124
125         split_options = conf_values["options"].split()
126
127         # parse out the rest of the options from the config file
128         for x in options:
129                 if x[0] in split_options:
130                         msg(x[2])
131                         conf_values[x[1]] = "1"
132
133         if "digests" in myconf:
134                 conf_values["digests"] = myconf["digests"]
135
136         if "contents" in myconf:
137                 conf_values["contents"] = myconf["contents"]
138
139         if "envscript" in myconf:
140                 msg("Envscript support enabled.")
141                 conf_values["ENVSCRIPT"] = myconf["envscript"]
142
143 def verify_digest_and_hash_functions():
144         # Start checking that digests are valid now that the hash_map was imported from catalyst_support
145         if "digests" in conf_values:
146                 for i in conf_values["digests"].split():
147                         if not i in hash_map:
148                                 msg()
149                                 msg(i + " is not a valid digest entry")
150                                 msg("Valid digest entries:")
151                                 msg("\n".join(hash_map.keys()))
152                                 msg()
153                                 msg("Catalyst aborting....")
154                                 sys.exit(2)
155                         if catalyst.util.find_binary(hash_map[i][1]) == None:
156                                 msg()
157                                 msg("digest=" + i)
158                                 msg("\tThe " + hash_map[i][1] + \
159                                         " binary was not found. It needs to be in your system path")
160                                 msg()
161                                 msg("Catalyst aborting....")
162                                 sys.exit(2)
163
164         if "hash_function" in conf_values:
165                 if not conf_values["hash_function"] in hash_map:
166                         msg()
167                         msg(conf_values["hash_function"] + " is not a valid hash_function entry")
168                         msg("Valid hash_function entries:")
169                         msg("\n".join(hash_map.keys()))
170                         msg()
171                         msg("Catalyst aborting....")
172                         sys.exit(2)
173                 if catalyst.util.find_binary(hash_map[conf_values["hash_function"]][1]) == None:
174                         msg()
175                         msg("hash_function=" + conf_values["hash_function"])
176                         msg("\tThe " + hash_map[conf_values["hash_function"]][1] + \
177                                 " binary was not found. It needs to be in your system path")
178                         msg()
179                         msg("Catalyst aborting....")
180                         sys.exit(2)
181
182 def parse_commandline():
183         # parse out the command line arguments
184         try:
185                 opts,args = getopt.getopt(sys.argv[1:], "apPhvdc:C:f:FVs:", ["purge", "purgeonly", "help", "version", "debug",\
186                         "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
187
188         except getopt.GetoptError:
189                 usage()
190                 sys.exit(2)
191
192         # defaults for commandline opts
193         conf_values["command_line"] = []
194
195         # check preconditions
196         if len(opts) == 0:
197                 warn("please specify one of either -f or -C\n")
198                 usage()
199                 sys.exit(2)
200
201         run = False
202         for o, a in opts:
203                 if o in ("-h", "--help"):
204                         usage()
205                         sys.exit(1)
206
207                 if o in ("-V", "--version"):
208                         show_version()
209                         sys.exit(1)
210
211                 if o in ("-d", "--debug"):
212                         conf_values["DEBUG"]="1"
213                         conf_values["VERBOSE"]="1"
214
215                 if o in ("-c", "--config"):
216                         conf_values["config_file"] = a
217
218                 if o in ("-C", "--cli"):
219                         run = True
220                         x = sys.argv.index(o) + 1
221                         while x < len(sys.argv):
222                                 conf_values["command_line"].append(sys.argv[x])
223                                 x = x + 1
224
225                 if o in ("-f", "--file"):
226                         run = True
227                         conf_values["spec_file"] = a
228
229                 if o in ("-F", "--fetchonly"):
230                         conf_values["FETCH"] = "1"
231
232                 if o in ("-v", "--verbose"):
233                         conf_values["VERBOSE"] = "1"
234
235                 if o in ("-s", "--snapshot"):
236                         if len(sys.argv) < 3:
237                                 warn("missing snapshot identifier")
238                                 usage()
239                                 sys.exit(2)
240                         else:
241                                 run = True
242                                 conf_values["command_line"].append("target=snapshot")
243                                 conf_values["command_line"].append("version_stamp="+a)
244
245                 if o in ("-p", "--purge"):
246                         conf_values["PURGE"] = "1"
247
248                 if o in ("-P", "--purgeonly"):
249                         conf_values["PURGEONLY"] = "1"
250
251                 if o in ("-a", "--clear-autoresume"):
252                         conf_values["CLEAR_AUTORESUME"] = "1"
253
254         if not run:
255                 warn("please specify one of either -f or -C")
256                 usage()
257                 sys.exit(2)
258
259 if __name__ == "__main__":
260
261         show_version()
262
263         if os.getuid() != 0:
264                 # catalyst cannot be run as a normal user due to chroots, mounts, etc
265                 die("This script requires root privileges to operate", 2)
266
267         parse_commandline()
268
269         parse_config()
270
271         verify_digest_and_hash_functions()
272
273         targetmap = catalyst.target.build_target_map()
274         spec = catalyst.config.Spec()
275
276         if "spec_file" in conf_values:
277                 specparser = catalyst.config.SpecParser(conf_values["spec_file"])
278                 spec_values = specparser.get_values()
279                 spec.parse_values(spec_values)
280
281         if "command_line" in conf_values:
282                 try:
283                         cmdline = catalyst.config.ConfigParser()
284                         cmdline.parse_lines(conf_values["command_line"])
285                         cmdline_values = cmdline.get_values()
286                         spec.parse_values(cmdline_values)
287                 except CatalystError:
288                         die("Could not parse commandline, exiting.")
289
290         config.set_spec(spec)
291         config.set_conf(conf_values)
292         config.set_targetmap(targetmap)
293
294         # everything is setup, so the build is a go
295         try:
296                 catalyst.target.build_targets()
297
298         except CatalystError:
299                 msg()
300                 msg("Catalyst aborting....")
301                 sys.exit(2)
302
303         except KeyboardInterrupt:
304                 msg()
305                 msg("Catalyst build aborted due to user interrupt ( Ctrl-C )")
306                 msg()
307                 msg("Catalyst aborting....")
308                 sys.exit(2)
309
310         except LockInUse:
311                 msg("Catalyst aborting....")
312                 sys.exit(2)
313
314         except:
315                 msg("Catalyst aborting....")
316                 raise
317                 sys.exit(2)
318
319         #except KeyError:
320         #       print "\nproblem with command line or spec file ( Key Error )"
321         #       print "Key: "+str(sys.exc_value)+" was not found"
322         #       print "Catalyst aborting...."
323         #       sys.exit(2)
324         #except UnboundLocalError:
325         #       print
326         #       print "UnboundLocalError: "+str(sys.exc_value)+" was not found"
327         #       raise
328         #       print
329         #       print "Catalyst aborting...."
330         #       sys.exit(2)