forked from RT-Thread/rt-thread
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
将windows和linux下的scons --menuconfig/--pyconfig/--pyconfig-silent统一为pyt…
…hon版本kconfiglib,同时兼容windows env中menuconfig.exe
- Loading branch information
1 parent
22106bb
commit 4cc8e1e
Showing
27 changed files
with
8,793 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.py[co] | ||
build/ | ||
*.egg-info/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Copyright (c) 2011-2019, Ulf Magnusson <[email protected]> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Include the license file in source distributions | ||
include LICENSE.txt |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2018-2019, Ulf Magnusson | ||
# SPDX-License-Identifier: ISC | ||
|
||
""" | ||
Writes a configuration file where all symbols are set to their their default | ||
values. | ||
The default output filename is '.config'. A different filename can be passed in | ||
the KCONFIG_CONFIG environment variable. | ||
Usage for the Linux kernel: | ||
$ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/alldefconfig.py | ||
""" | ||
import kconfiglib | ||
|
||
|
||
def main(): | ||
kconf = kconfiglib.standard_kconfig(__doc__) | ||
kconf.load_allconfig("alldef.config") | ||
print(kconf.write_config()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2018-2019, Ulf Magnusson | ||
# SPDX-License-Identifier: ISC | ||
|
||
""" | ||
Writes a configuration file where as many symbols as possible are set to 'm'. | ||
The default output filename is '.config'. A different filename can be passed | ||
in the KCONFIG_CONFIG environment variable. | ||
Usage for the Linux kernel: | ||
$ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allmodconfig.py | ||
""" | ||
import kconfiglib | ||
|
||
|
||
def main(): | ||
kconf = kconfiglib.standard_kconfig(__doc__) | ||
|
||
# See allnoconfig.py | ||
kconf.warn = False | ||
|
||
for sym in kconf.unique_defined_syms: | ||
if sym.orig_type == kconfiglib.BOOL: | ||
# 'bool' choice symbols get their default value, as determined by | ||
# e.g. 'default's on the choice | ||
if not sym.choice: | ||
# All other bool symbols get set to 'y', like for allyesconfig | ||
sym.set_value(2) | ||
elif sym.orig_type == kconfiglib.TRISTATE: | ||
sym.set_value(1) | ||
|
||
for choice in kconf.unique_choices: | ||
choice.set_value(2 if choice.orig_type == kconfiglib.BOOL else 1) | ||
|
||
kconf.warn = True | ||
|
||
kconf.load_allconfig("allmod.config") | ||
|
||
print(kconf.write_config()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2018-2019, Ulf Magnusson | ||
# SPDX-License-Identifier: ISC | ||
|
||
""" | ||
Writes a configuration file where as many symbols as possible are set to 'n'. | ||
The default output filename is '.config'. A different filename can be passed | ||
in the KCONFIG_CONFIG environment variable. | ||
Usage for the Linux kernel: | ||
$ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allnoconfig.py | ||
""" | ||
|
||
# See examples/allnoconfig_walk.py for another way to implement this script | ||
|
||
import kconfiglib | ||
|
||
|
||
def main(): | ||
kconf = kconfiglib.standard_kconfig(__doc__) | ||
|
||
# Avoid warnings that would otherwise get printed by Kconfiglib for the | ||
# following: | ||
# | ||
# 1. Assigning a value to a symbol without a prompt, which never has any | ||
# effect | ||
# | ||
# 2. Assigning values invalid for the type (only bool/tristate symbols | ||
# accept 0/1/2, for n/m/y). The assignments will be ignored for other | ||
# symbol types, which is what we want. | ||
kconf.warn = False | ||
for sym in kconf.unique_defined_syms: | ||
sym.set_value(2 if sym.is_allnoconfig_y else 0) | ||
kconf.warn = True | ||
|
||
kconf.load_allconfig("allno.config") | ||
|
||
print(kconf.write_config()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2018-2019, Ulf Magnusson | ||
# SPDX-License-Identifier: ISC | ||
|
||
""" | ||
Writes a configuration file where as many symbols as possible are set to 'y'. | ||
The default output filename is '.config'. A different filename can be passed | ||
in the KCONFIG_CONFIG environment variable. | ||
Usage for the Linux kernel: | ||
$ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allyesconfig.py | ||
""" | ||
import kconfiglib | ||
|
||
|
||
def main(): | ||
kconf = kconfiglib.standard_kconfig(__doc__) | ||
|
||
# See allnoconfig.py | ||
kconf.warn = False | ||
|
||
# Try to set all symbols to 'y'. Dependencies might truncate the value down | ||
# later, but this will at least give the highest possible value. | ||
# | ||
# Assigning 0/1/2 to non-bool/tristate symbols has no effect (int/hex | ||
# symbols still take a string, because they preserve formatting). | ||
for sym in kconf.unique_defined_syms: | ||
# Set choice symbols to 'm'. This value will be ignored for choices in | ||
# 'y' mode (the "normal" mode), which will instead just get their | ||
# default selection, but will set all symbols in m-mode choices to 'm', | ||
# which is as high as they can go. | ||
# | ||
# Here's a convoluted example of how you might get an m-mode choice | ||
# even during allyesconfig: | ||
# | ||
# choice | ||
# tristate "weird choice" | ||
# depends on m | ||
sym.set_value(1 if sym.choice else 2) | ||
|
||
# Set all choices to the highest possible mode | ||
for choice in kconf.unique_choices: | ||
choice.set_value(2) | ||
|
||
kconf.warn = True | ||
|
||
kconf.load_allconfig("allyes.config") | ||
|
||
print(kconf.write_config()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2018-2019, Ulf Magnusson | ||
# SPDX-License-Identifier: ISC | ||
|
||
""" | ||
Generates a header file with #defines from the configuration, matching the | ||
format of include/generated/autoconf.h in the Linux kernel. | ||
Optionally, also writes the configuration output as a .config file. See | ||
--config-out. | ||
The --sync-deps, --file-list, and --env-list options generate information that | ||
can be used to avoid needless rebuilds/reconfigurations. | ||
Before writing a header or configuration file, Kconfiglib compares the old | ||
contents of the file against the new contents. If there's no change, the write | ||
is skipped. This avoids updating file metadata like the modification time, and | ||
might save work depending on your build setup. | ||
By default, the configuration is generated from '.config'. A different | ||
configuration file can be passed in the KCONFIG_CONFIG environment variable. | ||
A custom header string can be inserted at the beginning of generated | ||
configuration and header files by setting the KCONFIG_CONFIG_HEADER and | ||
KCONFIG_AUTOHEADER_HEADER environment variables, respectively (this also works | ||
for other scripts). The string is not automatically made a comment (this is by | ||
design, to allow anything to be added), and no trailing newline is added, so | ||
add '/* */', '#', and newlines as appropriate. | ||
See https://www.gnu.org/software/make/manual/make.html#Multi_002dLine for a | ||
handy way to define multi-line variables in makefiles, for use with custom | ||
headers. Remember to export the variable to the environment. | ||
""" | ||
import argparse | ||
import os | ||
import sys | ||
|
||
import kconfiglib | ||
|
||
|
||
DEFAULT_SYNC_DEPS_PATH = "deps/" | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description=__doc__) | ||
|
||
parser.add_argument( | ||
"--header-path", | ||
metavar="HEADER_FILE", | ||
help=""" | ||
Path to write the generated header file to. If not specified, the path in the | ||
environment variable KCONFIG_AUTOHEADER is used if it is set, and 'config.h' | ||
otherwise. | ||
""") | ||
|
||
parser.add_argument( | ||
"--config-out", | ||
metavar="CONFIG_FILE", | ||
help=""" | ||
Write the configuration to CONFIG_FILE. This is useful if you include .config | ||
files in Makefiles, as the generated configuration file will be a full .config | ||
file even if .config is outdated. The generated configuration matches what | ||
olddefconfig would produce. If you use sync-deps, you can include | ||
deps/auto.conf instead. --config-out is meant for cases where incremental build | ||
information isn't needed. | ||
""") | ||
|
||
parser.add_argument( | ||
"--sync-deps", | ||
metavar="OUTPUT_DIR", | ||
nargs="?", | ||
const=DEFAULT_SYNC_DEPS_PATH, | ||
help=""" | ||
Enable generation of symbol dependency information for incremental builds, | ||
optionally specifying the output directory (default: {}). See the docstring of | ||
Kconfig.sync_deps() in Kconfiglib for more information. | ||
""".format(DEFAULT_SYNC_DEPS_PATH)) | ||
|
||
parser.add_argument( | ||
"--file-list", | ||
metavar="OUTPUT_FILE", | ||
help=""" | ||
Write a list of all Kconfig files to OUTPUT_FILE, with one file per line. The | ||
paths are relative to $srctree (or to the current directory if $srctree is | ||
unset). Files appear in the order they're 'source'd. | ||
""") | ||
|
||
parser.add_argument( | ||
"--env-list", | ||
metavar="OUTPUT_FILE", | ||
help=""" | ||
Write a list of all environment variables referenced in Kconfig files to | ||
OUTPUT_FILE, with one variable per line. Each line has the format NAME=VALUE. | ||
Only environment variables referenced with the preprocessor $(VAR) syntax are | ||
included, and not variables referenced with the older $VAR syntax (which is | ||
only supported for backwards compatibility). | ||
""") | ||
|
||
parser.add_argument( | ||
"kconfig", | ||
metavar="KCONFIG", | ||
nargs="?", | ||
default="Kconfig", | ||
help="Top-level Kconfig file (default: Kconfig)") | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
kconf = kconfiglib.Kconfig(args.kconfig, suppress_traceback=True) | ||
kconf.load_config() | ||
|
||
if args.header_path is None: | ||
if "KCONFIG_AUTOHEADER" in os.environ: | ||
kconf.write_autoconf() | ||
else: | ||
# Kconfiglib defaults to include/generated/autoconf.h to be | ||
# compatible with the C tools. 'config.h' is used here instead for | ||
# backwards compatibility. It's probably a saner default for tools | ||
# as well. | ||
kconf.write_autoconf("config.h") | ||
else: | ||
kconf.write_autoconf(args.header_path) | ||
|
||
if args.config_out is not None: | ||
kconf.write_config(args.config_out, save_old=False) | ||
|
||
if args.sync_deps is not None: | ||
kconf.sync_deps(args.sync_deps) | ||
|
||
if args.file_list is not None: | ||
with _open_write(args.file_list) as f: | ||
for path in kconf.kconfig_filenames: | ||
f.write(path + "\n") | ||
|
||
if args.env_list is not None: | ||
with _open_write(args.env_list) as f: | ||
for env_var in kconf.env_vars: | ||
f.write("{}={}\n".format(env_var, os.environ[env_var])) | ||
|
||
|
||
def _open_write(path): | ||
# Python 2/3 compatibility. io.open() is available on both, but makes | ||
# write() expect 'unicode' strings on Python 2. | ||
|
||
if sys.version_info[0] < 3: | ||
return open(path, "w") | ||
return open(path, "w", encoding="utf-8") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.