Exemplo n.º 1
0
def main():
    '''
    codechecker main command line
    '''

    def signal_handler(sig, frame):
        '''
        Without this handler the postgreSql
        server does not terminated at signal
        '''
        sys.exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    try:
        parser = argparse.ArgumentParser(
            prog='CodeChecker',
            formatter_class=argparse.RawDescriptionHelpFormatter,
            description='''
Run the CodeChecker source analyzer framework.
See the subcommands for specific features.''',
            epilog='''
Example usage:
--------------
Analyzing a project with default settings:
CodeChecker check -w ~/workspace -b "cd ~/myproject && make" -n myproject

Start the viewer to see the results:
CodeChecker server -w ~/workspace

See the results in a web browser: localhost:8001
See results in  the command line: CodeChecker cmd results -p 8001 -n myproject

To analyze a small project quickcheck feature can be used.
The results will be printed only to the standard output. (No database will be used)

CodeChecker quickcheck -w ~/workspace -b "cd ~/myproject && make"
''')

        subparsers = parser.add_subparsers(help='commands')

        workspace_help_msg = """Directory where the codechecker can store analysis related data."""

        name_help_msg = """Name of the analysis."""

        jobs_help_msg = """Number of jobs. Start multiple processes for faster analysis""";

        log_argument_help_msg="""Path to the log file which is created during the build. \nIf there is an already generated log file with the compilation commands\ngenerated by 'CodeChecker log' or 'cmake -DCMAKE_EXPORT_COMPILE_COMMANDS' \nCodechecker check can use it for the analysis in that case running the original build will \nbe left out from the analysis process (no log is needed)."""

        # --------------------------------------
        # check commands
        check_parser = subparsers.add_parser('check',
                                             formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                             help='''\
Run the supported source code analyzers on a project''')
        check_parser.add_argument('-w', '--workspace', type=str,
                                  default=util.get_default_workspace(),
                                  dest="workspace",
                                  help=workspace_help_msg)
        check_parser.add_argument('-n', '--name', type=str,
                                  dest="name", required=True,
                                  default=argparse.SUPPRESS,
                                  help=name_help_msg)
        checkgroup = check_parser.add_mutually_exclusive_group(required=True)
        checkgroup.add_argument('-b', '--build', type=str, dest="command",
                                default=argparse.SUPPRESS,
                                required=False, help='''\
Build command which is used to build the project''')
        checkgroup.add_argument('-l', '--log', type=str, dest="logfile",
                                default=argparse.SUPPRESS,
                                required=False,
                                help=log_argument_help_msg)
        check_parser.add_argument('-j', '--jobs', type=int, dest="jobs",
                                  default=1, required=False,
                                  help=jobs_help_msg)
        check_parser.add_argument('-u', '--suppress', type=str, dest="suppress",
                                  default=argparse.SUPPRESS,
                                  required=False, help="""Path to suppress file. \nSuppress file can be used to suppress analysis results during the analysis.\nIt is based on the bug identifier generated by the compiler which is experimental.\nDo not depend too much on this file because identifier or file format can be changed.\nFor other in source suppress features see the user guide.""")
        check_parser.add_argument('-c', '--clean',
                                  default=argparse.SUPPRESS,
                                  action=DeprecatedOptionAction)
        check_parser.add_argument('--update', action=DeprecatedOptionAction,
                                  dest="update", default=False, required=False,
                                  help='''\
Incremental parsing, update the results of a previous run.
Only the files changed since the last build will be reanalyzed. Depends on the build system.''')

        check_parser.add_argument('--force', action="store_true",
                                  dest="force", default=False, required=False,
                                  help='''\
Delete analysis results form the database if a run with the given name already exists''')
        check_parser.add_argument('-s', '--skip', type=str, dest="skipfile",
                                  default=argparse.SUPPRESS,
                                  required=False, help='Path to skip file.')
        add_analyzer_arguments(check_parser)
        add_database_arguments(check_parser)
        check_parser.set_defaults(func=arg_handler.handle_check)

        # --------------------------------------
        # quickcheck commands
        qcheck_parser = subparsers.add_parser('quickcheck',
                                              formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                              help='''\
Run CodeChecker for a project without database.''')
        qcheckgroup = qcheck_parser.add_mutually_exclusive_group(required=True)
        qcheckgroup.add_argument('-b', '--build', type=str, dest="command",
                                 default=argparse.SUPPRESS,
                                 required=False, help='Build command.')
        qcheckgroup.add_argument('-l', '--log', type=str, dest="logfile",
                                 required=False,
                                 default=argparse.SUPPRESS,
                                 help=log_argument_help_msg)
        qcheck_parser.add_argument('-s', '--steps', action="store_true",
                                   dest="print_steps", help='Print steps.')
        add_analyzer_arguments(qcheck_parser)
        qcheck_parser.set_defaults(func=arg_handler.handle_quickcheck)


        # --------------------------------------
        # log commands
        logging_parser = subparsers.add_parser('log',
                                              formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                               help='''\
Runs the given build command. During the build the compilation commands are collected and
stored into a compilation command json file (no analysis is done during the build).''')
        logging_parser.add_argument('-o', '--output', type=str, dest="logfile",
                                    default=argparse.SUPPRESS,
                                    required=True, help='Path to the log file.')
        logging_parser.add_argument('-b', '--build', type=str, dest="command",
                                    default=argparse.SUPPRESS,
                                    required=True, help='Build command.')
        logging_parser.set_defaults(func=arg_handler.handle_log)

        # --------------------------------------
        # checkers parser
        checkers_parser = subparsers.add_parser('checkers',
                                                formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                                help="""List the available checkers for the supported analyzers and show their default status (+ for being enabled, - for being disabled by default).""")
        checkers_parser.add_argument('--analyzers', nargs='+',
                            dest="analyzers", required=False,
                            help="""Select which analyzer checkers should be listed.\nCurrently supported analyzers:\n""" + analyzers)
        checkers_parser.set_defaults(func=arg_handler.handle_list_checkers)

        # --------------------------------------
        # server
        server_parser = subparsers.add_parser('server',
                                             formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                              help='Start the codechecker web server.')
        server_parser.add_argument('-w', '--workspace', type=str,
                                   dest="workspace",
                                   default=util.get_default_workspace(),
                                   help=workspace_help_msg)
        server_parser.add_argument('-v', '--view-port', type=int, dest="view_port",
                                   default=8001, required=False,
                                   help='Port used for viewing.')
        server_parser.add_argument('-u', '--suppress', type=str, dest="suppress",
                                   required=False, help='Path to suppress file.')
        server_parser.add_argument('--not-host-only', action="store_true",
                                   dest="not_host_only",
                                   help='Viewing the results is possible not \
                                   only by browsers or clients started locally.')
        server_parser.add_argument('--check-port', type=int, dest="check_port",
                                   default=None, required=False,
                                   help='Port used for checking.')
        server_parser.add_argument('--check-address', type=str,
                                   dest="check_address", default="localhost",
                                   required=False, help='Server address.')
        add_database_arguments(server_parser)
        server_parser.set_defaults(func=arg_handler.handle_server)

        # --------------------------------------
        # cmd_line
        cmd_line_parser = subparsers.add_parser('cmd',
                                                help='Command line client')
        cmd_line_client.register_client_command_line(cmd_line_parser)

        # --------------------------------------
        # debug parser
        debug_parser = subparsers.add_parser('debug',
                                             formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                             help="""Generate gdb debug dump files for all the failed compilation commands in the last analyzer run.\nRequires a database with the failed compilation commands""")
        debug_parser.add_argument('-w', '--workspace', type=str,
                                  dest="workspace",
                                  default=util.get_default_workspace(),
                                  help=workspace_help_msg)
        debug_parser.add_argument('-f', '--force', action="store_true",
                                  dest="force", required=False, default=False,
                                  help='Overwrite already generated files.')
        add_database_arguments(debug_parser)
        debug_parser.set_defaults(func=arg_handler.handle_debug)

        # --------------------------------------
        # plist parser
        plist_parser = subparsers.add_parser('plist',
                                             formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                             help='Parse plist files in the given directory.')
        plist_parser.add_argument('-w', '--workspace', type=str,
                                  dest="workspace",
                                  default=util.get_default_workspace(),
                                  help=workspace_help_msg)
        plist_parser.add_argument('-n', '--name', type=str,
                                  dest="name", required=True,
                                  default=argparse.SUPPRESS,
                                  help=name_help_msg)
        plist_parser.add_argument('-d', '--directory', type=str,
                                  dest="directory", required=True,
                                  help='Path of a directory containing plist files to parse.')
        plist_parser.add_argument('-j', '--jobs', type=int, dest="jobs",
                                  default=1, required=False,
                                  help=jobs_help_msg)
        plist_parser.add_argument('-s', '--steps', action="store_true",
                                  dest="print_steps", help='Print steps.')
        plist_parser.add_argument('--stdout', action="store_true", dest="stdout",
                                  required=False, default=False,
                                  help="Print results to stdout instead of database.")
        plist_parser.add_argument('--force', action="store_true",
                                  dest="force", default=False, required=False,
                                  help='''\
Delete analysis results form the database if a run with the given name already exists''')
        add_database_arguments(plist_parser)
        plist_parser.set_defaults(func=arg_handler.handle_plist)

        # --------------------------------------
        # package version info
        version_parser = subparsers.add_parser('version',
                                               help='Print package version information.')
        version_parser.set_defaults(func=arg_handler.handle_version_info)

        args = parser.parse_args()
        args.func(args)

    except KeyboardInterrupt as kb_err:
        LOG.info(str(kb_err))
        LOG.info("Interupted by user...")
        sys.exit(1)

    except shared.ttypes.RequestFailed as thrift_ex:
        LOG.info("Server error.")
        LOG.info("Error code: " + str(thrift_ex.error_code))
        LOG.info("Error message: " + str(thrift_ex.message))
        sys.exit(1)

    # Handle all exception, but print stacktrace. It is needed for atexit.
    # atexit does not work correctly when an unhandled exception occured.
    # So in this case, the servers left running when the script exited.
    except Exception:
        import traceback
        traceback.print_exc(file=sys.stdout)
        sys.exit(2)
