Exemple #1
0
def exec_func(func, d, dirs=None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        if body is None:
            logger.warn("Function %s doesn't exist", func)
        return

    flags = data.getVarFlags(func, d)
    cleandirs = flags.get('cleandirs')
    if cleandirs:
        for cdir in data.expand(cleandirs, d).split():
            bb.utils.remove(cdir, True)

    if dirs is None:
        dirs = flags.get('dirs')
        if dirs:
            dirs = data.expand(dirs, d).split()

    if dirs:
        for adir in dirs:
            bb.utils.mkdirhier(adir)
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)
        bb.utils.mkdirhier(adir)

    ispython = flags.get('python')

    lockflag = flags.get('lockfiles')
    if lockflag:
        lockfiles = [data.expand(f, d) for f in lockflag.split()]
    else:
        lockfiles = None

    tempdir = data.getVar('T', d, 1)

    # or func allows items to be executed outside of the normal
    # task set, such as buildhistory
    task = data.getVar('BB_RUNTASK', d, 1) or func
    if task == func:
        taskfunc = task
    else:
        taskfunc = "%s.%s" % (task, func)

    runfmt = data.getVar('BB_RUNFMT', d, 1) or "run.{func}.{pid}"
    runfn = runfmt.format(taskfunc=taskfunc,
                          task=task,
                          func=func,
                          pid=os.getpid())
    runfile = os.path.join(tempdir, runfn)
    bb.utils.mkdirhier(os.path.dirname(runfile))

    with bb.utils.fileslocked(lockfiles):
        if ispython:
            exec_func_python(func, d, runfile, cwd=adir)
        else:
            exec_func_shell(func, d, runfile, cwd=adir)
Exemple #2
0
def exec_func(func, d, dirs=None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        return

    flags = data.getVarFlags(func, d)
    for item in [
            'deps', 'check', 'interactive', 'python', 'cleandirs', 'dirs',
            'lockfiles', 'fakeroot'
    ]:
        if not item in flags:
            flags[item] = None

    ispython = flags['python']

    cleandirs = (data.expand(flags['cleandirs'], d) or "").split()
    for cdir in cleandirs:
        os.system("rm -rf %s" % cdir)

    if dirs:
        dirs = data.expand(dirs, d)
    else:
        dirs = (data.expand(flags['dirs'], d) or "").split()
    for adir in dirs:
        mkdirhier(adir)

    if len(dirs) > 0:
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)

    try:
        prevdir = os.getcwd()
    except OSError:
        prevdir = data.getVar('TOPDIR', d, True)
    if adir and os.access(adir, os.F_OK):
        os.chdir(adir)

    locks = []
    lockfiles = (data.expand(flags['lockfiles'], d) or "").split()
    for lock in lockfiles:
        locks.append(bb.utils.lockfile(lock))

    if flags['python']:
        exec_func_python(func, d)
    else:
        exec_func_shell(func, d, flags)

    for lock in locks:
        bb.utils.unlockfile(lock)

    if os.path.exists(prevdir):
        os.chdir(prevdir)
Exemple #3
0
def exec_func(func, d, dirs=None, logfile=NULL):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        if body is None:
            logger.warn("Function %s doesn't exist", func)
        return

    flags = data.getVarFlags(func, d)
    cleandirs = flags.get('cleandirs')
    if cleandirs:
        for cdir in data.expand(cleandirs, d).split():
            bb.utils.remove(cdir, True)

    if dirs is None:
        dirs = flags.get('dirs')
        if dirs:
            dirs = data.expand(dirs, d).split()

    if dirs:
        for adir in dirs:
            bb.utils.mkdirhier(adir)
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)
        if not os.path.exists(adir):
            adir = None

    ispython = flags.get('python')
    fakeroot = flags.get('fakeroot')

    lockflag = flags.get('lockfiles')
    if lockflag:
        lockfiles = [data.expand(f, d) for f in lockflag.split()]
    else:
        lockfiles = None

    tempdir = data.getVar('T', d, 1)
    runfile = os.path.join(tempdir, 'run.{0}.{1}'.format(func, os.getpid()))

    with bb.utils.fileslocked(lockfiles):
        if ispython:
            exec_func_python(func, d, runfile, logfile, cwd=adir)
        else:
            exec_func_shell(func,
                            d,
                            runfile,
                            logfile,
                            cwd=adir,
                            fakeroot=fakeroot)
