diff options
Diffstat (limited to 'tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl')
-rw-r--r-- | tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl | 31 |
1 files changed, 31 insertions, 0 deletions
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. |