从 wscript 中的 waf 中删除一些主要命令 and/or 默认选项
Remove some main commands and/or default options from waf in wscript
我有一个添加了一些选项的 waf 脚本,因此我使用 waflib
.
中的 Options
一个最小的工作示例是:
from waflib import Context, Options
from waflib.Tools.compiler_c import c_compiler
def options(opt):
opt.load('compiler_c')
def configure(cnf):
cnf.load('compiler_c')
cnf.env.abc = 'def'
def build(bld):
print('hello')
这导致很多选项我不支持,但其他选项我愿意或必须支持。默认支持命令的完整列表如下所示。但是如何删除实际上不支持的选项,如
- 一些主要命令,例如
dist
、step
和 install
或
- 一些选项,例如
--no-msvs-lazy
或
- 一些配置选项,例如
-t
或
- 完全整段
Installation and uninstallation options
选项的完整输出是:
waf [commands] [options]
Main commands (example: ./waf build -j4)
build : executes the build
clean : cleans the project
configure: configures the project
dist : makes a tarball for redistributing the sources
distcheck: checks if the project compiles (tarball from 'dist')
distclean: removes build folders and data
install : installs the targets on the system
list : lists the targets to execute
step : executes tasks in a step-by-step fashion, for debugging
uninstall: removes the targets installed
Options:
--version show program's version number and exit
-c COLORS, --color=COLORS
whether to use colors (yes/no/auto) [default: auto]
-j JOBS, --jobs=JOBS amount of parallel jobs (8)
-k, --keep continue despite errors (-kk to try harder)
-v, --verbose verbosity level -v -vv or -vvv [default: 0]
--zones=ZONES debugging zones (task_gen, deps, tasks, etc)
-h, --help show this help message and exit
--msvc_version=MSVC_VERSION
msvc version, eg: "msvc 10.0,msvc 9.0"
--msvc_targets=MSVC_TARGETS
msvc targets, eg: "x64,arm"
--no-msvc-lazy lazily check msvc target environments
Configuration options:
-o OUT, --out=OUT build dir for the project
-t TOP, --top=TOP src dir for the project
--prefix=PREFIX installation prefix [default: 'C:\users\user\appdata\local\temp']
--bindir=BINDIR bindir
--libdir=LIBDIR libdir
--check-c-compiler=CHECK_C_COMPILER
list of C compilers to try [msvc gcc clang]
Build and installation options:
-p, --progress -p: progress bar; -pp: ide output
--targets=TARGETS task generators, e.g. "target1,target2"
Step options:
--files=FILES files to process, by regexp, e.g. "*/main.c,*/test/main.o"
Installation and uninstallation options:
--destdir=DESTDIR installation root [default: '']
-f, --force force file installation
--distcheck-args=ARGS
arguments to pass to distcheck
对于选项,选项上下文有一个 parser
属性,它是一个 python optparse.OptionParser
。可以使用OptionParser
的remove_option
方法:
def options(opt):
opt.parser.remove_option("--top")
opt.parser.remove_option("--no-msvs-lazy")
对于命令,waf中有一个元类会自动注册Context 类(参见waflib.Context sources)。
所以所有Context
类都存储在全局变量waflib.Context.classes
中。要摆脱它们,您可以操纵此变量。例如,要摆脱 StepContext
等,您可以执行以下操作:
import waflib
def options(opt):
all_contexts = waflib.Context.classes
all_contexts.remove(waflib.Build.StepContext)
all_contexts.remove(waflib.Build.InstallContext)
all_contexts.remove(waflib.Build.UninstallContext)
命令 dist/distcheck
是 waflib.Scripting
中定义的特殊情况。摆脱它们并不容易。
我有一个添加了一些选项的 waf 脚本,因此我使用 waflib
.
Options
一个最小的工作示例是:
from waflib import Context, Options
from waflib.Tools.compiler_c import c_compiler
def options(opt):
opt.load('compiler_c')
def configure(cnf):
cnf.load('compiler_c')
cnf.env.abc = 'def'
def build(bld):
print('hello')
这导致很多选项我不支持,但其他选项我愿意或必须支持。默认支持命令的完整列表如下所示。但是如何删除实际上不支持的选项,如
- 一些主要命令,例如
dist
、step
和install
或 - 一些选项,例如
--no-msvs-lazy
或 - 一些配置选项,例如
-t
或 - 完全整段
Installation and uninstallation options
选项的完整输出是:
waf [commands] [options]
Main commands (example: ./waf build -j4)
build : executes the build
clean : cleans the project
configure: configures the project
dist : makes a tarball for redistributing the sources
distcheck: checks if the project compiles (tarball from 'dist')
distclean: removes build folders and data
install : installs the targets on the system
list : lists the targets to execute
step : executes tasks in a step-by-step fashion, for debugging
uninstall: removes the targets installed
Options:
--version show program's version number and exit
-c COLORS, --color=COLORS
whether to use colors (yes/no/auto) [default: auto]
-j JOBS, --jobs=JOBS amount of parallel jobs (8)
-k, --keep continue despite errors (-kk to try harder)
-v, --verbose verbosity level -v -vv or -vvv [default: 0]
--zones=ZONES debugging zones (task_gen, deps, tasks, etc)
-h, --help show this help message and exit
--msvc_version=MSVC_VERSION
msvc version, eg: "msvc 10.0,msvc 9.0"
--msvc_targets=MSVC_TARGETS
msvc targets, eg: "x64,arm"
--no-msvc-lazy lazily check msvc target environments
Configuration options:
-o OUT, --out=OUT build dir for the project
-t TOP, --top=TOP src dir for the project
--prefix=PREFIX installation prefix [default: 'C:\users\user\appdata\local\temp']
--bindir=BINDIR bindir
--libdir=LIBDIR libdir
--check-c-compiler=CHECK_C_COMPILER
list of C compilers to try [msvc gcc clang]
Build and installation options:
-p, --progress -p: progress bar; -pp: ide output
--targets=TARGETS task generators, e.g. "target1,target2"
Step options:
--files=FILES files to process, by regexp, e.g. "*/main.c,*/test/main.o"
Installation and uninstallation options:
--destdir=DESTDIR installation root [default: '']
-f, --force force file installation
--distcheck-args=ARGS
arguments to pass to distcheck
对于选项,选项上下文有一个 parser
属性,它是一个 python optparse.OptionParser
。可以使用OptionParser
的remove_option
方法:
def options(opt):
opt.parser.remove_option("--top")
opt.parser.remove_option("--no-msvs-lazy")
对于命令,waf中有一个元类会自动注册Context 类(参见waflib.Context sources)。
所以所有Context
类都存储在全局变量waflib.Context.classes
中。要摆脱它们,您可以操纵此变量。例如,要摆脱 StepContext
等,您可以执行以下操作:
import waflib
def options(opt):
all_contexts = waflib.Context.classes
all_contexts.remove(waflib.Build.StepContext)
all_contexts.remove(waflib.Build.InstallContext)
all_contexts.remove(waflib.Build.UninstallContext)
命令 dist/distcheck
是 waflib.Scripting
中定义的特殊情况。摆脱它们并不容易。