Exemplo n.º 1
0
def option_conf(value):
    """
    Allows the user to specify a make configuration on the command line.

    :param value: Option value string to parse into make configuration.
    """
    global conf
    conf = makeconf.from_dict(ast.literal_eval(value))
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 pymake2(conf=None, args=None):
    args = sys.argv if args is None else [sys.argv[0]] + args

    # Keep arguments beginning with two hyphens.
    opts = [arg for arg in args if arg.startswith('--')]

    # Keep arguments *not* beginning with two hyphens.
    args = [arg for arg in args if arg not in opts]

    # Parse command line options.
    options.parse(opts)

    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[1:]
    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.º 4
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.º 5
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.º 6
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)