Skip to content

Commit 5190029

Browse files
committed
Add support for sccache
Signed-off-by: idealseal <[email protected]>
1 parent 5ee2d40 commit 5190029

File tree

9 files changed

+48
-5
lines changed

9 files changed

+48
-5
lines changed

bin/ebuild.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2}
121121

122122
# These two functions wrap sourcing and calling respectively. At present they
123123
# perform a qa check to make sure eclasses and ebuilds and profiles don't mess
124-
# with shell opts (shopts). Ebuilds/eclasses changing shopts should reset them
124+
# with shell opts (shopts). Ebuilds/eclasses changing shopts should reset them
125125
# when they are done.
126126

127127
__qa_source() {
@@ -732,6 +732,13 @@ if [[ ${EBUILD_PHASE} != clean?(rm) ]]; then
732732

733733
[[ -n ${CCACHE_SIZE} ]] && ccache -M ${CCACHE_SIZE} &> /dev/null
734734
fi
735+
736+
if contains_word sccache "${FEATURES}"; then
737+
if [[ -n ${SCCACHE_DIR} ]] ; then
738+
addread "${SCCACHE_DIR}"
739+
addwrite "${SCCACHE_DIR}"
740+
fi
741+
fi
735742
fi
736743
fi
737744
fi

bin/phase-functions.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@ __ebuild_main() {
10871087

10881088
local x
10891089
for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
1090-
CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
1090+
CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS \
1091+
SCCACHE_DIR SCCACHE_CACHE_SIZE ; do
10911092
[[ ${!x+set} = set ]] && export ${x}
10921093
done
10931094
unset x

bin/save-ebuild-env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ __save_ebuild_env() (
162162
INSTALL_MASK
163163
PKG_INSTALL_MASK
164164

165-
# CCACHE and DISTCC configuration variables.
165+
# CCACHE, DISTCC, and SCCACHE configuration variables.
166166
"${!CCACHE_@}"
167167
"${!DISTCC_@}"
168+
"${!SCCACHE_@}"
168169
)
169170

170171
# Unset the collected variables before moving on to functions.

lib/_emerge/EbuildPhase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class EbuildPhase(CompositeTask):
139139
"nostrip",
140140
"preserve-libs",
141141
"sandbox",
142+
"sccache",
142143
"selinux",
143144
"sesandbox",
144145
"splitdebug",

lib/_emerge/actions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,23 @@ def action_info(settings, trees, myopts, myfiles):
20752075
ccache_str += " [disabled]"
20762076
append(ccache_str)
20772077

2078+
try:
2079+
proc = subprocess.Popen(
2080+
["sccache", "-V"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
2081+
)
2082+
except OSError:
2083+
output = (1, None)
2084+
else:
2085+
output = _unicode_decode(proc.communicate()[0]).rstrip("\n")
2086+
output = (proc.wait(), output)
2087+
if output[0] == os.EX_OK:
2088+
sccache_str = output[1].split("\n", 1)[0]
2089+
if "sccache" in settings.features:
2090+
sccache_str += " [enabled]"
2091+
else:
2092+
sccache_str += " [disabled]"
2093+
append(sccache_str)
2094+
20782095
myvars = [
20792096
"dev-build/autoconf",
20802097
"dev-build/automake",

lib/portage/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
"python-trace",
224224
"qa-unresolved-soname-deps",
225225
"sandbox",
226+
"sccache",
226227
"selinux",
227228
"sesandbox",
228229
"sfperms",

lib/portage/package/ebuild/_config/special_env_vars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
)
246246
)
247247

248-
environ_whitelist_re = re.compile(r"^(CCACHE_|DISTCC_).*")
248+
environ_whitelist_re = re.compile(r"^(S?CCACHE_|DISTCC_).*")
249249

250250
# Filter selected variables in the config.environ() method so that
251251
# they don't needlessly propagate down into the ebuild environment.

lib/portage/package/ebuild/doebuild.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,9 @@ def doebuild_environment(
609609
ccache = "ccache" in mysettings.features
610610
distcc = "distcc" in mysettings.features
611611
icecream = "icecream" in mysettings.features
612+
sccache = "sccache" in mysettings.features
612613

613-
if ccache or distcc or icecream:
614+
if ccache or distcc or icecream or sccache:
614615
libdir = None
615616
default_abi = mysettings.get("DEFAULT_ABI")
616617
if default_abi:
@@ -628,6 +629,8 @@ def doebuild_environment(
628629
masquerades.append(("icecream", "icecc"))
629630
if ccache:
630631
masquerades.append(("ccache", "ccache"))
632+
if sccache:
633+
masquerades.append(("sccache", "sccache"))
631634

632635
for feature, m in masquerades:
633636
for l in possible_libexecdirs:
@@ -645,6 +648,13 @@ def doebuild_environment(
645648
)
646649
mysettings.features.remove(feature)
647650

651+
if sccache:
652+
port = mysettings.get("SCCACHE_SERVER_PORT")
653+
if port:
654+
writemsg(f"!!! SCCACHE_SERVER_PORT - {port}")
655+
else:
656+
mysettings["SCCACHE_SERVER_PORT"] = "6224"
657+
648658
# MAKEOPTS conflicts with MAKEFLAGS, so skip this if MAKEFLAGS exists.
649659
if "MAKEOPTS" not in mysettings and "MAKEFLAGS" not in mysettings:
650660
nproc = get_cpu_count()

lib/portage/package/ebuild/prepare_build_dirs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ def _prepare_features_dirs(mysettings):
216216
"subdirs": ("lock", "state"),
217217
"always_recurse": True,
218218
},
219+
"sccache": {
220+
"basedir_var": "SCCACHE_DIR",
221+
"default_dir": os.path.join(mysettings["PORTAGE_TMPDIR"], "sccache"),
222+
"always_recurse": False,
223+
},
219224
}
220225
dirmode = 0o2070
221226
filemode = 0o60

0 commit comments

Comments
 (0)