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

[question] Conan-2.x and global.conf #13798

Closed
1 task done
maitrey opened this issue May 2, 2023 · 21 comments
Closed
1 task done

[question] Conan-2.x and global.conf #13798

maitrey opened this issue May 2, 2023 · 21 comments
Assignees

Comments

@maitrey
Copy link
Contributor

maitrey commented May 2, 2023

What is your question?

Dear Conan Folks,

I just started to use Conan-2.x. I am using : Conan version 2.0.4.
I have a couple of questions:

  1. After installing , I do not find the global.conf in CONAN_HOME directory. Do I need to create it ? I expected there shall be a default one created which can be edited.
  2. I used to have this set with conan-1.56 in the profiles section:
    [conf] tools.cmake.cmaketoolchain:generator=MinGW Makefiles
    I tried to port this to self written global.conf but this fails with "Error in Conan initialization: Bad conf definition: [conf]"
    If I leave it in the profile , it still fails with : 'cmake' is not recognized as an internal or external command,
    operable program or batch file.
    While I explicilty set in profiles:
    PATH+=C:/Tools/MinGW/4.8.1/bin; C:/Program Files/CMake/bin

Somewhere I am missing something. Could someone give me a hint please?
Many thanks for your help.

Thanks!
Br,
Maitrey

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this May 2, 2023
@memsharded
Copy link
Member

Hi @maitrey

Thanks for your questions.

  1. this has been changed in next 2.0.5: auto create default global.conf #13746. At the moment you need to create it manually, from 2.0.5 it will be auto-created
  2. The global.conf doesn't have the [conf] declaration, as everything is a conf (the auto-created global.conf will help with it, as it will have some comments). So you can remove the [conf] line, and it should work.

@maitrey
Copy link
Contributor Author

maitrey commented May 2, 2023

Hi James,

Thanks a lot for your reply.
Ok I could remove the conf section however, I still could not get the builds working.
CMAKE_SH="CMAKE_SH-NOTFOUND" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Debug" "C:\Users\user.conan2\p\t\qasw86de269f0299e\b."
'cmake' is not recognized as an internal or external command,
operable program or batch file.
But I do have cmake in PATH environment variable and explicitly also set in the profiles like this:
PATH=[C:/Tools/MinGW/4.8.1/bin, C:/Program Files/CMake/bin ]
What am I still missing? Could you please help me?

@memsharded
Copy link
Member

In profiles you should be setting something like:

[buildenv]
PATH+=(path)C:/Tools/MinGW/4.8.1/bin
PATH+=(path)C:/Program Files/CMake/bin

It is important to give the (path) qualifier, and use 1 addition per line, so it doesn't hardcode the ; path separation assumption, that might not hold for some Windows subsystems.

@maitrey
Copy link
Contributor Author

maitrey commented May 3, 2023

Now it worked! Thanks James.
I have one another question:

  • In Conan-2.x why are the package names changed to lower case?

@memsharded
Copy link
Member

In Conan-2.x why are the package names changed to lower case?

To avoid typo-squatting security attacks, someone trying to replace boost/1.80 with Boost/1.80 (if we make it globally case-sensitive), or to avoid unnecessary confusion and complexity if it was case-insensitive, like boost, Boost and BOOST being all the same, making everything more complex and slower.

We have already been using lowercase for years in ConanCenter, and it was already approved by the tribe 2 years ago: conan-io/tribe#17

@maitrey
Copy link
Contributor Author

maitrey commented May 3, 2023

Okay thanks James for answering my questions.
When I use the export method as replacement of the scm attribute:
def export(self):
git = Git(self, self.recipe_folder)
scm_url, scm_commit = git.get_url_and_commit()
update_conandata(self, {"sources": {"commit": scm_commit, "url": scm_url}})
I have not commited my changes into my remote, I get the error:
Error in export() method, line 49
scm_url, scm_commit = git.get_url_and_commit()
ConanException: Repo is dirty, cannot capture url and commit: C:\Projects\qasw

I donot want to check in yet as I have not yet tested my changes locally.
I would like to test locally before checking in.
How to handle this ? Can I use the export method at all for well tested commits?

@memsharded
Copy link
Member

I have not commited my changes into my remote, I get the error:

It shouldn't be necessary to push the changes to the remote.
Just a local commit to test will make it, and Conan will use as origin url the local clone, it will not go to the server. After things work locally, those local commits can be squashed, before pushing to the server.

@maitrey
Copy link
Contributor Author

maitrey commented May 3, 2023

