Merge tools/gyp from https://chromium.googlesource.com/external/gyp.git at 46282cedf40ff7fe803be4af357b9d59050f02e4

This commit was generated by merge_from_chromium.py.

Change-Id: Ic9e634e90d0fc142bc58bdfcc1a27e4f45b1f9cd
diff --git a/pylib/gyp/generator/android.py b/pylib/gyp/generator/android.py
index d7aa902..5afeb53 100644
--- a/pylib/gyp/generator/android.py
+++ b/pylib/gyp/generator/android.py
@@ -50,6 +50,8 @@
 generator_additional_non_configuration_keys = [
     # Boolean to declare that this target does not want its name mangled.
     'android_unmangled_name',
+    # Map of android build system variables to set.
+    'aosp_build_settings',
 ]
 generator_additional_path_sections = []
 generator_extra_sources_for_rules = []
@@ -66,33 +68,6 @@
 
 """
 
-android_standard_include_paths = set([
-    # JNI_H_INCLUDE in build/core/binary.mk
-    'dalvik/libnativehelper/include/nativehelper',
-    # from SRC_HEADERS in build/core/config.mk
-    'system/core/include',
-    'hardware/libhardware/include',
-    'hardware/libhardware_legacy/include',
-    'hardware/ril/include',
-    'dalvik/libnativehelper/include',
-    'frameworks/native/include',
-    'frameworks/native/opengl/include',
-    'frameworks/base/include',
-    'frameworks/base/opengl/include',
-    'frameworks/base/native/include',
-    'external/skia/include',
-    # TARGET_C_INCLUDES in build/core/combo/TARGET_linux-arm.mk
-    'bionic/libc/arch-arm/include',
-    'bionic/libc/include',
-    'bionic/libstdc++/include',
-    'bionic/libc/kernel/common',
-    'bionic/libc/kernel/arch-arm',
-    'bionic/libm/include',
-    'bionic/libm/include/arm',
-    'bionic/libthread_db/include',
-    ])
-
-
 # Map gyp target types to Android module classes.
 MODULE_CLASSES = {
     'static_library': 'STATIC_LIBRARIES',
@@ -185,7 +160,6 @@
     if self.android_stem != self.android_module:
       self.WriteLn('LOCAL_MODULE_STEM := ' + self.android_stem)
     self.WriteLn('LOCAL_MODULE_SUFFIX := ' + self.android_suffix)
-    self.WriteLn('LOCAL_MODULE_TAGS := optional')
     if self.toolset == 'host':
       self.WriteLn('LOCAL_IS_HOST_MODULE := true')
       self.WriteLn('LOCAL_MULTILIB := $(GYP_HOST_MULTILIB)')
@@ -713,9 +687,7 @@
 
   def NormalizeIncludePaths(self, include_paths):
     """ Normalize include_paths.
-    Convert absolute paths to relative to the Android top directory;
-    filter out include paths that are already brought in by the Android build
-    system.
+    Convert absolute paths to relative to the Android top directory.
 
     Args:
       include_paths: A list of unprocessed include paths.
@@ -726,10 +698,7 @@
     for path in include_paths:
       if path[0] == '/':
         path = gyp.common.RelativePath(path, self.android_top_dir)
-
-      # Filter out the Android standard search path.
-      if path not in android_standard_include_paths:
-        normalized.append(path)
+      normalized.append(path)
     return normalized
 
   def ExtractIncludesFromCFlags(self, cflags):
