gpt4 book ai didi

waf - 从 wscript 中的 waf 中删除一些主要命令和/或默认选项

转载 作者:行者123 更新时间:2023-12-03 09:04:06 27 4
gpt4 key购买 nike

我有一个添加了一些选项的 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')

这导致了很多我不支持的选项,但其他选项我想或必须支持。默认支持命令的完整列表如下所示。但是如何删除实际上不支持的选项,例如

  • 一些主要命令,例如 diststepinstall
  • 一些选项,例如--no-msvs-lazy
  • 一些配置选项,例如-t
  • 完全整个部分安装和卸载选项

选项的完整输出是:

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。您可以使用OptionParserremove_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 - 从 wscript 中的 waf 中删除一些主要命令和/或默认选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48464688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com