def main(kconfig_file, config1, config2):

    kconf = Kconfig(kconfig_file, suppress_traceback=True)

    # Enable warnings for assignments to undefined symbols
    kconf.warn_assign_undef = False

    # (This script uses alldefconfig as the base. Other starting states could be
    # set up here as well. The approach in examples/allnoconfig_simpler.py could
    # provide an allnoconfig starting state for example.)

    # Disable warnings generated for multiple assignments to the same symbol within
    # a (set of) configuration files. Assigning a symbol multiple times might be
    # done intentionally when merging configuration files.
    kconf.warn_assign_override = False
    kconf.warn_assign_redun = False

    # Create a merged configuration by loading the fragments with replace=False.
    # load_config() and write_config() returns a message to print.
    print(kconf.load_config(config1, replace=False))
    print(kconf.load_config(config2, replace=False))

    # Modification for PX4 unset all symbols (INT,HEX etc) from 2nd config

    f = open(config2, 'r')

    unset_match = re.compile(r"# {}([^ ]+) is not set".format("CONFIG_"),
                             re.ASCII).match

    for line in f:
        match = unset_match(line)
        #pprint.pprint(match)
        if match is not None:
            sym_name = match.group(1)
            kconf.syms[sym_name].unset_value()
    f.close()

    # Print warnings for symbols whose actual value doesn't match the assigned
    # value
    for sym in kconf.defined_syms:
        # Was the symbol assigned to?
        if sym.user_value is not None:
            # Tristate values are represented as 0, 1, 2. Having them as
            # "n", "m", "y" is more convenient here, so convert.
            if sym.type in (BOOL, TRISTATE):
                user_value = TRI_TO_STR[sym.user_value]
            else:
                user_value = sym.user_value

            if user_value != sym.str_value:
                print("warning: {} was assigned the value '{}' but got the "
                      "value '{}' -- check dependencies".format(
                          sym.name_and_loc, user_value, sym.str_value),
                      file=sys.stderr)

    return kconf
예제 #2
0
파일: merge-config.py 프로젝트: nuta/resea
def main():
    parser = argparse.ArgumentParser(description="Merge .config files.")
    parser.add_argument("--outfile", required=True)
    parser.add_argument("config_files", nargs="+")
    args = parser.parse_args()

    config = Kconfig("Kconfig")
    config.warn_assign_override = False
    config.warn_assign_redun = False

    for config_file in args.config_files:
        config.load_config(config_file, replace=False)

    config.write_config(args.outfile)
예제 #3
0
if len(sys.argv) < 4:
    sys.exit("usage: merge_config.py Kconfig merged_config config1 [config2 ...]")

kconf = Kconfig(sys.argv[1])

# Enable warnings for assignments to undefined symbols
kconf.warn_assign_undef = True

# (This script uses alldefconfig as the base. Other starting states could be
# set up here as well. The approach in examples/allnoconfig_simpler.py could
# provide an allnoconfig starting state for example.)

# Disable warnings generated for multiple assignments to the same symbol within
# a (set of) configuration files. Assigning a symbol multiple times might be
# done intentionally when merging configuration files.
kconf.warn_assign_override = False
kconf.warn_assign_redun = False

# Create a merged configuration by loading the fragments with replace=False.
# load_config() and write_config() returns a message to print.
for config in sys.argv[3:]:
    print(kconf.load_config(config, replace=False))

# Write the merged configuration
print(kconf.write_config(sys.argv[2]))

# Print warnings for symbols whose actual value doesn't match the assigned
# value
for sym in kconf.defined_syms:
    # Was the symbol assigned to?
    if sym.user_value is not None:
