Last active
March 20, 2017 21:51
-
-
Save aldanor/ace2fba5b38a11ef815a730eeb9dde4e to your computer and use it in GitHub Desktop.
libpcap versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import fnmatch | |
import git | |
import os | |
import pprint | |
import pycparser | |
import subprocess | |
import tempfile | |
repo = git.Repo() | |
[master] = [branch for branch in repo.branches if branch.name == 'master'] | |
tags = [tag for tag in repo.tags if fnmatch.fnmatch(tag.name, 'libpcap-?.?.?') | |
and tag.name >= 'libpcap-0.8.1'] | |
# collect PCAP_API exports for all post-0.8 versions | |
api = collections.OrderedDict() | |
with tempfile.TemporaryDirectory() as tempdir: | |
git.Repo.clone_from('https://github.com/eliben/pycparser.git', | |
tempdir + '/pycparser') | |
fake_libc_include = tempdir + '/pycparser/utils/fake_libc_include' | |
output_file = tempdir + '/pcap.h' | |
for tag in tags: | |
repo.head.reference = tag | |
repo.head.reset(index=True, working_tree=True) | |
input_file = 'pcap/pcap.h' if os.path.isfile('pcap/pcap.h') else 'pcap.h' | |
subprocess.check_call(['gcc', '-E', input_file, '-o', output_file, | |
'-I', fake_libc_include, '-I', '.']) | |
header = pycparser.parse_file(output_file) | |
api[tag.name] = sorted(set(item.name for _, item in header.children() | |
if isinstance(item.type, pycparser.c_ast.FuncDecl) | |
and item.name.startswith('pcap_'))) | |
# ensure that all versions are backwards-compatible | |
for v1, v2 in zip(api, list(api)[1:]): | |
assert set(api[v1]).issubset(api[v2]) | |
# get API diffs between the versions | |
initial = api[list(api)[0]] | |
diffs = {v2: set(api[v2]).difference(api[v1]) | |
for v1, v2 in zip(api, list(api)[1:]) | |
if api[v2] != api[v1]} | |
pprint.pprint(initial) | |
pprint.pprint(diffs) |
Author
aldanor
commented
Mar 20, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment