Stop checking for duplicate basenames

Chromium doesn't care about MSVC08 or Mac OS X makefiles anymore,
whereas some third_party libraries we'd like to use within Chromium
contain source files with duplicate basenames.

Discussion link: https://groups.google.com/a/chromium.org/d/msg/chromium-dev/0rDiXgLvywY/sm0LSj-hiDIJ

Patch from mdempsky@chromium.org

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/670063006

git-svn-id: http://gyp.googlecode.com/svn/trunk@1993 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/__init__.py b/pylib/gyp/__init__.py
index 1cd57b0..c24239a 100755
--- a/pylib/gyp/__init__.py
+++ b/pylib/gyp/__init__.py
@@ -49,7 +49,7 @@
 
 def Load(build_files, format, default_variables={},
          includes=[], depth='.', params=None, check=False,
-         circular_check=True, duplicate_basename_check=True):
+         circular_check=True):
   """
   Loads one or more specified build files.
   default_variables and includes will be copied before use.
@@ -126,7 +126,6 @@
   # Process the input specific to this generator.
   result = gyp.input.Load(build_files, default_variables, includes[:],
                           depth, generator_input_info, check, circular_check,
-                          duplicate_basename_check,
                           params['parallel'], params['root_targets'])
   return [generator] + result
 
@@ -325,16 +324,6 @@
   parser.add_option('--no-circular-check', dest='circular_check',
                     action='store_false', default=True, regenerate=False,
                     help="don't check for circular relationships between files")
-  # --no-duplicate-basename-check disables the check for duplicate basenames
-  # in a static_library/shared_library project. Visual C++ 2008 generator
-  # doesn't support this configuration. Libtool on Mac also generates warnings
-  # when duplicate basenames are passed into Make generator on Mac.
-  # TODO(yukawa): Remove this option when these legacy generators are
-  # deprecated.
-  parser.add_option('--no-duplicate-basename-check',
-                    dest='duplicate_basename_check', action='store_false',
-                    default=True, regenerate=False,
-                    help="don't check for duplicate basenames")
   parser.add_option('--no-parallel', action='store_true', default=False,
                     help='Disable multiprocessing')
   parser.add_option('-S', '--suffix', dest='suffix', default='',
@@ -509,8 +498,7 @@
     # Start with the default variables from the command line.
     [generator, flat_list, targets, data] = Load(
         build_files, format, cmdline_default_variables, includes, options.depth,
-        params, options.check, options.circular_check,
-        options.duplicate_basename_check)
+        params, options.check, options.circular_check)
 
     # TODO(mark): Pass |data| for now because the generator needs a list of
     # build files that came in.  In the future, maybe it should just accept
diff --git a/pylib/gyp/input.py b/pylib/gyp/input.py
index 4f07eaa..7d3654a 100644
--- a/pylib/gyp/input.py
+++ b/pylib/gyp/input.py
@@ -2476,37 +2476,6 @@
                                                              target_type))
 
 
-def ValidateSourcesInTarget(target, target_dict, build_file,
-                            duplicate_basename_check):
-  if not duplicate_basename_check:
-    return
-  # TODO: Check if MSVC allows this for loadable_module targets.
-  if target_dict.get('type', None) not in ('static_library', 'shared_library'):
-    return
-  sources = target_dict.get('sources', [])
-  basenames = {}
-  for source in sources:
-    name, ext = os.path.splitext(source)
-    is_compiled_file = ext in [
-        '.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.s', '.S']
-    if not is_compiled_file:
-      continue
-    basename = os.path.basename(name)  # Don't include extension.
-    basenames.setdefault(basename, []).append(source)
-
-  error = ''
-  for basename, files in basenames.iteritems():
-    if len(files) > 1:
-      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 and Make generator '
-          'for Mac, cannot handle that. Use --no-duplicate-basename-check to'
-          'disable this validation.')
-    raise GypError('Duplicate basenames in sources section, see list above')
-
-
 def ValidateRulesInTarget(target, target_dict, extra_sources_for_rules):
   """Ensures that the rules sections in target_dict are valid and consistent,
   and determines which sources they apply to.
@@ -2727,7 +2696,7 @@
 
 
 def Load(build_files, variables, includes, depth, generator_input_info, check,
-         circular_check, duplicate_basename_check, parallel, root_targets):
+         circular_check, parallel, root_targets):
   SetGeneratorGlobals(generator_input_info)
   # A generator can have other lists (in addition to sources) be processed
   # for rules.
@@ -2852,11 +2821,6 @@
     ProcessVariablesAndConditionsInDict(
         target_dict, PHASE_LATELATE, variables, build_file)
 
-  # TODO(thakis): Get vpx_scale/arm/scalesystemdependent.c to be renamed to
-  #               scalesystemdependent_arm_additions.c or similar.
-  if 'arm' in variables.get('target_arch', ''):
-    duplicate_basename_check = False
-
   # Make sure that the rules make sense, and build up rule_sources lists as
   # needed.  Not all generators will need to use the rule_sources lists, but
   # some may, and it seems best to build the list in a common spot.
