diff options
author | 2016-10-25 13:49:28 +0000 | |
---|---|---|
committer | 2016-10-25 20:18:38 +0000 | |
commit | 81aede1f9bdddfe0e2327d6cf0ba9bd40fd62718 (patch) | |
tree | 9bccf6c64b547e03cfa336ffa4b1e7da144f9cab /tools/cpp/wrapper/bin/pydir | |
parent | ca99bb71b8120e61a3bbde8e54f1a9488fa0478f (diff) |
Reimplement whole archive on Windows
Use wrapper script to get object files if /WHOLEARCHIVE is not supported.
fix https://github.com/bazelbuild/bazel/issues/1978
work towards https://github.com/bazelbuild/bazel/issues/1918
--
Change-Id: I675311478e65a1e1f3fa963187a5a8da531150d3
Reviewed-on: https://bazel-review.googlesource.com/#/c/6833
MOS_MIGRATED_REVID=137151817
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. |