Skip to content

Commit

Permalink
win: Add NoImportLibrary flag for ninja generator
Browse files Browse the repository at this point in the history
This adds a flag that tells ninja not to expect an import library
to be generated. This is only needed very rarely in the case of
DLLs that have no exported symbols.

There is no corresponding functionality in the msvs generator, so
the test and functionality are ninja generator-only.

R=grt@chromium.org
BUG=gyp:397, chromium:451499

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

git-svn-id: http://gyp.googlecode.com/svn/trunk@2030 78cadc50-ecff-11dd-a971-7dbc132099af
  • Loading branch information
sgraham committed Jan 30, 2015
1 parent 104e21e commit 4d7c139
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pylib/gyp/generator/ninja.py
Expand Up @@ -1217,7 +1217,8 @@ def WriteLinkForArch(self, ninja_file, spec, config_name, config,
gyp.common.EncodePOSIXShellArgument(link_file_list)))
if self.flavor == 'win':
extra_bindings.append(('binary', output))
if '/NOENTRY' not in ldflags:
if ('/NOENTRY' not in ldflags and
not self.msvs_settings.GetNoImportLibrary(config_name)):
self.target.import_lib = output + '.lib'
extra_bindings.append(('implibflag',
'/IMPLIB:%s' % self.target.import_lib))
Expand Down
7 changes: 7 additions & 0 deletions pylib/gyp/msvs_emulation.py
Expand Up @@ -407,6 +407,13 @@ def GetPDBName(self, config, expand_special, default):
else:
return None

def GetNoImportLibrary(self, config):
"""If NoImportLibrary: true, ninja will not expect the output to include
an import library."""
config = self._TargetConfig(config)
noimplib = self._Setting(('NoImportLibrary',), config)
return noimplib == 'true'

def GetAsmflags(self, config):
"""Returns the flags that need to be added to ml invocations."""
config = self._TargetConfig(config)
Expand Down
30 changes: 30 additions & 0 deletions test/win/gyptest-link-noimportlib.py
@@ -0,0 +1,30 @@
#!/usr/bin/env python

# Copyright (c) 2015 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 sure that the (custom) NoImportLibrary flag is handled correctly.
"""

import TestGyp

import os
import sys

if sys.platform == 'win32':
test = TestGyp.TestGyp(formats=['ninja'])

CHDIR = 'importlib'
test.run_gyp('noimplib.gyp', chdir=CHDIR)
test.build('noimplib.gyp', test.ALL, chdir=CHDIR)

# The target has an entry point, but no exports. Ordinarily, ninja expects
# all DLLs to export some symbols (with the exception of /NOENTRY resource-
# only DLLs). When the NoImportLibrary flag is set, this is suppressed. If
# this is not working correctly, the expected .lib will never be generated
# but will be expected, so the build will not be up to date.
test.up_to_date('noimplib.gyp', test.ALL, chdir=CHDIR)

test.pass_test()
9 changes: 9 additions & 0 deletions test/win/importlib/dll_no_exports.cc
@@ -0,0 +1,9 @@
// Copyright (c) 2015 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.

#include <windows.h>

BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) {
return TRUE;
}
16 changes: 16 additions & 0 deletions test/win/importlib/noimplib.gyp
@@ -0,0 +1,16 @@
# Copyright (c) 2015 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': 'no_import_library',
'type': 'loadable_module',
'msvs_settings': {
'NoImportLibrary': 'true',
},
'sources': ['dll_no_exports.cc'],
},
]
}

0 comments on commit 4d7c139

Please sign in to comment.