Exemple #4
0
def add_tasks(tasklist, d):
    task_deps = data.getVar('_task_deps', d)
    if not task_deps:
        task_deps = {}
    if not 'tasks' in task_deps:
        task_deps['tasks'] = []
    if not 'parents' in task_deps:
        task_deps['parents'] = {}

    for task in tasklist:
        task = data.expand(task, d)
        data.setVarFlag(task, 'task', 1, d)

        if not task in task_deps['tasks']:
            task_deps['tasks'].append(task)

        flags = data.getVarFlags(task, d)

        def getTask(name):
            if not name in task_deps:
                task_deps[name] = {}
            if name in flags:
                deptask = data.expand(flags[name], d)
                task_deps[name][task] = deptask

        getTask('depends')
        getTask('rdepends')
        getTask('deptask')
        getTask('rdeptask')
        getTask('recrdeptask')
        getTask('nostamp')
        getTask('fakeroot')
        getTask('noexec')
        getTask('umask')
        task_deps['parents'][task] = []
        for dep in flags['deps']:
            dep = data.expand(dep, d)
            task_deps['parents'][task].append(dep)

    # don't assume holding a reference
    data.setVar('_task_deps', task_deps, d)
Exemple #5
0
def add_tasks(tasklist, d):
    task_graph = data.getVar('_task_graph', d)
    task_deps = data.getVar('_task_deps', d)
    if not task_graph:
        task_graph = bb.digraph()
    if not task_deps:
        task_deps = {}

    for task in tasklist:
        deps = tasklist[task]
        task = data.expand(task, d)

        data.setVarFlag(task, 'task', 1, d)
        task_graph.addnode(task, None)
        for dep in deps:
            dep = data.expand(dep, d)
            if not task_graph.hasnode(dep):
                task_graph.addnode(dep, None)
            task_graph.addnode(task, dep)

        flags = data.getVarFlags(task, d)    
        def getTask(name):
            if name in flags:
                deptask = data.expand(flags[name], d)
                if not name in task_deps:
                    task_deps[name] = {}
                task_deps[name][task] = deptask
        getTask('depends')
        getTask('deptask')
        getTask('rdeptask')
        getTask('recrdeptask')
        getTask('nostamp')

    # don't assume holding a reference
    data.setVar('_task_graph', task_graph, d)
    data.setVar('_task_deps', task_deps, d)
Exemple #6
0
def exec_func(func, d, dirs = None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        logger.warn("Function %s doesn't exist" % func)
        return

    flags = data.getVarFlags(func, d)
    cleandirs = flags.get('cleandirs')
    if cleandirs:
        for cdir in data.expand(cleandirs, d).split():
            os.system("rm -rf %s" % cdir)

    if dirs is None:
        dirs = flags.get('dirs')
        if dirs:
            dirs = data.expand(dirs, d).split()

    if dirs:
        for adir in dirs:
            bb.utils.mkdirhier(adir)
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)
        bb.utils.mkdirhier(adir)

    ispython = flags.get('python')
    fakeroot = flags.get('fakeroot')

    t = data.getVar('T', d, 1)
    if not t:
        bb.fatal("T variable not set, unable to build")
    bb.utils.mkdirhier(t)
    loglink = os.path.join(t, 'log.{0}'.format(func))
    logfn = os.path.join(t, 'log.{0}.{1}'.format(func, os.getpid()))
    runfile = os.path.join(t, 'run.{0}.{1}'.format(func, os.getpid()))

    if loglink:
        try:
           os.remove(loglink)
        except OSError:
           pass

        try:
           os.symlink(logfn, loglink)
        except OSError:
           pass

    if logger.getEffectiveLevel() <= logging.DEBUG:
        logfile = tee(logfn, 'w')
    else:
        logfile = open(logfn, 'w')

    lockflag = flags.get('lockfiles')
    if lockflag:
        lockfiles = [data.expand(f, d) for f in lockflag.split()]
    else:
        lockfiles = None

    with nested(logfile, bb.utils.fileslocked(lockfiles)):
        try:
            if ispython:
                exec_func_python(func, d, runfile, logfile, cwd=adir)
            else:
                exec_func_shell(func, d, runfile, logfile, cwd=adir, fakeroot=fakeroot)
        finally:
            if os.path.exists(logfn) and os.path.getsize(logfn) == 0:
                logger.debug(2, "Zero size logfn %s, removing", logfn)
                bb.utils.remove(logfn)
                bb.utils.remove(loglink)
