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

CMake cmakeArgs does not evaluate environment variables #12848

Closed
Lectem opened this issue May 8, 2020 · 4 comments
Closed

CMake cmakeArgs does not evaluate environment variables #12848

Lectem opened this issue May 8, 2020 · 4 comments
Assignees
Labels
Area: ABTT Akvelon Build Tasks Team area of work Area: Build bug p1 Priority 1 (should have immediate attention) Task: CMake

Comments

@Lectem
Copy link

Lectem commented May 8, 2020

Question, Bug, or Feature?
Type: Bug

Enter Task Name:

CMake

Environment

  • Server - Azure Pipelines

  • Agent - Private:

Agent name: 'Hosted Agent'
Agent machine name: 'fv-az598'
Current agent version: '2.166.4'
Current image version: '20200430.2'
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Downloading task: CmdLine (2.164.0)
Downloading task: CMake (1.166.0)

OS: ubuntu

Issue Description

When using environment variables in the cmakeArgs parameter, the environment variables are not evaluated anymore.

For example, with the EMSCRIPTEN environment variable set in the image:

  steps:
  - script: cmake -B build-script -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake
  - task: CMake@1
    inputs:
      workingDirectory: build-task
      cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake ..

The first script works fine, but the one with the task will give the error

/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCF_USE_ISPC=OFF -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake ..
CMake Error at /opt/cmake/share/cmake-3.14/Modules/CMakeDetermineSystem.cmake:99 (message):
Could not find toolchain file:
$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake
Call Stack (most recent call first):
CMakeLists.txt:19 (project)

We can see that CMake receives the string with $EMSCRIPTEN instead of its value.

Multiple possibilities:

  • The task cleans the environment variables (I doubt so)
  • The task escapes the cmakeArgs
  • The task does not go through the shell to start cmake, hence not evaluating env vars
@damccorm damccorm added Area: ABTT Akvelon Build Tasks Team area of work Area: Build and removed route labels May 8, 2020
@egor-bryzgalov egor-bryzgalov self-assigned this May 11, 2020
@egor-bryzgalov
Copy link
Member

Hello, @Lectem!

Thanks for your report! Could you please try to use macro syntax to reference EMSCRIPTEN variable in 'cmakeArgs' by wrapping the variable in parentheses like this?

'...-DCMAKE_TOOLCHAIN_FILE=$(EMSCRIPTEN)/cmake/Modules/...'

Please, let us know if it helps. You may also find more information about variables here:
https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#understand-variable-syntax

@Lectem
Copy link
Author

Lectem commented May 11, 2020

Could you please try to use macro syntax to reference EMSCRIPTEN variable in 'cmakeArgs' by wrapping the variable in parentheses like this?

'...-DCMAKE_TOOLCHAIN_FILE=$(EMSCRIPTEN)/cmake/Modules/...'

Yes I tried this too and it gave me the following:

/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCF_USE_ISPC=OFF -DCMAKE_TOOLCHAIN_FILE=$(EMSCRIPTEN)/cmake/Modules/Platform/Emscripten.cmake ..
CMake Error at /opt/cmake/share/cmake-3.14/Modules/CMakeDetermineSystem.cmake:99 (message):
  Could not find toolchain file:
  $(EMSCRIPTEN)/cmake/Modules/Platform/Emscripten.cmake
Call Stack (most recent call first):
  CMakeLists.txt:19 (project)

I think it can probably be easily reproduced with any CMake variable and a small CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
message(STATUS "Value of TEST_CMAKE_TASK is: ${TEST_CMAKE_TASK}")

and something using an env var such as

steps:
  - script: cmake -B build-script -DTEST_CMAKE_TASK=$USER
  - task: CMake@1
    inputs:
      workingDirectory: build-task
      cmakeArgs: -DTEST_CMAKE_TASK=$USER ..

(I do not have time to test this right now, but it should help reproduce the issue)

@egor-bryzgalov
Copy link
Member

Closing the issue since changes should be deployed now. Please feel free to reopen.

@egor-bryzgalov egor-bryzgalov removed the awaiting deployment Related changes are waiting for deployment to be completed label Jul 28, 2020
@KrisThielemans
Copy link

KrisThielemans commented Nov 16, 2022

I'm not sure if this is the same issue, but I'm trying to set a package location from a previous stage in UCL/PETPVC#84. Actual code is like this

steps:
  - script: |
      #brew tap bathomas/homebrew-bat
      #brew install ninja insighttoolkit
      brew install ninja itk
      Qt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5
      echo "##vso[task.setvariable variable=Qt5_DIR;isOutput=true]$Qt5_DIR"
    displayName: Brew install dependencies
  - script: |
      mkdir build.debug
      mkdir build.release
    displayName: Make Build Directories
  - task: CMake@1
    inputs:
      workingDirectory: 'build.debug'
      cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Debug -DQt5_DIR=$(Qt5_DIR) ..'

I checked that Qt5_DIR is set to /usr/local/opt/qt@5/lib/cmake/Qt5 and the cmake files are there, but CMake still doesn't find Qt5, implying that the variable didn't make it.

Any ideas?

Edit:

  • using runInsideShell: true didn't help
  • I've confirmed that the problem is the setting of the variable by hard-wiring the location, as in
cmakeArgs: '-G Ninja -DCMAKE_BUILD_TYPE=Debug -DQt5_DIR=/usr/local/opt/qt@5/lib/cmake/Qt5 ..'

If this should work, it'd be great to see an example. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ABTT Akvelon Build Tasks Team area of work Area: Build bug p1 Priority 1 (should have immediate attention) Task: CMake
Projects
None yet
Development

No branches or pull requests

5 participants