diff options
Diffstat (limited to 'tools/cpp/wrapper/bin/pydir')
-rw-r--r-- | tools/cpp/wrapper/bin/pydir/msvc_link.py | 3 | ||||
-rw-r--r-- | tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl | 31 |
2 files changed, 34 insertions, 0 deletions
diff --git a/tools/cpp/wrapper/bin/pydir/msvc_link.py b/tools/cpp/wrapper/bin/pydir/msvc_link.py index b9aa81abb7..98c1a0b5e7 100644 --- a/tools/cpp/wrapper/bin/pydir/msvc_link.py +++ b/tools/cpp/wrapper/bin/pydir/msvc_link.py @@ -68,6 +68,9 @@ class MsvcLinker(msvc_tools.WindowsRunner): # Build argument list. parser = msvc_tools.ArgParser(self, argv, LINKPATTERNS) + # Preprocessing arguments for linking whole archive libraries + parser.WholeArchivePreprocess() + # Find the output file name. name = '' for arg in parser.options: diff --git a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl index 99b2e39c3e..813b07d6cf 100644 --- a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl +++ b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl @@ -31,6 +31,7 @@ TMP_PATH = '%{tmp}' PATH = "%{path}" INCLUDE = "%{include}" LIB = "%{lib}" +LIB_TOOL = "%{lib_tool}" class Error(Exception): """Base class for all script-specific errors.""" @@ -52,8 +53,38 @@ class ArgParser(object): self.deps_file = None self.output_file = None self.params_file = None + self.support_whole_archive = %{support_whole_archive} + self.need_global_whole_archive = None self._ParseArgs(argv) + def ReplaceLibrary(self, arg): + """Do the actual replacement if necessary.""" + if arg == "/WHOLEARCHIVE": + return [] + if arg.startswith("/OUT:") or os.path.splitext(arg)[1] not in ['.a', '.lo']: + return [arg] + if self.global_whole_archive or arg.startswith("/WHOLEARCHIVE:"): + if arg.startswith("/WHOLEARCHIVE:"): + arg = arg[len("/WHOLEARCHIVE:"):] + output = subprocess.check_output([LIB_TOOL, "/list", arg]).decode("utf-8") + object_files = [] + for line in output.split("\n"): + line = line.strip() + if line.endswith(".o"): + object_files.append(line) + return object_files + return [arg] + + def WholeArchivePreprocess(self): + """Replace library file with object files if /WHOLEARCHIVE is not supported.""" + if self.support_whole_archive: + return + options = [] + self.global_whole_archive = "/WHOLEARCHIVE" in self.options + for arg in self.options: + options.extend(self.ReplaceLibrary(arg)) + self.options = options + def _MatchOneArg(self, args): """Finds a pattern which matches the beginning elements of args. |