예제 #4
0
def main():
    args = parse_args()

    print("Parsing " + args.kconfig_file)
    kconf = Kconfig(args.kconfig_file,
                    warn_to_stderr=False,
                    suppress_traceback=True)

    if args.handwritten_input_configs:
        # Warn for assignments to undefined symbols, but only for handwritten
        # fragments, to avoid warnings-turned-errors when using an old
        # configuration file together with updated Kconfig files
        kconf.warn_assign_undef = True

        # prj.conf may override settings from the board configuration, so
        # disable warnings about symbols being assigned more than once
        kconf.warn_assign_override = False
        kconf.warn_assign_redun = False

    # Load configuration files
    print(kconf.load_config(args.configs_in[0]))
    for config in args.configs_in[1:]:
        # replace=False creates a merged configuration
        print(kconf.load_config(config, replace=False))

    if args.handwritten_input_configs:
        # Check that there are no assignments to promptless symbols, which
        # have no effect.
        #
        # This only makes sense when loading handwritten fragments and not when
        # loading zephyr/.config, because zephyr/.config is configuration
        # output and also assigns promptless symbols.
        check_no_promptless_assign(kconf)

        # Print warnings for symbols that didn't get the assigned value. Only
        # do this for handwritten input too, to avoid likely unhelpful warnings
        # when using an old configuration and updating Kconfig files.
        check_assigned_sym_values(kconf)
        check_assigned_choice_values(kconf)

    # Hack: Force all symbols to be evaluated, to catch warnings generated
    # during evaluation. Wait till the end to write the actual output files, so
    # that we don't generate any output if there are warnings-turned-errors.
    #
    # Kconfiglib caches calculated symbol values internally, so this is still
    # fast.
    kconf.write_config(os.devnull)

    if kconf.warnings:
        # Put a blank line between warnings to make them easier to read
        for warning in kconf.warnings:
            print("\n" + warning, file=sys.stderr)

        # Turn all warnings into errors, so that e.g. assignments to undefined
        # Kconfig symbols become errors.
        #
        # A warning is generated by this script whenever a symbol gets a
        # different value than the one it was assigned. Keep that one as just a
        # warning for now.
        err("Aborting due to Kconfig warnings")

    # Write the merged configuration and the C header
    print(kconf.write_config(args.config_out))
    kconf.write_autoconf(args.header_out)

    # Write the list of parsed Kconfig files to a file
    write_kconfig_filenames(kconf, args.kconfig_list_out)
예제 #5
0
파일: kconfig.py 프로젝트: wuruoyu/zephyr
def main():
    args = parse_args()

    print("Parsing " + args.kconfig_file)
    kconf = Kconfig(args.kconfig_file, warn_to_stderr=False,
                    suppress_traceback=True)

    if args.handwritten_input_configs:
        # Warn for assignments to undefined symbols, but only for handwritten
        # fragments, to avoid warnings-turned-errors when using an old
        # configuration file together with updated Kconfig files
        kconf.warn_assign_undef = True

        # prj.conf may override settings from the board configuration, so
        # disable warnings about symbols being assigned more than once
        kconf.warn_assign_override = False
        kconf.warn_assign_redun = False

    # Load configuration files
    print(kconf.load_config(args.configs_in[0]))
    for config in args.configs_in[1:]:
        # replace=False creates a merged configuration
        print(kconf.load_config(config, replace=False))

    if args.handwritten_input_configs:
        # Check that there are no assignments to promptless symbols, which
        # have no effect.
        #
        # This only makes sense when loading handwritten fragments and not when
        # loading zephyr/.config, because zephyr/.config is configuration
        # output and also assigns promptless symbols.
        check_no_promptless_assign(kconf)

        # Print warnings for symbols that didn't get the assigned value. Only
        # do this for handwritten input too, to avoid likely unhelpful warnings
        # when using an old configuration and updating Kconfig files.
        check_assigned_sym_values(kconf)
        check_assigned_choice_values(kconf)

    # Hack: Force all symbols to be evaluated, to catch warnings generated
    # during evaluation. Wait till the end to write the actual output files, so
    # that we don't generate any output if there are warnings-turned-errors.
    #
    # Kconfiglib caches calculated symbol values internally, so this is still
    # fast.
    kconf.write_config(os.devnull)

    # Print warnings ourselves so that we can put a blank line between them for
    # readability. We could roll this into the loop below, but it's nice to
    # always print all warnings, even if one of them turns out to be fatal.
    for warning in kconf.warnings:
        print("\n" + warning, file=sys.stderr)

    # Turn all warnings except for explicitly whitelisted ones into errors. In
    # particular, this will turn assignments to undefined Kconfig variables
    # into errors.
    #
    # A warning is generated by this script whenever a symbol gets a different
    # value than the one it was assigned. Keep that one as just a warning for
    # now as well.
    for warning in kconf.warnings:
        if fatal(warning):
            err(f"""\
Aborting due to non-whitelisted Kconfig warning '{warning}'. If this warning
doesn't point to an actual problem, you can add it to the whitelist at the top
of {sys.argv[0]}.""")

    # Write the merged configuration and the C header
    print(kconf.write_config(args.config_out))
    kconf.write_autoconf(args.header_out)

    # Write the list of parsed Kconfig files to a file
    write_kconfig_filenames(kconf, args.kconfig_list_out)