Exemple #7
0
def exec_func(func, d, dirs=None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        return

    flags = data.getVarFlags(func, d)
    for item in [
            'deps', 'check', 'interactive', 'python', 'cleandirs', 'dirs',
            'lockfiles', 'fakeroot'
    ]:
        if not item in flags:
            flags[item] = None

    ispython = flags['python']

    cleandirs = (data.expand(flags['cleandirs'], d) or "").split()
    for cdir in cleandirs:
        os.system("rm -rf %s" % cdir)

    if dirs:
        dirs = data.expand(dirs, d)
    else:
        dirs = (data.expand(flags['dirs'], d) or "").split()
    for adir in dirs:
        mkdirhier(adir)

    if len(dirs) > 0:
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)

    # Save current directory
    try:
        prevdir = os.getcwd()
    except OSError:
        prevdir = data.getVar('TOPDIR', d, True)

    # Setup logfiles
    t = data.getVar('T', d, 1)
    if not t:
        bb.msg.fatal(bb.msg.domain.Build, "T not set")
    mkdirhier(t)
    logfile = "%s/log.%s.%s" % (t, func, str(os.getpid()))
    runfile = "%s/run.%s.%s" % (t, func, str(os.getpid()))

    # Change to correct directory (if specified)
    if adir and os.access(adir, os.F_OK):
        os.chdir(adir)

    # Handle logfiles
    si = file('/dev/null', 'r')
    try:
        if bb.msg.debug_level['default'] > 0 or ispython:
            so = os.popen("tee \"%s\"" % logfile, "w")
        else:
            so = file(logfile, 'w')
    except OSError, e:
        bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e)
        pass
Exemple #8
-1
def exec_func(func, d, dirs = None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        return

    flags = data.getVarFlags(func, d)
    for item in ['deps', 'check', 'interactive', 'python', 'cleandirs', 'dirs', 'lockfiles', 'fakeroot']:
        if not item in flags:
            flags[item] = None

    ispython = flags['python']

    cleandirs = (data.expand(flags['cleandirs'], d) or "").split()
    for cdir in cleandirs:
        os.system("rm -rf %s" % cdir)

    if dirs:
        dirs = data.expand(dirs, d)
    else:
        dirs = (data.expand(flags['dirs'], d) or "").split()
    for adir in dirs:
        mkdirhier(adir)

    if len(dirs) > 0:
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)

    # Save current directory
    try:
        prevdir = os.getcwd()
    except OSError:
        prevdir = data.getVar('TOPDIR', d, True)

    # Setup logfiles
    t = data.getVar('T', d, 1)
    if not t:
        bb.msg.fatal(bb.msg.domain.Build, "T not set")
    mkdirhier(t)
    # Gross hack, FIXME
    import random
    logfile = "%s/log.%s.%s.%s" % (t, func, str(os.getpid()),random.random())
    runfile = "%s/run.%s.%s" % (t, func, str(os.getpid()))

    # Change to correct directory (if specified)
    if adir and os.access(adir, os.F_OK):
        os.chdir(adir)

    # Handle logfiles
    si = file('/dev/null', 'r')
    try:
        if bb.msg.debug_level['default'] > 0 or ispython:
            so = os.popen("tee \"%s\"" % logfile, "w")
        else:
            so = file(logfile, 'w')
    except OSError, e:
        bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e)
        pass
