ninja&make/mac: Only pass -x to strip for loadable_modules.

I misinterpreted what "Bundle products" meant in the "Default value" row
for STRIP_STYLE on
https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW153

BUG=280718
R=mark@chromium.org

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

git-svn-id: http://gyp.googlecode.com/svn/trunk@1730 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/xcode_emulation.py b/pylib/gyp/xcode_emulation.py
index 2ced319..92cba63 100644
--- a/pylib/gyp/xcode_emulation.py
+++ b/pylib/gyp/xcode_emulation.py
@@ -684,7 +684,7 @@
         self._Test('STRIP_INSTALLED_PRODUCT', 'YES', default='NO')):
 
       default_strip_style = 'debugging'
-      if self._IsBundle():
+      if self.spec['type'] == 'loadable_module' and self._IsBundle():
         default_strip_style = 'non-global'
       elif self.spec['type'] == 'executable':
         default_strip_style = 'all'
diff --git a/test/mac/gyptest-cflags.py b/test/mac/gyptest-cflags.py
index 3888322..7d24863 100644
--- a/test/mac/gyptest-cflags.py
+++ b/test/mac/gyptest-cflags.py
@@ -1,4 +1,3 @@
-
 #!/usr/bin/env python
 
 # Copyright (c) 2012 Google Inc. All rights reserved.
