Import patch tmpfile
[vuplus_bitbake] / bin / oe / make.py
1 #!/usr/bin/python
2 """
3 OpenEmbedded 'Make' implementations
4
5 Functions for reading OE files, building a dependency graph and
6 building a set of OE files while walking along the dependency graph.
7
8 This file is part of the OpenEmbedded (http://openembedded.org) build infrastructure.
9 """
10
11 from oe import debug, digraph, data, fetch, fatal, error, note, event, parse
12 import copy, oe, re, sys, os, glob
13
14 # These variables are allowed to be reinitialized by client code
15 pkgdata = {}
16 cfg = {}
17
18 digits = "0123456789"
19 ascii_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
20
21 def get_oefiles( path = os.getcwd() ):
22     """Get list of default .oe files by reading out the current directory"""
23     contents = os.listdir(path)
24     oefiles = []
25     for f in contents:
26         (root, ext) = os.path.splitext(f)
27         if ext == ".oe":
28             oefiles.append(os.path.abspath(os.path.join(os.getcwd(),f)))
29     return oefiles
30
31 def find_oefiles( path ):
32     """Find all the .oe files in a directory (uses find)"""
33     findcmd = 'find ' + path + ' -name *.oe | grep -v SCCS/'
34     try:
35         finddata = os.popen(findcmd)
36     except OSError:
37         return []
38     return finddata.readlines()
39
40 def load_oefile( oefile ):
41     """Load and parse one .oe build file"""
42     oepath = data.getVar('OEPATH', cfg)
43     topdir = data.getVar('TOPDIR', cfg)
44     if not topdir:
45         topdir = os.path.abspath(os.getcwd())
46         # set topdir to here
47         data.setVar('TOPDIR', topdir, cfg)
48     oefile = os.path.abspath(oefile)
49     oefile_loc = os.path.abspath(os.path.dirname(oefile))
50     # expand tmpdir to include this topdir
51     data.setVar('TMPDIR', data.getVar('TMPDIR', cfg, 1) or "", cfg)
52     # add topdir to oepath
53     oepath += ":%s" % topdir
54     # set topdir to location of .oe file
55     topdir = oefile_loc
56     #data.setVar('TOPDIR', topdir, cfg)
57     # add that topdir to oepath
58     oepath += ":%s" % topdir
59     # go there
60     oldpath = os.path.abspath(os.getcwd())
61     os.chdir(topdir)
62     data.setVar('OEPATH', oepath, cfg)
63     oe = copy.deepcopy(cfg)
64     try:
65         parse.handle(oefile, oe) # read .oe data
66         os.chdir(oldpath)
67         return oe
68     finally:
69         os.chdir(oldpath)
70
71 def collect_oefiles( progressCallback ):
72     """Collect all available .oe build files"""
73
74     files = (data.getVar( "OEFILES", cfg, 1 ) or "").split()
75     data.setVar("OEFILES", " ".join(files), cfg)
76
77     if not len(files):
78         files = get_oefiles()
79
80     if not len(files):
81         oe.error("no files to build.")
82
83     newfiles = []
84     for f in files:
85         if os.path.isdir(f):
86             dirfiles = find_oefiles(f)
87             if dirfiles:
88                 newfiles += dirfiles
89                 continue
90         newfiles += glob.glob(f) or [ f ]
91
92     for i in xrange( len( newfiles ) ):
93         f = newfiles[i]
94         oemask = oe.data.getVar('OEMASK', cfg, 1)
95         if oemask:
96             if re.search(oemask, f):
97                 oe.debug(1, "oemake: skipping %s" % f)
98                 continue
99
100         progressCallback( i + 1, len( newfiles ), f )
101         debug(1, "oemake: parsing %s" % f)
102
103         # read a file's metadata
104         try:
105             pkgdata[f] = load_oefile(f)
106             deps = None
107             if pkgdata[f] is not None:
108                 # allow metadata files to add items to OEFILES
109                 #data.update_data(pkgdata[f])
110                 addoefiles = data.getVar('OEFILES', pkgdata[f]) or None
111                 if addoefiles:
112                     for aof in addoefiles.split():
113                         if not files.count(aof):
114                             if not os.path.isabs(aof):
115                                 aof = os.path.join(os.path.dirname(f),aof)
116                             files.append(aof)
117                 for var in pkgdata[f].keys():
118                     if data.getVarFlag(var, "handler", pkgdata[f]) and data.getVar(var, pkgdata[f]):
119                         event.register(data.getVar(var, pkgdata[f]))
120         except IOError:
121             oe.error("opening %s" % f)
122             pass
123         except oe.parse.SkipPackage:
124             pass
125
126 def explode_version(s):
127         import string
128         r = []
129         alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$')
130         numeric_regexp = re.compile('^(\d+)(.*)$')
131         while (s != ''):
132             if s[0] in digits:
133                 m = numeric_regexp.match(s)
134                 r.append(int(m.group(1)))
135                 s = m.group(2)
136                 continue
137             if s[0] in ascii_letters:
138                 m = alpha_regexp.match(s)
139                 r.append(m.group(1))
140                 s = m.group(2)
141                 continue
142             s = s[1:]
143         return r
144
145 def vercmp_part(a, b):
146         va = explode_version(a)
147         vb = explode_version(b)
148         while True:
149             if va == []:
150                 ca = None
151             else:
152                 ca = va.pop(0)
153             if vb == []:
154                 cb = None
155             else:
156                 cb = vb.pop(0)
157             if ca == None and cb == None:
158                 return 0
159             if ca > cb:
160                 return 1
161             if ca < cb:
162                 return -1
163
164 def vercmp(ta, tb):
165         (va, ra) = ta
166         (vb, rb) = tb
167         
168         r = vercmp_part(va, vb)
169         if (r == 0):
170             r = vercmp_part(ra, rb)
171         return r