Thanks again. On succesful creation of a package with 2.x, I get this message:
Package folder C:\Users.conan2\p\qasw0a63b8c55927c\p
{'cmakedeps_macros.cmake': '\nmacro(conan_find_apple_frameworks FRAMEWORKS_FOUND FRAMEWORKS FRAMEWORKS_DIRS)\n if(APPLE)\n foreach(FRAMEWORK ${FRAMEWORKS})\n # https://cmake.org/pipermail/cmake-developers/2017-August/030199.html\n find_library(CONAN_FRAMEWORK${_FRAMEWORK}_FOUND NAMES ${FRAMEWORK} PATHS ${FRAMEWORKS_DIRS} CMAKE_FIND_ROOT_PATH_BOTH)\n if(CONAN_FRAMEWORK${_FRAMEWORK}FOUND)\n list(APPEND ${FRAMEWORKS_FOUND} ${CONAN_FRAMEWORK${_FRAMEWORK}_FOUND})\n message(VERBOSE "Framework found! ${FRAMEWORKS_FOUND}")\n else()\n message(FATAL_ERROR "Framework library ${_FRAMEWORK} not found in paths: ${FRAMEWORKS_DIRS}")\n endif()\n endforeach()\n endif()\nendmacro()\n\n\nfunction(conan_package_library_targets libraries package_libdir package_bindir library_type\n is_host_windows deps_target out_libraries_target config_suffix package_name no_soname_mode)\n set(_out_libraries_target "")\n\n foreach(_LIBRARY_NAME ${libraries})\n find_library(CONAN_FOUND_LIBRARY NAMES ${_LIBRARY_NAME} PATHS ${package_libdir}\n NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)\n if(CONAN_FOUND_LIBRARY)\n message(VERBOSE "Conan: Library ${LIBRARY_NAME} found ${CONAN_FOUND_LIBRARY}")\n\n # Create a micro-target for each lib/a found\n # Allow only some characters for the target name\n string(REGEX REPLACE "[^A-Za-z0-9.+_-]" "" _LIBRARY_NAME ${_LIBRARY_NAME})\n set(LIB_NAME CONAN_LIB::${package_name}${_LIBRARY_NAME}${config_suffix})\n\n if(is_host_windows AND library_type STREQUAL "SHARED")\n set(CMAKE_FIND_LIBRARY_SUFFIXES .dll ${CMAKE_FIND_LIBRARY_SUFFIXES})\n find_library(CONAN_SHARED_FOUND_LIBRARY NAMES ${_LIBRARY_NAME} PATHS ${package_bindir}\n NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)\n if(NOT CONAN_SHARED_FOUND_LIBRARY)\n message(STATUS "Cannot locate shared library: ${_LIBRARY_NAME}")\n message(DEBUG "DLL library not found, creating UNKNOWN IMPORTED target")\n if(NOT TARGET ${_LIB_NAME})\n add_library(${_LIB_NAME} UNKNOWN IMPORTED)\n endif()\n set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_FOUND_LIBRARY})\n else()\n if(NOT TARGET ${_LIB_NAME})\n add_library(${_LIB_NAME} SHARED IMPORTED)\n endif()\n set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_SHARED_FOUND_LIBRARY})\n set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_IMPLIB ${CONAN_FOUND_LIBRARY})\n message(DEBUG "Found DLL and STATIC at ${CONAN_SHARED_FOUND_LIBRARY}, ${CONAN_FOUND_LIBRARY}")\n endif()\n unset(CONAN_SHARED_FOUND_LIBRARY CACHE)\n else()\n if(NOT TARGET ${_LIB_NAME})\n # library_type can be STATIC, still UNKNOWN (if no package type available in the recipe) or SHARED (but no windows)\n add_library(${_LIB_NAME} ${library_type} IMPORTED)\n endif()\n message(DEBUG "Created target ${_LIB_NAME} ${library_type} IMPORTED")\n set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_FOUND_LIBRARY} IMPORTED_NO_SONAME ${no_soname_mode})\n endif()\n # Link library file\n set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY})\n list(APPEND _out_libraries_target ${_LIB_NAME})\n message(VERBOSE "Conan: Found: ${CONAN_FOUND_LIBRARY}")\n else()\n message(FATAL_ERROR "Library '${_LIBRARY_NAME}' not found in package. If '${_LIBRARY_NAME}' is a system library, declare it with 'cpp_info.system_libs' property")\n endif()\n unset(CONAN_FOUND_LIBRARY CACHE)\n endforeach()\n\n # Add the dependencies target for all the imported libraries\n foreach(_T ${_out_libraries_target})\n set_property(TARGET ${_T} PROPERTY INTERFACE_LINK_LIBRARIES ${deps_target} APPEND)\n endforeach()\n\n set(${out_libraries_target} ${_out_libraries_target} PARENT_SCOPE)\nendfunction()\n\nmacro(check_build_type_defined)\n # Check that the -DCMAKE_BUILD_TYPE argument is always present\n get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)\n if(NOT isMultiConfig AND NOT CMAKE_BUILD_TYPE)\n message(FATAL_ERROR "Please, set the CMAKE_BUILD_TYPE variable when calling to CMake "\n "adding the '-DCMAKE_BUILD_TYPE=<build_type>' argument.")\n endif()\nendmacro()\n'}

How can I disable the bold parts? I want to know if package was succesfully created or failed as it was with Conan-1.x.

@memsharded
Copy link
Member

Not sure what is that, it seems that someone (maybe the conanfile.py recipe?) is printing the contents of the generated files, but that is not expected. If you can share some minimal example to reproduce and get that output, it would help.

@maitrey
Copy link
Contributor Author

