summaryrefslogtreecommitdiff
path: root/bitbake-dev/lib/bb/manifest.py
blob: 4e4b7d98eca7eba2d20b079df0bbd0eb0b4e7a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# Copyright (C) 2003, 2004  Chris Larson
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os, sys
import bb, bb.data

def getfields(line):
    fields = {}
    fieldmap = ( "pkg", "src", "dest", "type", "mode", "uid", "gid", "major", "minor", "start", "inc", "count" )
    for f in xrange(len(fieldmap)):
        fields[fieldmap[f]] = None

    if not line:
        return None

    splitline = line.split()
    if not len(splitline):
        return None

    try:
        for f in xrange(len(fieldmap)):
            if splitline[f] == '-':
                continue
            fields[fieldmap[f]] = splitline[f]
    except IndexError:
        pass
    return fields

def parse (mfile, d):
    manifest = []
    while 1:
        line = mfile.readline()
        if not line:
            break
        if line.startswith("#"):
            continue
        fields = getfields(line)
        if not fields:
            continue
        manifest.append(fields)
    return manifest

def emit (func, manifest, d):
#str = "%s () {\n" % func
    str = ""
    for line in manifest:
        emittedline = emit_line(func, line, d)
        if not emittedline:
            continue
        str += emittedline + "\n"
#       str += "}\n"
    return str

def mangle (func, line, d):
    import copy
    newline = copy.copy(line)
    src = bb.data.expand(newline["src"], d)

    if src:
        if not os.path.isabs(src):
            src = "${WORKDIR}/" + src

    dest = newline["dest"]
    if not dest:
        return

    if dest.startswith("/"):
        dest = dest[1:]

    if func is "do_install":
        dest = "${D}/" + dest

    elif func is "do_populate":
        dest = "${WORKDIR}/install/" + newline["pkg"] + "/" + dest

    elif func is "do_stage":
        varmap = {}
        varmap["${bindir}"] = "${STAGING_DIR}/${HOST_SYS}/bin"
        varmap["${libdir}"] = "${STAGING_DIR}/${HOST_SYS}/lib"
        varmap["${includedir}"] = "${STAGING_DIR}/${HOST_SYS}/include"
        varmap["${datadir}"] = "${STAGING_DATADIR}"

        matched = 0
        for key in varmap.keys():
            if dest.startswith(key):
                dest = varmap[key] + "/" + dest[len(key):]
                matched = 1
        if not matched:
            newline = None
            return
    else:
        newline = None
        return

    newline["src"] = src
    newline["dest"] = dest
    return newline

def emit_line (func, line, d):
    import copy
    newline = copy.deepcopy(line)
    newline = mangle(func, newline, d)
    if not newline:
        return None

    str = ""
    type = newline["type"]
    mode = newline["mode"]
    src = newline["src"]
    dest = newline["dest"]
    if type is "d":
        str = "install -d "
        if mode:
            str += "-m %s " % mode
        str += dest
    elif type is "f":
        if not src:
            return None
        if dest.endswith("/"):
            str = "install -d "
            str += dest + "\n"
            str += "install "
        else:
            str = "install -D "
        if mode:
            str += "-m %s " % mode
        str += src + " " + dest
    del newline
    return str