updated gyp to a newer version that doesn't import itself from sys.path

The old version of gyp would import (all of) itself from sys.path if it
could, which caused problems with people who had local installations. In
order to work with this new version, I also had to update the version of
ninja that was used and the way that the cRIO setup creates .out files.
diff --git a/aos/build/aos.gypi b/aos/build/aos.gypi
index f6c3126..9c74438 100644
--- a/aos/build/aos.gypi
+++ b/aos/build/aos.gypi
@@ -23,12 +23,8 @@
   'conditions': [
     ['OS=="crio"', {
         'make_global_settings': [
-          ['CC', '<!(which powerpc-wrs-vxworks-gcc)'],
-          ['CXX', '<!(which powerpc-wrs-vxworks-g++)'],
-          ['LD', '<!(readlink -f <(AOS)/build/crio_link_out)'],
-          #['LD', 'powerpc-wrs-vxworks-ld'],
-          #['AR', '<!(which powerpc-wrs-vxworks-ar)'],
-          #['NM', '<!(which powerpc-wrs-vxworks-nm)'],
+          ['CC', '<!(readlink -f <(AOS)/build/crio_cc)'],
+          ['CXX', '<!(readlink -f <(AOS)/build/crio_cxx)'],
         ],
         'variables': {
           'aos_target': 'static_library',
diff --git a/aos/build/build.sh b/aos/build/build.sh
index eb639de..4ac467c 100755
--- a/aos/build/build.sh
+++ b/aos/build/build.sh
@@ -1,31 +1,37 @@
-#!/bin/bash -e
+#!/bin/bash
 #set -x
 
+set -e
+
 # This file should be called to build the code.
-# Usage: build.sh platform main_file.gyp debug [action]
+# Usage: build.sh platform main_file.gyp debug [action]...
 
 PLATFORM=$1
 GYP_MAIN=$2
 DEBUG=$3
 ACTION=$4
 
+shift 3
+shift || true # We might not have a 4th argument if ACTION is empty.
+
 export WIND_BASE=${WIND_BASE:-"/usr/local/powerpc-wrs-vxworks/wind_base"}
 
-[ ${PLATFORM} == "crio" -o ${PLATFORM} == "atom" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "atom"'. ; exit 1 )
-[ ${DEBUG} == "yes" -o ${DEBUG} == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 )
+[ "${PLATFORM}" == "crio" -o "${PLATFORM}" == "atom" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "atom"'. ; exit 1 )
+[ "${DEBUG}" == "yes" -o "${DEBUG}" == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 )
 
 AOS=`dirname $0`/..
-NINJA_DIR=${AOS}/externals/ninja
+NINJA_RELEASE=v1.4.0
+NINJA_DIR=${AOS}/externals/ninja-${NINJA_RELEASE}
 NINJA=${NINJA_DIR}/ninja
 # From chromium@154360:trunk/src/DEPS.
-GYP_REVISION=1488
+GYP_REVISION=1738
 GYP_DIR=${AOS}/externals/gyp-${GYP_REVISION}
 GYP=${GYP_DIR}/gyp
 
 OUTDIR=${AOS}/../out_${PLATFORM}
 BUILD_NINJA=${OUTDIR}/Default/build.ninja
 
-[ -d ${NINJA_DIR} ] || git clone --branch release https://github.com/martine/ninja.git ${NINJA_DIR}
+[ -d ${NINJA_DIR} ] || git clone --branch ${NINJA_RELEASE} https://github.com/martine/ninja.git ${NINJA_DIR}
 [ -x ${NINJA} ] || ${NINJA_DIR}/bootstrap.py
 [ -d ${GYP_DIR} ] || ( svn co http://gyp.googlecode.com/svn/trunk -r ${GYP_REVISION} ${GYP_DIR} && patch -p1 -d ${GYP_DIR} < ${AOS}/externals/gyp.patch )
 ${AOS}/build/download_externals.sh
@@ -56,14 +62,14 @@
 fi
 
 if [ "${ACTION}" == "clean" ]; then
-  rm -r ${OUTDIR}
+  rm -r ${OUTDIR} || true
 else
   if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" -a "${ACTION}" != "redeploy" ]; then
-    GYP_ACTION=${ACTION}
+    NINJA_ACTION=${ACTION}
   else
-    GYP_ACTION=
+    NINJA_ACTION=
   fi
-  ${NINJA} -C ${OUTDIR}/Default ${GYP_ACTION}
+  ${NINJA} -C ${OUTDIR}/Default ${NINJA_ACTION} "$@"
   if [[ ${ACTION} == deploy || ${ACTION} == redeploy ]]; then
     [ ${PLATFORM} == atom ] && \
       rsync --progress -c -r \
diff --git a/aos/build/crio_cc b/aos/build/crio_cc
new file mode 100755
index 0000000..442d3fe
--- /dev/null
+++ b/aos/build/crio_cc
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# This is a helper script that gets called as a replacement for gcc. It just
+# passes all arguments on unless it is being called as a shared linker.
+
+[ $1 != '-shared' ] && exec powerpc-wrs-vxworks-gcc "$@"
+exec $(dirname $0)/crio_link_out "$@"
diff --git a/aos/build/crio_cxx b/aos/build/crio_cxx
new file mode 100755
index 0000000..ea68e58
--- /dev/null
+++ b/aos/build/crio_cxx
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# This is a helper script that gets called as a replacement for g++. It just
+# passes all arguments on unless it is being called as a shared linker.
+
+[ $1 != '-shared' ] && exec powerpc-wrs-vxworks-g++ "$@"
+exec $(dirname $0)/crio_link_out "$@"
diff --git a/aos/build/crio_link_out b/aos/build/crio_link_out
index e5a66e7..0630341 100755
--- a/aos/build/crio_link_out
+++ b/aos/build/crio_link_out
@@ -1,7 +1,11 @@
-#!/bin/bash -e
+#!/bin/bash
+#set -x
 
-# This is a helper script that compiles .out files for the cRIO. It is designed
-# to be called as a replacement for g++ being used as a linker.
+set -e
+
+# This is a helper script that compiles .out files for the cRIO. It gets called
+# by the gcc and g++ wrapper scripts if they detect that the tool is being used
+# as a shared linker.
 
 # All the flags except -shared.
 INPUTS_FLAGS=`echo "$@" | sed 's/-shared//g'`
@@ -9,7 +13,6 @@
 OUTPUT=`echo ${INPUTS_FLAGS} | awk \
   'BEGIN { RS=" " }; output { print ; output = 0 }; /-o/ { output = 1 }'`
 # All arguments that don't start with a - and aren't ${OUTPUT}.
-#INPUTS=`echo ${INPUTS_FLAGS} | sed "s:-[^ ]*::g; s:${OUTPUT}::g;"`
 INPUTS=`echo ${INPUTS_FLAGS} | awk \
   'BEGIN { RS=" " }; /-Wl,--no-whole-archive/ { output = 0 }; \
   output { print }; \
@@ -17,7 +20,8 @@
 TEMPDIR=`dirname ${OUTPUT}`
 AOS=`dirname $0`/..
 powerpc-wrs-vxworks-nm ${INPUTS} | \
-  tclsh ${WIND_BASE}/host/resource/hutils/tcl/munch.tcl -c ppc > ${TEMPDIR}/ctdt.c
+  tclsh ${WIND_BASE}/host/resource/hutils/tcl/munch.tcl -c ppc > \
+    ${TEMPDIR}/ctdt.c
 powerpc-wrs-vxworks-gcc -I${AOS}/.. -c ${TEMPDIR}/ctdt.c -o ${TEMPDIR}/ctdt.o
 powerpc-wrs-vxworks-g++ ${INPUTS_FLAGS} ${TEMPDIR}/ctdt.o
 ln -f ${OUTPUT} `echo ${OUTPUT} | sed 's/lib\([A-Za-z0-9_]*\)\.so$/\1.out/'`
diff --git a/aos/externals/.gitignore b/aos/externals/.gitignore
index 80bd460..73cb3e2 100644
--- a/aos/externals/.gitignore
+++ b/aos/externals/.gitignore
@@ -7,13 +7,13 @@
 /gccdist/
 /gtest-1.6.0-p1/
 /gtest-1.6.0.zip
-/gyp-1488/
+/gyp-1738/
 /javacv-0.2-bin.zip
 /javacv-bin/
 /jpeg-8d/
 /jpegsrc.v8d.tar.gz
 /libjpeg/
-/ninja/
+/ninja-v1.4.0/
 /one-jar-boot-0.97.jar
 /gflags-2.0-prefix/
 /gflags-2.0.tar.gz
diff --git a/aos/externals/gyp.patch b/aos/externals/gyp.patch
index 9019406..b09b67d 100644
--- a/aos/externals/gyp.patch
+++ b/aos/externals/gyp.patch
@@ -1,7 +1,7 @@
 diff -rupN before/pylib/gyp/input.py after/pylib/gyp/input.py
 --- before/pylib/gyp/input.py	2012-11-20 16:38:09.394784918 -0800
 +++ after/pylib/gyp/input.py	2012-11-20 16:39:10.527105964 -0800
-@@ -2156,17 +2156,6 @@ def ValidateSourcesInTarget(target, targ
+@@ -2412,17 +2412,6 @@ def ValidateSourcesInTarget(target, targ
      basename = os.path.basename(name)  # Don't include extension.
      basenames.setdefault(basename, []).append(source)
  
@@ -11,10 +11,10 @@
 -      error += '  %s: %s\n' % (basename, ' '.join(files))
 -
 -  if error:
--    print ('static library %s has several files with the same basename:\n' %
--           target + error + 'Some build systems, e.g. MSVC08, '
--           'cannot handle that.')
--    raise KeyError, 'Duplicate basenames in sources section, see list above'
+-    print('static library %s has several files with the same basename:\n' %
+-          target + error + 'Some build systems, e.g. MSVC08, '
+-          'cannot handle that.')
+-    raise GypError('Duplicate basenames in sources section, see list above')
 -
  
  def ValidateRulesInTarget(target, target_dict, extra_sources_for_rules):
diff --git a/frc971/atom_code/build.sh b/frc971/atom_code/build.sh
index d1dff19..b8129ab 100755
--- a/frc971/atom_code/build.sh
+++ b/frc971/atom_code/build.sh
@@ -1,3 +1,3 @@
 #!/bin/bash
 
-../../aos/build/build.sh atom atom_code.gyp no $1
+../../aos/build/build.sh atom atom_code.gyp no "$@"
diff --git a/frc971/crio/build.sh b/frc971/crio/build.sh
index ec04978..b3fc031 100755
--- a/frc971/crio/build.sh
+++ b/frc971/crio/build.sh
@@ -1,3 +1,3 @@
 #!/bin/bash
 
-../../aos/build/build.sh crio crio.gyp no $1
+../../aos/build/build.sh crio crio.gyp no "$@"