From 4d7c139b1820c5fcb993868c61f170a02cda8a40 Mon Sep 17 00:00:00 2001 From: "scottmg@chromium.org" Date: Fri, 30 Jan 2015 20:24:26 +0000 Subject: [PATCH] win: Add NoImportLibrary flag for ninja generator 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 --- pylib/gyp/generator/ninja.py | 3 ++- pylib/gyp/msvs_emulation.py | 7 +++++++ test/win/gyptest-link-noimportlib.py | 30 ++++++++++++++++++++++++++++ test/win/importlib/dll_no_exports.cc | 9 +++++++++ test/win/importlib/noimplib.gyp | 16 +++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/win/gyptest-link-noimportlib.py create mode 100644 test/win/importlib/dll_no_exports.cc create mode 100644 test/win/importlib/noimplib.gyp diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py index 0c7ce547..5407795b 100644 --- a/pylib/gyp/generator/ninja.py +++ b/pylib/gyp/generator/ninja.py @@ -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)) diff --git a/pylib/gyp/msvs_emulation.py b/pylib/gyp/msvs_emulation.py index d18863ac..050e95c2 100644 --- a/pylib/gyp/msvs_emulation.py +++ b/pylib/gyp/msvs_emulation.py @@ -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) diff --git a/test/win/gyptest-link-noimportlib.py b/test/win/gyptest-link-noimportlib.py new file mode 100644 index 00000000..d12e0ad3 --- /dev/null +++ b/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() diff --git a/test/win/importlib/dll_no_exports.cc b/test/win/importlib/dll_no_exports.cc new file mode 100644 index 00000000..96dd7970 --- /dev/null +++ b/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 + +BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { + return TRUE; +} diff --git a/test/win/importlib/noimplib.gyp b/test/win/importlib/noimplib.gyp new file mode 100644 index 00000000..0245058a --- /dev/null +++ b/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'], + }, + ] +}