maitrey commented May 3, 2023

The recipe is very simple and its a header only library.

from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.cmake import cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.env import VirtualRunEnv
from conan.errors import ConanException
from conan.tools.files import load, update_conandata


class QASW(ConanFile):
    name = 'qasw'
    url  = 'https://github.com/qasw.git'
    exports_sources = "include/*", "CMakeLists.txt", "LICENSE"
    settings =  "os", "compiler", "arch", "build_type"
    author = "Maitrey Mishra"
    options = {"tests": ["true", "false"]}
    default_options = {"qasw/*:tests": "false"}
    package_type = "header-library"

    def export(self):
        git = Git(self, self.recipe_folder)
        scm_url, scm_commit = git.get_url_and_commit()
        update_conandata(self, {"sources": {"commit": scm_commit, "url": scm_url}})

    def layout(self):
        cmake_layout(self)

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        print(deps.content)
        tc = CMakeToolchain(self)
        tc.generate()
        
    def build(self): 
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.install()
    
    def package_info(self):
        self.cpp_info.includedirs = ['include'] `

@memsharded
Copy link
Member

You are printing it yourself in print(deps.content) 😄

@maitrey
Copy link
Contributor Author

maitrey commented May 3, 2023

This is silly really from my end. Sorry about that.
Last question for today:
What is the recommended visual studio code extension for conan and for eclipse IDE?

@memsharded
Copy link
Member

This is silly really from my end. Sorry about that.

NP! :)

For VS Code, probably the standard CMake extension with CMakePresets is good, we have tested and seems to be working well. So terminal conan install ... + VSCode CMake integration seems a good combination.

For Eclipse IDE I don't know, does it have a CMake integration too? There is no Conan extension that we are aware.

@maitrey
Copy link
Contributor Author

maitrey commented May 4, 2023

@memsharded
Copy link
Member

Not at this moment, we don't know what is the status of those extensions, so not possible to recommend any. It is even likely that many of those are still not ready for 2.0, but we really don't know.
What is the problem you are trying to solve with an extension? To avoid typing conan install? I was recommending the cmake one, because for normal usage we find it pretty convenient to do the conan install and then just pick the presets.

@maitrey
Copy link
Contributor Author

maitrey commented May 4, 2023

My automation uses:
conan create . --user autosar --channel bringupconan2.x -pr:b=default -pr:h=hightec-compiler -o tests=False
All the conan commands are wrapped in a build.py. build.py is almost same for all packages as we have the same number of platform/variant combination for almost all packages. In future build.py will be a shared library that will read from a yaml file in every repository and call the conan commands.
But our colleagues use VSCode and some use Eclipse IDE and the idea is to give a good developer experience. Many of them donot know conan yet. Thats why we would like them to benefit from any extensions which have features like intellisense , directly pointing to the cache and such .

@memsharded
Copy link
Member

Most the extensions/plugin approach would be to call conan install to install dependencies, not to call conan create.

For such custom functionality, it seems you could leverage the Conan 2.0 custom commands: https://docs.conan.io/2/reference/extensions/custom_commands.html

For colleagues using other tools like Eclipse, which are unlikely to have any extension/plugin, probably the best is a script that can be executed in the project that does the necessary calls.

@maitrey
Copy link
Contributor Author

maitrey commented May 4, 2023

Thanks a lot for your help. Next problem I have is conan lock create .
{
"version": "0.5",
"requires": [],
"build_requires": [],
"python_requires": []
}
What is the version (in bold ) from? I see the same in the example: https://docs.conan.io/2.0/tutorial/versioning/lockfiles.html#tutorial-versioning-lockfiles
Also, I am a bit divided shall the conan.lock shall be a part of package in artifactory or the repository itself?
Could you please help ?

@memsharded
Copy link
Member

It is the format of the lockfile itself. Lockfiles format has evolved over time, and that is a way to catch mismatches, if you try to use a lockfile what was created in an older Conan version (1.X) and it is 0.4, it will give you an error. It will also error if in the future we change the version to 0.6 or greater

Lockfiles cannot easily be part of the package, I guess that you can do conan install then export the lockfile into the package or something like that. But one package can belong to more than one graph, so there is no 1:1 correspondence between packages and lockfiles, it would make sense only as "this was the lockfile used at the moment this was created".

So were to store lockfiles, depends on the usage you plan to do:

  • In many cases, lockfiles are a CI mechanism, and can be stored in the CI, or in any auxiliary place (like a side git repo or an Artifactory generic repo), but doesn't need to be together with the recipes
  • In "consumer" applications repositories, it could be in the git repo, no prob.
  • For conan packages, committing it to the git repo would make the revision change if using revision_mode = "scm", which would be undesirable, so better make sure that the lockfile is not being exported and the revision_mode is the default hash.

@maitrey
Copy link
Contributor Author

maitrey commented May 4, 2023

Thanks for answering all my questions. I am closing the ticket. Many thanks!

@memsharded
Copy link
Member

memsharded commented May 4, 2023

Happy to help! :)

Don't hesitate to open new tickets if you have further questions.

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

No branches or pull requests

2 participants