Exemplo n.º 2
0
def main():
    """
    codechecker main command line
    """

    def signal_handler(sig, frame):
        """
        Without this handler the postgreSql
        server does not terminated at signal
        """
        sys.exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    try:
        parser = argparse.ArgumentParser(
            formatter_class=argparse.RawDescriptionHelpFormatter, description="""Run the codechecker script.\n """
        )

        subparsers = parser.add_subparsers(help="commands")

        # --------------------------------------
        # check commands
        check_parser = subparsers.add_parser("check", help="Run CodeChecker for a project.")
        check_parser.add_argument(
            "-w",
            "--workspace",
            type=str,
            dest="workspace",
            required=True,
            help="Directory where the codechecker can \
                                  store analysis related data.",
        )
        check_parser.add_argument("-n", "--name", type=str, dest="name", required=True, help="Name of the project.")

        checkgroup = check_parser.add_mutually_exclusive_group(required=True)
        checkgroup.add_argument("-b", "--build", type=str, dest="command", required=False, help="Build command.")
        checkgroup.add_argument(
            "-l",
            "--log",
            type=str,
            dest="logfile",
            required=False,
            help="Path to the log file which is created \
                                during the build.",
        )

        check_parser.add_argument(
            "-j", "--jobs", type=int, dest="jobs", default=1, required=False, help="Number of jobs."
        )
        check_parser.add_argument(
            "-f", "--config", type=str, dest="configfile", required=False, help="Config file for the checkers."
        )
        check_parser.add_argument("-s", "--skip", type=str, dest="skipfile", required=False, help="Path to skip file.")
        check_parser.add_argument(
            "-u", "--suppress", type=str, dest="suppress", required=False, help="Path to suppress file."
        )
        check_parser.add_argument("-e", "--enable", default=[], action=OrderedCheckersAction, help="Enable checker.")
        check_parser.add_argument("-d", "--disable", default=[], action=OrderedCheckersAction, help="Disable checker.")
        check_parser.add_argument("-c", "--clean", action=DeprecatedOptionAction)
        check_parser.add_argument(
            "--keep-tmp",
            action="store_true",
            dest="keep_tmp",
            required=False,
            help="Keep temporary report files \
                                  after sending data to database storage server.",
        )
        check_parser.add_argument(
            "--update",
            action="store_true",
            dest="update",
            default=False,
            required=False,
            help="Incremental parsing, \
                                  update the results of a previous run.",
        )
        add_database_arguments(check_parser)
        check_parser.set_defaults(func=arg_handler.handle_check)

        # --------------------------------------
        # quickcheck commands
        qcheck_parser = subparsers.add_parser(
            "quickcheck",
            help="Run CodeChecker for a \
                                                    project without database.",
        )
        qcheckgroup = qcheck_parser.add_mutually_exclusive_group(required=True)
        qcheckgroup.add_argument("-b", "--build", type=str, dest="command", required=False, help="Build command.")
        qcheckgroup.add_argument(
            "-l",
            "--log",
            type=str,
            dest="logfile",
            required=False,
            help="Path to the log file which is created \
                                       during the build.",
        )
        qcheck_parser.add_argument("-e", "--enable", default=[], action=OrderedCheckersAction, help="Enable checker.")
        qcheck_parser.add_argument("-d", "--disable", default=[], action=OrderedCheckersAction, help="Disable checker.")
        qcheck_parser.add_argument("-s", "--steps", action="store_true", dest="print_steps", help="Print steps.")
        qcheck_parser.set_defaults(func=arg_handler.handle_quickcheck)

        # --------------------------------------
        # log commands
        logging_parser = subparsers.add_parser(
            "log",
            help="Build the project and \
                                               create a log file (no checking).",
        )
        logging_parser.add_argument(
            "-o", "--output", type=str, dest="logfile", required=True, help="Path to the log file."
        )
        logging_parser.add_argument("-b", "--build", type=str, dest="command", required=True, help="Build command.")
        logging_parser.set_defaults(func=arg_handler.handle_log)

        # --------------------------------------
        # checkers parser
        checkers_parser = subparsers.add_parser("checkers", help="List avalaible checkers.")
        checkers_parser.set_defaults(func=arg_handler.handle_list_checkers)

        # --------------------------------------
        # server
        server_parser = subparsers.add_parser("server", help="Start the codechecker database server.")
        server_parser.add_argument(
            "-w",
            "--workspace",
            type=str,
            dest="workspace",
            required=False,
            help="Directory where the codechecker \
                                   stored analysis related data \
                                   (automatically created posgtreSql database).",
        )
        server_parser.add_argument(
            "-v",
            "--view-port",
            type=int,
            dest="view_port",
            default=11444,
            required=False,
            help="Port used for viewing.",
        )
        server_parser.add_argument(
            "-u", "--suppress", type=str, dest="suppress", required=False, help="Path to suppress file."
        )
        server_parser.add_argument(
            "--not-host-only",
            action="store_true",
            dest="not_host_only",
            help="Viewing the results is possible not \
                                   only by browsers or clients started locally.",
        )
        server_parser.add_argument(
            "--check-port", type=int, dest="check_port", default=None, required=False, help="Port used for checking."
        )
        server_parser.add_argument(
            "--check-address",
            type=str,
            dest="check_address",
            default="localhost",
            required=False,
            help="Server address.",
        )
        add_database_arguments(server_parser)
        server_parser.set_defaults(func=arg_handler.handle_server)

        # --------------------------------------
        # cmd_line
        cmd_line_parser = subparsers.add_parser("cmd", help="Command line client")
        cmd_line_client.register_client_command_line(cmd_line_parser)

        # --------------------------------------
        # debug parser
        debug_parser = subparsers.add_parser(
            "debug",
            help="Create debug logs \
                                             for failed buildactions",
        )
        debug_parser.add_argument(
            "-w",
            "--workspace",
            type=str,
            dest="workspace",
            required=False,
            help="Directory where the codechecker stores \
                                  analysis related data.",
        )
        debug_parser.add_argument(
            "-f",
            "--force",
            action="store_true",
            dest="force",
            required=False,
            default=False,
            help="Generate dump for all failed action.",
        )
        add_database_arguments(debug_parser)
        debug_parser.set_defaults(func=arg_handler.handle_debug)

        # --------------------------------------
        # package version info
        version_parser = subparsers.add_parser("version", help="Print package version information.")
        version_parser.set_defaults(func=arg_handler.handle_version_info)

        args = parser.parse_args()
        args.func(args)

    except KeyboardInterrupt as kb_err:
        LOG.info(str(kb_err))
        LOG.info("Interupted by user...")
        sys.exit(1)

    except shared.ttypes.RequestFailed as thrift_ex:
        LOG.info("Server error.")
        LOG.info("Error code: " + str(thrift_ex.error_code))
        LOG.info("Error message: " + str(thrift_ex.message))
        sys.exit(1)

    # Handle all exception, but print stacktrace. It is needed for atexit.
    # atexit does not work correctly when an unhandled exception occured.
    # So in this case, the servers left running when the script exited.
    except Exception:
        import traceback

        traceback.print_exc(file=sys.stdout)
        sys.exit(2)
