コード例 #1
0
    def test_evaluate_shell_command(self):
        if sysutil.unversioned_platform() != 'linux':
            # This test runs shell commands, so only run it on Linux for now.
            pass

        opts_string = """
!! unix- _ K1 = a \\"`echo 123`\\" b
!! unix- _ K2 = $(shell echo 123)
!! unix- _ K3 = $(subst 1,,$(K2))
        """
        opts_file = StringIO(opts_string)
        parser = optionsparser.OptionsParser(opts_file)
        parser.parse()

        ev = optionsevaluator.OptionsEvaluator(
            optiontypes.Uplid.from_str('unix-linux-x86-3.2.0-gcc-4.7.2'),
            optiontypes.Ufid.from_str('dbg_mt_exc'))

        # ev.store_option_rules(parser.option_rules, ['K1', 'K2'])
        # ev.evaluate(['K1', 'K2'])
        ev.store_option_rules(parser.option_rules)
        ev.evaluate()

        expected_results = {
            'K1': 'a "123" b',
            'K2': '123',
        }
        self.assertEqual(ev.results, expected_results)
コード例 #2
0
    def setUp(self):
        repos_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'repos')
        self.repo_root = os.path.join(repos_path, 'one')

        self.cap_repo_root = os.path.join(repos_path, 'two')

        self.flags_parser = buildflagsparser.BuildFlagsParser(
            '-Wl,-Bdynamic', '-Wl,-Bstatic', '-l([^ =]+)', '-L([^ =]+)',
            '-I([^ =]+)', '-D')

        default_rules_path = os.path.join(repos_path, 'repo_test_def.opts')
        with open(default_rules_path) as f:
            parser = optionsparser.OptionsParser(f)
            parser.parse()
            self.default_rules = parser.option_rules
コード例 #3
0
    def test_parse(self):
        parser = optionsparser.OptionsParser(self.opts_file)
        parser.parse()

        lines = self.opts_string.split('\n')
        exp_option_rules = []
        exp_all_lines = []
        for val in self.expected_vals:
            pos = val[0]
            rule = optiontypes.OptionRule(*val[1])
            exp_option_rules.append(rule)
            while len(exp_all_lines) < pos:
                exp_all_lines.append((lines[len(exp_all_lines)], None))
            exp_all_lines.append((lines[len(exp_all_lines)], rule))

        exp_all_lines.append(('', None))

        self.assertEqual(exp_option_rules, parser.option_rules)
        self.assertEqual(exp_all_lines, parser.all_lines)
コード例 #4
0
    def test_evaluate(self):
        opts_string = """
!! unix- _   K1 = V1
!! unix- dbg K2 = V2 $(K1)
unix- dbg K2 = V3
!! unix- opt K2 = V4
++ unix- _ K1 = V5
>> unix- _ K1 = V6
<< unix- _ K1 = V7
-- unix- _ K1 = V8
!! unix- _ XLC_INTERNAL_PREFIX1 = IGNORED
!! unix- _ BDE_COMPILER_FLAG = gcc
!! windows- _ BDE_COMPILER_FLAG = msvc
!! unix-*-*-*-def _ K3 = DEF_MATCH
!! unix-*-*-*-clang _ K4 = DEF_MATCH
!! unix- _ K5 =
++ unix- _ K5 = K5_VAL
        """
        opts_file = StringIO(opts_string)
        parser = optionsparser.OptionsParser(opts_file)
        parser.parse()

        ev = optionsevaluator.OptionsEvaluator(
            optiontypes.Uplid.from_str('unix-linux-x86-3.2.0-gcc-4.7.2'),
            optiontypes.Ufid.from_str('dbg_mt_exc'))

        # ev.store_option_rules(parser.option_rules, ['K1', 'K2'])
        # ev.evaluate(['K1', 'K2'])
        ev.store_option_rules(parser.option_rules)
        ev.evaluate()

        expected_results = {
            'K1': 'V8 V7V1 V5V6',
            'K2': 'V2 V8 V7V1 V5V6 V3',
            'K3': 'DEF_MATCH',
            'K5': 'K5_VAL',
            'BDE_COMPILER_FLAG': 'gcc'
        }
        self.assertEqual(ev.results, expected_results)
コード例 #5
0
ファイル: bde_optsformat.py プロジェクト: wcorrea/bde-tools
if __name__ == "__main__":
    usage = \
        """Usage: cat <opts_file> | bde_opts_format.py

Format the text from stdin in the options file format, which is used by opts
and defs meta-data files, and print the result to stdout.

The formatter aligns each section of the option rules using two spaces as
padding. Comments and blank lines will be left in-place unmodified.
"""

    if len(sys.argv) > 1:
        print(usage, file=sys.stderr)
        sys.exit(1)

    parser = optionsparser.OptionsParser(sys.stdin)
    parser.parse()

    max_field_widths = [2, 0, 0, 0]
    option_field_index = {
        'command': (0, optiontypes.OptionCommand.to_str),
        'uplid': (1, str),
        'ufid': (2, str),
        'key': (3, str),
    }

    for rule in parser.option_rules:
        for name in option_field_index:
            attr = getattr(rule, name)
            index = option_field_index[name][0]
            func = option_field_index[name][1]
コード例 #6
0
 def _parse_opts_str(self, str_):
     opts_file = StringIO(str_)
     parser = optionsparser.OptionsParser(opts_file)
     parser.parse()
     return parser.option_rules