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

libostree: add versioning macros #728

Closed
wants to merge 2 commits into from

Conversation

GeorgesStavracas
Copy link
Contributor

OSTree currently provides no way to inspect the versioning
information at run time, being only available at compile
time through pkg-config.

This is a problem for e.g. Flatpak, that needs to check
whether the 'update-frequency' option is available. Checking
at compile time isn't great since it's not looking for new
symbols, but only if an optional feature is present.

This pull request, then, adds a new header that is generated
at compile time, exposing OSTree's versioning information.

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor question, otherwise looks good. While it's not worth respinning for, I think general best practice nowadays is to only generate configure from configure.ac, and do everything else via sed in Makefile.am, like how we do for e.g. systemd unit files. But again, not worth respinning for.

#define OSTREE_VERSION_S "@VERSION@"

#define OSTREE_ENCODE_VERSION(year,release) \
((year) << 16 | (release) << 8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not (year) << 8 | (release) ?

Copy link
Member

@cgwalters cgwalters Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternatively if we want to allow ourselves more than 256 releases, (year) << 16 | (release) ?

@GeorgesStavracas GeorgesStavracas force-pushed the master branch 2 times, most recently from 12130b9 to 4554150 Compare March 10, 2017 17:53
@GeorgesStavracas
Copy link
Contributor Author

Fixed the shifting. I'm not sure why the builds are failing; I'm pretty sure the headers are being exported...

@cgwalters
Copy link
Member

cgwalters commented Mar 10, 2017

I think it's a srcdir != builddir issue; your new header will live in the builddir. So we have to duplicate all the makefile includes to do e.g.:

diff --git a/Makefile-ostree.am b/Makefile-ostree.am
index 0b520c6..0c15cf5 100644
--- a/Makefile-ostree.am
+++ b/Makefile-ostree.am
@@ -105,6 +105,7 @@ EXTRA_DIST += src/ostree/parse-datetime.y
 CLEANFILES += src/ostree/parse-datetime.c
 
 ostree_bin_shared_cflags = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree \
+  -I$(builddir)/src/libostree \
 	-I$(srcdir)/src/ostree -I$(srcdir)/libglnx $(OT_INTERNAL_GIO_UNIX_CFLAGS) \
 	-DPKGLIBEXECDIR=\"$(pkglibexecdir)\"
 ostree_bin_shared_ldadd = $(AM_LDFLAGS) libglnx.la libotutil.la libostree-1.la \

@GeorgesStavracas GeorgesStavracas force-pushed the master branch 3 times, most recently from 3fd2c37 to 51a95c4 Compare March 10, 2017 19:58
@@ -34,7 +34,7 @@ DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml
# gtk-doc will search all .c & .h files beneath here for inline comments
# documenting the functions and macros.
# e.g. DOC_SOURCE_DIR=../../../gtk
DOC_SOURCE_DIR=$(top_srcdir)/src/libostree
DOC_SOURCE_DIR=$(top_builddir)/src/libostree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be top_srcdir, no?

*/
#define OSTREE_CHECK_VERSION(year,release) \
(OSTREE_YEAR_VERSION > (year) || \
(OSTREE_YEAR_VERSION == (year) && OSTREE_RELEASE_VERSION > (release)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think I would prefer the semantic for this to be >=. E.g.: https://github.com/libvirt/libvirt/blob/master/include/libvirt/libvirt-common.h.in#L87

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really cool addition BTW!

*
* ostree year version component (e.g. 2017 if %OSTREE_VERSION is 2017.2)
*/
#define OSTREE_YEAR_VERSION (@YEAR_VERSION@)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this information be exported with a function so that it is evaluated after the library is loaded? Otherwise, IMHO, it adds not much more value than pkg-config --modversion

@cgwalters
Copy link
Member

cgwalters commented Mar 10, 2017

@giuseppe You're 100% correct in that this PR is for a user who wants runtime dependency, and this is compile time only.

However, two things. First, I think this is nicer for compile time checking than pkg-config --modversion since one doesn't need to mess with autoconf in configure.ac (or I guess theoretically Makefile.am conditionals) in the consuming projects - you just do #ifdef FOO_CHECK_VERSION(42, 3) at each call site naturally. (Like we do with our use of libcurl today)

Second, doing compile time checking is a prerequisite IMO for having the runtime equivalent - we should steal the code from glib I'd say.

@cgwalters
Copy link
Member

@GeorgesStavracas If you want I can fix it, I have a lot of autogoop experience, just let me know.

@giuseppe
Copy link
Member

@cgwalters sure, I didn't mean to block the PR. At the time these new macros will be available though, we can assume all the previous features are available as well. Just wanted to point out to @GeorgesStavracas that if he needs to check a particular feature not available in older versions, he could use PKG_CHECK_MODULES to check for it.

OSTree currently provides no way to inspect the versioning
information at run time, being only available at compile
time through pkg-config.

This is a problem for e.g. Flatpak, that needs to check
whether the 'update-frequency' option is available. Checking
at compile time isn't great since it's not looking for new
symbols, but only if an optional feature is present.

This commit, then, adds a new header that is generated
at compile time, exposing OSTree's versioning information.
@GeorgesStavracas
Copy link
Contributor Author

@cgwalters would be great if you could fix that, but more important than the fix itself, I'm curious to learn what's failing, and why. I'm obviously missing something related to the tests project files, for it only breaks when ci_test=yes.

@cgwalters
Copy link
Member

I pushed a fixup! ⬆️

@rh-atomic-bot r+ ad2fb44

@rh-atomic-bot
Copy link

⌛ Testing commit ad2fb44 with merge f24da79...

rh-atomic-bot pushed a commit that referenced this pull request Mar 11, 2017
OSTree currently provides no way to inspect the versioning
information at run time, being only available at compile
time through pkg-config.

This is a problem for e.g. Flatpak, that needs to check
whether the 'update-frequency' option is available. Checking
at compile time isn't great since it's not looking for new
symbols, but only if an optional feature is present.

This commit, then, adds a new header that is generated
at compile time, exposing OSTree's versioning information.

Closes: #728
Approved by: cgwalters
@rh-atomic-bot
Copy link

💔 Test failed - status-atomicjenkins

@cgwalters
Copy link
Member

Sigh, need to get libsoup patches out.

@rh-atomic-bot retry

@rh-atomic-bot
Copy link

⌛ Testing commit ad2fb44 with merge fda4a47...

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: cgwalters
Pushing fda4a47 to master...

cgwalters added a commit to cgwalters/ostree that referenced this pull request Mar 13, 2017
[Previously](ostreedev#728) we added compile-time
checking for versions, but there are use cases for runtime checking as well,
because in a number of API calls we use `GVariant` as an API extension
mechanism.
@cgwalters
Copy link
Member

Followup in #735

rh-atomic-bot pushed a commit that referenced this pull request Mar 13, 2017
[Previously](#728) we added compile-time
checking for versions, but there are use cases for runtime checking as well,
because in a number of API calls we use `GVariant` as an API extension
mechanism.

Closes: #735
Approved by: jlebon
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

Successfully merging this pull request may close these issues.

5 participants