Exemple #9
-1
def add_tasks(tasklist, d):
    task_deps = data.getVar('_task_deps', d)
    if not task_deps:
        task_deps = {}
    if not 'tasks' in task_deps:
        task_deps['tasks'] = []
    if not 'parents' in task_deps:
        task_deps['parents'] = {}

    for task in tasklist:
        task = data.expand(task, d)
        data.setVarFlag(task, 'task', 1, d)

        if not task in task_deps['tasks']:
            task_deps['tasks'].append(task)

        flags = data.getVarFlags(task, d)    
        def getTask(name):
            if not name in task_deps:
                task_deps[name] = {}
            if name in flags:
                deptask = data.expand(flags[name], d)
                task_deps[name][task] = deptask
        getTask('depends')
        getTask('deptask')
        getTask('rdeptask')
        getTask('recrdeptask')
        getTask('nostamp')
        task_deps['parents'][task] = []
        for dep in flags['deps']:
            dep = data.expand(dep, d)
            task_deps['parents'][task].append(dep)

    # don't assume holding a reference
    data.setVar('_task_deps', task_deps, d)
Exemple #10
-1
def exec_func(func, d, dirs = None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        if body is None:
            logger.warn("Function %s doesn't exist", func)
        return

    flags = data.getVarFlags(func, d)
    cleandirs = flags.get('cleandirs')
    if cleandirs:
        for cdir in data.expand(cleandirs, d).split():
            bb.utils.remove(cdir, True)

    if dirs is None:
        dirs = flags.get('dirs')
        if dirs:
            dirs = data.expand(dirs, d).split()

    if dirs:
        for adir in dirs:
            bb.utils.mkdirhier(adir)
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)
        bb.utils.mkdirhier(adir)

    ispython = flags.get('python')

    lockflag = flags.get('lockfiles')
    if lockflag:
        lockfiles = [data.expand(f, d) for f in lockflag.split()]
    else:
        lockfiles = None

    tempdir = data.getVar('T', d, 1)

    # or func allows items to be executed outside of the normal
    # task set, such as buildhistory
    task = data.getVar('BB_RUNTASK', d, 1) or func
    if task == func:
        taskfunc = task
    else:
        taskfunc = "%s.%s" % (task, func)

    runfmt = data.getVar('BB_RUNFMT', d, 1) or "run.{func}.{pid}"
    runfn = runfmt.format(taskfunc=taskfunc, task=task, func=func, pid=os.getpid())
    runfile = os.path.join(tempdir, runfn)
    bb.utils.mkdirhier(os.path.dirname(runfile))

    with bb.utils.fileslocked(lockfiles):
        if ispython:
            exec_func_python(func, d, runfile, cwd=adir)
        else:
            exec_func_shell(func, d, runfile, cwd=adir)
    def testVarFlags(self):
        # import the data modules
        from bb import data
        from bb import data_smart

        d = data_smart.DataSmart()
        myflags = {}
        myflags['test'] = 'blah'
        myflags['blah'] = 'test'
        data.setVarFlags('TEST', myflags, d)
        self.assertEquals(data.getVarFlags('TEST',d)['blah'], 'test')
        self.assertEquals(data.getVarFlags('TEST',d)['test'], 'blah')

        data.setVarFlags('TEST', { 'abc' : 10}, d)
        self.assertTrue(data.getVarFlags('TEST',d).has_key('abc'))

        # delete the flags now
        data.delVarFlags('TEST', d)
        self.assertEquals(data.getVarFlags('TEST',d), None)
Exemple #12
-1
def exec_func(func, d, dirs = None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        return

    flags = data.getVarFlags(func, d)
    for item in ['deps', 'check', 'interactive', 'python', 'cleandirs', 'dirs', 'lockfiles', 'fakeroot']:
        if not item in flags:
            flags[item] = None

    ispython = flags['python']

    cleandirs = (data.expand(flags['cleandirs'], d) or "").split()
    for cdir in cleandirs:
        os.system("rm -rf %s" % cdir)

    if dirs:
        dirs = data.expand(dirs, d)
    else:
        dirs = (data.expand(flags['dirs'], d) or "").split()
    for adir in dirs:
        mkdirhier(adir)

    if len(dirs) > 0:
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)

    try:
        prevdir = os.getcwd()
    except OSError:
        prevdir = data.getVar('TOPDIR', d, True)
    if adir and os.access(adir, os.F_OK):
        os.chdir(adir)

    locks = []
    lockfiles = (data.expand(flags['lockfiles'], d) or "").split()
    for lock in lockfiles:
        locks.append(bb.utils.lockfile(lock))

    if flags['python']:
        exec_func_python(func, d)
    else:
        exec_func_shell(func, d, flags)

    for lock in locks:
        bb.utils.unlockfile(lock)

    if os.path.exists(prevdir):
        os.chdir(prevdir)
