示例#1
0
文件: kconfig.py 项目: restnek/zephyr
def main():
    parse_args()

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

    # Enable warnings for assignments to undefined symbols
    kconf.enable_undef_warnings()

    # 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.

    print("Using {} as base".format(args.conf_fragments[0]))
    for config in args.conf_fragments[1:]:
        print("Merging {}".format(config))
    # Create a merged configuration by loading the fragments with replace=False
    for config in args.conf_fragments:
        kconf.load_config(config, replace=False)

    # Write the merged configuration and the C header. This will evaluate all
    # symbols, which might generate additional warnings, so do it before
    # checking for warnings.
    kconf.write_config(args.dotconfig)
    kconf.write_autoconf(args.autoconf)

    # Print warnings for symbols whose actual value doesn't match the assigned
    # value
    for sym in kconf.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.choices:
        if choice.user_selection:
            verify_assigned_choice_value(choice)

    # 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:
        if enabled(warning):
            print(warning, file=sys.stderr)

    # Turn all warnings except for explicity 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("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]))
示例#2
0
#!/usr/bin/env python3
# Modified from: https://github.com/ulfalizer/Kconfiglib/blob/master/examples/merge_config.py
from kconfiglib import Kconfig, Symbol, BOOL, STRING, TRISTATE, TRI_TO_STR
import sys

if len(sys.argv) < 5:
    print('usage: {} Kconfig dotconfig autoconf conf1 [conf2 ...]'.format(
        sys.argv[0]))
    sys.exit(1)

print("Parsing Kconfig tree in {}".format(sys.argv[1]))
kconf = Kconfig(sys.argv[1])

# Enable warnings for assignments to undefined symbols
kconf.enable_undef_warnings()

# (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.)

print("Using {} as base".format(sys.argv[4]))
for config in sys.argv[5:]:
    print("Merging {}".format(config))
# Create a merged configuration by loading the fragments with replace=False
for config in sys.argv[4:]:
    kconf.load_config(config, replace=False)

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

# Output autoconf
示例#3
0
def main():
    parse_args()

    print("Parsing Kconfig tree in {}".format(args.kconfig_root))
    kconf = Kconfig(args.kconfig_root)

    # Enable warnings for assignments to undefined symbols
    kconf.enable_undef_warnings()

    # 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.

    print("Using {} as base".format(args.conf_fragments[0]))
    for config in args.conf_fragments[1:]:
        print("Merging {}".format(config))
    # Create a merged configuration by loading the fragments with replace=False
    for config in args.conf_fragments:
        kconf.load_config(config, replace=False)


    # Print warnings for symbols whose actual value doesn't match the assigned
    # value

    def name_and_loc(sym):
        # Helper for printing symbol names and Kconfig file location(s) in warnings

        if not sym.nodes:
            return sym.name + " (undefined)"

        return "{} (defined at {})".format(
            sym.name,
            ", ".join("{}:{}".format(node.filename, node.linenr)
                      for node in sym.nodes))

    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(
                          name_and_loc(sym), user_value, sym.str_value
                      ),
                      file=sys.stderr)


    # Turn the warning for malformed .config lines into an error
    for warning in kconf.warnings:
        if "ignoring malformed line" in warning:
            print("Aborting due to malformed configuration settings",
                  file=sys.stderr)
            sys.exit(1)


    # Write the merged configuration
    kconf.write_config(args.dotconfig)

    # Write the C header
    kconf.write_autoconf(args.autoconf)
示例#4
0
def main():
    parse_args()

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

    # Enable warnings for assignments to undefined symbols
    kconf.enable_undef_warnings()

    for i, config in enumerate(args.conf_fragments):
        print(
            ("Loading {} as base" if i == 0 else "Merging {}").format(config))
        # replace=False creates a merged configuration
        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)

    # 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:
        if enabled(warning):
            print("\n" + warning, file=sys.stderr)

    # Turn all warnings except for explicity 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
    kconf.write_config(args.dotconfig)
    kconf.write_autoconf(args.autoconf)
示例#5
0
#     # CONFIG_FOO is not set
#     CONFIG_BAR=y
#     CONFIG_BAZ="baz string"

import sys

from kconfiglib import Kconfig, BOOL, TRISTATE, TRI_TO_STR


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.enable_undef_warnings()

# (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.disable_override_warnings()
kconf.disable_redun_warnings()

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