-
Notifications
You must be signed in to change notification settings - Fork 993
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
Add detect_gnu_libc() and detect_musl_libc() functions #15683
Conversation
This documents the functions added in conan-io/conan#15683.
Not sure the best way to add some automated unit tests for these functions, particularly since they are only applicable under Linux and need to run on a Linux system, unless I mock out |
This PR adds a simple function to detect the version of glibc to the detect_api. This functionality is only intended for Linux systems using glibc. The function is detect_gnu_libc(). It simply runs ldd --version to detect the version of glibc. It is also possible to detect the version of the libc library by running the libc.so file. The location of this library varies much more than the path to ldd, so ldd --version is used instead. The path to ldd is passed as an argument, /usr/bin/ldd by default. This can modified to suite alternate sysroots. It can even be used in cross-compilation scenarios where emulation is available to execute ldd. The detect_gnu_libc function does a simple sanity check to verify that glibc is indeed being used. This avoids confusion on systems using an alternative libc implementation, i.e. musl. I also added a function to detect the version of the musl libc library as well. This function is detect_musl_libc() and works the same way. Addresses conan-io#3972, at least in part.
f0f11d1
to
06f735b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for your contribution @jwillikers
It is true that testing these is typically not easy.
I would test it very similarly to TestProfileDetectAPI
in "functional" tests, without a strict validation of the specific return version, just checking that it doesn't crash and return a version is fine. For the musl
that will not be in CI, checking that it returns None without crashing would be enough, as long as you test it locally and works for you.
conan/internal/api/detect_api.py
Outdated
return None | ||
|
||
|
||
def detect_musl_libc(ldd="/usr/bin/ldd"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally looks good, but it would be necessary to understand the usage patterns, which can be made explicit in a test.
Maybe it is better just a single function that returns libc, version = detect_api.detect_libc()
, so libc
gets the value glibc
or musl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's definitely possible and seems useful. I think it might imply the scope applies to more than just Linux, however, since macOS, BSD*, and Windows are all going to have their own libc implementation. I guess the functionality could always be expanded in the future, but it is quite nice to be able to pass ldd
as an argument, too. I'll work on getting the tests sorted out tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly, I think it can be expanded in the future in different forms like detect_api.detect_osx_libc()
, via a new argument, or just by adding functionality if we are sure it will not break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I've added a detect_libc
function to be used instead of ones for the individual C libraries which returns a tuple of the name, i.e. gnu
or musl
, and the version.
I broke out the actual parsing logic into separate functions and added unit tests for this logic using the output of the ldd
command.
I added a functional test for the detect_libc
function.
These just check that the functions run without errors. This avoids assumptions about what C library is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a minor detail about returning None
instead of None, None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, many thanks!
Merging this for next release 2.2.
I'd recommend documenting this as "experimental", we might discover cases we didn't think about it when other users use it.
* Document detect_glib_libc() and detect_musl_libc() functions This documents the functions added in conan-io/conan#15683. * Document the detect_libc() function * Revert "Document detect_glib_libc() and detect_musl_libc() functions" This reverts commit b4f58e8. * Mark detect_libc as experimental
Changelog: Feature: Add
detect_libc
to thedetect_api
to get the name and version of the C library.Docs: conan-io/docs#3590
This PR adds a simple function to detect the version of glibc to the detect_api. This functionality is only intended for Linux systems using glibc. The function is detect_gnu_libc().
It simply runs ldd --version to detect the version of glibc. It is also possible to detect the version of the libc library by running the libc.so file. The location of this library varies much more than the path to ldd, so ldd --version is used instead. The path to ldd is passed as an argument, /usr/bin/ldd by default. This can modified to suite alternate sysroots.
It can even be used in cross-compilation scenarios where emulation is available to execute ldd.
The detect_gnu_libc function does a simple sanity check to verify that glibc is indeed being used. This avoids confusion on systems using an alternative libc implementation, i.e. musl.
I also added a function to detect the version of the musl libc library as well. This function is detect_musl_libc() and works the same way.
Addresses #3972, at least in part.
develop
branch, documenting this one.