Exemplo n.º 1
0
def pymake3(conf=None, args=None):
    targets = sorted(t.name for t in Maker.inst().targets)
    parser = argparse.ArgumentParser()
    parser.add_argument("todo", nargs="*", choices=targets, default=[])
    parser.add_argument("--conf", help="set the configuration to use")
    parser.add_argument("--no-color", action="store_true")
    parser.add_argument("--targets", action="store_true")
    parser.add_argument("--version", action="store_true")
    if argcomplete is not None:
        argcomplete.autocomplete(parser)
    args = parser.parse_args()
    if args.conf:
        options.option_conf(args.conf)
    options.disable_color = args.no_color
    if args.version:
        options.option_version()
        return
    if args.targets:
        info.print_targets()
        return

    if conf and isinstance(conf, dict):
        conf = makeconf.from_dict(conf)

    conf = conf or options.conf or makeconf.from_dict({})

    if options.conf:
        conf = makeconf.merge(conf, options.conf)

    Maker.inst().check_targets()

    report_problems()

    targets = args.todo
    if not targets:
        targets = [None]
    for name in targets:
        if not name and not Maker.inst().def_target:
            println("\nNo target specified and there is no default target.")
            info.print_targets()

            sys.exit(EXIT_NO_MAKE)

        try:
            Maker.inst().make(name, conf)
        except NoSuchTargetError as e:
            fatal("no such target: '{}'", e.target_name)
Exemplo n.º 2
0
def default_conf(conf):
    if isinstance(conf, dict):
        conf = makeconf.from_dict(conf)

    def decorator(func):
        name   = func.__name__
        target = Maker.inst().get_target(name)

        target.def_conf = conf

        return func

    return decorator
Exemplo n.º 3
0
    def __init__(self, name, func=None):
        """
        Initializes the target to default values.

        :param name: Name of the target.
        :param func: Target make function.
        """
        self.checked = False
        self.def_conf = makeconf.from_dict({})
        self.depends = []
        self.desc = None
        self.func = func
        self.name = name
        self.post_funcs = []
        self.pre_funcs = []
Exemplo n.º 4
0
    def decorator(func):
        conf    = kwargs.get('conf'   , None )
        bind    = kwargs.get('bind'   , None)
        default = kwargs.get('default', False)
        depends = kwargs.get('depends', None )
        desc    = kwargs.get('desc'   , None ) or func.__doc__
        name    = kwargs.get('name'   , None ) or func.__name__
        target  = Maker.inst().get_target(name)

        if target.func and bind != 'override':
            report.error("target already bound: '{}'", name)
            return

        target.func = func

        if conf:
            if isinstance(conf, dict):
                conf = makeconf.from_dict(conf)

            target.def_conf = conf

        if default:
            if Maker.inst().def_target:
                report.warn("default target set more than once.")

            Maker.inst().def_target = target

        if depends:
            # Add dependencies that are not already in the target's dependency
            # list.
            target.depends.extend(x for x in depends if x not in target.depends)

        if desc:
            desc = desc.replace('\n', '').replace('\r', '').strip()

            i = len(desc)
            while True:
                desc = desc.replace('  ', ' ')
                j = len(desc)
                if i == j:
                    break

                i = j

            target.desc = desc

        return func
Exemplo n.º 5
0
    def make(self, conf):
        """
        Makes the target by invoking its make function with the specified
        configuration.

        :param conf: Make configuration.
        """

        cwd = os.getcwd()

        if isinstance(conf, dict):
            conf = makeconf.from_dict(conf)

        conf = makeconf.merge(self.def_conf, conf)

        for f in self.pre_funcs:
            self.__call(f, conf)

        self.__call(self.func, conf)

        for f in self.post_funcs:
            self.__call(f, conf)

        os.chdir(cwd)
Exemplo n.º 6
0
def option_conf(value):
    global conf
    conf = makeconf.from_dict(ast.literal_eval(value))