예제 #6
0
def main():
    args = parse_args()

    print("Parsing Kconfig tree in " + args.kconfig_root)
    kconf = Kconfig(args.kconfig_root, warn_to_stderr=False)

    # Warn for assignments to undefined symbols
    kconf.warn_assign_undef = True

    # prj.conf may override settings from the board configuration, so disable
    # warnings about symbols being assigned more than once
    kconf.warn_assign_override = False
    kconf.warn_assign_redun = False

    print(kconf.load_config(args.conf_fragments[0]))
    for config in args.conf_fragments[1:]:
        # replace=False creates a merged configuration
        print(kconf.load_config(config, replace=False))

    # Print warnings for symbols whose actual value doesn't match the assigned
    # value
    for sym in kconf.unique_defined_syms:
        # Was the symbol assigned to? Choice symbols are checked separately.
        if sym.user_value is not None and not sym.choice:
            verify_assigned_sym_value(sym)

    # Print warnings for choices whose actual selection doesn't match the user
    # selection
    for choice in kconf.unique_choices:
        if choice.user_selection:
            verify_assigned_choice_value(choice)

    # Hack: Force all symbols to be evaluated, to catch warnings generated
    # during evaluation. Wait till the end to write the actual output files, so
    # that we don't generate any output if there are warnings-turned-errors.
    #
    # Kconfiglib caches calculated symbol values internally, so this is still
    # fast.
    kconf.write_config(os.devnull)

    # Print warnings ourselves so that we can put a blank line between them for
    # readability. We could roll this into the loop below, but it's nice to
    # always print all warnings, even if one of them turns out to be fatal.
    for warning in kconf.warnings:
        print("\n" + warning, file=sys.stderr)

    # Turn all warnings except for explicitly whitelisted ones into errors. In
    # particular, this will turn assignments to undefined Kconfig variables
    # into errors.
    #
    # A warning is generated by this script whenever a symbol gets a different
    # value than the one it was assigned. Keep that one as just a warning for
    # now as well.
    for warning in kconf.warnings:
        if fatal(warning):
            sys.exit("\n" + textwrap.fill(
                "Error: Aborting due to non-whitelisted Kconfig "
                "warning '{}'.\nNote: If this warning doesn't point "
                "to an actual problem, you can add it to the "
                "whitelist at the top of {}.".format(warning, sys.argv[0]),
                100) + "\n")

    # Write the merged configuration and the C header
    print(kconf.write_config(args.dotconfig))
    kconf.write_autoconf(args.autoconf)

    # Write the list of processed Kconfig sources to a file
    write_kconfig_filenames(kconf.kconfig_filenames, kconf.srctree,
                            args.sources)