aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake/bin/bitbake-runtask
blob: 469949091ac580a0db597e0040b3146a02462493 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python

import os
import sys
import warnings
import re
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))

try:
    import cPickle as pickle
except ImportError:
    import pickle
    bb.msg.note(1, bb.msg.domain.Cache, "Importing cPickle failed. Falling back to a very slow implementation.")

class BBConfiguration(object):
    """
    Manages build options and configurations for one run
    """

    def __init__(self, debug, debug_domains):
        setattr(self, "data", {})
        setattr(self, "file", [])
        setattr(self, "cmd", None)
        setattr(self, "dump_signatures", True)
        setattr(self, "debug", debug)
        setattr(self, "debug_domains", debug_domains)

_warnings_showwarning = warnings.showwarning
def _showwarning(message, category, filename, lineno, file=None, line=None):
    """Display python warning messages using bb.msg"""
    if file is not None:
        if _warnings_showwarning is not None:
            _warnings_showwarning(message, category, filename, lineno, file, line)
    else:
        s = warnings.formatwarning(message, category, filename, lineno)
        s = s.split("\n")[0]
        bb.msg.warn(None, s)

warnings.showwarning = _showwarning
warnings.simplefilter("ignore", DeprecationWarning)

import bb.event

# Need to map our I/O correctly. stdout is a pipe to the server expecting 
# events. We save this and then map stdout to stderr.

eventfd = os.dup(sys.stdout.fileno())
bb.event.worker_pipe = os.fdopen(eventfd, 'w', 0)

# map stdout to stderr
os.dup2(sys.stderr.fileno(), sys.stdout.fileno())

# Replace those fds with our own
#logout = data.expand("${TMPDIR}/log/stdout.%s" % os.getpid(), self.cfgData, True)
#mkdirhier(os.path.dirname(logout))
#newso = open("/tmp/stdout.%s" % os.getpid(), 'w')
#os.dup2(newso.fileno(), sys.stdout.fileno())
#os.dup2(newso.fileno(), sys.stderr.fileno())

# Don't read from stdin from the parent
si = file("/dev/null", 'r')
os.dup2(si.fileno( ), sys.stdin.fileno( ))

# We don't want to see signals to our parent, e.g. Ctrl+C
os.setpgrp()

# Save out the PID so that the event can include it the
# events
bb.event.worker_pid = os.getpid()
bb.event.useStdout = False

hashfile = sys.argv[1]
buildfile = sys.argv[2]
taskname = sys.argv[3]
socketname = sys.argv[5] or None

p = pickle.Unpickler(file(hashfile, "rb"))
hashdata = p.load()

debug = hashdata["msg-debug"]
debug_domains = hashdata["msg-debug-domains"]
verbose = hashdata["verbose"]

bb.utils.init_logger(bb.msg, verbose, debug, debug_domains)

if socketname:
    import bb, bb.data, bb.parse, socket
    import time

    fn = buildfile

    configuration = BBConfiguration(debug, debug_domains)

    try:
        the_data = bb.data.init()
        datasock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        datasock.connect(socketname)
        bb.data.setVar("_remote_data", datasock, the_data)
    except:
        socketname = ""

if socketname:
    bb.codeparser.parser_cache_init(the_data)
    bb.parse.init_parser(the_data, configuration.dump_signatures)

    datasock.send("_cmd_parsed_fns")
    l = int(datasock.recv(4), 16)
    parsed = pickle.loads(datasock.recv(l))
    for key in parsed.keys():
        funcname = re.sub('_', '-', key)
        f = bb.data.getVar(funcname, the_data, False)
        if f:
            bb.methodpool.check_insert_method(key, f, fn)

    for var in bb.data.getVar('__BBHANDLERS', the_data) or []:
        bb.event.register(var, bb.data.getVar(var, the_data))

    if not bb.data.getVar("BUILDNAME", the_data):
        bb.data.setVar("BUILDNAME", time.strftime('%Y%m%d%H%M'), the_data)
    bb.data.setVar("BUILDSTART", time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime()), the_data)


    bb.data.setVar("BB_WORKERCONTEXT", "1", the_data)
    bb.event.fire(bb.event.ConfigParsed(), the_data)

else:
    import bb.cooker

    cooker = bb.cooker.BBCooker(BBConfiguration(debug, debug_domains), None)
    cooker.parseConfiguration()

    cooker.bb_cache = bb.cache.init(cooker)
    cooker.status = bb.cache.CacheData()

    (fn, cls) = cooker.bb_cache.virtualfn2realfn(buildfile)
    buildfile = cooker.matchFile(fn)
    fn = cooker.bb_cache.realfn2virtual(buildfile, cls)

    cooker.buildSetVars()

    # Load data into the cache for fn and parse the loaded cache data
    the_data = cooker.bb_cache.loadDataFull(fn, cooker.get_file_appends(fn), cooker.configuration.data)
    cooker.bb_cache.setData(fn, buildfile, the_data)
    cooker.bb_cache.handle_data(fn, cooker.status)

    #exportlist = bb.utils.preserved_envvars_export_list()
    #bb.utils.filter_environment(exportlist)

if taskname.endswith("_setscene"):
    the_data.setVarFlag(taskname, "quieterrors", "1")

bb.parse.siggen.set_taskdata(hashdata["hashes"], hashdata["deps"])

for h in hashdata["hashes"]:
    bb.data.setVar("BBHASH_%s" % h, hashdata["hashes"][h], the_data)
for h in hashdata["deps"]:
    bb.data.setVar("BBHASHDEPS_%s" % h, hashdata["deps"][h], the_data)

ret = 0
if sys.argv[4] != "True":
    ret = bb.build.exec_task(fn, taskname, the_data)

if socketname:
    datasock.send("_cmd_end")
    datasock.close()

sys.exit(ret)