Automotive Software

패킷과 사용모듈의 의존성 명시 및 사용 본문

프로그래밍 (Programming)/코난 (Conan)

패킷과 사용모듈의 의존성 명시 및 사용

AutoSW 2023. 3. 14. 20:38

패키지의 정보 제공을 위해 conanfile.py파일 내에서 두 가지 메서드를 사용하여 의존성을 명시할 수 있다.

  • build_requirements()
    • 해당 패키지가 소스코드로 부터 생성되는 경우에 한해 명시된 요구 모듈들이 설치되고 사용된다.
    • 하지만, 패키지와 설치될 모듈 간의 의존성이 다른 형식으로 (예, Makefile을 위한 변수) 나타나지 않는다.
def build_requirements(self):
    self.tool_requires("tool_to_be_installed/0.1@my/testing")
  • requirement()
    • 좀 더 명시적으로 의존성 관계를 표현할 수 있다.
    • 패키지와 설치될 또는 패키지 내에서 사용될 모듈 간의 의존성이 다른 형식으로 (예, Makefile의 변수) 생성된다.
def requirements(self):
    self.requires("tool_to_be_installed_and_used/0.1@my/testing")

이후, build()를 통해 아래와 같은 conanbuildinfo.mak가 생성된다.

물론, 해당 패킷의 class 상에서 generator를 make로 명시한 경우이다.

class MyConanPacket(ConanFile):
    ...
    generators = "make"
    ...
#-------------------------------------------------------------------#
#             Makefile variables from Conan Dependencies            #
#-------------------------------------------------------------------#

CONAN_ROOT_QNX-TOOL_TO_BE_INSTALLED_AND_USED ?=  \
/home/user/.conan/data/tool_to_be_installed_and_used/0.1/my/testing/package/1234567acfe1f23c4fae0ab88f26e3a396351ac9

CONAN_SYSROOT_QNX-TOOL_TO_BE_INSTALLED_AND_USED ?=  \
...

생성된 conanbuildinfo.mak는 해당 코난 패킷을 사용하는 make 프로젝트에서 생성된 변수를 참조할 수 있다.

include $(WHERE_MAK_FILE_IS_LOCATED_IN)/conanbuildinfo.mak

 

!!! 코난 버전이 1.58 이전인 경우, 요구되는 모듈이 사용되는 곳을 명시적으로 표시하여야 한다.

(https://github.com/conan-io/conan/pull/12966/files)

이때, :: 는 모듈의 의존성을 명확하게 필요하기 위한 것으로,(https://github.com/conan-io/conan/issues/7475)

모듈명::모듈명 은 모듈의 모든 것으로 필요함을 나타내며,

특정 라이브러리만 필요한 경우, 특정 라이브러리::모듈명과 같이 표현할 수 있다.

 

def requirements(self):
    self.requires("tool_to_be_installed_and_used/0.1@my/testing")
    

def package_info(self):
    ...
    self.cpp_info.components["MY_PKG"].requires = ["tool_to_be_installed_and_used::tool_to_be_installed_and_used"]