Re: [PATCH v3 14/14] perf kbuild: add generated Kconfig build-test cases

From: Ulf Magnusson
Date: Sun May 31 2015 - 15:22:26 EST


Hello, I'm the author of Kconfiglib.

I happened to notice this message just now. Might be a bit late, but I'll add
some comments anyway. :)

First of all, Kconfiglib now lives at https://github.com/ulfalizer/Kconfiglib,
just so that no one uses the old patch I sent to LKML a few years back.

Here's some comments on the script:

> +# Get all the symbols
> +symbols = dict([(s.get_name(), s) for s in ref_config.get_symbols()])
>
> +# Remove odd symbols
> +symbols.pop('y', None)
> +symbols.pop('m', None)
> +symbols.pop('n', None)

To avoid special symbols being included, you could use
get_symbols(all_symbols = False). That will also leave out symbols that are
referenced but never defined (e.g., 'depends on FOO' when there's no 'config
FOO' in the Kconfig files). That's safe here, as setting a user value on such
symbols won't have any effect anyway.

The shorthand 'for sym in ref_config:' for iterating over all symbols skips
special and undefined symbols too. get_symbols() was meant to be the
exceptional case where you really need to see all the symbols.

> +# Remove choice-related symbols
> +choices = ref_config.get_choices()
> +items = [c.get_items() for c in choices]
> +names = [i.get_name() for i in itertools.chain.from_iterable(items)]
> +for name in names:
> + symbols.pop(name, None)

You could use Symbol.is_choice_symbol() to filter out choice symbols. If you
want to be safe against the Kconfig oddity (bug?) that you can have symbols
inside choices that aren't considered choice symbols (see
_determine_actual_symbols()), then I think checking if Symbol.get_parent()
is_choice() instead would work.

Only drivers/usb/gadget/Kconfig seems to use that "feature" of Kconfig by the
way.

> +for name in symbols:
> + symbol = symbols[name]
> + if not symbol.is_modifiable():
> + continue
> + if symbol.get_value() != 'y':
> + continue
> + symbol.set_user_value('n')
> + filename = 'NO_' + name + '_config'
> + ref_config.write_config(filename)
> + symbol.set_user_value('y')

symbol.unset_user_value() instead of symbol.set_user_value('y') is another
option. Both ought to work here though.

I'm guessing it's okay, but this code also 'continue's if 'symbol' is 'm'.
Maybe modules aren't even used here.

Cheers,
Ulf
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/