aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts
diff options
context:
space:
mode:
authorspreis <spreis@yandex-team.com>2024-07-10 07:48:05 +0300
committerspreis <spreis@yandex-team.com>2024-07-10 07:59:28 +0300
commite16b329fb8d258f106d4f5345195d1fba93cf09c (patch)
treec23841b2b8fcf1a848a286ee0024389407aca828 /build/scripts
parent7724c3dfc71cbaab5961f87addef86833d079723 (diff)
downloadydb-e16b329fb8d258f106d4f5345195d1fba93cf09c.tar.gz
,Support thinlto caches
ac03c8c8d7beb99b5a8fcda8c0c6bf948ca2bb2e
Diffstat (limited to 'build/scripts')
-rw-r--r--build/scripts/link_dyn_lib.py8
-rw-r--r--build/scripts/link_exe.py8
-rw-r--r--build/scripts/thinlto_cache.py27
3 files changed, 40 insertions, 3 deletions
diff --git a/build/scripts/link_dyn_lib.py b/build/scripts/link_dyn_lib.py
index 6171e83179..3b7c0d3e51 100644
--- a/build/scripts/link_dyn_lib.py
+++ b/build/scripts/link_dyn_lib.py
@@ -6,8 +6,9 @@ import collections
import optparse
import pipes
-from process_whole_archive_option import ProcessWholeArchiveOption
+import thinlto_cache
+from process_whole_archive_option import ProcessWholeArchiveOption
from fix_py2_protobuf import fix_py2
@@ -208,6 +209,8 @@ def parse_args():
parser.add_option('--arch')
parser.add_option('--target')
parser.add_option('--soname')
+ parser.add_option('--source-root')
+ parser.add_option('--build-root')
parser.add_option('--fix-elf')
parser.add_option('--linker-output')
parser.add_option('--musl', action='store_true')
@@ -216,6 +219,7 @@ def parse_args():
parser.add_option('--whole-archive-libs', action='append')
parser.add_option('--custom-step')
parser.add_option('--python')
+ thinlto_cache.add_options(parser)
return parser.parse_args()
@@ -235,6 +239,7 @@ if __name__ == '__main__':
cmd = fix_cmd_for_dynamic_cuda(cmd)
cmd = ProcessWholeArchiveOption(opts.arch, opts.whole_archive_peers, opts.whole_archive_libs).construct_cmd(cmd)
+ thinlto_cache.preprocess(opts, cmd)
if opts.custom_step:
assert opts.python
@@ -247,6 +252,7 @@ if __name__ == '__main__':
proc = subprocess.Popen(cmd, shell=False, stderr=sys.stderr, stdout=stdout)
proc.communicate()
+ thinlto_cache.postprocess(opts)
if proc.returncode:
print >> sys.stderr, 'linker has failed with retcode:', proc.returncode
diff --git a/build/scripts/link_exe.py b/build/scripts/link_exe.py
index c1533c4dfc..2b69486183 100644
--- a/build/scripts/link_exe.py
+++ b/build/scripts/link_exe.py
@@ -7,9 +7,9 @@ import optparse
import textwrap
import process_command_files as pcf
+import thinlto_cache
from process_whole_archive_option import ProcessWholeArchiveOption
-
from fix_py2_protobuf import fix_py2
@@ -305,17 +305,18 @@ def parse_args():
parser.add_option('--custom-step')
parser.add_option('--python')
parser.add_option('--source-root')
+ parser.add_option('--build-root')
parser.add_option('--clang-ver')
parser.add_option('--dynamic-cuda', action='store_true')
parser.add_option('--cuda-architectures',
help='List of supported CUDA architectures, separated by ":" (e.g. "sm_52:compute_70:lto_90a"')
parser.add_option('--nvprune-exe')
parser.add_option('--objcopy-exe')
- parser.add_option('--build-root')
parser.add_option('--arch')
parser.add_option('--linker-output')
parser.add_option('--whole-archive-peers', action='append')
parser.add_option('--whole-archive-libs', action='append')
+ thinlto_cache.add_options(parser)
return parser.parse_args()
@@ -362,5 +363,8 @@ if __name__ == '__main__':
else:
stdout = sys.stdout
+ thinlto_cache.preprocess(opts, cmd)
rc = subprocess.call(cmd, shell=False, stderr=sys.stderr, stdout=stdout)
+ thinlto_cache.postprocess(opts)
+
sys.exit(rc)
diff --git a/build/scripts/thinlto_cache.py b/build/scripts/thinlto_cache.py
new file mode 100644
index 0000000000..35ab755262
--- /dev/null
+++ b/build/scripts/thinlto_cache.py
@@ -0,0 +1,27 @@
+import os
+import tarfile
+
+
+CACHE_DIR_NAME='thinlto_cache_dir'
+
+
+def add_options(parser):
+ parser.add_option('--thinlto-cache')
+ parser.add_option('--thinlto-cache-write', action='store_true')
+
+def preprocess(opts, cmd):
+ if opts.thinlto_cache:
+ cache_dir = os.path.join(opts.build_root, CACHE_DIR_NAME)
+ cmd +=['-Wl,--thinlto-cache-dir={}'.format(cache_dir)]
+ if opts.thinlto_cache_write:
+ os.mkdir(cache_dir)
+ else:
+ with tarfile.open(opts.thinlto_cache, 'r') as tar:
+ tar.extractall(opts.build_root)
+
+def postprocess(opts):
+ if opts.thinlto_cache:
+ cache_dir = os.path.join(opts.build_root, CACHE_DIR_NAME)
+ if opts.thinlto_cache_write:
+ with tarfile.open(opts.thinlto_cache, 'w:gz') as tar:
+ tar.add(cache_dir, arcname=os.path.basename(cache_dir))