threeal / cmake-action

Configure and build CMake projects on GitHub Actions
https://github.com/marketplace/actions/cmake-action
MIT License
25 stars 2 forks source link

Cannot use paths with spaces in options param #519

Open MartinSalinas98 opened 3 hours ago

MartinSalinas98 commented 3 hours ago

Introduction

I am using this action in my CI/CD pipeline, where, specifically for Windows, I am having trouble setting a flag in the options parameter.

Description

The problematic parameter is CUDA_TOOLKIT_ROOT_DIR. This param is set previously by the action Jimver/cuda-toolkit, however, that's not very relevant, since the real cause of the issue is that the default installation path contains spaces (C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8, for example).

The error received is:

CMake Error: Parse error in command line argument: Files/NVIDIA
 Should be: VAR:type=value

I have tried, for no avail, to add quotes around the path (simple and/or double), to scape the spaces with a backwards slash, to replace all backwards slashes with forward ones, and all possible combinations of all the options mentioned.

Cause of the issue

Diving a bit inside this action's code, I found this line, which splits the options parameter by spaces. That makes sense if you have multiple options set, but it does not take into account that the value of any of those options could contain spaces, which is the case for some paths.

Suggestion

My suggestion to fix this issue would be to detect quotes around the right side of the =, so that the spaces inside such value are copied to the final cmake command instead of being used as a separator. For example, for this options:

...
options: |
            CMAKE_BUILD_TYPE=Release
            CUDA_TOOLKIT_ROOT_DIR="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8"

The following parameters would be generated:

-DCMAKE_BUILD_TYPE=Release -DCUDA_TOOLKIT_ROOT_DIR="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8"

(keeping the quotes to avoid errors down the road).

threeal commented 3 hours ago

Thank you for raising this out. When I first created this action, I was aware that this kind of issue might occur. Your suggestion is correct, maybe we can introduce some kind of quote parsing to accommodate values that may contain spaces.

threeal commented 2 hours ago

@MartinSalinas98 Try threeal/cmake-action@parse-multi-vals-inputs-with-quotation, let me know if it works. Thank you.

MartinSalinas98 commented 1 hour ago

I now get another error related to CUDA not being found.

-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.42.34433.0
-- The CXX compiler identification is MSVC 19.42.34433.0
CMake Error at C:/Program Files/CMake/share/cmake-3.31/Modules/CMakeDetermineCompilerId.cmake:614 (message):
  No CUDA toolset found.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.31/Modules/CMakeDetermineCompilerId.cmake:8 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  C:/Program Files/CMake/share/cmake-3.31/Modules/CMakeDetermineCompilerId.cmake:53 (__determine_compiler_id_test)
  C:/Program Files/CMake/share/cmake-3.31/Modules/CMakeDetermineCUDACompiler.cmake:131 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:26 (project)
-- Configuring incomplete, errors occurred!
Error: Command failed: cmake D:\a\my-test-project\my-test-project -B D:\a\my-test-project\my-test-project/build -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release -DCUDA_TOOLKIT_ROOT_DIR=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8 -DCMAKE_CUDA_COMPILER=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin\nvcc.exe

However, looks more cmake related and not necessarily to this action which looks like it parsed the arguments correctly.

Thanks for the fix!