conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.14k stars 970 forks source link

[bug] Conan2 tutorials fail, CMAKE_CXX_COMPILER not passed. #13646

Closed gazzatav closed 1 year ago

gazzatav commented 1 year ago

Environment details

Steps to reproduce

Upgrade OS to Ubuntu 20.04 install conan2 (python3 -m pip install conan) checkout hello tutorial (At this point profile contains a buildenv section: [buildenv] CXX=/usr/bin/g++-9 CC=/usr/bin/gcc-9 ) run: conan install (results in logs) cmake (results in logs)

Search for 'conan2 fails to set cmake_cxx_compiler' Choose search result '[question] Why does conan not pass CMAKE_CXX_COMPILER to CMAKE #10877' Add 'tools.build.compiler_executables={"c": "/usr/bin/gcc-9", "cpp": "/usr/bin/g++-9"}' to profile.

Read error: ERROR: Unknown conf 'tools.build.compiler_executables'. Use 'conan config list' to display existing configurations Run conan config list (result in logs) - it's there! Try that config in a [conf] section, try it in the [settings] section, try it with and without paths to executables Read another error: ERROR: Error reading '/home/gary/.conan2/profiles/default' profile: Error parsing the profile text file: not enough values to unpack (expected 2, got 1)

But it worked yesterday after I added the [buildenv] section!!!

Logs

2023-04-07 10:08:48 vostro in ~/Projects/conan2_tut/hello/build ○ → conan install ../source/

======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu14 compiler.libcxx=libstdc++11 compiler.version=9 os=Linux [buildenv] CXX=/usr/bin/g++-9 CC=/usr/bin/gcc-9

Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu14 compiler.libcxx=libstdc++11 compiler.version=9 os=Linux [buildenv] CXX=/usr/bin/g++-9 CC=/usr/bin/gcc-9

======== Computing dependency graph ======== Graph root conanfile.py (hello/1.0): /home/gary/Projects/conan2_tut/hello/source/conanfile.py

======== Computing necessary packages ========

======== Installing packages ========

======== Finalizing install (deploy, generators) ======== conanfile.py (hello/1.0): Calling generate() conanfile.py (hello/1.0): Generators folder: /home/gary/Projects/conan2_tut/hello/source/build/Release/generators conanfile.py (hello/1.0): CMakeToolchain generated: conan_toolchain.cmake conanfile.py (hello/1.0): Preset 'conan-release' added to CMakePresets.json. Invoke it manually using 'cmake --preset conan-release' if using CMake>=3.23 conanfile.py (hello/1.0): If your CMake version is not compatible with CMakePresets (<3.23) call cmake like: 'cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/home/gary/Projects/conan2_tut/hello/source/build/Release/generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release' conanfile.py (hello/1.0): CMakeToolchain generated: CMakePresets.json conanfile.py (hello/1.0): CMakeToolchain generated: ../../../CMakeUserPresets.json conanfile.py (hello/1.0): Generating aggregated env files conanfile.py (hello/1.0): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] Install finished successfully

2023-04-07 10:08:55 vostro in ~/Projects/conan2_tut/hello/build ○ → cmake ../source/ -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:2 (project): No CMAKE_CXX_COMPILER could be found.

ERROR: Unknown conf 'tools.build.compiler_executables'. Use 'conan config list' to display existing configurations

