ccache fixups
[catalyst.git] / catalyst
1 #!/usr/bin/python
2
3 import os,sys,imp,string
4
5 def usage():
6         print "Usage: catalyst [-f file] [variable=value ...]"
7         print " -h --help               print this usage and exit"
8         print " -v --version            display version information"
9         print " -f --file               read specified file for build instructions"
10         print " variable=value          specify a variable/value pair"
11
12 def vers():
13         print "Gentoo catalyst, version "+version
14         print "Copyright 2003-2004 Gentoo Technologies, Inc."
15         print "Distributed under the GNU General Public License version 2"
16
17 version="1.0"
18
19 if len(sys.argv)==1 or sys.argv[1] in ["-h","--help"]:
20         usage()
21         sys.exit(1)
22 elif sys.argv[1] in ["-v","--version"]:
23         vers()
24         sys.exit(1)
25 if os.getuid()!=0:
26         #non-root callers can't go any further than here. 
27         print "catalyst: This script requires root privileges to operate."
28         sys.exit(1)
29
30 myspec={}
31 myconf={}
32 if os.path.exists("/etc/catalyst.conf"):
33         try:
34                 execfile("/etc/catalyst.conf",myconf,myconf)
35         except:
36                 print "catalyst: Unable to /etc/catalyst.conf config file (syntax error)"
37                 sys.exit(1)
38
39 confdefaults={ "storedir":"/var/tmp/catalyst","sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",
40 "portdir":"/usr/portage","options":"ccache"}
41
42 for x in confdefaults.keys():
43         if myconf.has_key(x):
44                 print "Setting",x,"to config file value \""+myconf[x]+"\""
45                 myspec[x]=myconf[x]
46         else:
47                 print "Setting",x,"to default value \""+confdefaults[x]+"\""
48                 myspec[x]=confdefaults[x]
49
50 #This allows plugins (and this code) to import modules in the /modules dir
51 sys.path.append(myspec["sharedir"]+"/modules")
52 try:
53         from catalyst_support import *
54         import targets
55 except ImportError:
56         print "catalyst: python modules not found in "+myspec["sharedir"]+"/modules; exiting."
57         sys.exit(1)
58
59 targetmap={}
60 targets.register(targetmap)
61
62 if "ccache" in string.split(myspec["options"]):
63         if not os.environ.has_key["CCACHE_DIR"]:
64                 print "Compiler cache support disabled (no CCACHE_DIR defined)"
65         elif not os.path.exists(os.environ["CCACHE_DIR"]):
66                 print "Compiler cache support disabled (no cache found at CCACHE_DIR)"
67         else:
68                 myspec["CCACHE"]="1"
69                 print "Compiler cache support enabled."
70 if "pkgcache" in string.split(myspec["options"]):
71         print "Package cache support enabled."
72         myspec["PKGCACHE"]="1"
73
74 if "distcc" in string.split(myspec["options"]):
75         print "Distcc support enabled."
76         myspec["DISTCC"]="1"
77
78 if sys.argv[1] in ["-f", "--file" ]:
79         try:
80                 addlargs=read_spec(sys.argv[2])
81         except:
82                 raise CatalystError,"Unable to read spec file: "+sys.argv[2]
83         unparsedargs=sys.argv[3:]
84 else:
85         addlargs={}
86         unparsedargs=sys.argv[1:]
87 try:
88         arg_parse(myspec,addlargs,unparsedargs)
89         if not targetmap.has_key(myspec["target"]):
90                 raise CatalystError,"Target \""+myspec["target"]+"\" not available."
91         mytarget=targetmap[myspec["target"]](myspec,addlargs)
92         
93         mytarget.run()
94 except CatalystError:
95         sys.exit(1)