diff --git a/test/mac/gyptest-strip-default.py b/test/mac/gyptest-strip-default.py
new file mode 100644
index 0000000..f73fa11
--- /dev/null
+++ b/test/mac/gyptest-strip-default.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2013 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 the default STRIP_STYLEs match between different generators.
+"""
+
+import TestGyp
+
+import re
+import subprocess
+import sys
+import time
+
+if sys.platform == 'darwin':
+  test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
+
+  CHDIR='strip'
+  test.run_gyp('test-defaults.gyp', chdir=CHDIR)
+
+  test.build('test-defaults.gyp', test.ALL, chdir=CHDIR)
+
+  # Lightweight check if stripping was done.
+  def OutPath(s):
+    return test.built_file_path(s, chdir=CHDIR)
+
+  def CheckNsyms(p, o_expected):
+    proc = subprocess.Popen(['nm', '-aU', p], stdout=subprocess.PIPE)
+    o = proc.communicate()[0]
+
+    # Filter out mysterious "00 0000   OPT radr://5614542" symbol which
+    # is apparently only printed on the bots (older toolchain?).
+    # Yes, "radr", not "rdar".
+    o = ''.join(filter(lambda s: 'radr://5614542' not in s, o.splitlines(True)))
+
+    o = o.replace('A', 'T')
+    o = re.sub(r'^[a-fA-F0-9]+', 'XXXXXXXX', o, flags=re.MULTILINE)
+    assert not proc.returncode
+    if o != o_expected:
+      print 'Stripping: Expected symbols """\n%s""", got """\n%s"""' % (
+          o_expected, o)
+      test.fail_test()
+
+  CheckNsyms(OutPath('libsingle_dylib.dylib'),
+"""\
+XXXXXXXX S _ci
+XXXXXXXX S _i
+XXXXXXXX T _the_function
+XXXXXXXX t _the_hidden_function
+XXXXXXXX T _the_used_function
+XXXXXXXX T _the_visible_function
+""")
+  CheckNsyms(OutPath('single_so.so'),
+"""\
+XXXXXXXX S _ci
+XXXXXXXX S _i
+XXXXXXXX T _the_function
+XXXXXXXX t _the_hidden_function
+XXXXXXXX T _the_used_function
+XXXXXXXX T _the_visible_function
+""")
+  CheckNsyms(OutPath('single_exe'),
+"""\
+XXXXXXXX T __mh_execute_header
+""")
+
+  CheckNsyms(test.built_file_path(
+      'bundle_dylib.framework/Versions/A/bundle_dylib', chdir=CHDIR),
+"""\
+XXXXXXXX S _ci
+XXXXXXXX S _i
+XXXXXXXX T _the_function
+XXXXXXXX t _the_hidden_function
+XXXXXXXX T _the_used_function
+XXXXXXXX T _the_visible_function
+""")
+  CheckNsyms(test.built_file_path(
+      'bundle_so.bundle/Contents/MacOS/bundle_so', chdir=CHDIR),
+"""\
+XXXXXXXX S _ci
+XXXXXXXX S _i
+XXXXXXXX T _the_function
+XXXXXXXX T _the_used_function
+XXXXXXXX T _the_visible_function
+""")
+  CheckNsyms(test.built_file_path(
+      'bundle_exe.app/Contents/MacOS/bundle_exe', chdir=CHDIR),
+"""\
+XXXXXXXX T __mh_execute_header
+""")
+
+  test.pass_test()
diff --git a/test/mac/gyptest-strip.py b/test/mac/gyptest-strip.py
index bae2338..9ab26a5 100755
--- a/test/mac/gyptest-strip.py
+++ b/test/mac/gyptest-strip.py
@@ -39,15 +39,15 @@
 
   # The actual numbers here are not interesting, they just need to be the same
   # in both the xcode and the make build.
-  CheckNsyms(OutPath('no_postprocess'), 10)
-  CheckNsyms(OutPath('no_strip'), 10)
+  CheckNsyms(OutPath('no_postprocess'), 29)
+  CheckNsyms(OutPath('no_strip'), 29)
   CheckNsyms(OutPath('strip_all'), 0)
-  CheckNsyms(OutPath('strip_nonglobal'), 2)
-  CheckNsyms(OutPath('strip_debugging'), 2)
+  CheckNsyms(OutPath('strip_nonglobal'), 6)
+  CheckNsyms(OutPath('strip_debugging'), 7)
   CheckNsyms(OutPath('strip_all_custom_flags'), 0)
   CheckNsyms(test.built_file_path(
       'strip_all_bundle.framework/Versions/A/strip_all_bundle', chdir='strip'),
       0)
-  CheckNsyms(OutPath('strip_save'), 2)
+  CheckNsyms(OutPath('strip_save'), 7)
 
   test.pass_test()
diff --git a/test/mac/strip/file.c b/test/mac/strip/file.c
index 421f040..a4c504d 100644
--- a/test/mac/strip/file.c
+++ b/test/mac/strip/file.c
@@ -3,7 +3,20 @@
 // found in the LICENSE file.
 
 static void the_static_function() {}
+__attribute__((used)) void the_used_function() {}
+
+__attribute__((visibility("hidden"))) __attribute__((used))
+    void the_hidden_function() {}
+__attribute__((visibility("default"))) __attribute__((used))
+    void the_visible_function() {}
+
+extern const int eci;
+__attribute__((used)) int i;
+__attribute__((used)) const int ci = 34623;
 
 void the_function() {
   the_static_function();
+  the_used_function();
+  the_hidden_function();
+  the_visible_function();
 }
diff --git a/test/mac/strip/main.c b/test/mac/strip/main.c
new file mode 100644
index 0000000..b2291a6
--- /dev/null
+++ b/test/mac/strip/main.c
@@ -0,0 +1,25 @@
+// Copyright (c) 2013 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.
+
+static void the_static_function() {}
+__attribute__((used)) void the_used_function() {}
+
+__attribute__((visibility("hidden"))) __attribute__((used))
+void the_hidden_function() {}
+__attribute__((visibility("default"))) __attribute__((used))
+void the_visible_function() {}
+
+void the_function() {}
+
+extern const int eci;
+__attribute__((used)) int i;
+__attribute__((used)) const int ci = 34623;
+
+int main() {
+  the_function();
+  the_static_function();
+  the_used_function();
+  the_hidden_function();
+  the_visible_function();
+}
diff --git a/test/mac/strip/test-defaults.gyp b/test/mac/strip/test-defaults.gyp
new file mode 100644
index 0000000..e688b95
--- /dev/null
+++ b/test/mac/strip/test-defaults.gyp
@@ -0,0 +1,51 @@
+# Copyright (c) 2013 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.
+{
+  'make_global_settings': [
+    ['CC', '/usr/bin/clang'],
+  ],
+  'target_defaults': {
+    'xcode_settings': {
+      'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
+      'DEPLOYMENT_POSTPROCESSING': 'YES',
+      'STRIP_INSTALLED_PRODUCT': 'YES',
+    },
+  },
+  'targets': [
+    {
+      'target_name': 'single_dylib',
+      'type': 'shared_library',
+      'sources': [ 'file.c', ],
+    },
+    {
+      'target_name': 'single_so',
+      'type': 'loadable_module',
+      'sources': [ 'file.c', ],
+    },
+    {
+      'target_name': 'single_exe',
+      'type': 'executable',
+      'sources': [ 'main.c', ],
+    },
+
+    {
+      'target_name': 'bundle_dylib',
+      'type': 'shared_library',
+      'mac_bundle': '1',
+      'sources': [ 'file.c', ],
+    },
+    {
+      'target_name': 'bundle_so',
+      'type': 'loadable_module',
+      'mac_bundle': '1',
+      'sources': [ 'file.c', ],
+    },
+    {
+      'target_name': 'bundle_exe',
+      'type': 'executable',
+      'mac_bundle': '1',
+      'sources': [ 'main.c', ],
+    },
+  ],
+}