@@ -810,28 +779,41 @@
     spec, configs: input from gyp.
     link_deps: link dependency list; see ComputeDeps()
     """
-    for configname, config in sorted(configs.iteritems()):
-      ldflags = list(config.get('ldflags', []))
-      self.WriteLn('')
-      self.WriteList(ldflags, 'LOCAL_LDFLAGS_%s' % configname)
-    self.WriteLn('\nLOCAL_LDFLAGS := $(LOCAL_LDFLAGS_$(GYP_CONFIGURATION))')
+    if self.type != 'static_library':
+      for configname, config in sorted(configs.iteritems()):
+        ldflags = list(config.get('ldflags', []))
+        self.WriteLn('')
+        self.WriteList(ldflags, 'LOCAL_LDFLAGS_%s' % configname)
+      self.WriteLn('\nLOCAL_LDFLAGS := $(LOCAL_LDFLAGS_$(GYP_CONFIGURATION))')
 
     # Libraries (i.e. -lfoo)
+    # These must be included even for static libraries as some of them provide
+    # implicit include paths through the build system.
     libraries = gyp.common.uniquer(spec.get('libraries', []))
     static_libs, dynamic_libs = self.ComputeAndroidLibraryModuleNames(
         libraries)
 
-    # Link dependencies (i.e. libfoo.a, libfoo.so)
-    static_link_deps = [x[1] for x in link_deps if x[0] == 'static']
-    shared_link_deps = [x[1] for x in link_deps if x[0] == 'shared']
-    self.WriteLn('')
-    self.WriteList(static_libs + static_link_deps,
-                   'LOCAL_STATIC_LIBRARIES')
-    self.WriteLn('# Enable grouping to fix circular references')
-    self.WriteLn('LOCAL_GROUP_STATIC_LIBRARIES := true')
-    self.WriteLn('')
-    self.WriteList(dynamic_libs + shared_link_deps,
-                   'LOCAL_SHARED_LIBRARIES')
+    # Link dependencies (i.e. other gyp targets this target depends on)
+    # These need not be included for static libraries as within the gyp build
+    # we do not use the implicit include path mechanism.
+    if self.type != 'static_library':
+      static_link_deps = [x[1] for x in link_deps if x[0] == 'static']
+      shared_link_deps = [x[1] for x in link_deps if x[0] == 'shared']
+    else:
+      static_link_deps = []
+      shared_link_deps = []
+
+    # Only write the lists if they are non-empty.
+    if static_libs or static_link_deps:
+      self.WriteLn('')
+      self.WriteList(static_libs + static_link_deps,
+                     'LOCAL_STATIC_LIBRARIES')
+      self.WriteLn('# Enable grouping to fix circular references')
+      self.WriteLn('LOCAL_GROUP_STATIC_LIBRARIES := true')
+    if dynamic_libs or shared_link_deps:
+      self.WriteLn('')
+      self.WriteList(dynamic_libs + shared_link_deps,
+                     'LOCAL_SHARED_LIBRARIES')
 
 
   def WriteTarget(self, spec, configs, deps, link_deps, part_of_all,
@@ -849,6 +831,16 @@
     if self.type != 'none':
       self.WriteTargetFlags(spec, configs, link_deps)
 
+    settings = spec.get('aosp_build_settings', {})
+    if settings:
+      self.WriteLn('### Set directly by aosp_build_settings.')
+      for k, v in settings.iteritems():
+        if isinstance(v, list):
+          self.WriteList(v, k)
+        else:
+          self.WriteLn('%s := %s' % (k, make.QuoteIfNecessary(v)))
+      self.WriteLn('')
+
     # Add to the set of targets which represent the gyp 'all' target. We use the
     # name 'gyp_all_modules' as the Android build system doesn't allow the use
     # of the Make target 'all' and because 'all_modules' is the equivalent of
diff --git a/test/android/gyptest-settings-list.py b/test/android/gyptest-settings-list.py
new file mode 100755
index 0000000..5850d47
--- /dev/null
+++ b/test/android/gyptest-settings-list.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2014 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.
+
+"""
+Verifies that it's possible to set Android build system settings using the
+aosp_build_settings key, with list values.
+"""
+
+import TestGyp
+
+test = TestGyp.TestGyp(formats=['android'])
+
+test.run_gyp('settings-list.gyp')
+
+test.build('settings-list.gyp', 'hello')
+
+test.run_built_executable('hello.foo', stdout="Hello, world!\n")
+
+test.up_to_date('settings-list.gyp', test.DEFAULT)
+
+test.pass_test()
diff --git a/test/android/gyptest-settings.py b/test/android/gyptest-settings.py
new file mode 100755
index 0000000..f4e89d1
--- /dev/null
+++ b/test/android/gyptest-settings.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2014 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.
+
+"""
+Verifies that it's possible to set Android build system settings using the
+aosp_build_settings key.
+"""
+
+import TestGyp
+
+test = TestGyp.TestGyp(formats=['android'])
+
+test.run_gyp('settings.gyp')
+
+test.build('settings.gyp', 'hello')
+
+test.run_built_executable('hello.foo', stdout="Hello, world!\n")
+
+test.up_to_date('settings.gyp', test.DEFAULT)
+
+test.pass_test()
diff --git a/test/android/settings-list.gyp b/test/android/settings-list.gyp
new file mode 100644
index 0000000..b392ce2
--- /dev/null
+++ b/test/android/settings-list.gyp
@@ -0,0 +1,18 @@
+# Copyright (c) 2014 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': 'hello',
+      'type': 'executable',
+      'sources': [
+        'hello.c',
+      ],
+      'aosp_build_settings': {
+        'LOCAL_MODULE_SUFFIX': ['.foo'],
+      }
+    },
+  ],
+}
diff --git a/test/android/settings.gyp b/test/android/settings.gyp
new file mode 100644
index 0000000..2f8ce7f
--- /dev/null
+++ b/test/android/settings.gyp
@@ -0,0 +1,18 @@
+# Copyright (c) 2014 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': 'hello',
+      'type': 'executable',
+      'sources': [
+        'hello.c',
+      ],
+      'aosp_build_settings': {
+        'LOCAL_MODULE_SUFFIX': '.foo',
+      }
+    },
+  ],
+}
diff --git a/tools/emacs/gyp.el b/tools/emacs/gyp.el
index 3db9f64..60619b5 100644
--- a/tools/emacs/gyp.el
+++ b/tools/emacs/gyp.el
@@ -15,14 +15,15 @@
                  "recent emacsen), not from the older and less maintained "
                  "python-mode.el")))
 
-(defadvice python-calculate-indentation (after ami-outdent-closing-parens
-                                               activate)
+(defadvice python-indent-calculate-levels (after gyp-outdent-closing-parens
+                                                 activate)
   "De-indent closing parens, braces, and brackets in gyp-mode."
-  (if (and (eq major-mode 'gyp-mode)
-           (string-match "^ *[])}][],)}]* *$"
-                         (buffer-substring-no-properties
-                          (line-beginning-position) (line-end-position))))
-      (setq ad-return-value (- ad-return-value 2))))
+  (when (and (eq major-mode 'gyp-mode)
+             (string-match "^ *[])}][],)}]* *$"
+                           (buffer-substring-no-properties
+                            (line-beginning-position) (line-end-position))))
+    (setf (first python-indent-levels)
+          (- (first python-indent-levels) python-indent-offset))))
 
 (define-derived-mode gyp-mode python-mode "Gyp"
   "Major mode for editing .gyp files. See http://code.google.com/p/gyp/"
@@ -36,8 +37,8 @@
 (defun gyp-set-indentation ()
   "Hook function to configure python indentation to suit gyp mode."
   (setq python-continuation-offset 2
-        python-indent 2
-        python-guess-indent nil))
+        python-indent-offset 2
+        python-indent-guess-indent-offset nil))
 
 (add-hook 'gyp-mode-hook 'gyp-set-indentation)
 
@@ -218,8 +219,8 @@
     ;; Top-level keywords
     (list (concat "['\"]\\("
               (regexp-opt (list "action" "action_name" "actions" "cflags"
-                                "conditions" "configurations" "copies" "defines"
-                                "dependencies" "destination"
+                                "cflags_cc" "conditions" "configurations"
+                                "copies" "defines" "dependencies" "destination"
                                 "direct_dependent_settings"
                                 "export_dependent_settings" "extension" "files"
                                 "include_dirs" "includes" "inputs" "libraries"