Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add "standalone_static_library" target flag

This flag is only valid for targets of type "static_library"

Adding 'standalone_static_library': 1, ensures:
1) "thin" archive optimisation is disabled for this target (it will contain
symbols)
2) The static_library will be "installed" to PRODUCT_DIR

Review URL: http://codereview.chromium.org/11031005/
Patch from Eric Boren <borenet@google.com>!
Review URL: https://codereview.chromium.org/11048018

git-svn-id: http://gyp.googlecode.com/svn/trunk@1510 78cadc50-ecff-11dd-a971-7dbc132099af
  • Loading branch information...
commit bc070f09a8f53fd47d8bd010b5f48e22d10668d2 1 parent 2ea5a87
thakis@chromium.org authored
View
28 pylib/gyp/generator/make.py
@@ -125,7 +125,10 @@ def ensure_directory_exists(path):
LINK_COMMANDS_LINUX = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
-cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
+cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
+
+quiet_cmd_alink_thin = AR($(TOOLSET)) $@
+cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
# Due to circular dependencies between libraries :(, we wrap the
# special "figure out circular dependencies" flags around the entire
@@ -176,7 +179,10 @@ def ensure_directory_exists(path):
LINK_COMMANDS_ANDROID = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
-cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
+cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
+
+quiet_cmd_alink_thin = AR($(TOOLSET)) $@
+cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
# Due to circular dependencies between libraries :(, we wrap the
# special "figure out circular dependencies" flags around the entire
@@ -717,9 +723,12 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
else:
self.output = self.output_binary = self.ComputeOutput(spec)
+ self.is_standalone_static_library = bool(
+ spec.get('standalone_static_library', 0))
self._INSTALLABLE_TARGETS = ('executable', 'loadable_module',
'shared_library')
- if self.type in self._INSTALLABLE_TARGETS:
+ if (self.is_standalone_static_library or
+ self.type in self._INSTALLABLE_TARGETS):
self.alias = os.path.basename(self.output)
install_path = self._InstallableTargetInstallPath()
else:
@@ -1532,8 +1541,12 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
for link_dep in link_deps:
assert ' ' not in link_dep, (
"Spaces in alink input filenames not supported (%s)" % link_dep)
- self.WriteDoCmd([self.output_binary], link_deps, 'alink', part_of_all,
- postbuilds=postbuilds)
+ if self.is_standalone_static_library:
+ self.WriteDoCmd([self.output_binary], link_deps, 'alink', part_of_all,
+ postbuilds=postbuilds)
+ else:
+ self.WriteDoCmd([self.output_binary], link_deps, 'alink_thin',
+ part_of_all, postbuilds=postbuilds)
elif self.type == 'shared_library':
self.WriteLn('%s: LD_INPUTS := %s' % (
QuoteSpaces(self.output_binary),
@@ -1573,9 +1586,12 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
# 1) They need to install to the build dir or "product" dir.
# 2) They get shortcuts for building (e.g. "make chrome").
# 3) They are part of "make all".
- if self.type in self._INSTALLABLE_TARGETS:
+ if (self.type in self._INSTALLABLE_TARGETS or
+ self.is_standalone_static_library):
if self.type == 'shared_library':
file_desc = 'shared library'
+ elif self.type == 'static_library':
+ file_desc = 'static library'
else:
file_desc = 'executable'
install_path = self._InstallableTargetInstallPath()
View
16 pylib/gyp/generator/ninja.py
@@ -366,6 +366,8 @@ def WriteSpec(self, spec, config_name, generator_flags,
self.toolset = spec['toolset']
config = spec['configurations'][config_name]
self.target = Target(spec['type'])
+ self.is_standalone_static_library = bool(
+ spec.get('standalone_static_library', 0))
self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
self.xcode_settings = self.msvs_settings = None
@@ -952,8 +954,12 @@ def WriteTarget(self, spec, config_name, config, link_deps, compile_deps):
if self.xcode_settings:
variables.append(('libtool_flags',
self.xcode_settings.GetLibtoolflags(config_name)))
- self.ninja.build(self.target.binary, 'alink', link_deps,
- order_only=compile_deps, variables=variables)
+ if self.is_standalone_static_library:
+ self.ninja.build(self.target.binary, 'alink', link_deps,
+ order_only=compile_deps, variables=variables)
+ else:
+ self.ninja.build(self.target.binary, 'alink_thin', link_deps,
+ order_only=compile_deps, variables=variables)
else:
self.WriteLink(spec, config_name, config, link_deps)
return self.target.binary
@@ -1137,7 +1143,7 @@ def ComputeOutput(self, spec, type=None):
elif self.flavor == 'win' and self.toolset == 'target':
type_in_output_root += ['shared_library']
- if type in type_in_output_root:
+ if type in type_in_output_root or self.is_standalone_static_library:
return filename
elif type == 'shared_library':
libdir = 'lib'
@@ -1494,6 +1500,10 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
master_ninja.rule(
'alink',
description='AR $out',
+ command='rm -f $out && $ar rcs $out $in')
+ master_ninja.rule(
+ 'alink_thin',
+ description='AR $out',
command='rm -f $out && $ar rcsT $out $in')
# This allows targets that only need to depend on $lib's API to declare an
View
7 pylib/gyp/input.py
@@ -83,6 +83,7 @@ def IsPathSection(section):
'rules',
'run_as',
'sources',
+ 'standalone_static_library',
'suppress_wildcard',
'target_name',
'toolset',
@@ -106,6 +107,7 @@ def IsPathSection(section):
'libraries',
'link_settings',
'sources',
+ 'standalone_static_library',
'target_name',
'type',
]
@@ -2280,6 +2282,11 @@ def ValidateTargetType(target, target_dict):
raise GypError("Target %s has an invalid target type '%s'. "
"Must be one of %s." %
(target, target_type, '/'.join(VALID_TARGET_TYPES)))
+ if (target_dict.get('standalone_static_library', 0) and
+ not target_type == 'static_library'):
+ raise GypError('Target %s has type %s but standalone_static_library flag is'
+ ' only valid for static_library type.' % (target,
+ target_type))
def ValidateSourcesInTarget(target, target_dict, build_file):
View
1  test/configurations/invalid/gyptest-configurations.py
@@ -20,6 +20,7 @@
'libraries',
'link_settings',
'sources',
+ 'standalone_static_library',
'target_name',
'type',
]
View
17 test/configurations/invalid/standalone_static_library.gyp
@@ -0,0 +1,17 @@
+# Copyright (c) 2012 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': 'configurations',
+ 'type': 'none',
+ 'configurations': {
+ 'Debug': {
+ 'standalone_static_library': 1,
+ },
+ }
+ },
+ ],
+}
View
35 test/standalone-static-library/gyptest-standalone-static-library.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2012 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 build of a static_library with the standalone_static_library flag set.
+"""
+
+import os
+import subprocess
+import sys
+import TestGyp
+
+test = TestGyp.TestGyp()
+
+test.run_gyp('mylib.gyp')
+test.build('mylib.gyp', target='prog')
+
+# Verify that the static library is copied to PRODUCT_DIR
+built_lib = test.built_file_basename('mylib', type=test.STATIC_LIB)
+path = test.built_file_path(built_lib)
+test.must_exist(path)
+
+# Verify that the program runs properly
+expect = 'hello from mylib.c\n'
+test.run_built_executable('prog', stdout=expect)
+
+# Verify that libmylib.a contains symbols. "ar -x" fails on a 'thin' archive.
+if test.format in ('make', 'ninja') and sys.platform.startswith('linux'):
+ retcode = subprocess.call(['ar', '-x', path])
+ assert retcode == 0
+
+test.pass_test()
View
7 test/standalone-static-library/mylib.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void print(void)
+{
+ printf("hello from mylib.c\n");
+ return;
+}
View
26 test/standalone-static-library/mylib.gyp
@@ -0,0 +1,26 @@
+# Copyright (c) 2012 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': 'mylib',
+ 'type': 'static_library',
+ 'standalone_static_library': 1,
+ 'sources': [
+ 'mylib.c',
+ ],
+ },
+ {
+ 'target_name': 'prog',
+ 'type': 'executable',
+ 'sources': [
+ 'prog.c',
+ ],
+ 'dependencies': [
+ 'mylib',
+ ],
+ },
+ ],
+}
View
7 test/standalone-static-library/prog.c
@@ -0,0 +1,7 @@
+extern void print(void);
+
+int main(int argc, char *argv[])
+{
+ print();
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.