Work around problem with corrupt npm cache on Mac.

https://build.chromium.org/p/chromium.webrtc/builders/Mac%20Tester/
has a tendency to amass corrupted data. Add a workaround which purges
the npm folder when this happens.

BUG=None
R=grunell@chromium.org

Review URL: https://codereview.chromium.org/1305013003 .
diff --git a/build_apprtc_appengine_app.py b/build_apprtc_appengine_app.py
index c1f91b2..9d15b75 100755
--- a/build_apprtc_appengine_app.py
+++ b/build_apprtc_appengine_app.py
@@ -12,6 +12,7 @@
 import fileinput
 import os
 import shutil
+import subprocess
 import sys
 
 import utils
@@ -30,6 +31,14 @@
         sys.stdout.write(line)
 
 
+def _WorkAroundMacNpmCorruptedDataOnInstall(command):
+  print 'Wiping .npm folder and trying again...'
+  npm_storage = os.path.expanduser('~/.npm')
+  assert npm_storage.endswith('.npm')
+  shutil.rmtree(npm_storage, ignore_errors=True)
+  utils.RunSubprocessWithRetry(command)
+
+
 def main():
   node_path = os.path.abspath('node')
   if not os.path.exists(node_path):
@@ -48,7 +57,14 @@
     npm_bin = os.path.join(node_path, 'bin', 'npm')
     node_bin = os.path.join(node_path, 'bin', 'node')
 
-  utils.RunSubprocessWithRetry([npm_bin, 'install'])
+  command = [npm_bin, 'install']
+  try:
+    utils.RunSubprocessWithRetry(command)
+  except subprocess.CalledProcessError:
+    if utils.GetPlatform() is not 'mac':
+      raise
+    _WorkAroundMacNpmCorruptedDataOnInstall(command)
+
   local_grunt_bin = os.path.join('node_modules', 'grunt-cli', 'bin', 'grunt')
 
   if not os.path.exists(local_grunt_bin):