vcpkg/ports/tensorflow-common/generate_static_link_cmd_windows.py
Joachim Gehweiler 8ad33ead90
[tensorflow] update to 2.6 (#20015)
* Revert "incorporate changes from microsoft:master"

* Revert "Revert "incorporate changes from microsoft:master""

* WIP: update to tensorflow 2.6

* update patch

* update more patches

* fix patch again

* fix new Windows compile/linkage errors

* fix patch

* fix patch again

* temporarily revert Windows build option fix to test whether upstream fix doesn't work

* check if constexpr is sufficient (is_same_v requires C++17)

* try patch for build parameters

* remove fastbuild patch and improve constexpr patch (no C++17 requirement)
(fastbuild patch didn't work because bazel overrides it with /DEBUG:FULL)

* x-add-version

* add C++17 preprocessor switch for "if constexpr"

* x-add-version

* remove pre-processor switch (doesn't work without)

* x-add-version

* work-around toolchain issues on macOS

* x-add-version

* fix Windows build options (must be string, not list)

* x-add-version

* temporarily add code to debug CI

* temporarily add more debug output as build doesn't even start on macOS CI

* remove debug code, add switch for linker parameters on macOS and re-introduce old behaviour (some platforms still use old behaviour)

* x-add-version

* fix broken string termination

* x-add-version

* fix function name

* x-add-version

Co-authored-by: jgehw <Joachim_Gehweiler@McAfee.com>
Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
2021-09-29 20:43:32 -07:00

45 lines
2.1 KiB
Python

import os.path
import re
import sys
version = sys.argv[2]
lib_suffix = "" if len(sys.argv) < 4 else sys.argv[3]
with open(sys.argv[1], "r") as f_in:
with open("static_link.bat", "w") as f_out:
p_setenv = re.compile(r"^\s*(SET .+=.*)$")
p_linker = re.compile(fr".+link\.exe.+tensorflow{lib_suffix}\.dll-2\.params.*")
env = []
for line in f_in:
if line.startswith("cd"):
# new command, reset
env = []
else:
m = p_setenv.match(line)
if m:
env.append(m.group(1))
else:
m = p_linker.match(line)
if m:
for e in env:
f_out.write(e + "\n")
tokens = line.split()
line = "\""
params_file = None
for t in tokens:
if t.endswith("link.exe"):
t = t[:-len("link.exe")] + "lib.exe\""
elif t == "/DLL" or t.lower()[1:].startswith("defaultlib:") or t.lower()[1:].startswith("ignore") or t.startswith("/OPT:") or t.startswith("/DEF:") or t.startswith("/DEBUG:") or t.startswith("/INCREMENTAL:"):
continue
elif t[0] == '@' and t.endswith(f"tensorflow{lib_suffix}.dll-2.params"):
t = t[:-len("dll-2.params")] + "lib-2.params-part1"
params_file = t[1:-len("-part1")]
line += t + " "
f_out.write(line + "\n")
# check for more parts if library needs to be split
file_no = 2
while os.path.isfile(f"{params_file}-part{file_no}"):
f_out.write(line.replace("lib-2.params-part1", f"lib-2.params-part{file_no}") + "\n")
file_no += 1
break