コード例 #1
0
ファイル: arguments.py プロジェクト: nelo360/sdclang-6.0.2
def validate_args_for_analyze(parser, args, from_build_command):
    """ Command line parsing is done by the argparse module, but semantic
    validation still needs to be done. This method is doing it for
    analyze-build and scan-build commands.

    :param parser: The command line parser object.
    :param args: Parsed argument object.
    :param from_build_command: Boolean value tells is the command suppose
    to run the analyzer against a build command or a compilation db.
    :return: No return value, but this call might throw when validation
    fails. """

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif from_build_command and not args.build:
        parser.error(message='missing build command')
    elif not from_build_command and not os.path.exists(args.cdb):
        parser.error(message='compilation database is missing')
 # If the user wants CTU mode
    if not from_build_command and hasattr(args, 'ctu_phases') \
            and hasattr(args.ctu_phases, 'dir'):
        # If CTU analyze_only, the input directory should exist
        if args.ctu_phases.analyze and not args.ctu_phases.collect \
                and not os.path.exists(args.ctu_dir):
            parser.error(message='missing CTU directory')
        # Check CTU capability via checking clang-func-mapping
        if not is_ctu_capable(args.clang, args.func_map_cmd):
            parser.error(message="""This version of clang does not support CTU
            functionality or clang-func-mapping command not found.""")
コード例 #2
0
def analyze_validate(parser, args, from_build_command):
    """ Validation done by the parser itself, but semantic check still
    needs to be done. This method is doing it for analyze related commands."""

    # Make plugins always a list. (It might be None when not specified.)
    args.plugins = args.plugins if args.plugins else []
    # Make sure that these checks are bellow this ^
    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif from_build_command and not args.build:
        parser.error(message='missing build command')
    elif not from_build_command and not os.path.exists(args.cdb):
        parser.error(message='compilation database is missing')

    # Make exclude directory list unique and absolute
    uniq_excludes = set(os.path.abspath(entry) for entry in args.excludes)
    args.excludes = list(uniq_excludes)

    # because shared codes for all tools, some common used methods are
    # expecting some argument to be present. so, instead of query the args
    # object about the presence of the flag, we fake it here. to make those
    # methods more readable. (it's an arguable choice, took it only for those
    #  which have good default value.)
    if from_build_command:
        # add cdb parameter invisibly to make report module working
        args.cdb = 'compile_commands.json'
コード例 #3
0
def analyze_validate(parser, args, from_build_command):
    """ Validation done by the parser itself, but semantic check still
    needs to be done. This method is doing it for analyze related commands."""

    # Make plugins always a list. (It might be None when not specified.)
    args.plugins = args.plugins if args.plugins else []
    # Make sure that these checks are bellow this ^
    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif from_build_command and not args.build:
        parser.error(message='missing build command')
    elif not from_build_command and not os.path.exists(args.cdb):
        parser.error(message='compilation database is missing')

    # Make exclude directory list unique and absolute
    uniq_excludes = set(os.path.abspath(entry) for entry in args.excludes)
    args.excludes = list(uniq_excludes)

    # because shared codes for all tools, some common used methods are
    # expecting some argument to be present. so, instead of query the args
    # object about the presence of the flag, we fake it here. to make those
    # methods more readable. (it's an arguable choice, took it only for those
    #  which have good default value.)
    if from_build_command:
        # add cdb parameter invisibly to make report module working
        args.cdb = 'compile_commands.json'
コード例 #4
0
ファイル: arguments.py プロジェクト: LegalizeAdulthood/clang
def validate_args_for_analyze(parser, args, from_build_command):
    """ Command line parsing is done by the argparse module, but semantic
    validation still needs to be done. This method is doing it for
    analyze-build and scan-build commands.

    :param parser: The command line parser object.
    :param args: Parsed argument object.
    :param from_build_command: Boolean value tells is the command suppose
    to run the analyzer against a build command or a compilation db.
    :return: No return value, but this call might throw when validation
    fails. """

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif from_build_command and not args.build:
        parser.error(message='missing build command')
    elif not from_build_command and not os.path.exists(args.cdb):
        parser.error(message='compilation database is missing')

    # If the user wants CTU mode
    if not from_build_command and hasattr(args, 'ctu_phases') \
            and hasattr(args.ctu_phases, 'dir'):
        # If CTU analyze_only, the input directory should exist
        if args.ctu_phases.analyze and not args.ctu_phases.collect \
                and not os.path.exists(args.ctu_dir):
            parser.error(message='missing CTU directory')
        # Check CTU capability via checking clang-extdef-mapping
        if not is_ctu_capable(args.extdef_map_cmd):
            parser.error(message="""This version of clang does not support CTU
            functionality or clang-extdef-mapping command not found.""")
コード例 #5
0
def validate(parser, args, from_build_command):
    """ Validation done by the parser itself, but semantic check still
    needs to be done. This method is doing that. """

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()

    if from_build_command and not args.build:
        parser.error('missing build command')
コード例 #6
0
ファイル: analyze.py プロジェクト: AlexDenisov/clang
def validate(parser, args, from_build_command):
    """ Validation done by the parser itself, but semantic check still
    needs to be done. This method is doing that. """

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()

    if from_build_command and not args.build:
        parser.error('missing build command')
コード例 #7
0
ファイル: analyze.py プロジェクト: bmanga/clang
def validate(parser, args, from_build_command):
    """ Validation done by the parser itself, but semantic check still
    needs to be done. This method is doing that. """

    # Make plugins always a list. (It might be None when not specified.)
    args.plugins = args.plugins if args.plugins else []

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()

    if from_build_command and not args.build:
        parser.error('missing build command')
