Update kernel headers to v3.14.

Other changes:
- Modify update_all.py to skip ion header files when importing into aosp.
- Fix generate_uapi_headers.sh to handle imports from a linux-stable kernel.

Change-Id: I1ad81b9ccb063c21740f9875f2cc1238052cd4b3
diff --git a/libc/kernel/tools/generate_uapi_headers.sh b/libc/kernel/tools/generate_uapi_headers.sh
index 9eeb2a5..386159a 100755
--- a/libc/kernel/tools/generate_uapi_headers.sh
+++ b/libc/kernel/tools/generate_uapi_headers.sh
@@ -148,22 +148,28 @@
   exit 1
 fi
 
+if [[ -d "${KERNEL_DIR}/linux-stable" ]]; then
+  src_dir="linux-stable"
+else
+  src_dir="common"
+fi
+
 if [[ ${KERNEL_DOWNLOAD} -eq 1 ]]; then
   TMPDIR=$(mktemp -d /tmp/android_kernelXXXXXXXX)
   cd "${TMPDIR}"
   echo "Fetching android kernel source ${KERNEL_VERSION}"
   git clone https://android.googlesource.com/kernel/common.git
-  cd common
+  cd "${COMMON}"
   git checkout "${KERNEL_VERSION}"
   KERNEL_DIR="${TMPDIR}"
 elif [[ "${KERNEL_DIR}" == "" ]]; then
   echo "Must specify one of --use-kernel-dir or --download-kernel."
   exit 1
-elif [[ ! -d "${KERNEL_DIR}" ]] || [[ ! -d "${KERNEL_DIR}/common" ]]; then
-  echo "The kernel directory $KERNEL_DIR or $KERNEL_DIR/common does not exist."
+elif [[ ! -d "${KERNEL_DIR}" ]] || [[ ! -d "${KERNEL_DIR}/${src_dir}" ]]; then
+  echo "The kernel directory $KERNEL_DIR or $KERNEL_DIR/${src_dir} does not exist."
   exit 1
 else
-  cd "${KERNEL_DIR}/common"
+  cd "${KERNEL_DIR}/${src_dir}"
 fi
 
 if [[ ${SKIP_GENERATION} -eq 0 ]]; then
@@ -175,27 +181,27 @@
 fi
 
 # Copy all of the include/uapi files to the kernel headers uapi directory.
-copy_hdrs "${KERNEL_DIR}/common/include/uapi" "${ANDROID_KERNEL_DIR}/uapi"
+copy_hdrs "${KERNEL_DIR}/${src_dir}/include/uapi" "${ANDROID_KERNEL_DIR}/uapi"
 
 # Copy the staging files to uapi/linux.
-copy_hdrs "${KERNEL_DIR}/common/drivers/staging/android/uapi" \
+copy_hdrs "${KERNEL_DIR}/${src_dir}/drivers/staging/android/uapi" \
           "${ANDROID_KERNEL_DIR}/uapi/linux" "no-copy-dirs"
 
 # Copy the generated headers.
-copy_hdrs "${KERNEL_DIR}/common/include/generated/uapi" \
+copy_hdrs "${KERNEL_DIR}/${src_dir}/include/generated/uapi" \
           "${ANDROID_KERNEL_DIR}/uapi"
 
 for arch in "${ARCH_LIST[@]}"; do
   # Copy arch headers.
-  copy_hdrs "${KERNEL_DIR}/common/arch/${arch}/include/uapi" \
+  copy_hdrs "${KERNEL_DIR}/${src_dir}/arch/${arch}/include/uapi" \
             "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}"
   # Copy the generated arch headers.
-  copy_hdrs "${KERNEL_DIR}/common/arch/${arch}/include/generated/uapi" \
+  copy_hdrs "${KERNEL_DIR}/${src_dir}/arch/${arch}/include/generated/uapi" \
             "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}"
 
   # Special copy of generated header files from arch/<ARCH>/generated/asm that
   # also exist in uapi/asm-generic.
-  copy_if_exists "${KERNEL_DIR}/common/include/uapi/asm-generic" \
-                 "${KERNEL_DIR}/common/arch/${arch}/include/generated/asm" \
+  copy_if_exists "${KERNEL_DIR}/${src_dir}/include/uapi/asm-generic" \
+                 "${KERNEL_DIR}/${src_dir}/arch/${arch}/include/generated/asm" \
                  "${ANDROID_KERNEL_DIR}/uapi/asm-${arch}/asm"
 done
diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py
index 3f1d1e6..73862da 100755
--- a/libc/kernel/tools/update_all.py
+++ b/libc/kernel/tools/update_all.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-import sys, cpp, kernel, glob, os, re, getopt, clean_header
+import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess
 from defaults import *
 from utils import *
 
@@ -40,11 +40,22 @@
     if not os.path.isdir(original_dir):
         panic( "Missing directory, please specify one through command-line: %s\n" % original_dir )
 
+# Fixme: This should be removed after next release.
+# Do not update ion.h ion_test.h until after next release in aosp.
+source = subprocess.check_output('git remote show', shell=True).strip()
+skip_ion = False
+if source == "aosp":
+    skip_ion = True
+
 # find all source files in 'original'
 #
 sources = []
+warning_ion = []
 for root, dirs, files in os.walk( original_dir ):
     for file in files:
+        if skip_ion and (file == "ion.h" or file == "ion_test.h"):
+            warning_ion.append("  Skipped file %s/%s" % (root, file))
+            continue
         base, ext = os.path.splitext(file)
         if ext == ".h":
             sources.append( "%s/%s" % (root,file) )
@@ -90,4 +101,7 @@
 
 b.updateGitFiles()
 
+if warning_ion:
+    print "NOTE: Due to import into aosp, some files were not processed."
+    print "\n".join(warning_ion)
 sys.exit(0)