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

[bug] test_requires dependency not present in component requires causes an error #13187

Closed
nyibbang opened this issue Feb 22, 2023 · 1 comment · Fixed by #13191
Closed

[bug] test_requires dependency not present in component requires causes an error #13187

nyibbang opened this issue Feb 22, 2023 · 1 comment · Fixed by #13191
Assignees
Labels
Milestone

Comments

@nyibbang
Copy link

nyibbang commented Feb 22, 2023

Environment details

  • Operating System+version: Ubuntu 20.04 (x86_64)
  • Compiler+version: g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
  • Conan version: 2.0.0
  • Python version: 3.8.10

Steps to reproduce

Here is a complete Conan + CMake project that reproduces the issue.

conanfile.py

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout

class MyLib(ConanFile):
    name = "mylib"
    version = "0.1.0"
    description = "MyLib says hello"

    requires = [
        "openssl/[^1.1]"
    ]

    test_requires = [
        "gtest/cci.20210126",
    ]

    exports_sources = [
        "CMakeLists.txt",
        "*.hpp",
        "*.cpp",
    ]

    generators = "CMakeToolchain"

    settings = "os", "compiler", "build_type", "arch"

    def layout(self):
        cmake_layout(self)

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.components["mylib"].libs = ["mylib"]
        self.cpp_info.components["mylib"].requires = ["openssl::openssl"]

CMakeLists.txt

cmake_minimum_required(VERSION 3.23)

project(MyLib)
include(CTest)

add_library(mylib STATIC)
target_sources(
    mylib
    PUBLIC
        FILE_SET HEADERS
            FILES mylib.hpp
    PRIVATE
        mylib.cpp
)
install(
    TARGETS mylib
    ARCHIVE
    LIBRARY
    FILE_SET HEADERS
)

if(BUILD_TESTING)
    find_package(GTest REQUIRED)
    add_executable(mytest)
    target_sources(mytest PRIVATE mytest.cpp)
    target_link_libraries(mytest PRIVATE mylib GTest::gtest_main)
    add_test(NAME mytest COMMAND mytest)
endif()

mylib.hpp

#pragma once

#include <string>
#include <ostream>

namespace mylib
{
    void say_hello(std::ostream& os, const std::string& name);
}

mylib.cpp

#include "mylib.hpp"

namespace mylib
{
    void say_hello(std::ostream& os, const std::string& name)
    {
        os << "hello " << name;
    }
}

mytest.cpp

#include "mylib.hpp"
#include <gtest/gtest.h>
#include <sstream>

TEST(MyLib, SayHello)
{
    std::ostringstream oss;
    mylib::say_hello(oss, "John Doe");
    EXPECT_EQ(oss.str(), "hello John Doe");
}

Then run conan create . --build=missing

Logs

mylib/0.1.0: Exporting package recipe: /home/myuser/work/mylib/conanfile.py
mylib/0.1.0: Copied 1 '.py' file: conanfile.py
mylib/0.1.0: Copied 1 '.hpp' file: mylib.hpp
mylib/0.1.0: Copied 1 '.txt' file: CMakeLists.txt
mylib/0.1.0: Copied 3 '.cpp' files: mylib.cpp, mytest.cpp, CMakeCXXCompilerId.cpp
mylib/0.1.0: Exported to cache folder: /home/myuser/.conan2/p/mylibb078cdb97f13f/e
mylib/0.1.0: Exported: mylib/0.1.0#52ea9a5a56d2c6b4fd3ebb4ac1536a93 (2023-02-22 18:16:40 UTC)

======== 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

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu14
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux


======== Computing dependency graph ========
Graph root
    cli
Requirements
    mylib/0.1.0#52ea9a5a56d2c6b4fd3ebb4ac1536a93 - Cache
    openssl/1.1.1t#1e58dd56a2a930f23160558c572a62fd - Cache
Test requirements
    gtest/cci.20210126#dafbdf84b58cd687075ace7314651c1a - Cache
Resolved version ranges
    openssl/[^1.1]: openssl/1.1.1t

======== Computing necessary packages ========
Requirements
    mylib/0.1.0#52ea9a5a56d2c6b4fd3ebb4ac1536a93:367bcdba5a3cecc102ce32b2e49cd853fe932213#2f790914b2705c52e1c1604ddfabe6b1 - Cache
    openssl/1.1.1t#1e58dd56a2a930f23160558c572a62fd:519af2652d4d356cb8131159d7bac54ecb13b249#d08412695909834b6571fd41487ad71b - Cache
Test requirements
    gtest/cci.20210126#dafbdf84b58cd687075ace7314651c1a:d2f1054acdd89023cf363b7e5f2c6098b9878cb9#e64da3cf5102c1ee73e4f91d4eb19531 - Skip

