Ejemplo n.º 1
0
def OptionBuild(argv):
    """
    Get build or test options.
    Args:
        argv : command line argv
    Return:
        None : fail
        options : build or test options
        options["all_log"] : show all build log
        options["mode"] : debug or release
        options["path"] : modular path
        options["jobs"] : the number of build threads
    """
    options = dict()
    options["all_log"] = False
    options["path"] = ""
    options["mode"] = "debug"
    options["jobs"] = 4

    try:
        opts, args = getopt.gnu_getopt(argv, "", ["all-log", "mode=", "jobs="])
    except getopt.GetoptError as ex:
        Log.colorprint("DEFAULT", "%s\nType '%s help' for usage" % \
                (str(ex), os.path.basename(sys.argv[0])), False)
        return None

    if len(args) <= 0:
        options["path"] = os.getcwd()
    elif len(args) == 1:
        options["path"] = args[0]
    else:
        Log.colorprint("RED", "invalid arguments %s\nType '%s help' for usage" % \
                (str(args), os.path.basename(sys.argv[0])), False)
        return None

    for opt, arg in opts:
        if opt == "--all-log":
            options["all_log"] = True
            continue
        if opt == "--mode":
            if arg != "debug" and arg != "release":
                Log.colorprint(
                    "RED",
                    "invalid mode %s. Please use debug or release" % arg,
                    False)
                return None
            options["mode"] = arg
            continue
        if opt == "--jobs":
            options["jobs"] = int(arg)
            continue
        return None

    return options
Ejemplo n.º 2
0
def OptionBuild(argv):
    """
    Get build or test options.
    Args:
        argv : command line argv
    Return:
        None : fail
        options : build or test options
        options["all_log"] : show all build log
        options["mode"] : debug or release
        options["path"] : modular path
        options["jobs"] : the number of build threads
    """
    options = dict()
    options["all_log"] = False
    options["path"] = ""
    options["mode"] = "debug"
    options["jobs"] = 4

    try:
        opts, args = getopt.gnu_getopt(argv, "", ["all-log", "mode=", "jobs="])
    except getopt.GetoptError as ex:
        Log.colorprint("DEFAULT", "%s\nType '%s help' for usage" % \
                (str(ex), os.path.basename(sys.argv[0])), False)
        return None

    if len(args) <= 0:
        options["path"] = os.getcwd()
    elif len(args) == 1:
        options["path"] = args[0]
    else:
        Log.colorprint("RED", "invalid arguments %s\nType '%s help' for usage" % \
                (str(args), os.path.basename(sys.argv[0])), False)
        return None
    
    for opt, arg in opts:
        if opt == "--all-log":
            options["all_log"] = True
            continue
        if opt == "--mode":
            if arg != "debug" and arg != "release":
                Log.colorprint("RED", "invalid mode %s. Please use debug or release" % arg, False)
                return None
            options["mode"] = arg
            continue
        if opt == "--jobs":
            options["jobs"] = int(arg)
            continue
        return None

    return options
Ejemplo n.º 3
0
def Help(bin_name, subcommand=None):
    """
    Show help imformation
    Args:
        bin_name : executable file name
        subcommand : executable file subcommand. In broc, it's in [""]
    Return:
        0 : success
    """
    if subcommand is None:
        Log.colorprint("DEFAULT", "Usage: %s <subcommand> [option] [args]" % (bin_name), False)
        Log.colorprint("DEFAULT",
                "Type %s help <subcommand> for help on a specific subcommand" % (bin_name),
                False)
        Log.colorprint("DEFAULT", "Available subcommands:", False)
        Log.colorprint("DEFAULT", "    build      : Build the specified targets", False)
        Log.colorprint("DEFAULT", "    test       : Build and runs the specified targets",
                False)
        Log.colorprint("DEFAULT", "    show-deps  : Print the dependency graph", False)
        Log.colorprint("DEFAULT", "    clean      : Remove output files", False)
        Log.colorprint("DEFAULT", "    scratch    : Create a BROC template", False)
        Log.colorprint("DEFAULT", "    version    : Display the version", False)
        Log.colorprint("DEFAULT", "    config     : Display broc's config items", False)
        Log.colorprint("DEFAULT", "    help       : Print the help commands", False)
        return 0

    if subcommand == "build" or subcommand == "test":
        if subcommand == "build":
            Log.colorprint("DEFAULT", "build: Builds the specified targets", False)
        else:
            Log.colorprint("DEFAULT", "test: Builds and runs the specified targets", False)
        Log.colorprint("DEFAULT", "Usage: %s %s [option] <path>" % (bin_name, subcommand), False)
        Log.colorprint("DEFAULT", "Valid options:", False)
        Log.colorprint("DEFAULT",
            "\t--mode=[release|debug]  : Set build mode, default mode is debug",
            False)
        Log.colorprint("DEFAULT",
            "\t--jobs=num\t\t: Set the number of build threads",
            False)
        Log.colorprint("DEFAULT", "\t --all-log\t\t: Show all build log infomation")
        return 0

    if subcommand == "show-deps":
        Log.colorprint("DEFAULT", "show-deps: Print the dependency graph", False)
        Log.colorprint("DEFAULT", "Usage: %s %s <path>" % (bin_name, subcommand), False)
        return 0

    if subcommand == "clean":
        Log.colorprint("DEFAULT", "clean: Remove output files", False)
        Log.colorprint("DEFAULT", "Usage: %s clean" % (bin_name), False)
        return 0

    if subcommand == "scratch":
        Log.colorprint("DEFAULT", "scratch: Create a BROC template", False)
        Log.colorprint("DEFAULT", "Usage: %s scratch" % (bin_name), False)
        return 0

    if subcommand == "version":
        Log.colorprint("DEFAULT", "version: Display the version", False)
        Log.colorprint("DEFAULT", "Usage: %s version" % (bin_name), False)
        return 0

    if subcommand == "help":
        Log.colorprint("DEFAULT", "help: Print the for commands", False)
        Log.colorprint("DEFAULT", "Usage: %s help <subcommand>" % (bin_name), False)
        return 0
    
    Log.colorprint("DEFAULT", "%s unknow commmand" % subcommand, False)
    return 0