@@ -2865,8 +2829,6 @@
     target_dict = targets[target]
     build_file = gyp.common.BuildFile(target)
     ValidateTargetType(target, target_dict)
-    ValidateSourcesInTarget(target, target_dict, build_file,
-                            duplicate_basename_check)
     ValidateRulesInTarget(target, target_dict, extra_sources_for_rules)
     ValidateRunAsInTarget(target, target_dict, build_file)
     ValidateActionsInTarget(target, target_dict, build_file)
diff --git a/test/errors/duplicate_basenames.gyp b/test/errors/duplicate_basenames.gyp
deleted file mode 100644
index b3dceb3..0000000
--- a/test/errors/duplicate_basenames.gyp
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright (c) 2009 Google Inc. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-{
-  'targets': [
-    {
-      'target_name': 'foo',
-      'type': 'static_library',
-      'sources': ['foo.c', 'foo.cc'],
-    },
-  ]
-}
diff --git a/test/errors/gyptest-errors.py b/test/errors/gyptest-errors.py
index 4612c16..d544622 100755
--- a/test/errors/gyptest-errors.py
+++ b/test/errors/gyptest-errors.py
@@ -47,19 +47,6 @@
 test.run_gyp('file_cycle0.gyp', status=1, stderr=stderr,
              match=TestCmd.match_re_dotall)
 
-stderr = 'gyp: Duplicate basenames in sources section, see list above\n'
-test.run_gyp('duplicate_basenames.gyp', status=1, stderr=stderr)
-
-# Check if '--no-duplicate-basename-check' works.
-if ((test.format == 'make' and sys.platform == 'darwin') or
-    (test.format == 'msvs' and
-        int(os.environ.get('GYP_MSVS_VERSION', 2010)) < 2010)):
-  stderr = 'gyp: Duplicate basenames in sources section, see list above\n'
-  test.run_gyp('duplicate_basenames.gyp', '--no-duplicate-basename-check',
-               status=1, stderr=stderr)
-else:
-  test.run_gyp('duplicate_basenames.gyp', '--no-duplicate-basename-check')
-
 stderr = ("gyp: Dependency '.*missing_dep.gyp:missing.gyp#target' not found "
           "while trying to load target .*missing_dep.gyp:foo#target\n")
 test.run_gyp('missing_dep.gyp', status=1, stderr=stderr,
diff --git a/test/same-source-file-name/gyptest-shared.py b/test/same-source-file-name/gyptest-shared.py
index a57eb61..4cad63f 100755
--- a/test/same-source-file-name/gyptest-shared.py
+++ b/test/same-source-file-name/gyptest-shared.py
@@ -5,7 +5,7 @@
 # found in the LICENSE file.
 
 """
-Checks that gyp fails on shared_library targets which have several files with
+Checks that gyp succeeds on shared_library targets which have several files with
 the same basename.
 """
 
@@ -15,16 +15,12 @@
 
 test = TestGyp.TestGyp()
 
-# Fails by default for the compatibility with Visual C++ 2008 generator.
-# TODO: Update expected behavior when these legacy generators are deprecated.
-test.run_gyp('double-shared.gyp', chdir='src', status=1, stderr=None)
-
 if ((test.format == 'msvs') and
        (int(os.environ.get('GYP_MSVS_VERSION', 2010)) < 2010)):
-  test.run_gyp('double-shared.gyp', '--no-duplicate-basename-check',
+  test.run_gyp('double-shared.gyp',
                chdir='src', status=0, stderr=None)
 else:
-  test.run_gyp('double-shared.gyp', '--no-duplicate-basename-check',
+  test.run_gyp('double-shared.gyp',
                chdir='src')
   test.build('double-shared.gyp', test.ALL, chdir='src')
 
diff --git a/test/same-source-file-name/gyptest-static.py b/test/same-source-file-name/gyptest-static.py
index 7fa2772..fc067e9 100755
--- a/test/same-source-file-name/gyptest-static.py
+++ b/test/same-source-file-name/gyptest-static.py
@@ -5,7 +5,7 @@
 # found in the LICENSE file.
 
 """
-Checks that gyp fails on static_library targets which have several files with
+Checks that gyp succeeds on static_library targets which have several files with
 the same basename.
 """
 
@@ -16,18 +16,13 @@
 
 test = TestGyp.TestGyp()
 
-# Fails by default for the compatibility with legacy generators such as
-# VCProj generator for Visual C++ 2008 and Makefile generator on Mac.
-# TODO: Update expected behavior when these legacy generators are deprecated.
-test.run_gyp('double-static.gyp', chdir='src', status=1, stderr=None)
-
 if ((test.format == 'make' and sys.platform == 'darwin') or
     (test.format == 'msvs' and
         int(os.environ.get('GYP_MSVS_VERSION', 2010)) < 2010)):
-  test.run_gyp('double-static.gyp', '--no-duplicate-basename-check',
+  test.run_gyp('double-static.gyp',
                chdir='src', status=1, stderr=None)
 else:
-  test.run_gyp('double-static.gyp', '--no-duplicate-basename-check',
+  test.run_gyp('double-static.gyp',
                chdir='src')
   test.build('double-static.gyp', test.ALL, chdir='src')