Esempio n. 1
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
Esempio n. 2
0
    def decorator(func):
        name = func.__name__
        target = Maker.inst().get_target(name)

        target.def_conf = conf

        return func
Esempio n. 3
0
def print_targets():
    targets = sorted(Maker.inst().targets, key=lambda t: t.name)

    if len(targets) == 0:
        return

    print "\nTargets:"

    n = 0

    for target in targets:
        # Add one since we also add a space or an asterisk to the target name
        # when printing it.
        n = max(len(target.name) + 1, n)

    s1 = " {: <" + str(n) + "}"
    s2 = s1 + " -"

    maxlen = 72 - n

    for target in targets:
        default = target is Maker.inst().def_target
        desc = target.desc
        name = " " + target.name if not default else "*" + target.name

        s = s2 if desc else s1
        print s.format(name),

        if desc:
            words = desc.split(' ')
            desc = ''
            while len(words) > 0:
                while len(words) > 0 and len(desc) + len(words[0]) < maxlen:
                    desc += words[0] + " "
                    words = words[1:]

                print desc
                desc = ' ' * (n + 4)
        else:
            print

    print
Esempio n. 4
0
    def decorator(func):
        depends = args
        name = func.__name__
        target = Maker.inst().get_target(name)

        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)

        return func
Esempio n. 5
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)
Esempio n. 6
0
def print_usage():
    name = os.path.split(sys.argv[0])[1]
    s = "[target]" if Maker.inst().def_target else "<target>"

    print("""
Usage: python {} [options] {}

Options:
  --conf=<s> - set the configuration to use
  --help     - display information about pymake2
  --no-color - disable text color
  --no-exit  - do not exit automatically after making
  --no-warn  - do not display warnings
  --targets  - show available targets
  --version  - show pymake2 version
""").format(name, s)
Esempio n. 7
0
    def decorator(func):
        target = Maker.inst().get_target(name)

        target.pre_funcs.append(func)

        return func