Ejemplo n.º 4
0
def Help(bin_name, subcommand=None):
    """
    Show help imformation
    Args:
        bin_name : executable file name
        subcommand : executable file subcommand. In broc, it's in [""]
    Return:
        0 : success
    """
    if subcommand is None:
        Log.colorprint("DEFAULT",
                       "Usage: %s <subcommand> [option] [args]" % (bin_name),
                       False)
        Log.colorprint(
            "DEFAULT",
            "Type %s help <subcommand> for help on a specific subcommand" %
            (bin_name), False)
        Log.colorprint("DEFAULT", "Available subcommands:", False)
        Log.colorprint("DEFAULT",
                       "    build      : Build the specified targets", False)
        Log.colorprint(
            "DEFAULT", "    test       : Build and runs the specified targets",
            False)
        Log.colorprint("DEFAULT",
                       "    show-deps  : Print the dependency graph", False)
        Log.colorprint("DEFAULT", "    clean      : Remove output files",
                       False)
        Log.colorprint("DEFAULT", "    scratch    : Create a BROC template",
                       False)
        Log.colorprint("DEFAULT", "    version    : Display the version",
                       False)
        Log.colorprint("DEFAULT",
                       "    config     : Display broc's config items", False)
        Log.colorprint("DEFAULT", "    help       : Print the help commands",
                       False)
        return 0

    if subcommand == "build" or subcommand == "test":
        if subcommand == "build":
            Log.colorprint("DEFAULT", "build: Builds the specified targets",
                           False)
        else:
            Log.colorprint("DEFAULT",
                           "test: Builds and runs the specified targets",
                           False)
        Log.colorprint("DEFAULT",
                       "Usage: %s %s [option] <path>" % (bin_name, subcommand),
                       False)
        Log.colorprint("DEFAULT", "Valid options:", False)
        Log.colorprint(
            "DEFAULT",
            "\t--mode=[release|debug]  : Set build mode, default mode is debug",
            False)
        Log.colorprint("DEFAULT",
                       "\t--jobs=num\t\t: Set the number of build threads",
                       False)
        Log.colorprint("DEFAULT",
                       "\t --all-log\t\t: Show all build log infomation")
        return 0

    if subcommand == "show-deps":
        Log.colorprint("DEFAULT", "show-deps: Print the dependency graph",
                       False)
        Log.colorprint("DEFAULT",
                       "Usage: %s %s <path>" % (bin_name, subcommand), False)
        return 0

    if subcommand == "clean":
        Log.colorprint("DEFAULT", "clean: Remove output files", False)
        Log.colorprint("DEFAULT", "Usage: %s clean" % (bin_name), False)
        return 0

    if subcommand == "scratch":
        Log.colorprint("DEFAULT", "scratch: Create a BROC template", False)
        Log.colorprint("DEFAULT", "Usage: %s scratch" % (bin_name), False)
        return 0

    if subcommand == "version":
        Log.colorprint("DEFAULT", "version: Display the version", False)
        Log.colorprint("DEFAULT", "Usage: %s version" % (bin_name), False)
        return 0

    if subcommand == "help":
        Log.colorprint("DEFAULT", "help: Print the for commands", False)
        Log.colorprint("DEFAULT", "Usage: %s help <subcommand>" % (bin_name),
                       False)
        return 0

    Log.colorprint("DEFAULT", "%s unknow commmand" % subcommand, False)
    return 0