Exemplo n.º 1
0
    def __init__(self, options, args, config):
        self.options = options
        self.debug = self.options.debug
        self.debug_loglines = getattr(self.options, 'debug_loglines', None)

        # Bakery 3 compatibility, configure the logging module
        if (not hasattr(oebakery, "__version__") or
            oebakery.__version__.split(".")[0] < 4):
            logging.basicConfig(format="%(message)s")
            if self.debug:
                logging.getLogger().setLevel(logging.DEBUG)
            else:
                logging.getLogger().setLevel(logging.INFO)

        self.config = oelite.meta.DictMeta(meta=config)
        self.config["OE_IMPORTS"] = INITIAL_OE_IMPORTS
        self.config.import_env()
        os.environ.clear()
        self.config.pythonfunc_init()
        self.topdir = self.config.get("TOPDIR", True)
        self.set_manifest_origin()
        # FIXME: self.config.freeze("TOPDIR")

        self.confparser = confparse.ConfParser(self.config)
        self.confparser.parse("conf/oe-lite.conf")

        oelite.pyexec.exechooks(self.config, "post_conf_parse")

        # FIXME: refactor oelite.arch.init to a post_conf_parse hook
        oelite.arch.init(self.config)

        # Handle any INHERITs and inherit the base class
        inherits  = ["core"] + (self.config.get("INHERIT", 1) or "").split()
        # and inherit rmwork when needed
        try:
            rmwork = self.options.rmwork
            if rmwork is None:
                rmwork = self.config.get("RMWORK", True)
                if rmwork == "0":
                    rmwork = False
            if rmwork:
                debug("rmwork")
                inherits.append("rmwork")
                self.options.rmwork = True
        except AttributeError:
            pass
        self.oeparser = oeparse.OEParser(self.config)
        for inherit in inherits:
            self.oeparser.reset_lexstate()
            self.oeparser.parse("classes/%s.oeclass"%(inherit), require=True)

        oelite.pyexec.exechooks(self.config, "post_common_inherits")

        self.cookbook = CookBook(self)

        # things (ritem, item, recipe, or package) to do
        if args:
            self.things_todo = args
        elif "OE_DEFAULT_THING" in self.config:
            self.things_todo = self.config.get("OE_DEFAULT_THING", 1).split()
        else:
            self.things_todo = [ "world" ]

        recipe_types = ("machine", "native", "sdk",
                        "cross", "sdk-cross", "canadian-cross")
        def thing_todo(thing):
            if not thing in self.things_todo:
                self.things_todo.append(thing)
        def dont_do_thing(thing):
            while thing in self.things_todo:
                self.things_todo.remove(thing)
        self.recipes_todo = set()
        if "universe" in self.things_todo:
            dont_do_thing("universe")
            for recipe_type in recipe_types:
                thing_todo(recipe_type + ":world")
        if "world" in self.things_todo:
            dont_do_thing("world")
            thing_todo("machine:world")
        for recipe_type in recipe_types:
            world = recipe_type + ":world"
            if world in self.things_todo:
                dont_do_thing(world)
                for recipe in self.cookbook.get_recipes(type=recipe_type):
                    self.recipes_todo.add(recipe)

        return
