Use six.moves.collections_abc where appropriate

Some classes from collections module were moved to collections.abc in
Python 3.3.

This came up when trying to compile Mozc on Windows. That enables gyp to
work with Python 3.3+ on Windows. I also looked for other potentially
problematic places and updated them as well.

Bug: 217559564
Change-Id: I8a573fa8e5a21caf2a6a5b068d3412986f660da3
Reviewed-on: https://chromium-review.googlesource.com/c/external/gyp/+/3536247
Reviewed-by: Mark Mentovai <mark@chromium.org>
diff --git a/pylib/gyp/common.py b/pylib/gyp/common.py
index b268d22..f3ba8a0 100644
--- a/pylib/gyp/common.py
+++ b/pylib/gyp/common.py
@@ -4,7 +4,6 @@
 
 from __future__ import with_statement
 
-import collections
 import errno
 import filecmp
 import os.path
@@ -12,6 +11,8 @@
 import tempfile
 import sys
 
+from six.moves import collections_abc
+
 
 # A minimal memoizing decorator. It'll blow up if the args aren't immutable,
 # among other "problems".
@@ -494,7 +495,7 @@
 
 
 # Based on http://code.activestate.com/recipes/576694/.
-class OrderedSet(collections.MutableSet):
+class OrderedSet(collections_abc.MutableSet):
   def __init__(self, iterable=None):
     self.end = end = []
     end += [None, end, end]         # sentinel node for doubly linked list
diff --git a/pylib/gyp/generator/msvs.py b/pylib/gyp/generator/msvs.py
index 843e706..8014ad1 100644
--- a/pylib/gyp/generator/msvs.py
+++ b/pylib/gyp/generator/msvs.py
@@ -4,7 +4,6 @@
 
 from __future__ import print_function
 
-import collections
 import copy
 import ntpath
 import os
@@ -13,6 +12,8 @@
 import subprocess
 import sys
 
+from six.moves import collections_abc
+
 import gyp.common
 import gyp.easy_xml as easy_xml
 import gyp.generator.ninja as ninja_generator
@@ -195,7 +196,7 @@
   if not prefix: prefix = []
   result = []
   excluded_result = []
-  folders = collections.OrderedDict()
+  folders = collections_abc.OrderedDict()
   # Gather files into the final result, excluded, or folders.
   for s in sources:
     if len(s) == 1:
diff --git a/pylib/gyp/msvs_emulation.py b/pylib/gyp/msvs_emulation.py
index 63d40e6..8d64199 100644
--- a/pylib/gyp/msvs_emulation.py
+++ b/pylib/gyp/msvs_emulation.py
@@ -7,12 +7,13 @@
 build systems, primarily ninja.
 """
 
-import collections
 import os
 import re
 import subprocess
 import sys
 
+from six.moves import collections_abc
+
 from gyp.common import OrderedSet
 import gyp.MSVSUtil
 import gyp.MSVSVersion
@@ -91,7 +92,7 @@
   """Add |prefix| to |element| or each subelement if element is iterable."""
   if element is None:
     return element
-  if (isinstance(element, collections.Iterable) and
+  if (isinstance(element, collections_abc.Iterable) and
       not isinstance(element, basestring)):
     return [prefix + e for e in element]
   else:
@@ -104,7 +105,7 @@
   if map is not None and element is not None:
     if not callable(map):
       map = map.get # Assume it's a dict, otherwise a callable to do the remap.
-    if (isinstance(element, collections.Iterable) and
+    if (isinstance(element, collections_abc.Iterable) and
         not isinstance(element, basestring)):
       element = filter(None, [map(elem) for elem in element])
     else:
@@ -117,7 +118,7 @@
   then add |element| to it, adding each item in |element| if it's a list or
   tuple."""
   if append is not None and element is not None:
-    if (isinstance(element, collections.Iterable) and
+    if (isinstance(element, collections_abc.Iterable) and
         not isinstance(element, basestring)):
       append.extend(element)
     else:
diff --git a/test/lib/TestGyp.py b/test/lib/TestGyp.py
index cba2d3c..2aa7868 100644
--- a/test/lib/TestGyp.py
+++ b/test/lib/TestGyp.py
@@ -7,7 +7,6 @@
 """
 from __future__ import print_function
 
-import collections
 import errno
 import itertools
 import os
@@ -19,6 +18,8 @@
 
 from contextlib import contextmanager
 
+from six.moves import collections_abc
+
 import TestCmd
 import TestCommon
 from TestCommon import __all__
@@ -496,7 +497,7 @@
     if status is None:
       kw['status'] = None
     else:
-      if not isinstance(status, collections.Iterable): status = (status,)
+      if not isinstance(status, collections_abc.Iterable): status = (status,)
       kw['status'] = list(itertools.chain((0,), status))
     self.cmake_build(gyp_file, target, **kw)
     kw['status'] = status