Skip to content

Commit

Permalink
[bcc] Add macros to check libbcc version
Browse files Browse the repository at this point in the history
Summary: Currently, libbcc only exposes its version via a string constant.
This makes it complicated for libraries built on top of libbcc to be compatible across multiple versions when there is API changes for instances, as happens in iovisor/gobpf#311

Exposing MAJOR/MINOR/PATCH versions would allow libraries which are not shipped as part of iovisor/bcc to handle those API changes.

This diffs exposes those values, provides a macro to perform version comparison (a la `LINUX_VERSION()`).

One thing it does not address currently is exposing whether this is an "exact tag" version, e.g a release, or in between releases.

Test plan:

When building:
```
-- Latest recognized Git tag is v0.24.0
-- Git HEAD is f26cdb33068187d04d9dc058834985df841e28fa
-- Revision is 0.24.0-f26cdb33 (major 0, minor 24, patch 0)
-- Found LLVM: /usr/lib/llvm-11/include 11.1.0 (Use LLVM_ROOT envronment variable for another version of LLVM)
...
...
```

and the produced `bcc_version.h`:
```
$ cat build/src/cc/bcc_version.h

```
  • Loading branch information
chantra authored and yonghong-song committed Jul 21, 2022
1 parent d109d58 commit 83a379e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ else()
set(REVISION_LAST "${REVISION}")
endif()

if (REVISION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
set(REVISION_MAJOR ${CMAKE_MATCH_1})
set(REVISION_MINOR ${CMAKE_MATCH_2})
set(REVISION_PATCH ${CMAKE_MATCH_3})
else()
message(WARNING "Could not extract major/minor/patch from revision ${REVISION}" )
endif()
# strip leading 'v', and make unique for the tag
message(STATUS "Revision is ${REVISION}")
message(STATUS "Revision is ${REVISION} (major ${REVISION_MAJOR}, minor ${REVISION_MINOR}, patch ${REVISION_PATCH})")
7 changes: 7 additions & 0 deletions src/cc/bcc_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@
#define LIBBCC_VERSION_H

#define LIBBCC_VERSION "@REVISION@"
#define LIBBCC_MAJOR_VERSION @REVISION_MAJOR@
#define LIBBCC_MINOR_VERSION @REVISION_MINOR@
#define LIBBCC_PATCH_VERSION @REVISION_PATCH@

#define __LIBBCC_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + ((c) > 255 ? 255 : (c)))
#define LIBBCC_VERSION_CODE __LIBBCC_VERSION(LIBBCC_MAJOR_VERSION, LIBBCC_MINOR_VERSION, LIBBCC_PATCH_VERSION)
#define LIBBCC_VERSION_GEQ(a,b,c) LIBBCC_VERSION_CODE >= __LIBBCC_VERSION(a, b, c)

#endif

0 comments on commit 83a379e

Please sign in to comment.