Exemplo n.º 2
0
    def __init__(self, options, args, config):
        self.options = options
        self.debug = self.options.debug
        self.debug_loglines = getattr(self.options, 'debug_loglines', None)

        # Bakery 3 compatibility, configure the logging module
        if (not hasattr(oebakery, "__version__")
                or oebakery.__version__.split(".")[0] < 4):
            logging.basicConfig(format="%(message)s")
            if self.debug:
                logging.getLogger().setLevel(logging.DEBUG)
            else:
                logging.getLogger().setLevel(logging.INFO)

        self.config = oelite.meta.DictMeta(meta=config)
        self.config["OE_IMPORTS"] = INITIAL_OE_IMPORTS
        self.config.import_env()
        os.environ.clear()
        self.config.pythonfunc_init()
        self.topdir = self.config.get("TOPDIR", True)
        self.set_manifest_origin()
        # FIXME: self.config.freeze("TOPDIR")

        self.confparser = confparse.ConfParser(self.config)
        self.confparser.parse("conf/oe-lite.conf")

        oelite.pyexec.exechooks(self.config, "post_conf_parse")

        # FIXME: refactor oelite.arch.init to a post_conf_parse hook
        oelite.arch.init(self.config)

        # Handle any INHERITs and inherit the base class
        inherits = ["core"] + (self.config.get("INHERIT", 1) or "").split()
        self.oeparser = oeparse.OEParser(self.config)
        for inherit in inherits:
            self.oeparser.reset_lexstate()
            self.oeparser.parse("classes/%s.oeclass" % (inherit), require=True)

        oelite.pyexec.exechooks(self.config, "post_common_inherits")

        self.cookbook = CookBook(self)

        # things (ritem, item, recipe, or package) to do
        if args:
            self.things_todo = args
        elif "OE_DEFAULT_THING" in self.config:
            self.things_todo = self.config.get("OE_DEFAULT_THING", 1).split()
        else:
            self.things_todo = ["world"]

        recipe_types = ("machine", "native", "sdk", "cross", "sdk-cross",
                        "canadian-cross")

        def thing_todo(thing):
            if not thing in self.things_todo:
                self.things_todo.append(thing)

        def dont_do_thing(thing):
            while thing in self.things_todo:
                self.things_todo.remove(thing)

        self.recipes_todo = set()
        if "universe" in self.things_todo:
            dont_do_thing("universe")
            for recipe_type in recipe_types:
                thing_todo(recipe_type + ":world")

        return