○ → conan config list core.cache:storage_path: Absolute path where the packages and database are stored core.download:download_cache: Define path to a file download cache core.download:parallel: Number of concurrent threads to download packages core.download:retry: Number of retries in case of failure when downloading from Conan server core.download:retry_wait: Seconds to wait between download attempts from Conan server core.gzip:compresslevel: The Gzip compresion level for Conan artifacts (default=9) core.net.http:cacert_path: Path containing a custom Cacert file core.net.http:clean_system_proxy: If defined, the proxies system env-vars will be discarded core.net.http:client_cert: Path or tuple of files containing a client cert (and key) core.net.http:max_retries: Maximum number of connection retries (requests library) core.net.http:no_proxy_match: List of urls to skip from proxies configuration core.net.http:proxies: Dictionary containing the proxy configuration core.net.http:timeout: Number of seconds without response to timeout (requests library) core.package_id:default_build_mode: By default, 'None' core.package_id:default_embed_mode: By default, 'full_mode' core.package_id:default_non_embed_mode: By default, 'minor_mode' core.package_id:default_python_mode: By default, 'minor_mode' core.package_id:default_unknown_mode: By default, 'semver_mode' core.sources:download_cache: Folder to store the sources backup core.sources:download_urls: List of URLs to download backup sources from core.sources:upload_url: Remote URL to upload backup sources to core.upload:retry: Number of retries in case of failure when uploading to Conan server core.upload:retry_wait: Seconds to wait between upload attempts to Conan server core.version_ranges:resolve_prereleases: Whether version ranges can resolve to pre-releases or not core:allow_uppercase_pkg_names: Temporarily (will be removed in 2.X) allow uppercase names core:default_build_profile: Defines the default build profile (None by default) core:default_profile: Defines the default host profile ('default' by default) core:non_interactive: Disable interactive user input, raises error if input necessary core:required_conan_version: Raise if current version does not match the defined range. tools.android:cmake_legacy_toolchain: Define to explicitly pass ANDROID_USE_LEGACY_TOOLCHAIN_FILE in CMake toolchain tools.android:ndk_path: Argument for the CMAKE_ANDROID_NDK tools.apple:enable_arc: (boolean) Enable/Disable ARC Apple Clang flags tools.apple:enable_bitcode: (boolean) Enable/Disable Bitcode Apple Clang flags tools.apple:enable_visibility: (boolean) Enable/Disable Visibility Apple Clang flags tools.apple:sdk_path: Path to the SDK to be used tools.build.cross_building:can_run: Bool value that indicates whether is possible to run a non-native app on the same architecture. It's used by 'can_run' tool tools.build:cflags: List of extra C flags used by different toolchains like CMakeToolchain, AutotoolsToolchain and MesonToolchain tools.build:compiler_executables: Defines a Python dict-like with the compilers path to be used. Allowed keys {'c', 'cpp', 'cuda', 'objc', 'objcxx', 'rc', 'fortran', 'asm', 'hip', 'ispc'} tools.build:cxxflags: List of extra CXX flags used by different toolchains like CMakeToolchain, AutotoolsToolchain and MesonToolchain tools.build:defines: List of extra definition flags used by different toolchains like CMakeToolchain and AutotoolsToolchain tools.build:download_source: Force download of sources for every package tools.build:exelinkflags: List of extra flags used by CMakeToolchain for CMAKE_EXE_LINKER_FLAGS_INIT variable tools.build:jobs: Default compile jobs number -jX Ninja, Make, /MP VS (default: max CPUs) tools.build:linker_scripts: List of linker script files to pass to the linker used by different toolchains like CMakeToolchain, AutotoolsToolchain, and MesonToolchain tools.build:sharedlinkflags: List of extra flags used by CMakeToolchain for CMAKE_SHARED_LINKER_FLAGS_INIT variable tools.build:skip_test: Do not execute CMake.test() and Meson.test() when enabled tools.build:sysroot: Pass the --sysroot= flag if available. (None by default) tools.build:verbosity: Verbosity of MSBuild and XCodeBuild build systems. Possible values are 'quiet', 'error', 'warning', 'notice', 'status', 'verbose', 'normal', 'debug', 'v', 'trace' and 'vv' tools.cmake.cmake_layout:build_folder_vars: Settings and Options that will produce a different build folder and different CMake presets names tools.cmake.cmaketoolchain:find_package_prefer_config: Argument for the CMAKE_FIND_PACKAGE_PREFER_CONFIG tools.cmake.cmaketoolchain:generator: User defined CMake generator to use instead of default tools.cmake.cmaketoolchain:system_name: Define CMAKE_SYSTEM_NAME in CMakeToolchain tools.cmake.cmaketoolchain:system_processor: Define CMAKE_SYSTEM_PROCESSOR in CMakeToolchain tools.cmake.cmaketoolchain:system_version: Define CMAKE_SYSTEM_VERSION in CMakeToolchain tools.cmake.cmaketoolchain:toolchain_file: Use other existing file rather than conan_toolchain.cmake one tools.cmake.cmaketoolchain:toolset_arch: Toolset architecture to be used as part of CMAKE_GENERATOR_TOOLSET in CMakeToolchain tools.cmake.cmaketoolchain:user_toolchain: Inject existing user toolchains at the beginning of conan_toolchain.cmake tools.env.virtualenv:powershell: If it is set to True it will generate powershell launchers if os=Windows tools.files.download:retry: Number of retries in case of failure when downloading tools.files.download:retry_wait: Seconds to wait between download attempts tools.gnu:define_libcxx11_abi: Force definition of GLIBCXX_USE_CXX11_ABI=1 for libstdc++11 tools.gnu:host_triplet: Custom host triplet to pass to Autotools scripts tools.gnu:make_program: Indicate path to make program tools.gnu:pkg_config: Path to pkg-config executable used by PkgConfig build helper tools.google.bazel:bazelrc_path: Defines Bazel rc-path tools.google.bazel:configs: Define Bazel config file tools.info.package_id:confs: List of existing configuration to be part of the package ID tools.intel:installation_path: Defines the Intel oneAPI installation root path tools.intel:setvars_args: Custom arguments to be passed onto the setvars.sh|bat script from Intel oneAPI tools.meson.mesontoolchain:backend: Any Meson backend: ninja, vs, vs2010, vs2012, vs2013, vs2015, vs2017, vs2019, xcode tools.meson.mesontoolchain:extra_machine_files: List of paths for any additional native/cross file references to be appended to the existing Conan ones tools.microsoft.bash:active: If Conan is already running inside bash terminal in Windows tools.microsoft.bash:path: The path to the shell to run when conanfile.win_bash==True tools.microsoft.bash:subsystem: The subsystem to be used when conanfile.win_bash==True. Possible values: msys2, msys, cygwin, wsl, sfu tools.microsoft.msbuild:installation_path: VS install path, to avoid auto-detect via vswhere, like C:/Program Files (x86)/Microsoft Visual Studio/2019/Community. Use empty string to disable tools.microsoft.msbuild:max_cpu_count: Argument for the /m when running msvc to build parallel projects tools.microsoft.msbuild:vs_version: Defines the IDE version when using the new msvc compiler tools.microsoft.msbuilddeps:exclude_code_analysis: Suppress MSBuild code analysis for patterns tools.microsoft.msbuildtoolchain:compile_options: Dictionary with MSBuild compiler options tools.system.package_manager:mode: Mode for package_manager tools: 'check' or 'install' tools.system.package_manager:sudo: Use 'sudo' when invoking the package manager tools in Linux (False by default) tools.system.package_manager:sudo_askpass: Use the '-A' argument if using sudo in Linux to invoke the system package manager (False by default) tools.system.package_manager:tool: Default package manager tool: 'apt-get', 'yum', 'dnf', 'brew', 'pacman', 'choco', 'zypper', 'pkg' or 'pkgutil'