Exemple #13
-1
def exec_func(func, d, dirs=None):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        if body is None:
            logger.warn("Function %s doesn't exist", func)
        return

    flags = data.getVarFlags(func, d)
    cleandirs = flags.get("cleandirs")
    if cleandirs:
        for cdir in data.expand(cleandirs, d).split():
            bb.utils.remove(cdir, True)

    if dirs is None:
        dirs = flags.get("dirs")
        if dirs:
            dirs = data.expand(dirs, d).split()

    if dirs:
        for adir in dirs:
            bb.utils.mkdirhier(adir)
        adir = dirs[-1]
    else:
        adir = data.getVar("B", d, 1)
        if not os.path.exists(adir):
            adir = None

    ispython = flags.get("python")
    if flags.get("fakeroot") and not flags.get("task"):
        bb.fatal("Function %s specifies fakeroot but isn't a task?!" % func)

    lockflag = flags.get("lockfiles")
    if lockflag:
        lockfiles = [data.expand(f, d) for f in lockflag.split()]
    else:
        lockfiles = None

    tempdir = data.getVar("T", d, 1)
    bb.utils.mkdirhier(tempdir)
    runfile = os.path.join(tempdir, "run.{0}.{1}".format(func, os.getpid()))

    with bb.utils.fileslocked(lockfiles):
        if ispython:
            exec_func_python(func, d, runfile, cwd=adir)
        else:
            exec_func_shell(func, d, runfile, cwd=adir)
Exemple #14
-1
def exec_func(func, d, dirs = None, logfile = NULL):
    """Execute an BB 'function'"""

    body = data.getVar(func, d)
    if not body:
        if body is None:
            logger.warn("Function %s doesn't exist", func)
        return

    flags = data.getVarFlags(func, d)
    cleandirs = flags.get('cleandirs')
    if cleandirs:
        for cdir in data.expand(cleandirs, d).split():
            bb.utils.remove(cdir, True)

    if dirs is None:
        dirs = flags.get('dirs')
        if dirs:
            dirs = data.expand(dirs, d).split()

    if dirs:
        for adir in dirs:
            bb.utils.mkdirhier(adir)
        adir = dirs[-1]
    else:
        adir = data.getVar('B', d, 1)
        if not os.path.exists(adir):
            adir = None

    ispython = flags.get('python')
    fakeroot = flags.get('fakeroot')

    lockflag = flags.get('lockfiles')
    if lockflag:
        lockfiles = [data.expand(f, d) for f in lockflag.split()]
    else:
        lockfiles = None

    tempdir = data.getVar('T', d, 1)
    runfile = os.path.join(tempdir, 'run.{0}.{1}'.format(func, os.getpid()))

    with bb.utils.fileslocked(lockfiles):
        if ispython:
            exec_func_python(func, d, runfile, logfile, cwd=adir)
        else:
            exec_func_shell(func, d, runfile, logfile, cwd=adir, fakeroot=fakeroot)
Exemple #15
-1
def add_tasks(tasklist, d):
    task_deps = data.getVar("_task_deps", d)
    if not task_deps:
        task_deps = {}
    if not "tasks" in task_deps:
        task_deps["tasks"] = []
    if not "parents" in task_deps:
        task_deps["parents"] = {}

    for task in tasklist:
        task = data.expand(task, d)
        data.setVarFlag(task, "task", 1, d)

        if not task in task_deps["tasks"]:
            task_deps["tasks"].append(task)

        flags = data.getVarFlags(task, d)

        def getTask(name):
            if not name in task_deps:
                task_deps[name] = {}
            if name in flags:
                deptask = data.expand(flags[name], d)
                task_deps[name][task] = deptask

        getTask("depends")
        getTask("deptask")
        getTask("rdeptask")
        getTask("recrdeptask")
        getTask("nostamp")
        getTask("fakeroot")
        getTask("noexec")
        getTask("umask")
        task_deps["parents"][task] = []
        for dep in flags["deps"]:
            dep = data.expand(dep, d)
            task_deps["parents"][task].append(dep)

    # don't assume holding a reference
    data.setVar("_task_deps", task_deps, d)