Exemplo n.º 3
0
class OEliteBaker:

    def __init__(self, options, args, config):
        self.options = options
        self.debug = self.options.debug
        self.debug_loglines = getattr(self.options, 'debug_loglines', None)

        # Bakery 3 compatibility, configure the logging module
        if (not hasattr(oebakery, "__version__") or
            oebakery.__version__.split(".")[0] < 4):
            logging.basicConfig(format="%(message)s")
            if self.debug:
                logging.getLogger().setLevel(logging.DEBUG)
            else:
                logging.getLogger().setLevel(logging.INFO)

        self.config = oelite.meta.DictMeta(meta=config)
        self.config["OE_IMPORTS"] = INITIAL_OE_IMPORTS
        self.config.import_env()
        os.environ.clear()
        self.config.pythonfunc_init()
        self.topdir = self.config.get("TOPDIR", True)
        self.set_manifest_origin()
        # FIXME: self.config.freeze("TOPDIR")

        self.confparser = confparse.ConfParser(self.config)
        self.confparser.parse("conf/oe-lite.conf")

        oelite.pyexec.exechooks(self.config, "post_conf_parse")

        # FIXME: refactor oelite.arch.init to a post_conf_parse hook
        oelite.arch.init(self.config)

        # Handle any INHERITs and inherit the base class
        inherits  = ["core"] + (self.config.get("INHERIT", 1) or "").split()
        # and inherit rmwork when needed
        try:
            rmwork = self.options.rmwork
            if rmwork is None:
                rmwork = self.config.get("RMWORK", True)
                if rmwork == "0":
                    rmwork = False
            if rmwork:
                debug("rmwork")
                inherits.append("rmwork")
                self.options.rmwork = True
        except AttributeError:
            pass
        self.oeparser = oeparse.OEParser(self.config)
        for inherit in inherits:
            self.oeparser.reset_lexstate()
            self.oeparser.parse("classes/%s.oeclass"%(inherit), require=True)

        oelite.pyexec.exechooks(self.config, "post_common_inherits")

        self.cookbook = CookBook(self)

        # things (ritem, item, recipe, or package) to do
        if args:
            self.things_todo = args
        elif "OE_DEFAULT_THING" in self.config:
            self.things_todo = self.config.get("OE_DEFAULT_THING", 1).split()
        else:
            self.things_todo = [ "world" ]

        recipe_types = ("machine", "native", "sdk",
                        "cross", "sdk-cross", "canadian-cross")
        def thing_todo(thing):
            if not thing in self.things_todo:
                self.things_todo.append(thing)
        def dont_do_thing(thing):
            while thing in self.things_todo:
                self.things_todo.remove(thing)
        self.recipes_todo = set()
        if "universe" in self.things_todo:
            dont_do_thing("universe")
            for recipe_type in recipe_types:
                thing_todo(recipe_type + ":world")
        if "world" in self.things_todo:
            dont_do_thing("world")
            thing_todo("machine:world")
        for recipe_type in recipe_types:
            world = recipe_type + ":world"
            if world in self.things_todo:
                dont_do_thing(world)
                for recipe in self.cookbook.get_recipes(type=recipe_type):
                    self.recipes_todo.add(recipe)

        return


    def __del__(self):
        return


    def set_manifest_origin(self):
        if not os.path.exists(os.path.join(self.topdir, '.git')):
            return
        url = oelite.util.shcmd("git config --get remote.origin.url",
                                quiet=True, silent_errorcodes=[1])
        if not url:
            return
        url = os.path.dirname(url.strip())
        if url.startswith('file:///'):
            url = url[7:]
        srcuri = None
        protocols = ('git', 'ssh', 'http', 'https', 'ftp', 'ftps', 'rsync')
        if url.startswith('/'):
            srcuri = 'git://%s'%(url)
            protocol = 'file'
        elif url.startswith('git://'):
            srcuri = url
            protocol = None
        elif not url.split('://')[0] in protocols:
            url = 'ssh://' + url.replace(':', '/', 1)
        if srcuri is None:
            for protocol in protocols:
                if url.startswith('%s://'%(protocol)):
                    srcuri = 'git://%s'%(url[len(protocol)+3:])
                    break
        self.config.set('MANIFEST_ORIGIN_URL', url)
        self.config.set_flag('MANIFEST_ORIGIN_URL', 'nohash', True)
        if srcuri is None:
            logging.warning("unsupported manifest origin: %s"%(url))
            return
        self.config.set('MANIFEST_ORIGIN_SRCURI', srcuri)
        self.config.set_flag('MANIFEST_ORIGIN_SRCURI', 'nohash', True)
        if protocol:
            self.config.set('MANIFEST_ORIGIN_PARAMS', ';protocol=%s'%(protocol))
        else:
            self.config.set('MANIFEST_ORIGIN_PARAMS', '')
        self.config.set_flag('MANIFEST_ORIGIN_PARAMS', 'nohash', True)


    def show(self):

        if len(self.things_todo) == 0:
            die("you must specify something to show")
        if len(self.recipes_todo) > 0:
            die("you cannot show world")

        thing = oelite.item.OEliteItem(self.things_todo[0])
        recipe = self.cookbook.get_recipe(
            type=thing.type, name=thing.name, version=thing.version,
            strict=False)
        if not recipe:
            die("Cannot find %s"%(thing))

        if self.options.task:
            if self.options.task.startswith("do_"):
                task = self.options.task
            else:
                task = "do_" + self.options.task
            self.runq = OEliteRunQueue(self.config, self.cookbook)
            self.runq._add_recipe(recipe, task)
            task = self.cookbook.get_task(recipe=recipe, name=task)
            task.prepare(self.runq)
            meta = task.meta()
        else:
            meta = recipe.meta

        #meta.dump(pretty=False, nohash=False, flags=True,
        #          ignore_flags=("filename", "lineno"),
        meta.dump(pretty=True, nohash=(not self.options.nohash),
                  only=(self.things_todo[1:] or None))

        return 0


    def bake(self):

        self.setup_tmpdir()

        # task(s) to do
        if self.options.task:
            tasks_todo = self.options.task
        elif "OE_DEFAULT_TASK" in self.config:
            tasks_todo = self.config.get("OE_DEFAULT_TASK", 1)
        else:
            #tasks_todo = "all"
            tasks_todo = "build"
        self.tasks_todo = tasks_todo.split(",")

        if self.options.rebuild:
            self.options.rebuild = max(self.options.rebuild)
            self.options.prebake = False
        else:
            self.options.rebuild = None
        if self.options.relax:
            self.options.relax = max(self.options.relax)
        else:
            default_relax = self.config.get("DEFAULT_RELAX", 1)
            if default_relax and default_relax != "0":
                self.options.relax = int(default_relax)
            else:
                self.options.relax = None

        # init build quue
        self.runq = OEliteRunQueue(self.config, self.cookbook,
                                   self.options.rebuild, self.options.relax)

        # first, add complete dependency tree, with complete
        # task-to-task and task-to-package/task dependency information
        debug("Building dependency tree")
        start = datetime.datetime.now()
        for task in self.tasks_todo:
            task = oelite.task.task_name(task)
            try:
                for thing in self.recipes_todo:
                    if not self.runq.add_recipe(thing, task):
                        die("No such recipe: %s"%(thing))
                for thing in self.things_todo:
                    thing = oelite.item.OEliteItem(thing)
                    if not self.runq.add_something(thing, task):
                        die("No such thing: %s"%(thing))
            except RecursiveDepends, e:
                die("dependency loop: %s\n\t--> %s"%(
                        e.args[1], "\n\t--> ".join(e.args[0])))
            except NoSuchTask, e:
                die("No such task: %s: %s"%(thing, e.__str__()))
            except oebakery.FatalError, e:
                die("Failed to add %s:%s to runqueue"%(thing, task))
