Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用--menu配置的选项会覆盖option:after_check中的脚本设置选项的结果 #5037

Open
xlf605401969 opened this issue Apr 30, 2024 · 7 comments
Labels

Comments

@xlf605401969
Copy link

Xmake 版本

xmake v2.9.1+HEAD.0c79f6162

操作系统版本和架构

Windows10 1809

描述问题

我想要通过选项依赖来控制编译的行为,例如有以下三个option

option A
   - option B
   - option C

A可以单独设置为true,但B或C设置为true的时候,A必须设置为true,尝试的解决方案是另A依赖于B和C,当B或C为ture时,将A设置为true

参照文档,我尝试在option:after_check中使能开关选项,
以下为xmake.lua脚本:

option("B")
    set_default(false)
    set_showmenu(true)

option("C")
    set_default(false)
    set_showmenu(true)

option("A")
    set_default(false)
    set_showmenu(true)
    add_deps("B","C")
    after_check(function (option)
        if option:dep("B"):enabled() or option:dep("C"):enabled() then
            option:enable(true)
        end
    end)

target("test_target")
    add_options("A", "B", "C")
    before_build(function (target)
        import("core.project.project")
        for optionname, option in pairs(project.options()) do 
            print(optionname, option:enabled())
        end
    end)

单独将B设置为true,输出符合预期,A选项被设置为了false:

(base) PS E:\XXX> xmake f --B=y
(base) PS E:\XXX> xmake b test_target
A true
B true
C false
[ 66%]: linking.release test_target.exe

如果在xmake f --menu中选择了B但未选择A,输出结果则为

(base) PS E:\XXX> xmake f --menu
checking for Microsoft Visual Studio (x64) version ... 2022
(base) PS E:\XXX> xmake b test_target
A false
C false
B true
[ 66%]: linking.release test_target.exe

脚本中对于A的设置并未生效

或者有没有办法在--menu的配置中就展示这个依赖关系,即选择了选项A才能够选择B和C?还是这种情况下只应该提示一个错误?

期待的结果

在after_check中脚本配置的选项能够修改命令或--menu配置时的指定项

工程配置

已附在问题描述中

附加信息和错误日志

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: The options configured using --menu will override the results of the script setting options in option:after_check

@waruqi
Copy link
Member

waruqi commented Apr 30, 2024

目前 option 依赖联动,在 --menu 中不支持。。也不太好实现,,after_check 是后期检测中触发的,那个时候 menu 都退出了,展示过程中 xmake 是解析不到这个依赖状态关系的

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Currently option relies on linkage and is not supported in --menu. .

@xlf605401969
Copy link
Author

好的,那我看看别的解决方案,不过我有些困惑的是after_check中脚本配置的项好像没办法覆盖menu中指定的选项或者命令行中指定的选项?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Okay, then I'll look at other solutions, but what I'm a little confused about is that the items configured in the script in after_check don't seem to be able to override the options specified in the menu or the options specified in the command line?

@waruqi
Copy link
Member

waruqi commented May 10, 2024

用户命令行设置的选项值,优先级最高,内部会标记成 readonly 。。脚本内默认是覆盖不了的,你要强行覆盖,只能在设置时候,加上 {force = true}

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The option value set by the user command line has the highest priority and will be marked as readonly internally. . It cannot be overridden by default in the script. If you want to force override, you can only add {force = true} when setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants