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

cmakeFlags cannot parse spaces #114044

Closed
IvarWithoutBones opened this issue Feb 22, 2021 · 9 comments
Closed

cmakeFlags cannot parse spaces #114044

IvarWithoutBones opened this issue Feb 22, 2021 · 9 comments
Labels
0.kind: bug Something is broken significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.

Comments

@IvarWithoutBones
Copy link
Member

IvarWithoutBones commented Feb 22, 2021

Describe the bug
The cmakeFlags array cannot parse spaces correctly, and thinks any argument after a space is a another CMake flag. I think it splits the flag on spaces upon parsing it. The flags do get printed out correctly, however they are not handled the same way.

I've tried using all kinds of different quotes, and escaping almost every single character, but nothing seemed to work.

To Reproduce
Steps to reproduce the behavior:

  1. Append an space to a CMake flag. (cmakeFlags = [ "-DFoo=\"foo bar\"" ];)
  2. Watch the cmakeConfigurePhase fail, as it thinks bar is an seperate flag, and it cannot find this local file.
    CMake Error: The source directory "/build/source/build/bar"" does not exist.

Expected behavior
cmakeFlags should be correctly passed to CMake, and the build should succeed.

Additional context
Note that when manually setting cmakeFlagsArray, this does work.

  preConfigure = ''
    cmakeFlagsArray=(
      $cmakeFlagsArray
      "-DFoo=\"foo bar\""
    )
  '';

When applying this flag from a nix-shell, it also succesfully parses it.

Notify maintainers
@ttuegel @LnL7

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.11.0, NixOS, 21.05pre271444.9816b99e71c (Okapi)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.10
  • channels(root): "nixos-21.05pre271444.9816b99e71c"
  • channels(ivv): "home-manager, nixpkgs-21.05pre271900.11cd34cd592"
  • nixpkgs: /home/ivv/.nix-defexpr/channels/nixpkgs

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: cmake
attribute: yuzu-{mainline,ea}
@IvarWithoutBones IvarWithoutBones added the 0.kind: bug Something is broken label Feb 22, 2021
@jtojnar
Copy link
Member

jtojnar commented Feb 23, 2021

See also #112054

I would just recommend:

preConfigure = ''
  cmakeFlagsArray+=(
    "-DFoo=\"foo bar\""
  )
'';

@stale

This comment was marked as off-topic.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 28, 2021
@IvarWithoutBones

This comment was marked as off-topic.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 30, 2021
@stale

This comment was marked as off-topic.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 28, 2022
@tpwrules

This comment was marked as off-topic.

@Et7f3
Copy link
Contributor

Et7f3 commented Nov 1, 2022

by just looking at the source I find

cmakeFlags="-DCMAKE_INSTALL_PREFIX=$prefix $cmakeFlags"
this pattern. I think bash transform array to string thus splitting get wrong. Can you modify this so everywhere cmakeFlags is used it is treated with bash array syntax. If you do push to a branch to ease review.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 1, 2022
@jtojnar
Copy link
Member

jtojnar commented Nov 1, 2022

@Et7f3 Nixpkgs does not pass cmakeFlags as an array currently, so it will be a string no matter what you do on the bash side. We need _structuredAttrs (e.g. #85042) or work around on Nix side with BC-breaking hacks like 2e55b73.

@Netruk44
Copy link
Contributor

I'm hitting this issue while trying to specify a generator for cmake. It appears to be impossible unless you want to use Ninja because most of them have spaces in them:

Generators
* Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Ninja Multi-Config           = Generates build-<Config>.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  Xcode                        = Generate Xcode project files.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.

Attempting to specify -G"Unix Makefiles" always fails:

CMake Error: Could not create named generator "Unix

@Qyriad Qyriad added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Jun 27, 2024
@wolfgangwalther
Copy link
Contributor

Since 34a2b7a the cmake setup hooks support spaces in cmakeFlags etc., if you set __structuredAttrs = true;.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc.
Projects
None yet
Development

No branches or pull requests

7 participants