memsharded commented 1 year ago

Hi @gazzatav

I would say this seems a typo. You are typing tools.build.compiler_executables, but the correct value is with :, like tools.build:compiler_executables. The pattern for every conf should be scope:key=value.

Please try that and lets us know.

gazzatav commented 1 year ago

Hmm, maybe the problem is 'tools.build.compiler_executables' without a ':'. I took it from #10877 where it's quoted several times without a colon and a few times with a colon. Easy to miss and the reference docs on some of the profile sections are a bit skimpy on best practices.

memsharded commented 1 year ago

Yeah, the thread in https://github.com/conan-io/conan/issues/10877 had some typos, I have fixed them, the correct syntax is using :.

Can you please confirm if it is working with :?

gazzatav commented 1 year ago

Hi @memsharded, yes thanks, that works. Sorry, I hadn't seen your reply when I made my previous comment so it sounds a bit weird. Didn't expect anyone to look at it over the Easter weekend so didn't refresh!

By the way, while working through the conan2 tutorials over the weekend I noticed lots of niggles in the docs e.g. -tf=None tries to find a folder 'None' and needs to be simply empty quotes (in bash 5.0.17). Do you prefer all all these individual items in issues or do you accept/review changes if I use the 'Edit on Github' link. My concern here is that folks new to conan are put off early - here's another example for fun - this really happens!!!:

→ conan list * Local Cache mms-utility mms-utility/1.0.0@mms/stable taocpp-json taocpp-json/1.0.0-beta.11 taojson taojson/1.0.0@gary/testing

And then in same shell a minute later:

→ conan list * usage: conan list [-h] [-f FORMAT] [-v [V]] [-p PACKAGE_QUERY] [-r REMOTE] [-c] reference conan list: error: unrecognized arguments: CMakeLists.txt conanbuildenv.sh conanbuild.sh conanfile.old.py conanfile.py conanrunenv.sh conanrun.sh contrib deactivate_conanbuild.sh deactivate_conanrun.sh doc external include LICENSE LICENSE.double-conversion LICENSE.itoa LICENSE.ryu Makefile README.md src tests ERROR: Exiting with code: 2

But if I quote the asterisk:

→ conan list "*" Local Cache mms-utility mms-utility/1.0.0@mms/stable taocpp-json taocpp-json/1.0.0-beta.11 taojson taojson/1.0.0@gary/testing

Lol!

memsharded commented 1 year ago

Hi @memsharded, yes thanks, that works. Sorry, I hadn't seen your reply when I made my previous comment so it sounds a bit weird. Didn't expect anyone to look at it over the Easter weekend so didn't refresh!

Sure, no prob! 😄

You are totally right about the docs, they might have some issues like that, as a result of quick iteration, many different hands modifying the docs (for example Windows users are typically not affected by the conan list * expansion without quotes, because that doesn't happen on Windows), etc.. It would be much better if all asterisks are quoted so it works in every platform the same.

Of course, if you would like to fix things of the docs, that is always appreciated, in any way you prefer, small PRs for every issue, or one PR with several (even unrelated) fixes. To fix the latest "live" 2.0 docs, the PR should go to the release/2.0 branch.