[PATCH rdma-core 5/7] build: Revise how gen-sparse finds the system headers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jason Gunthorpe <jgg@xxxxxxxxxxxx>

When the compiler is configured for true multi-arch the system headers are
not in /usr/include anymore, but in one of the arch specific directories.

Get gcc to give the include search path and look along that path for the
system header location for patching.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
---
 buildlib/RDMA_Sparse.cmake |  1 +
 buildlib/gen-sparse.py     | 30 ++++++++++++++++++++++++++----
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/buildlib/RDMA_Sparse.cmake b/buildlib/RDMA_Sparse.cmake
index 3d03ce6283eec4..72581fe5ceb9cf 100644
--- a/buildlib/RDMA_Sparse.cmake
+++ b/buildlib/RDMA_Sparse.cmake
@@ -22,6 +22,7 @@ int main(int argc,const char *argv[]) {return 0;}
     execute_process(COMMAND "${PYTHON_EXECUTABLE}" "${BUILDLIB}/gen-sparse.py"
       "--out" "${BUILD_INCLUDE}/"
       "--src" "${CMAKE_SOURCE_DIR}/"
+      "--cc" "${CMAKE_C_COMPILER}"
       RESULT_VARIABLE retcode)
     if(NOT "${retcode}" STREQUAL "0")
       message(FATAL_ERROR "glibc header file patching for sparse failed. Review include/*.rej and fix the rejects, then do "
diff --git a/buildlib/gen-sparse.py b/buildlib/gen-sparse.py
index 67e64de3202331..fe428b42a97462 100755
--- a/buildlib/gen-sparse.py
+++ b/buildlib/gen-sparse.py
@@ -5,6 +5,7 @@ import argparse
 import subprocess
 import os
 import collections
+import re
 
 headers = {
     "bits/sysmacros.h",
@@ -25,6 +26,27 @@ def norm_header(fn):
             return I;
     return None;
 
+def find_system_header(args,hdr):
+    """/usr/include is not always where the include files are, particularly if we
+    are running full multi-arch as the azure_pipeline container does. Get gcc
+    to tell us where /usr/include is"""
+    if "incpath" not in args:
+        cpp = subprocess.check_output([args.cc, "-print-prog-name=cpp"],universal_newlines=True).strip()
+        data = subprocess.check_output([cpp, "-v"],universal_newlines=True,stdin=subprocess.DEVNULL,
+                                       stderr=subprocess.STDOUT)
+        args.incpath = [];
+        for incdir in re.finditer(r"^ (/\S+)$", data, re.MULTILINE):
+            incdir = incdir.group(1)
+            if "fixed" in incdir:
+                continue;
+            args.incpath.append(incdir)
+
+    for incdir in args.incpath:
+        fn = os.path.join(incdir,hdr)
+        if os.path.exists(fn):
+            return fn
+    raise ValueError("Could not find system include directory.");
+
 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
@@ -78,7 +100,7 @@ def apply_patch(src,patch,dest):
 def replace_header(fn):
     tries = 0;
     for pfn in patches[fn]:
-        if apply_patch(os.path.join(args.REF,fn),
+        if apply_patch(find_system_header(args,fn),
                        pfn,os.path.join(args.INCLUDE,fn)):
             return;
         tries = tries + 1;
@@ -100,7 +122,7 @@ def save(fn,outdir):
     with open(flatfn,"wt") as F:
         try:
             subprocess.check_call(["diff","-u",
-                                   os.path.join(args.REF,fn),
+                                   find_system_header(args,fn),
                                    os.path.join(args.INCLUDE,fn)],
                                   stdout=F);
         except subprocess.CalledProcessError as ex:
@@ -113,8 +135,8 @@ parser.add_argument("--out",dest="INCLUDE",required=True,
                     help="Directory to write header files to");
 parser.add_argument("--src",dest="SRC",required=True,
                     help="Top of the source tree");
-parser.add_argument("--ref",dest="REF",default="/usr/include/",
-                    help="System headers to manipulate");
+parser.add_argument("--cc",default="gcc",
+                    help="System compiler to use to locate the default system headers");
 parser.add_argument("--save",action="store_true",default=False,
                     help="Save mode will write the current content of the headers to buildlib as a diff.");
 args = parser.parse_args();
-- 
2.21.0




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux