简体   繁体   English

在 azure 管道中使用 cmake 中的 bash 尝试调用 WSL,但从管道代码调用不会

[英]Using bash from cmake in azure pipelines tries to invoke WSL, but invoking from pipeline code does not

I have an execute_process(COMMAND bash script.sh) task in my CMakeLists.txt file which is being built on azure pipelines using the following pipline task:我的 CMakeLists.txt 文件中有一个execute_process(COMMAND bash script.sh)任务,该文件是使用以下管道任务在 azure 管道上构建的:

- bash: |
    cmake .

Recently this has stopped working and throws the error "Windows Subsystem for Linux has no installed distributions".最近这已经停止工作并抛出错误“用于 Linux 的 Windows 子系统没有安装的发行版”。

If I run the command using the following yaml in my azure-pipelines.yaml It works fine and does not throw any error.如果我在我的azure-pipelines.yaml使用以下 yaml 运行命令,它工作正常并且不会引发任何错误。

- bash:
    ./script.sh

Why does invoking the same script from cmake try to invoke WSL and how can i stop this from happening so it just runs the script?为什么从 cmake 调用相同的脚本会尝试调用 WSL,我该如何阻止这种情况发生,以便它只运行脚本?

The same script runs fine in both linux and mac pipeline stages, so i would like it to be consistent with windows.相同的脚本在 linux 和 mac 管道阶段运行良好,所以我希望它与 windows 保持一致。

I can reproduce the exact same issue.我可以重现完全相同的问题。 And i found this command execute_process(COMMAND powershell bash script.sh) works on windows agent.我发现这个命令execute_process(COMMAND powershell bash script.sh)适用于 Windows 代理。

If you want to make it consistent with windows.如果你想让它与windows一致。 You can add below additional line in your CMakeLists.txt file.您可以在 CMakeLists.txt 文件中添加以下附加行。 This additional line will only works on windows.此附加行仅适用于 Windows。

execute_process(COMMAND bash script.sh)
execute_process(COMMAND powershell bash script.sh) #works on windows

The workaround I used for this issue was to create a windows batch file with the same commands and then just call that if cmake is being run from windows.我用于此问题的解决方法是使用相同的命令创建一个 Windows 批处理文件,然后在 cmake 正在从 Windows 运行时调用它。

if(MSVC)
    execute_process ( COMMAND script.bat)
else()
    execute_process ( COMMAND bash script.sh)
endif()

The azure pipeline task then works OK:然后天蓝色管道任务正常工作:

- bash: |
    cmake .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM