Skip to content

Commit

Permalink
Merge pull request #534 from jgunthorpe/build-fixes
Browse files Browse the repository at this point in the history
Fix sparse in travis
  • Loading branch information
jgunthorpe authored May 28, 2019
2 parents 143df0a + 4d12df1 commit 9b8e220
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 33 deletions.
71 changes: 48 additions & 23 deletions buildlib/gen-sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import collections
import re
import itertools

headers = {
"bits/sysmacros.h",
Expand Down Expand Up @@ -45,26 +46,39 @@ def find_system_header(args,hdr):
fn = os.path.join(incdir,hdr)
if os.path.exists(fn):
return fn
raise ValueError("Could not find system include directory.");
return None;

def get_buildlib_patches(dfn):
"""Within the buildlib directory we store patches for the glibc headers. Each
patch is in a numbered sub directory that indicates the order to try, the
number should match the glibc version used to make the diff."""
res = [];
ver_hdrs = [];
all_hdrs = []
for d,_,files in os.walk(dfn):
for I in files:
if d != dfn:
bn = int(os.path.basename(d));
else:
bn = 0;

res.append((bn,os.path.join(d,I)));
res.sort(reverse=True);

ret = collections.defaultdict(list);
for _,I in res:
ret[norm_header(I)].append(I);
if bn == 0:
all_hdrs.append(os.path.join(d,I));
else:
ver_hdrs.append((bn,os.path.join(d,I)));
ver_hdrs.sort(reverse=True);

def add_to_dict(d,lst):
for I in lst:
nh = norm_header(I)
assert nh not in d
d[nh] = (I, find_system_header(args,nh))

ret = []
for k,g in itertools.groupby(ver_hdrs,key=lambda x:x[0]):
dd = {}
ret.append(dd)
add_to_dict(dd,(I for _,I in g))
add_to_dict(dd,all_hdrs)
return ret;

def is_patch(fn):
Expand All @@ -74,6 +88,9 @@ def is_patch(fn):
def apply_patch(src,patch,dest):
"""Patch a single system header. The output goes into our include search path
and takes precedence over the system version."""
if src is None:
return False

dfn = os.path.dirname(dest);
if not os.path.isdir(dfn):
os.makedirs(dfn);
Expand All @@ -97,17 +114,25 @@ def apply_patch(src,patch,dest):
return False;
return True;

def replace_header(fn):
tries = 0;
for pfn in patches[fn]:
if apply_patch(find_system_header(args,fn),
pfn,os.path.join(args.INCLUDE,fn)):
return;
tries = tries + 1;
def replace_headers(suite):
# Local system does not have the reference system header, this suite is
# not supported
for fn,pfn in suite.items():
if pfn[1] is None:
return False;

for fn,pfn in suite.items():
if not apply_patch(pfn[1],pfn[0],os.path.join(args.INCLUDE,fn)):
break;
else:
return True;

print("Unable to apply any patch to %r, tries %u"%(fn,tries));
global failed;
failed = True;
for fn,_ in suite.items():
try:
os.unlink(os.path.join(args.INCLUDE,fn))
except OSError:
continue;
return False;

def save(fn,outdir):
"""Diff the header file in our include directory against the system header and
Expand Down Expand Up @@ -154,9 +179,9 @@ def save(fn,outdir):
save(I,outdir);
else:
failed = False;
patches = get_buildlib_patches(os.path.join(args.SRC,"buildlib","sparse-include"));
for I in headers:
replace_header(I);

if failed:
suites = get_buildlib_patches(os.path.join(args.SRC,"buildlib","sparse-include"));
for I in suites:
if replace_headers(I):
break;
else:
raise ValueError("Patch applications failed");
1 change: 0 additions & 1 deletion ibacm/linux/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <malloc.h>
#include <sys/time.h>

#include <ccan/minmax.h>
Expand Down
1 change: 0 additions & 1 deletion providers/bnxt_re/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <signal.h>
#include <errno.h>
#include <pthread.h>
#include <malloc.h>
#include <sys/mman.h>
#include <netinet/in.h>
#include <unistd.h>
Expand Down
1 change: 0 additions & 1 deletion providers/bnxt_re/verbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <signal.h>
#include <errno.h>
#include <pthread.h>
#include <malloc.h>
#include <sys/mman.h>
#include <netinet/in.h>
#include <unistd.h>
Expand Down
1 change: 0 additions & 1 deletion providers/efa/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <assert.h>
#include <errno.h>
#include <malloc.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 0 additions & 1 deletion providers/mlx5/dr_action.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
*/

#include <unistd.h>
#include <malloc.h>
#include <arpa/inet.h>
#include <ccan/array_size.h>
#include "mlx5dv_dr.h"
Expand Down
1 change: 0 additions & 1 deletion providers/mlx5/dr_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
*/

#include <unistd.h>
#include <malloc.h>
#include <stdlib.h>
#include "mlx5dv_dr.h"

Expand Down
1 change: 0 additions & 1 deletion providers/mlx5/dr_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
#include <util/mmio.h>
#include "mlx5dv_dr.h"
Expand Down
1 change: 0 additions & 1 deletion providers/ocrdma/ocrdma_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <signal.h>
#include <errno.h>
#include <pthread.h>
#include <malloc.h>
#include <sys/mman.h>
#include <unistd.h>
#include <endian.h>
Expand Down
1 change: 0 additions & 1 deletion providers/qedr/qelr_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <signal.h>
#include <errno.h>
#include <pthread.h>
#include <malloc.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdbool.h>
Expand Down
2 changes: 1 addition & 1 deletion pyverbs/device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cdef extern from 'stdlib.h':
void free(void *ptr)
cdef extern from 'string.h':
void *memset(void *s, int c, size_t n)
cdef extern from 'malloc.h':
cdef extern from 'stdlib.h':
void *malloc(size_t size)
cdef extern from 'stdint.h':
ctypedef int uint64_t
Expand Down

0 comments on commit 9b8e220

Please sign in to comment.