Exemplo n.º 3
0
def main():
    """
    CodeChecker main command line.
    """

    def signal_handler(sig, frame):
        """
        Without this handler the PostgreSQL
        server does not terminated at signal.
        """
        sys.exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    try:
        parser = argparse.ArgumentParser(
            prog='CodeChecker',
            formatter_class=argparse.RawDescriptionHelpFormatter,
            description='''
Run the CodeChecker source analyzer framework.
See the subcommands for specific features.''',
            epilog='''
Example usage:
--------------
Analyzing a project with default settings:
CodeChecker check -w ~/workspace -b "cd ~/myproject && make" -n myproject

Start the viewer to see the results:
CodeChecker server -w ~/workspace

See the results in a web browser: localhost:8001
See results in  the command line: CodeChecker cmd results -p 8001 -n myproject

To analyze a small project quickcheck feature can be used.
The results will be printed only to the standard output.
(No database will be used)

CodeChecker quickcheck -w ~/workspace -b "cd ~/myproject && make"
''')

        subparsers = parser.add_subparsers(help='commands')

        workspace_help_msg = 'Directory where the CodeChecker can' \
            ' store analysis related data.'

        name_help_msg = 'Name of the analysis.'

        jobs_help_msg = 'Number of jobs.' \
            'Start multiple processes for faster analysis'

        log_argument_help_msg = "Path to the log file which is created "
        "during the build. \nIf there is an already generated log file "
        "with the compilation commands\ngenerated by 'CodeChecker log' or "
        "'cmake -DCMAKE_EXPORT_COMPILE_COMMANDS' \n CodeChecker check can "
        "use it for the analysis in that case running the original build "
        "will \nbe left out from the analysis process (no log is needed)."

        suppress_help_msg = "Path to suppress file.\nSuppress file can be used"
        "to suppress analysis results during the analysis.\nIt is based on the"
        "bug identifier generated by the compiler which is experimental.\nDo"
        "not depend too much on this file because identifier or file format "
        "can be changed.\nFor other in source suppress features see the user"
        "guide."

        # --------------------------------------
        # check commands
        check_parser = subparsers.add_parser('check',
                                             formatter_class=ADHF,
                                             help=''' \
Run the supported source code analyzers on a project''')

        check_parser.add_argument('-w', '--workspace', type=str,
                                  default=util.get_default_workspace(),
                                  dest="workspace",
                                  help=workspace_help_msg)

        check_parser.add_argument('-n', '--name', type=str,
                                  dest="name", required=True,
                                  default=argparse.SUPPRESS,
                                  help=name_help_msg)

        checkgroup = check_parser.add_mutually_exclusive_group(required=True)

        checkgroup.add_argument('-b', '--build', type=str, dest="command",
                                default=argparse.SUPPRESS,
                                required=False, help='''\
Build command which is used to build the project''')

        checkgroup.add_argument('-l', '--log', type=str, dest="logfile",
                                default=argparse.SUPPRESS,
                                required=False,
                                help=log_argument_help_msg)

        check_parser.add_argument('-j', '--jobs', type=int, dest="jobs",
                                  default=1, required=False,
                                  help=jobs_help_msg)

        check_parser.add_argument('-u', '--suppress', type=str,
                                  dest="suppress",
                                  default=argparse.SUPPRESS,
                                  required=False,
                                  help=suppress_help_msg)
        check_parser.add_argument('-c', '--clean',
                                  default=argparse.SUPPRESS,
                                  action=DeprecatedOptionAction)

        check_parser.add_argument('--update', action=DeprecatedOptionAction,
                                  dest="update", default=False, required=False,
                                  help="Incremental parsing, update the "
                                       "results of a previous run. "
                                       "Only the files changed since the last "
                                       "build will be reanalyzed. Depends on"
                                       " the build system.")

        check_parser.add_argument('--force', action="store_true",
                                  dest="force", default=False, required=False,
                                  help="Delete analysis results form the "
                                       "database if a run with the "
                                       "given name already exists")

        check_parser.add_argument('-s', '--skip', type=str, dest="skipfile",
                                  default=argparse.SUPPRESS,
                                  required=False, help='Path to skip file.')

        check_parser.add_argument('--quiet-build',
                                  action='store_true',
                                  default=False,
                                  required=False,
                                  help='Do not print out the output of the '
                                       'original build')

        add_analyzer_arguments(check_parser)
        add_database_arguments(check_parser)
        check_parser.set_defaults(func=arg_handler.handle_check)

        # --------------------------------------
        # QuickCheck commands.
        qcheck_parser = subparsers.add_parser('quickcheck',
                                              formatter_class=ADHF,
                                              help='Run CodeChecker for a'
                                                   'project without database.')

        qcheckgroup = qcheck_parser.add_mutually_exclusive_group(required=True)

        qcheckgroup.add_argument('-b', '--build', type=str, dest="command",
                                 default=argparse.SUPPRESS,
                                 required=False, help='Build command.')

        qcheckgroup.add_argument('-l', '--log', type=str, dest="logfile",
                                 required=False,
                                 default=argparse.SUPPRESS,
                                 help=log_argument_help_msg)

        qcheck_parser.add_argument('-s', '--steps', action="store_true",
                                   dest="print_steps", help='Print steps.')

        qcheck_parser.add_argument('--quiet-build',
                                   action='store_true',
                                   default=False,
                                   required=False,
                                   help='Do not print out the output of the '
                                        'original build')
        qcheck_parser.add_argument('-i', '--skip', type=str, dest="skipfile",
                                   default=argparse.SUPPRESS,
                                   required=False, help='Path to skip file.')
        qcheck_parser.add_argument('-j', '--jobs', type=int, dest="jobs",
                                   default=1, required=False,
                                   help=jobs_help_msg)
        qcheck_parser.add_argument('-u', '--suppress', type=str,
                                   dest="suppress",
                                   default=argparse.SUPPRESS,
                                   required=False,
                                   help=suppress_help_msg)
        add_analyzer_arguments(qcheck_parser)
        qcheck_parser.set_defaults(func=arg_handler.handle_quickcheck)

        # --------------------------------------
        # Log commands.
        logging_p = subparsers.add_parser('log',
                                          formatter_class=ADHF,
                                          help='Runs the given build '
                                               'command. During the '
                                               'build the compilation '
                                               'commands are collected '
                                               'and stored into a '
                                               'compilation command '
                                               'json file '
                                               '(no analysis is done '
                                               'during the build).')

        logging_p.add_argument('-o', '--output', type=str, dest="logfile",
                               default=argparse.SUPPRESS,
                               required=True,
                               help='Path to the log file.')

        logging_p.add_argument('-b', '--build', type=str, dest="command",
                               default=argparse.SUPPRESS,
                               required=True, help='Build command.')

        logging_p.set_defaults(func=arg_handler.handle_log)

        # --------------------------------------
        # Checkers parser.
        checker_p = subparsers.add_parser('checkers',
                                          formatter_class=ADHF,
                                          help='List the available checkers '
                                               'for the supported analyzers '
                                               'and show their default status '
                                               '(+ for being enabled, '
                                               '- for being disabled by '
                                               'default).')

        checker_p.add_argument('--analyzers', nargs='+',
                               dest="analyzers", required=False,
                               help='Select which analyzer checkers '
                               'should be listed.\nCurrently supported '
                               'analyzers:\n' + analyzers)

        checker_p.set_defaults(func=arg_handler.handle_list_checkers)

        # --------------------------------------
        # Server.
        server_parser = subparsers.add_parser('server',
                                              formatter_class=ADHF,
                                              help='Start the codechecker '
                                                   'web server.')
        server_parser.add_argument('-w', '--workspace', type=str,
                                   dest="workspace",
                                   default=util.get_default_workspace(),
                                   help=workspace_help_msg)

        server_parser.add_argument('-v', '--view-port', type=int,
                                   dest="view_port",
                                   default=8001, required=False,
                                   help='Port used for viewing.')

        server_parser.add_argument('-u', '--suppress', type=str,
                                   dest="suppress",
                                   required=False,
                                   help='Path to suppress file.')

        server_parser.add_argument('--not-host-only', action="store_true",
                                   dest="not_host_only",
                                   help='Viewing the results is possible not'
                                        'only by browsers or clients'
                                        ' started locally.')

        server_parser.add_argument('--check-port', type=int, dest="check_port",
                                   default=None, required=False,
                                   help='Port used for checking.')

        server_parser.add_argument('--check-address', type=str,
                                   dest="check_address", default="localhost",
                                   required=False, help='Server address.')

        add_database_arguments(server_parser)
        server_parser.set_defaults(func=arg_handler.handle_server)

        # --------------------------------------
        # Cmd_line.
        cmd_line_parser = subparsers.add_parser('cmd',
                                                help='Command line client')
        cmd_line_client.register_client_command_line(cmd_line_parser)

        # --------------------------------------
        # Debug parser.
        debug_parser = subparsers.add_parser('debug',
                                             formatter_class=ADHF,
                                             help='Generate gdb debug dump '
                                                  'files for all the failed '
                                                  'compilation commands in '
                                                  'the last analyzer run.\n'
                                                  'Requires a database with '
                                                  'the failed compilation '
                                                  'commands')

        debug_parser.add_argument('-w', '--workspace', type=str,
                                  dest="workspace",
                                  default=util.get_default_workspace(),
                                  help=workspace_help_msg)

        debug_parser.add_argument('-f', '--force', action="store_true",
                                  dest="force", required=False, default=False,
                                  help='Overwrite already generated files.')

        add_database_arguments(debug_parser)
        debug_parser.set_defaults(func=arg_handler.handle_debug)

        # --------------------------------------
        # Plist parser.
        plist_parser = subparsers.add_parser('plist',
                                             formatter_class=ADHF,
                                             help='Parse plist files in '
                                                  'the given directory.')

        plist_parser.add_argument('-w', '--workspace', type=str,
                                  dest="workspace",
                                  default=util.get_default_workspace(),
                                  help=workspace_help_msg)

        plist_parser.add_argument('-n', '--name', type=str,
                                  dest="name", required=True,
                                  default=argparse.SUPPRESS,
                                  help=name_help_msg)

        plist_parser.add_argument('-d', '--directory', type=str,
                                  dest="directory", required=True,
                                  help='Path of a directory containing plist '
                                  ' files to parse.')

        plist_parser.add_argument('-j', '--jobs', type=int, dest="jobs",
                                  default=1, required=False,
                                  help=jobs_help_msg)

        plist_parser.add_argument('-s', '--steps', action="store_true",
                                  dest="print_steps", help='Print steps.')

        plist_parser.add_argument('--stdout', action="store_true",
                                  dest="stdout",
                                  required=False, default=False,
                                  help='Print results to stdout instead of '
                                       'storing to the database.')

        plist_parser.add_argument('--force', action="store_true",
                                  dest="force", default=False, required=False,
                                  help='Delete analysis results form the '
                                       'database if a run with the given '
                                       'name already exists')

        add_database_arguments(plist_parser)
        plist_parser.set_defaults(func=arg_handler.handle_plist)

        # --------------------------------------
        # Package version info.
        version_parser = subparsers.add_parser('version',
                                               help='Print package version '
                                                    'information.')
        version_parser.set_defaults(func=arg_handler.handle_version_info)

        args = parser.parse_args()
        args.func(args)

    except KeyboardInterrupt as kb_err:
        LOG.info(str(kb_err))
        LOG.info("Interrupted by user...")
        sys.exit(1)

    except shared.ttypes.RequestFailed as thrift_ex:
        LOG.info("Server error.")
        LOG.info("Error code: " + str(thrift_ex.error_code))
        LOG.info("Error message: " + str(thrift_ex.message))
        sys.exit(1)

    # Handle all exception, but print stacktrace. It is needed for atexit.
    # atexit does not work correctly when an unhandled exception occurred.
    # So in this case, the servers left running when the script exited.
    except Exception:
        import traceback
        traceback.print_exc(file=sys.stdout)
        sys.exit(2)