======== Installing packages ========
openssl/1.1.1t: Already installed!
WARN: The use of 'cpp_info.names' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X
WARN: The use of 'cpp_info.names' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X
WARN: The use of 'cpp_info.build_modules' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X
WARN: The use of 'cpp_info.build_modules' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X
WARN: The use of 'cpp_info.names' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X
WARN: The use of 'cpp_info.names' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X
WARN: The use of 'cpp_info.names' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X
WARN: The use of 'cpp_info.names' is deprecated in Conan 2.0 and will be removed in Conan 2.X. Please, update your recipes unless you are maintaining compatibility with Conan 1.X

-------- Building package mylib/0.1.0 from source (3 of 3) --------
mylib/0.1.0: Package mylib/0.1.0:367bcdba5a3cecc102ce32b2e49cd853fe932213
mylib/0.1.0: Copying sources to build folder
mylib/0.1.0: Building your package in /home/myuser/.conan2/p/t/mylib312bd0a54335f/b
mylib/0.1.0: Writing generators to /home/myuser/.conan2/p/t/mylib312bd0a54335f/b/build/Release/generators
mylib/0.1.0: Generator 'CMakeToolchain' calling 'generate()'
mylib/0.1.0: CMakeToolchain generated: conan_toolchain.cmake
mylib/0.1.0: CMakeToolchain generated: CMakePresets.json
mylib/0.1.0: CMakeToolchain generated: ../../../CMakeUserPresets.json
mylib/0.1.0: Generating aggregated env files
mylib/0.1.0: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
mylib/0.1.0: Calling build()
mylib/0.1.0: Running CMake.configure()
mylib/0.1.0: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/home/myuser/.conan2/p/t/mylib312bd0a54335f/b/build/Release/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/myuser/.conan2/p/t/mylib312bd0a54335f/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/myuser/.conan2/p/t/mylib312bd0a54335f/b/."
-- Using Conan toolchain: /home/myuser/.conan2/p/t/mylib312bd0a54335f/b/build/Release/generators/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions ON
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_POLICY_DEFAULT_CMP0091


-- Build files have been written to: /home/myuser/.conan2/p/t/mylib312bd0a54335f/b/build/Release

mylib/0.1.0: Running CMake.build()
mylib/0.1.0: RUN: cmake --build "/home/myuser/.conan2/p/t/mylib312bd0a54335f/b/build/Release" -- -j8
[ 25%] Building CXX object CMakeFiles/mylib.dir/mylib.cpp.o
[ 50%] Linking CXX static library libmylib.a
[ 50%] Built target mylib
[ 75%] Building CXX object CMakeFiles/mytest.dir/mytest.cpp.o
[100%] Linking CXX executable mytest
[100%] Built target mytest

mylib/0.1.0: Package '367bcdba5a3cecc102ce32b2e49cd853fe932213' built
mylib/0.1.0: Build folder /home/myuser/.conan2/p/t/mylib312bd0a54335f/b/build/Release
mylib/0.1.0: Generating the package
mylib/0.1.0: Temporary package folder /home/myuser/.conan2/p/t/mylib312bd0a54335f/p
mylib/0.1.0: Calling package()
mylib/0.1.0: Running CMake.install()
mylib/0.1.0: RUN: cmake --install "/home/myuser/.conan2/p/t/mylib312bd0a54335f/b/build/Release" --prefix "/home/myuser/.conan2/p/t/mylib312bd0a54335f/p"
-- Install configuration: "Release"
-- Installing: /home/myuser/.conan2/p/t/mylib312bd0a54335f/p/lib/libmylib.a
-- Installing: /home/myuser/.conan2/p/t/mylib312bd0a54335f/p/include/mylib.hpp

mylib/0.1.0: package(): Packaged 1 '.a' file: libmylib.a
mylib/0.1.0: package(): Packaged 1 '.hpp' file: mylib.hpp
mylib/0.1.0: Created package revision 2f790914b2705c52e1c1604ddfabe6b1
mylib/0.1.0: Package '367bcdba5a3cecc102ce32b2e49cd853fe932213' created
mylib/0.1.0: Full package reference: mylib/0.1.0#f644e595be7310991f88d4656f5c4882:367bcdba5a3cecc102ce32b2e49cd853fe932213#2f790914b2705c52e1c1604ddfabe6b1
mylib/0.1.0: Package folder /home/myuser/.conan2/p/mylibada0622bd35f8/p
ERROR: mylib/0.1.0: Required package 'gtest' not in component 'requires'
@memsharded
Copy link
Member

Hi @nyibbang

Thanks very much for reporting, and thanks very much for the detailed reproduction, it really helped!

You are right, there is a bug in the checking of requirements when using components, and test_requires was not being filtered from that. I have already submitted a fix in #13191, we will release it in next patch release 2.0.1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants