Skip to content

Commit 164021c

Browse files
authored
Merge pull request #36058 from edymtt/relocate-xdg-cache-home-in-linux-presets-5.4
[5.4][Build] Add and use option to alter default location of module cache in Linux
2 parents bcba3cf + e8aae00 commit 164021c

File tree

7 files changed

+67
-0
lines changed

7 files changed

+67
-0
lines changed

utils/build-presets.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,13 @@ install-destdir=%(install_destdir)s
804804
# Path to the .tar.gz package we would create.
805805
installable-package=%(installable_package)s
806806

807+
# This ensures the default module cache
808+
# location is local to this run, allowing
809+
# to schedule multiple builds safely
810+
# in Linux CI bots
811+
relocate-xdg-cache-home-under-build-subdir
812+
813+
807814
[preset: buildbot_linux]
808815
mixin-preset=mixin_linux_installation
809816
build-subdir=buildbot_linux
@@ -1036,6 +1043,13 @@ lit-args=-v
10361043
build-ninja
10371044
reconfigure
10381045

1046+
# This ensures the default module cache
1047+
# location is local to this run, allowing
1048+
# to schedule multiple builds safely
1049+
# in Linux CI bots
1050+
relocate-xdg-cache-home-under-build-subdir
1051+
1052+
10391053
[preset: buildbot_incremental_linux]
10401054
mixin-preset=
10411055
buildbot_incremental_linux_base

utils/build-script

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,13 @@ def apply_default_arguments(toolchain, args):
336336
args.build_subdir = \
337337
workspace.compute_build_subdir(args)
338338

339+
if args.relocate_xdg_cache_home_under_build_subdir:
340+
cache_under_build_subdir = os.path.join(
341+
SWIFT_BUILD_ROOT, args.build_subdir, '.cache')
342+
if args.verbose_build:
343+
print("Relocating XDG_CACHE_HOME to {}".format(cache_under_build_subdir))
344+
workspace.relocate_xdg_cache_home_under(cache_under_build_subdir)
345+
339346
if args.install_destdir is None:
340347
args.install_destdir = os.path.join(
341348
SWIFT_BUILD_ROOT, args.build_subdir,

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ def create_argument_parser():
339339
metavar='PATH',
340340
help='name of the directory under $SWIFT_BUILD_ROOT where the '
341341
'build products will be placed')
342+
option('--relocate-xdg-cache-home-under-build-subdir',
343+
store_true,
344+
help='relocate $XDG_CACHE_HOME to the same location '
345+
'where build products will be placed; '
346+
'this supports having multiple runs for different branches '
347+
'in CI bots for Linux')
342348
option('--install-prefix', store_path,
343349
default=targets.install_prefix(),
344350
help='The installation prefix. This is where built Swift products '

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
'maccatalyst': False,
191191
'maccatalyst_ios_tests': False,
192192
'dump_config': False,
193+
'relocate_xdg_cache_home_under_build_subdir': False,
193194
'show_sdks': False,
194195
'skip_build': False,
195196
'skip_local_build': False,
@@ -642,6 +643,7 @@ class BuildScriptImplOption(_BaseOption):
642643
PathOption('--android-icu-data'),
643644
PathOption('--android-ndk'),
644645
PathOption('--build-subdir'),
646+
SetTrueOption('--relocate-xdg-cache-home-under-build-subdir'),
645647
PathOption('--clang-profile-instr-use'),
646648
PathOption('--cmake'),
647649
PathOption('--coverage-db'),

utils/swift_build_support/swift_build_support/workspace.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,14 @@ def compute_build_subdir(args):
102102
if args.enable_tsan:
103103
build_subdir += "+tsan"
104104
return build_subdir
105+
106+
107+
def relocate_xdg_cache_home_under(new_cache_location):
108+
"""
109+
This allows under Linux to relocate the default location
110+
of the module cache -- this can be useful when there are
111+
are lot of invocations to touch or when some invocations
112+
can't be easily configured (as is the case for Swift
113+
compiler detection in CMake)
114+
"""
115+
os.environ['XDG_CACHE_HOME'] = new_cache_location
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RUN: %empty-directory(%t)
2+
# RUN: mkdir -p %t
3+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --install-all --llbuild --swiftpm --foundation --libdispatch --relocate-xdg-cache-home-under-build-subdir --verbose-build --cmake %cmake 2>&1 | %FileCheck %s
4+
5+
# REQUIRES: standalone_build
6+
# REQUIRES: OS=linux-gnu
7+
8+
# CHECK: Relocating XDG_CACHE_HOME
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// REQUIRES: OS=linux-gnu
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: mkdir -p %t
5+
// RUN: split-file %s %t
6+
//
7+
// RUN: PYTHONPATH=%utils %{python} %t/run_swiftc_with_relocated_xdg_cache_home.py %t/.cache %swiftc_driver_plain %t/hello.swift
8+
// RUN: ls %t/.cache/clang/ModuleCache
9+
10+
//--- run_swiftc_with_relocated_xdg_cache_home.py
11+
import sys
12+
import subprocess
13+
from swift_build_support.swift_build_support import workspace
14+
15+
workspace.relocate_xdg_cache_home_under(sys.argv[1])
16+
subprocess.run([sys.argv[2], sys.argv[3]])
17+
18+
//--- hello.swift
19+
print("hello")

0 commit comments

Comments
 (0)