コード例 #8
0
def validate(parser, args, from_build_command):
    """ Validation done by the parser itself, but semantic check still
    needs to be done. This method is doing that. """

    # Make plugins always a list. (It might be None when not specified.)
    args.plugins = args.plugins if args.plugins else []

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()

    if from_build_command and not args.build:
        parser.error('missing build command')
コード例 #9
0
ファイル: test_clang.py プロジェクト: xikxp1/scan-build
 def test_get_checkers(self):
     # this test is only to see is not crashing
     result = sut.get_checkers('clang', [])
     self.assertTrue(result)
     # do check result types
     for key, value in result.items():
         self.assertTrue(isinstance(key, str))
         self.assertTrue(isinstance(value[0], str))
         self.assertTrue(isinstance(value[1], bool))
コード例 #10
0
ファイル: test_clang.py プロジェクト: rizsotto/scan-build
 def test_get_checkers(self):
     # this test is only to see is not crashing
     result = sut.get_checkers('clang', [])
     self.assertTrue(result)
     # do check result types
     for key, value in result.items():
         self.assertTrue(isinstance(key, str))
         self.assertTrue(isinstance(value[0], str))
         self.assertTrue(isinstance(value[1], bool))
コード例 #11
0
ファイル: test_clang.py プロジェクト: jaredmcneill/netbsd-src
 def test_get_checkers(self):
     # this test is only to see is not crashing
     result = sut.get_checkers('clang', [])
     self.assertTrue(len(result))
     # do check result types
     string_type = unicode if sys.version_info < (3,) else str
     for key, value in result.items():
         self.assertEqual(string_type, type(key))
         self.assertEqual(string_type, type(value[0]))
         self.assertEqual(bool, type(value[1]))
コード例 #12
0
 def test_get_checkers(self):
     # this test is only to see is not crashing
     result = sut.get_checkers('clang', [])
     self.assertTrue(len(result))
     # do check result types
     string_type = unicode if sys.version_info < (3, ) else str
     for key, value in result.items():
         self.assertEqual(string_type, type(key))
         self.assertEqual(string_type, type(value[0]))
         self.assertEqual(bool, type(value[1]))
コード例 #13
0
ファイル: interposition.py プロジェクト: blep/Beye
def parse_and_validate_arguments():
    """ Parse and validate command line arguments. """

    # create parser..
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    common_parameters(parser, False)
    analyze_parameters(parser)
    build_command(parser)
    # run it..
    args = parser.parse_args()
    # validate..
    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit()
    if not args.build:
        parser.error('missing build command')
    # return it..
    return args
コード例 #14
0
ファイル: arguments.py プロジェクト: typegrind/clang
def validate_args_for_analyze(parser, args, from_build_command):
    """ Command line parsing is done by the argparse module, but semantic
    validation still needs to be done. This method is doing it for
    analyze-build and scan-build commands.

    :param parser: The command line parser object.
    :param args: Parsed argument object.
    :param from_build_command: Boolean value tells is the command suppose
    to run the analyzer against a build command or a compilation db.
    :return: No return value, but this call might throw when validation
    fails. """

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif from_build_command and not args.build:
        parser.error(message='missing build command')
    elif not from_build_command and not os.path.exists(args.cdb):
        parser.error(message='compilation database is missing')
コード例 #15
0
ファイル: arguments.py プロジェクト: JaredCJR/clang
def validate_args_for_analyze(parser, args, from_build_command):
    """ Command line parsing is done by the argparse module, but semantic
    validation still needs to be done. This method is doing it for
    analyze-build and scan-build commands.

    :param parser: The command line parser object.
    :param args: Parsed argument object.
    :param from_build_command: Boolean value tells is the command suppose
    to run the analyzer against a build command or a compilation db.
    :return: No return value, but this call might throw when validation
    fails. """

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif from_build_command and not args.build:
        parser.error(message='missing build command')
    elif not from_build_command and not os.path.exists(args.cdb):
        parser.error(message='compilation database is missing')
コード例 #16
0
def validate_args_for_analyze(parser, args, from_build_command):
    # type: (argparse.ArgumentParser, argparse.Namespace, bool) -> None
    """ Command line parsing is done by the argparse module, but semantic
    validation still needs to be done. This method is doing it for
    analyze-build and scan-build commands.

    :param parser: The command line parser object.
    :param args: Parsed argument object.
    :param from_build_command: Boolean value tells is the command suppose
    to run the analyzer against a build command or a compilation db.
    :return: No return value, but this call might throw when validation
    fails. """

    if args.help_checkers_verbose:
        print_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif args.help_checkers:
        print_active_checkers(get_checkers(args.clang, args.plugins))
        parser.exit(status=0)
    elif from_build_command and not args.build:
        parser.error(message='missing build command')
    elif not from_build_command and not os.path.exists(args.cdb):
        parser.error(message='compilation database is missing')

    for x in args.prepend_compile_flags:
        if not os.path.exists(x):
            parser.error(
                message=
                'File {} does not exist but should be used to prepend to compile flags'
                .format(x))

    for x in args.append_compile_flags:
        if not os.path.exists(x):
            parser.error(
                message=
                'File {} does not exist but should be used to append to compile flags'
                .format(x))
コード例 #17
0
 def test_get_checkers(self):
     # this test is only to see is not crashing
     result = sut.get_checkers('clang', [])
     self.assertTrue(len(result))