diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-10-09 21:24:38 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-05-20 19:07:51 +0100 |
commit | e3d0d9897e45219c3964165666f0ceebff580678 (patch) | |
tree | adf8604636cc5e6e85cc01799e48697ef9763331 /meta | |
parent | 2a05bd9be0cb3961f394035bf0f4561283248a83 (diff) | |
download | poky-e3d0d9897e45219c3964165666f0ceebff580678.tar.gz |
Move packagedata code into oe.packagedata (sync from OE)
(From OE-Core rev: e6858627ab087f2f25ebbd6c4422eeae35f3b0ac)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes/package.bbclass | 4 | ||||
-rw-r--r-- | meta/classes/package_rpm.bbclass | 3 | ||||
-rw-r--r-- | meta/classes/packagedata.bbclass | 68 | ||||
-rw-r--r-- | meta/lib/oe/packagedata.py | 106 |
4 files changed, 115 insertions, 66 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 4eb349d431..2c6d30ccd8 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass | |||
@@ -295,7 +295,9 @@ def runstrip(file, elftype, d): | |||
295 | # | 295 | # |
296 | 296 | ||
297 | def get_package_mapping (pkg, d): | 297 | def get_package_mapping (pkg, d): |
298 | data = read_subpkgdata(pkg, d) | 298 | import oe.packagedata |
299 | |||
300 | data = oe.packagedata.read_subpkgdata(pkg, d) | ||
299 | key = "PKG_%s" % pkg | 301 | key = "PKG_%s" % pkg |
300 | 302 | ||
301 | if key in data: | 303 | if key in data: |
diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass index b86356de2e..1d8c686330 100644 --- a/meta/classes/package_rpm.bbclass +++ b/meta/classes/package_rpm.bbclass | |||
@@ -316,6 +316,7 @@ package_install_internal_rpm () { | |||
316 | 316 | ||
317 | python write_specfile () { | 317 | python write_specfile () { |
318 | import textwrap | 318 | import textwrap |
319 | import oe.packagedata | ||
319 | 320 | ||
320 | # We need to change '-' in a version field to '+' | 321 | # We need to change '-' in a version field to '+' |
321 | # This needs to be done BEFORE the mapping_rename_hook | 322 | # This needs to be done BEFORE the mapping_rename_hook |
@@ -328,7 +329,7 @@ python write_specfile () { | |||
328 | ver = depends_dict[dep] | 329 | ver = depends_dict[dep] |
329 | if dep and ver: | 330 | if dep and ver: |
330 | if '-' in ver: | 331 | if '-' in ver: |
331 | subd = read_subpkgdata_dict(dep, d) | 332 | subd = oe.packagedata.read_subpkgdata_dict(dep, d) |
332 | pv = subd['PV'] | 333 | pv = subd['PV'] |
333 | reppv = pv.replace('-', '+') | 334 | reppv = pv.replace('-', '+') |
334 | ver = ver.replace(pv, reppv) | 335 | ver = ver.replace(pv, reppv) |
diff --git a/meta/classes/packagedata.bbclass b/meta/classes/packagedata.bbclass index 86f18a9e96..bf051feea8 100644 --- a/meta/classes/packagedata.bbclass +++ b/meta/classes/packagedata.bbclass | |||
@@ -1,73 +1,13 @@ | |||
1 | def packaged(pkg, d): | ||
2 | return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK) | ||
3 | |||
4 | def read_pkgdatafile(fn): | ||
5 | pkgdata = {} | ||
6 | |||
7 | def decode(str): | ||
8 | import codecs | ||
9 | c = codecs.getdecoder("string_escape") | ||
10 | return c(str)[0] | ||
11 | |||
12 | if os.access(fn, os.R_OK): | ||
13 | import re | ||
14 | f = file(fn, 'r') | ||
15 | lines = f.readlines() | ||
16 | f.close() | ||
17 | r = re.compile("([^:]+):\s*(.*)") | ||
18 | for l in lines: | ||
19 | m = r.match(l) | ||
20 | if m: | ||
21 | pkgdata[m.group(1)] = decode(m.group(2)) | ||
22 | |||
23 | return pkgdata | ||
24 | |||
25 | def get_subpkgedata_fn(pkg, d): | ||
26 | archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ") | ||
27 | archs.reverse() | ||
28 | pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d) | ||
29 | targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d) | ||
30 | for arch in archs: | ||
31 | fn = pkgdata + arch + targetdir + pkg | ||
32 | if os.path.exists(fn): | ||
33 | return fn | ||
34 | return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d) | ||
35 | |||
36 | def has_subpkgdata(pkg, d): | ||
37 | return os.access(get_subpkgedata_fn(pkg, d), os.R_OK) | ||
38 | |||
39 | def read_subpkgdata(pkg, d): | ||
40 | return read_pkgdatafile(get_subpkgedata_fn(pkg, d)) | ||
41 | |||
42 | def has_pkgdata(pn, d): | ||
43 | fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d) | ||
44 | return os.access(fn, os.R_OK) | ||
45 | |||
46 | def read_pkgdata(pn, d): | ||
47 | fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d) | ||
48 | return read_pkgdatafile(fn) | ||
49 | |||
50 | python read_subpackage_metadata () { | 1 | python read_subpackage_metadata () { |
51 | data = read_pkgdata(bb.data.getVar('PN', d, 1), d) | 2 | import oe.packagedata |
3 | |||
4 | data = oe.packagedata.read_pkgdata(bb.data.getVar('PN', d, 1), d) | ||
52 | 5 | ||
53 | for key in data.keys(): | 6 | for key in data.keys(): |
54 | bb.data.setVar(key, data[key], d) | 7 | bb.data.setVar(key, data[key], d) |
55 | 8 | ||
56 | for pkg in bb.data.getVar('PACKAGES', d, 1).split(): | 9 | for pkg in bb.data.getVar('PACKAGES', d, 1).split(): |
57 | sdata = read_subpkgdata(pkg, d) | 10 | sdata = oe.packagedata.read_subpkgdata(pkg, d) |
58 | for key in sdata.keys(): | 11 | for key in sdata.keys(): |
59 | bb.data.setVar(key, sdata[key], d) | 12 | bb.data.setVar(key, sdata[key], d) |
60 | } | 13 | } |
61 | |||
62 | |||
63 | # | ||
64 | # Collapse FOO_pkg variables into FOO | ||
65 | # | ||
66 | def read_subpkgdata_dict(pkg, d): | ||
67 | ret = {} | ||
68 | subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d)) | ||
69 | for var in subd: | ||
70 | newvar = var.replace("_" + pkg, "") | ||
71 | ret[newvar] = subd[var] | ||
72 | return ret | ||
73 | |||
diff --git a/meta/lib/oe/packagedata.py b/meta/lib/oe/packagedata.py new file mode 100644 index 0000000000..7f0a89d282 --- /dev/null +++ b/meta/lib/oe/packagedata.py | |||
@@ -0,0 +1,106 @@ | |||
1 | import os | ||
2 | import bb.data | ||
3 | import codecs | ||
4 | |||
5 | def packaged(pkg, d): | ||
6 | return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK) | ||
7 | |||
8 | def read_pkgdatafile(fn): | ||
9 | pkgdata = {} | ||
10 | |||
11 | def decode(str): | ||
12 | c = codecs.getdecoder("string_escape") | ||
13 | return c(str)[0] | ||
14 | |||
15 | if os.access(fn, os.R_OK): | ||
16 | import re | ||
17 | f = file(fn, 'r') | ||
18 | lines = f.readlines() | ||
19 | f.close() | ||
20 | r = re.compile("([^:]+):\s*(.*)") | ||
21 | for l in lines: | ||
22 | m = r.match(l) | ||
23 | if m: | ||
24 | pkgdata[m.group(1)] = decode(m.group(2)) | ||
25 | |||
26 | return pkgdata | ||
27 | |||
28 | def get_subpkgedata_fn(pkg, d): | ||
29 | archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ") | ||
30 | archs.reverse() | ||
31 | pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d) | ||
32 | targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d) | ||
33 | for arch in archs: | ||
34 | fn = pkgdata + arch + targetdir + pkg | ||
35 | if os.path.exists(fn): | ||
36 | return fn | ||
37 | return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d) | ||
38 | |||
39 | def has_subpkgdata(pkg, d): | ||
40 | return os.access(get_subpkgedata_fn(pkg, d), os.R_OK) | ||
41 | |||
42 | def read_subpkgdata(pkg, d): | ||
43 | return read_pkgdatafile(get_subpkgedata_fn(pkg, d)) | ||
44 | |||
45 | def has_pkgdata(pn, d): | ||
46 | fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d) | ||
47 | return os.access(fn, os.R_OK) | ||
48 | |||
49 | def read_pkgdata(pn, d): | ||
50 | fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d) | ||
51 | return read_pkgdatafile(fn) | ||
52 | |||
53 | # | ||
54 | # Collapse FOO_pkg variables into FOO | ||
55 | # | ||
56 | def read_subpkgdata_dict(pkg, d): | ||
57 | ret = {} | ||
58 | subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d)) | ||
59 | for var in subd: | ||
60 | newvar = var.replace("_" + pkg, "") | ||
61 | ret[newvar] = subd[var] | ||
62 | return ret | ||
63 | |||
64 | def _pkgmap(d): | ||
65 | """Return a dictionary mapping package to recipe name.""" | ||
66 | |||
67 | target_os = d.getVar("TARGET_OS", True) | ||
68 | target_vendor = d.getVar("TARGET_VENDOR", True) | ||
69 | basedir = os.path.dirname(d.getVar("PKGDATA_DIR", True)) | ||
70 | |||
71 | dirs = ("%s%s-%s" % (arch, target_vendor, target_os) | ||
72 | for arch in d.getVar("PACKAGE_ARCHS", True).split()) | ||
73 | |||
74 | pkgmap = {} | ||
75 | for pkgdatadir in (os.path.join(basedir, sys) for sys in dirs): | ||
76 | try: | ||
77 | files = os.listdir(pkgdatadir) | ||
78 | except OSError: | ||
79 | continue | ||
80 | |||
81 | for pn in filter(lambda f: not os.path.isdir(os.path.join(pkgdatadir, f)), files): | ||
82 | try: | ||
83 | pkgdata = read_pkgdatafile(os.path.join(pkgdatadir, pn)) | ||
84 | except OSError: | ||
85 | continue | ||
86 | |||
87 | for pkg in pkgdata["PACKAGES"].split(): | ||
88 | pkgmap[pkg] = pn | ||
89 | |||
90 | return pkgmap | ||
91 | |||
92 | def pkgmap(d): | ||
93 | """Return a dictionary mapping package to recipe name. | ||
94 | Cache the mapping in the metadata""" | ||
95 | |||
96 | pkgmap_data = d.getVar("__pkgmap_data", False) | ||
97 | if pkgmap_data is None: | ||
98 | pkgmap_data = _pkgmap(d) | ||
99 | d.setVar("__pkgmap_data", pkgmap_data) | ||
100 | |||
101 | return pkgmap_data | ||
102 | |||
103 | def recipename(pkg, d): | ||
104 | """Return the recipe name for the given binary package name.""" | ||
105 | |||
106 | return pkgmap(d).get(pkg) | ||