@@ -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 "
@@ -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();