Exemplo n.º 4
0
class OEliteBaker:
    @oelite.profiling.profile_rusage_delta
    def __init__(self, options, args, config):
        self.options = options
        self.debug = self.options.debug
        self.debug_loglines = getattr(self.options, 'debug_loglines', None)

        # Bakery 3 compatibility, configure the logging module
        if (not hasattr(oebakery, "__version__")
                or oebakery.__version__.split(".")[0] < 4):
            logging.basicConfig(format="%(message)s")
            if self.debug:
                logging.getLogger().setLevel(logging.DEBUG)
            else:
                logging.getLogger().setLevel(logging.INFO)

        self.config = oelite.meta.DictMeta(meta=config)
        self.config["OE_IMPORTS"] = INITIAL_OE_IMPORTS
        self.config.import_env()
        os.environ.clear()
        self.config.pythonfunc_init()
        self.topdir = self.config.get("TOPDIR", True)
        self.set_manifest_origin()
        # FIXME: self.config.freeze("TOPDIR")

        self.confparser = confparse.ConfParser(self.config)
        self.confparser.parse("conf/oe-lite.conf")

        oelite.pyexec.exechooks(self.config, "post_conf_parse")

        # FIXME: refactor oelite.arch.init to a post_conf_parse hook
        oelite.arch.init(self.config)

        # Handle any INHERITs and inherit the base class
        inherits = ["core"] + (self.config.get("INHERIT", 1) or "").split()
        self.oeparser = oeparse.OEParser(self.config)
        for inherit in inherits:
            self.oeparser.reset_lexstate()
            self.oeparser.parse("classes/%s.oeclass" % (inherit), require=True)

        oelite.pyexec.exechooks(self.config, "post_common_inherits")

        self.cookbook = CookBook(self)

        # things (ritem, item, recipe, or package) to do
        if args:
            self.things_todo = args
        elif "OE_DEFAULT_THING" in self.config:
            self.things_todo = self.config.get("OE_DEFAULT_THING", 1).split()
        else:
            self.things_todo = ["world"]

        recipe_types = ("machine", "native", "sdk", "cross", "sdk-cross",
                        "canadian-cross")

        def thing_todo(thing):
            if not thing in self.things_todo:
                self.things_todo.append(thing)

        def dont_do_thing(thing):
            while thing in self.things_todo:
                self.things_todo.remove(thing)

        self.recipes_todo = set()
        if "universe" in self.things_todo:
            dont_do_thing("universe")
            for recipe_type in recipe_types:
                thing_todo(recipe_type + ":world")

        return

    def __del__(self):
        return

    def set_manifest_origin(self):
        if not os.path.exists(os.path.join(self.topdir, '.git')):
            return
        url = oelite.util.shcmd("git config --get remote.origin.url",
                                quiet=True,
                                silent_errorcodes=[1])
        if not url:
            return
        url = os.path.dirname(url.strip())
        if url.startswith('file:///'):
            url = url[7:]
        srcuri = None
        protocols = ('git', 'ssh', 'http', 'https', 'ftp', 'ftps', 'rsync')
        if url.startswith('/'):
            srcuri = 'git://%s' % (url)
            protocol = 'file'
        elif url.startswith('git://'):
            srcuri = url
            protocol = None
        elif not url.split('://')[0] in protocols:
            url = 'ssh://' + url.replace(':', '/', 1)
        if srcuri is None:
            for protocol in protocols:
                if url.startswith('%s://' % (protocol)):
                    srcuri = 'git://%s' % (url[len(protocol) + 3:])
                    break
        self.config.set('MANIFEST_ORIGIN_URL', url)
        self.config.set_flag('MANIFEST_ORIGIN_URL', 'nohash', True)
        if srcuri is None:
            logging.warning("unsupported manifest origin: %s" % (url))
            return
        self.config.set('MANIFEST_ORIGIN_SRCURI', srcuri)
        self.config.set_flag('MANIFEST_ORIGIN_SRCURI', 'nohash', True)
        if protocol:
            self.config.set('MANIFEST_ORIGIN_PARAMS',
                            ';protocol=%s' % (protocol))
        else:
            self.config.set('MANIFEST_ORIGIN_PARAMS', '')
        self.config.set_flag('MANIFEST_ORIGIN_PARAMS', 'nohash', True)

    def show(self):

        if len(self.things_todo) == 0:
            die("you must specify something to show")
        if len(self.recipes_todo) > 0:
            die("you cannot show world")

        thing = oelite.item.OEliteItem(self.things_todo[0])
        recipe = self.cookbook.get_recipe(type=thing.type,
                                          name=thing.name,
                                          version=thing.version,
                                          strict=False)
        if not recipe:
            die("Cannot find %s" % (thing))

        if self.options.task:
            if self.options.task.startswith("do_"):
                task = self.options.task
            else:
                task = "do_" + self.options.task
            self.runq = OEliteRunQueue(self.config, self.cookbook)
            self.runq._add_recipe(recipe, task)
            task = self.cookbook.get_task(recipe=recipe, name=task)
            task.prepare()
            meta = task.meta()
        else:
            meta = recipe.meta

        #meta.dump(pretty=False, nohash=False, flags=True,
        #          ignore_flags=re.compile("filename|lineno"),
        meta.dump(pretty=True,
                  show_nohash=(not self.options.nohash),
                  dynvar_replacement=(not self.options.nodynvar),
                  only=(self.things_todo[1:] or None))

        return 0

    def bake(self):

        self.setup_tmpdir()
        oelite.profiling.init(self.config)

        # task(s) to do
        if self.options.task:
            tasks_todo = self.options.task
        elif "OE_DEFAULT_TASK" in self.config:
            tasks_todo = self.config.get("OE_DEFAULT_TASK", 1)
        else:
            #tasks_todo = "all"
            tasks_todo = "build"
        self.tasks_todo = tasks_todo.split(",")

        if self.options.rebuild:
            self.options.rebuild = max(self.options.rebuild)
            self.options.prebake = False
        else:
            self.options.rebuild = None
        if self.options.relax:
            self.options.relax = max(self.options.relax)
        else:
            default_relax = self.config.get("DEFAULT_RELAX", 1)
            if default_relax and default_relax != "0":
                self.options.relax = int(default_relax)
            else:
                self.options.relax = None

        # init build quue
        self.runq = OEliteRunQueue(self.config, self.cookbook,
                                   self.options.rebuild, self.options.relax)

        # first, add complete dependency tree, with complete
        # task-to-task and task-to-package/task dependency information
        debug("Building dependency tree")
        rusage = oelite.profiling.Rusage("Building dependency tree")
        for task in self.tasks_todo:
            task = oelite.task.task_name(task)
            try:
                for thing in self.recipes_todo:
                    if not self.runq.add_recipe(thing, task):
                        die("No such recipe: %s" % (thing))
                for thing in self.things_todo:
                    thing = oelite.item.OEliteItem(thing)
                    if not self.runq.add_something(thing, task):
                        die("No such thing: %s" % (thing))
            except RecursiveDepends, e:
                die("dependency loop: %s\n\t--> %s" %
                    (e.args[1], "\n\t--> ".join(e.args[0])))
            except NoSuchTask, e:
                die("No such task: %s: %s" % (thing, e.__str__()))
            except oebakery.FatalError, e:
                die("Failed to add %s:%s to runqueue" % (thing, task))