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

xrepo install指定--includes时找不到文件 #6048

Closed
24bit-xjkp opened this issue Jan 6, 2025 · 11 comments
Closed

xrepo install指定--includes时找不到文件 #6048

24bit-xjkp opened this issue Jan 6, 2025 · 11 comments
Labels

Comments

@24bit-xjkp
Copy link
Contributor

Xmake 版本

xmake v2.9.7+HEAD.2bb99e0c3

操作系统版本和架构

Windows 11 24H2

描述问题

首先,在source.lua中定义一些表供后续使用:

-- source.lua
toolchain_list = {"myclang", "mygcc"}

然后在toolchain.lua中定义一些工具链:

-- toolchain.lua
includes("source.lua")
for _,v in ipairs(toolchain_list) do
    toolchain(v)
        on_check(function(toolchain)
            return true
        end)

        on_load(function(toolchain) end)
end

此时通过xmake.lua包含toolchain.lua加载工具链定义:

-- xmake.lua
includes("toolchain.lua")

运行xmake show -l toolchains可以正常得到工具链:

......
zig              Zig Programming Language Compiler
myclang
mygcc

但如果运行命令xrepo install --toolchain=myclang --includes="toolchain.lua" benchmark,这时toolchain.lua并没有被加载,因为xrepo在一个临时目录下执行xmake,而它会基于临时目录寻找toolchain.lua。将toolchain.lua改用绝对路径则会得到如下结果:

......
error: the toolchain myclang not found!
warning: includes("source.lua") cannot find any files!

因为通过XMAKE_RCFILES加载的脚本没有用includes函数的逻辑,此时不是基于toolchain.lua所在目录,而是基于临时目录查找source.lua。如果将includes("source.lua")也改为使用绝对路径则能正常工作,但这会导致脚本发布困难。

期待的结果

  1. 可以让XMAKE_RCFILES中的脚本使用includes逻辑,将工作目录切换到脚本所在目录后再执行脚本内容
  2. 可以提供一个类似import函数的rootdir参数,传递{rootdir="."}以强制基于当前文件所在路径搜索脚本
  3. 可以提供一种获取当前脚本所在目录绝对路径的api以便得到子脚本的绝对路径

工程配置

test.zip

附加信息和错误日志

toolchain.lua的最后添加print("Hello")语句后得到得到如下日志:

  1. --includes传递相对路径
xrepo install -vD --toolchain=myclang --includes="toolchain.lua" benchmark
Hello
D:\Tools\xmake\xmake.exe f -c --require=n -vD --toolchain=myclang
# 没有打印Hello,toolchain.lua没有加载
checking for platform ... windows
checking for architecture ... x64
error: @programdir\core\main.lua:329: @programdir\core\platform\platform.lua:185: the toolchain myclang not found!
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1075]:
    [@programdir\core\platform\platform.lua:185]: in function 'toolchains'
    [@programdir\core\platform\platform.lua:268]: in function 'check'
    [@programdir\actions\config\main.lua:367]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:244]:
    [@programdir\core\base\task.lua:491]: in function 'run'
    [@programdir\core\main.lua:327]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1075: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
error: @programdir\core\main.lua:329: @programdir\core\sandbox\modules\os.lua:378: execv(D:\Tools\xmake\xmake.exe f -c --require=n -vD --toolchain=myclang) failed(-1)
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1075]:
    [@programdir\core\sandbox\modules\os.lua:378]:
    [@programdir\core\sandbox\modules\os.lua:291]: in function 'vrunv'
    [@programdir\modules\private\xrepo\action\install.lua:247]: in function '_install_packages'
    [@programdir\modules\private\xrepo\action\install.lua:316]:
    [@programdir\modules\private\xrepo\main.lua:196]:
    [@programdir\plugins\lua\main.lua:124]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:244]:
    [@programdir\core\base\task.lua:491]: in function 'run'
    [@programdir\core\main.lua:327]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1075: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
  1. 将--includes以绝对路径传递:
xrepo install -vD --toolchain=myclang --includes="$env:USERPROFILE/Desktop/test/toolchain.lua" benchmark
Hello
D:\Tools\xmake\xmake.exe f -c --require=n -vD --toolchain=myclang
Hello
Hello
# 打印Hello,toolchain.lua成功加载
checking for platform ... windows
checking for architecture ... x64
error: @programdir\core\main.lua:329: @programdir\core\platform\platform.lua:185: the toolchain myclang not found!
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1075]:
    [@programdir\core\platform\platform.lua:185]: in function 'toolchains'
    [@programdir\core\platform\platform.lua:268]: in function 'check'
    [@programdir\actions\config\main.lua:367]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:244]:
    [@programdir\core\base\task.lua:491]: in function 'run'
    [@programdir\core\main.lua:327]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1075: in function 'os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
