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

Greater-than comparison of an unknown version yields true #4329

Closed
ernestask opened this issue Oct 5, 2018 · 8 comments
Closed

Greater-than comparison of an unknown version yields true #4329

ernestask opened this issue Oct 5, 2018 · 8 comments

Comments

@ernestask
Copy link
Contributor

Trying to build tracker-miners with some dependencies missing results in rather interesting errors. I’m missing libcue-devel in my Fedora installation, but the support for it is optional, depending on whether it was found and which version was found: https://gitlab.gnome.org/GNOME/tracker-miners/blob/f9e7de0fe0549b009defc68ba37ba2516a03f49c/meson.build#L317, however, the code ends up trying to include one of the headers anyway.

Adding a debug print for libcue.version() yields “unknown”, but then printing libcue.version() >= '2.0.0' results in “True”.

@ernestask
Copy link
Contributor Author

I guess one could argue that there should be another libcue.found() check, but I’m thinking that “unknown” version comparisons should always be false.

@ernestask
Copy link
Contributor Author

I forgot to mention that the version I’m using right now is 0.48.0.

@jon-turney
Copy link
Member

conf.set('HAVE_LIBCUE2', libcue.version() >= '2.0.0')

This is a string comparison. I guess libcue.version().version_compare('>=2.0.0') is what's meant, but I'm not sure that will work as expected.

but I’m thinking that “unknown” version comparisons should always be false.

Yeah, I agree. That's implemented for dependency(version:) constraints (6a4c2d6), but I don't think version_compare does the right thing forunknown yet.

@ernestask
Copy link
Contributor Author

This is a string comparison. I guess libcue.version().version_compare('>=2.0.0') is what's meant, but I'm not sure that will work as expected.

Oh, so it is, I totally forgot about that.

@ernestask
Copy link
Contributor Author

It seems to do the right thing, thanks! And sorry for the noise.

@jon-turney
Copy link
Member

It seems to do the right thing, thanks!

I think version_compare() only happens to work here because it compares the first element of the versions (unknown and 2) and considers alphabetic elements less than numeric ones.

This won't work as expected ('“unknown” version comparisons should always be false') if the comparision was the other way round e.g. 'unknown'.version_compare('<=2.0.0'), or when applied to a version where the first element is alphabetic. e.g. 'unknown'.version_compare('>=alpha').

And sorry for the noise.

No problem. Thanks for raising this issue.

@ernestask
Copy link
Contributor Author

I think version_compare() only happens to work here because it compares the first element of the versions (unknown and 2) and considers alphabetic elements less than numeric ones.

Yeah, I see it now:

if self._v[i].isdigit() != other._v[i].isdigit():

This won't work as expected ('“unknown” version comparisons should always be false') if the comparision was the other way round e.g. 'unknown'.version_compare('<=2.0.0'), or when applied to a version where the first element is alphabetic. e.g. 'unknown'.version_compare('>=alpha').

Was there ever a discussion about such cases and whether version() on a dependency that hasn’t been found should return a value? Seems easier than making sure that version comparison works intuitively 100% of the time.

@ernestask
Copy link
Contributor Author

Maybe a special Version object could be returned that unconditionally returns false in __cmp__() et al.

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

No branches or pull requests

2 participants