Exemplo n.º 4
0
def main():
    '''
    codechecker main command line
    '''

    def signal_handler(sig, frame):
        '''
        Without this handler the postgreSql
        server does not terminated at signal
        '''
        sys.exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    try:
        parser = argparse.ArgumentParser(
                    formatter_class=argparse.RawDescriptionHelpFormatter,
                    description='''Run the codechecker script.\n ''')

        subparsers = parser.add_subparsers(help='commands')

        # --------------------------------------
        # check commands
        check_parser = subparsers.add_parser('check',
                                             help='Run codechecker for a project.')
        check_parser.add_argument('-w', '--workspace', type=str,
                                  dest="workspace", required=True,
                                  help='Directory where the codechecker can \
                                  store analysis related data.')
        check_parser.add_argument('-n', '--name', type=str,
                                  dest="name", required=True,
                                  help='Name of the project.')

        checkgroup = check_parser.add_mutually_exclusive_group(required=True)
        checkgroup.add_argument('-b', '--build', type=str, dest="command",
                                required=False, help='Build command.')
        checkgroup.add_argument('-l', '--log', type=str, dest="logfile",
                                required=False,
                                help='Path to the log file which is created \
                                during the build.')

        check_parser.add_argument('-j', '--jobs', type=int, dest="jobs",
                                  default=1, required=False, help='Number of jobs.')
        check_parser.add_argument('-f', '--config', type=str, dest="configfile",
                                  required=False, help='Config file for the checkers.')
        check_parser.add_argument('-s', '--skip', type=str, dest="skipfile",
                                  required=False, help='Path to skip file.')
        check_parser.add_argument('-u', '--suppress', type=str, dest="suppress",
                                  required=False, help='Path to suppress file.')
        check_parser.add_argument('-e', '--enable', default=[],
                                  action=OrderedCheckersAction,
                                  help='Enable checker.')
        check_parser.add_argument('-d', '--disable', default=[],
                                  action=OrderedCheckersAction,
                                  help='Disable checker.')
        check_parser.add_argument('-c', '--clean', action="store_true",
                                  dest="clean", required=False,
                                  help='Delete temporary report files \
                                  after sending data to database storage server.')
        check_parser.add_argument('--dbaddress', type=str, dest="dbaddress",
                                  default="localhost", required=False,
                                  help='Postgres database server address.')
        check_parser.add_argument('--dbport', type=int, dest="dbport",
                                  default=8764, required=False,
                                  help='Postgres database server port.')
        check_parser.add_argument('--dbname', type=str, dest="dbname",
                                  default="codechecker", required=False,
                                  help='Name of the database.')
        check_parser.add_argument('--dbusername', type=str, dest="dbusername",
                                  default='codechecker', required=False,
                                  help='Database user name.')
        check_parser.add_argument('--update', action="store_true",
                                  dest="update", default=False, required=False,
                                  help='Incremental parsing, \
                                  update the results of a previous run.')
        check_parser.set_defaults(func=arg_handler.handle_check)


        # --------------------------------------
        # log commands
        logging_parser = subparsers.add_parser('log',
                                               help='Build the project and \
                                               create a log file (no checking).')
        logging_parser.add_argument('-o', '--output', type=str, dest="logfile",
                                    required=True, help='Path to the log file.')
        logging_parser.add_argument('-b', '--build', type=str, dest="command",
                                    required=True, help='Build command.')
        logging_parser.set_defaults(func=arg_handler.handle_log)


        # --------------------------------------
        # checkers parser
        checkers_parser = subparsers.add_parser('checkers',
                                                help='List avalaible checkers.')
        checkers_parser.set_defaults(func=arg_handler.handle_list_checkers)

        # --------------------------------------
        # server
        server_parser = subparsers.add_parser('server',
                                              help='Start the codechecker database server.')
        server_parser.add_argument('-w', '--workspace', type=str,
                                   dest="workspace", required=False,
                                   help='Directory where the codechecker \
                                   stored analysis related data \
                                   (automatically created posgtreSql database).')
        server_parser.add_argument('--dbport', type=int, dest="dbport",
                                   default=8764, required=False,
                                   help='Postgres server port.')
        server_parser.add_argument('--dbaddress', type=str, dest="dbaddress",
                                   default="localhost", required=False,
                                   help='Postgres database server address')
        server_parser.add_argument('--dbname', type=str, dest="dbname",
                                   default="codechecker", required=False,
                                   help='Name of the database.')
        server_parser.add_argument('--dbusername', type=str, dest="dbusername",
                                   default='codechecker', required=False,
                                   help='Database user name.')
        server_parser.add_argument('-v', '--view-port', type=int, dest="view_port",
                                   default=11444, required=False,
                                   help='Port used for viewing.')
        server_parser.add_argument('-u', '--suppress', type=str, dest="suppress",
                                   required=False, help='Path to suppress file.')
        server_parser.add_argument('--not-host-only', action="store_true",
                                   dest="not_host_only",
                                   help='Viewing the results is possible not \
                                   only by browsers or clients started locally.')
        server_parser.add_argument('--check-port', type=int, dest="check_port",
                                   default=None, required=False,
                                   help='Port used for checking.')
        server_parser.add_argument('--check-address', type=str,
                                   dest="check_address", default="localhost",
                                   required=False, help='Server address.')
        server_parser.set_defaults(func=arg_handler.handle_server)

        # --------------------------------------
        # cmd_line
        cmd_line_parser = subparsers.add_parser('cmd',
                                                help='Command line client')
        cmd_line_client.register_client_command_line(cmd_line_parser)

        # --------------------------------------
        # debug parser
        debug_parser = subparsers.add_parser('debug',
                                             help='Create debug logs \
                                             for failed buildactions')
        debug_parser.add_argument('-w', '--workspace', type=str,
                                  dest="workspace", required=False,
                                  help='Directory where the codechecker stores \
                                  analysis related data.')
        debug_parser.add_argument('--dbport', type=int, dest="dbport",
                                  default=8764, required=False,
                                  help='Postgres server port.')
        debug_parser.add_argument('--dbaddress', type=str, dest="dbaddress",
                                  default="localhost", required=False,
                                  help='Postgres database server address')
        debug_parser.add_argument('--dbname', type=str, dest="dbname",
                                  default="codechecker", required=False,
                                  help='Name of the database.')
        debug_parser.add_argument('--dbusername', type=str, dest="dbusername",
                                  default='codechecker', required=False,
                                  help='Database user name.')
        debug_parser.add_argument('-f', '--force', action="store_true",
                                  dest="force", required=False, default=False,
                                  help='Generate dump for all failed action.')
        debug_parser.set_defaults(func=arg_handler.handle_debug)

        args = parser.parse_args()
        args.func(args)

    except KeyboardInterrupt as kb_err:
        LOG.info(str(kb_err))
        LOG.info("Interupted by user...")
        sys.exit(1)

    except shared.ttypes.RequestFailed as thrift_ex:
        LOG.info("Server error.")
        LOG.info("Error code: " + str(thrift_ex.error_code))
        LOG.info("Error message: " + str(thrift_ex.message))
        sys.exit(1)

    # Handle all exception, but print stacktrace. It is needed for atexit.
    # atexit does not work correctly when an unhandled exception occured.
    # So in this case, the servers left running when the script exited.
    except Exception:
        import traceback
        traceback.print_exc(file=sys.stdout)
        sys.exit(2)