# 使用相对路径的source.lua没有成功加载
warning: includes("source.lua") cannot find any files!
error: @programdir\core\main.lua:329: @programdir\core\sandbox\modules\os.lua:378: execv(D:\Tools\xmake\xmake.exe f -c --require=n -vD --toolchain=myclang) failed(-1)
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1075]:
    [@programdir\core\sandbox\modules\os.lua:378]:
    [@programdir\core\sandbox\modules\os.lua:291]: in function 'vrunv'
    [@programdir\modules\private\xrepo\action\install.lua:247]: in function '_install_packages'
    [@programdir\modules\private\xrepo\action\install.lua:316]:
    [@programdir\modules\private\xrepo\main.lua:196]:
    [@programdir\plugins\lua\main.lua:124]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:244]:
    [@programdir\core\base\task.lua:491]: in function 'run'
    [@programdir\core\main.lua:327]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1075: in function 'os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
  1. includes("source.lua")改为绝对路径后不会报工具链找不到的错误
@24bit-xjkp 24bit-xjkp added the bug label Jan 6, 2025
@Issues-translate-bot
Copy link

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


Title: xrepo install cannot find the file when specifying --includes

@waruqi
Copy link
Member

waruqi commented Jan 9, 2025

includes(path.join(os.scriptdir(), "source.lua"))

@24bit-xjkp
Copy link
Contributor Author

includes(path.join(os.scriptdir(), "source.lua"))

这不行,XMAKE_RCFILES里的脚本执行os.scriptdir()的结果还是那个临时目录,我这里运行的结果就是

warning: includes("C:\Users\2283\AppData\Local\Temp\.xmake\250109\xrepo\working\source.lua") cannot find any files!

事实上source.lua在桌面上

@waruqi
Copy link
Member

waruqi commented Jan 11, 2025

那目前没办法,--includes 目前设计就是只支持单文件,不要内部调用 includes

如果要 includes 多个。直接 xrepo install --includes=foo.lua;bar.lua 挨个设置进去就行了

@24bit-xjkp
Copy link
Contributor Author

如果要 includes 多个。直接 xrepo install --includes=foo.lua;bar.lua 挨个设置进去就行了

--includes传递相对路径会直接找不到脚本,因为XMAKE_RCFILES传进去后,会进入一共临时目录,然后工作目录就变了,这里是不是可以改成,自动在XMAKE_RCFILES中传递脚本的绝对路径

@Issues-translate-bot
Copy link

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


If you want to include multiple. Just xrepo install --includes=foo.lua;bar.lua and set them one by one.

--includes will not find the script if you pass the relative path, because after XMAKE_RCFILES is passed in, it will enter a temporary directory, and then the working directory will change. Can it be changed here to automatically pass the absolute path of the script in XMAKE_RCFILES?

@waruqi
Copy link
Member

waruqi commented Jan 12, 2025

如果要 includes 多个。直接 xrepo install --includes=foo.lua;bar.lua 挨个设置进去就行了

--includes传递相对路径会直接找不到脚本,因为XMAKE_RCFILES传进去后,会进入一共临时目录,然后工作目录就变了,这里是不是可以改成,自动在XMAKE_RCFILES中传递脚本的绝对路径

改了 #6066

@24bit-xjkp
Copy link
Contributor Author

改了 #6066

现在可以传相对路径了。不过如果传的脚本里需要用到modules,那import的时候也会报错,这怎么处理?

@waruqi
Copy link
Member

waruqi commented Jan 13, 2025

改了 #6066

现在可以传相对路径了。不过如果传的脚本里需要用到modules,那import的时候也会报错,这怎么处理?

目前没办法,xrepo install --includes 原本仅仅就是为了支持传递 简单的单一 xmake.lua 脚本配置,不是用来搞复杂脚本的。

你全部整一个 xmake.lua ,import 不要用自定义的脚本

24bit-xjkp added a commit to 24bit-xjkp/toolchains that referenced this issue Jan 13, 2025
1. 支持通过XMAKE_RCFILES环境变量传递,可以填入--includes选项中
2. 通过读取XMAKE_RCFILES环境变量来查找脚本目录,要求XMAKE_RCFILES环境变量中只有一个名为toolchain.lua的文件
3. 参见xmake-io/xmake#6048
@Issues-translate-bot
Copy link

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


Modified #6066

Relative paths can now be passed. However, if modules need to be used in the passed script, an error will be reported when importing. How to deal with this?

@Issues-translate-bot
Copy link

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


Changed #6066

Relative paths can now be passed. However, if modules need to be used in the passed script, an error will be reported when importing. How to deal with this?

There is currently no way. xrepo install --includes was originally just to support the delivery of a simple single xmake.lua script configuration, not for complex scripts.

All you need is xmake.lua. Do not use custom scripts for import.

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