updated internal docs
[catalyst.git] / catalyst
1 #!/usr/bin/python
2
3 import os,sys,imp,string
4
5 def die(msg=None):
6         if msg:
7                 print "catalyst: "+msg
8         sys.exit(1)
9
10 def warn(msg):
11         print "catalyst: "+msg
12
13 def usage():
14         print "usage: meep!"
15
16 if len(sys.argv)==1 or sys.argv[1] in ["-h","--help"]:
17         usage()
18         sys.exit(1)
19 elif os.getuid()!=0:
20         #non-root callers can still get -h and --help to work.
21         die("This script requires root privileges to operate.") 
22
23 """
24 Overview of catalyst operation
25 ==============================
26
27 * The program starts, and the local machine type is detected. 
28
29 * Based on this information, catalyst determines what kind of machine types
30   it can build for (amd64 and ia64 can build for x86 as well, for example.)
31   The appropriate arch plugins are loaded, which contain builder classes
32   for each supported sub-arch.
33
34 * Command-line arguments are parsed. If specified, a spec file is read.
35
36 * These build variables are stored in an internal "spec" object, which will
37   be a standard python dictionary. This spec dictionary contains all relevant
38   build-related information.
39
40 * The spec object is passed to the appropriate subarch builder constructor.
41   The subarch builder constructor updates the spec object with variables
42   relevant to the sub-arch (pentium4, g3, etc.)
43
44 * The spec object is passed to the appropriate target constructor.
45   The target constructor updates the spec object to contain data relevant
46   to the particular target (stage1, stage3, grp, etc.)
47
48 * The full data of the spec object is written to disc, so there is a complete
49   record of all variables that will be used to build what we're building.
50   This will allow for another person to re-use this information to
51   replicate our work (it should be possible to distribute a spec file
52   along with a portage snapshot and a starter tarball, and our build can
53   be replicated exactly on any machine.) The spec object contains data like
54   CFLAGS, CHOST, subarch, mainarch, the profile used to build, and for GRP
55   and LiveCDs the complete package build list. This is important to allow
56   work to be replicated. It's possible that the stage1/2/3.sh scripts should
57   be distributed as well, to allow proper replication of work.
58
59 * The build process begins by calling the appropriate method of the builder
60   instance. This includes cleanup, setup of chroot, entering the chroot,
61   running the appropriate bash build script, checking for error conditions,
62   and finishing up.
63   
64 * The catalyst process is now complete :)
65
66 """
67
68
69 #This allows plugins to import modules in the /modules dir
70 sys.path.append(os.getcwd()+"/modules")
71
72 #map current machine information from uname() to the mainarch we are running
73 #under
74
75 machinemap={    "i386" : "x86",
76                 "i486" : "x86",
77                 "i586" : "x86",
78                 "i686" : "x86",
79                 "x86_64" : "amd64"
80         }
81
82 # map the mainarch we are running under to the mainarches we support for
83 # building stages and LiveCDs. (for example, on amd64, we can build stages for
84 # x86 or amd64.
85
86 targetmap={     "x86" : ["x86"],
87                 "amd64" : ["x86","amd64"]
88         }
89                 
90 mymachine=os.uname()[4]
91 if not machinemap.has_key(mymachine):
92         print "Unknown machine type:",mymachine
93         sys.exit(1)
94 hostarch=machinemap[mymachine]
95 print "Host architecture:",hostarch
96 print "Supported architectures for targets:",string.join(targetmap[hostarch])
97 print "Loading plugins:",
98 archmap={}
99 subarchmap={}
100 for x in targetmap[hostarch]:
101         fh=open("arch/"+x+".py")
102         #this next line loads the plugin as a module and assigns it to archmap[x]
103         archmap[x]=imp.load_module(x,fh,"arch/"+x+".py",(".py","r",imp.PY_SOURCE))
104         #this next line registers all the subarches supported in the plugin
105         archmap[x].register(subarchmap)
106         fh.close()      
107         print x,
108 print
109 print "Available subarches:",string.join(subarchmap.keys())
110
111 import targets
112 targetmap={}
113 targets.register(targetmap)
114 print "Available targets:",string.join(targetmap.keys())