Changes to bldpkg:

-> Replaced string '/etc/bldpkg.conf' with 'bldpkg.conf'
-> Removed hardlink checking and compiler validation code for sccache. sccache is now required to be defined as a
   rustc wrapper in $HOME/.cargo/config.toml file
-> Added code to autostart sccache. Sccache is already stopped when the build is interrupted or succeeds or fails.
This commit is contained in:
PktSurf 2023-03-19 23:30:18 +05:30
parent 66f329695f
commit bf48366a60

62
bldpkg
View file

@ -127,7 +127,7 @@ fi
# Error out if globalccache and globalsccache are set in the /etc/bldpkg.conf # Error out if globalccache and globalsccache are set in the /etc/bldpkg.conf
if [[ $globalccache = 1 ]] && [[ $globalsccache = 1 ]] ; then if [[ $globalccache = 1 ]] && [[ $globalsccache = 1 ]] ; then
err "Please only enable either ccache or sccache in /etc/bldpkg.conf at the same time, not both." err "Please only enable either ccache or sccache in bldpkg.conf at the same time, not both."
fi fi
# Function to validate the build file. # Function to validate the build file.
@ -407,9 +407,9 @@ inarray() {
# Check if $parenttmp is set and is a directory # Check if $parenttmp is set and is a directory
if [[ -z $parenttmp ]] ; then if [[ -z $parenttmp ]] ; then
err "parenttmp variable not set in /etc/bldpkg.conf." err "parenttmp variable not set in bldpkg.conf."
elif [[ ! -d $parenttmp ]] ; then elif [[ ! -d $parenttmp ]] ; then
err "parenttmp variable set to '$parenttmp' in /etc/bldpkg.conf is not a directory." err "parenttmp variable set to '$parenttmp' in bldpkg.conf is not a directory."
fi fi
# Attempt to write to the $parenttmp directory. This directory is used for everything related to the # Attempt to write to the $parenttmp directory. This directory is used for everything related to the
@ -498,7 +498,7 @@ if [[ $swapcheck = 1 ]]; then
if inarray "${app}" "${packagesrequiringswap[@]}" ; then if inarray "${app}" "${packagesrequiringswap[@]}" ; then
# Here we determine available system swap size needed to compile exceptional packages that pull # Here we determine available system swap size needed to compile exceptional packages that pull
# in a lot of RAM. Those packages are listed under the packagesrequiringswap array in /etc/bldpkg.conf. # in a lot of RAM. Those packages are listed under the packagesrequiringswap array in bldpkg.conf.
# Check whether swap is available on the system and if it is, determine its size. If its size # Check whether swap is available on the system and if it is, determine its size. If its size
# is >= swapsize, we are all good. If it's less than swapsize, we exit with a status 1. # is >= swapsize, we are all good. If it's less than swapsize, we exit with a status 1.
@ -518,7 +518,7 @@ fi
# if the $app is in the exception list and whether to build inside or outside the TMPFS directory. # if the $app is in the exception list and whether to build inside or outside the TMPFS directory.
if [[ $usetmpfs = 1 ]] && [[ -n $tmpfsdir ]] && [[ -z $tmpfscheckfailed ]] ; then if [[ $usetmpfs = 1 ]] && [[ -n $tmpfsdir ]] && [[ -z $tmpfscheckfailed ]] ; then
# If $app is in the TMPFS exception list inside /etc/bldpkg.conf, compile it *OUTSIDE* the TMPFS # If $app is in the TMPFS exception list inside bldpkg.conf, compile it *OUTSIDE* the TMPFS
# directory, i.e the non-TMPFS directory, else compile it *INSIDE* the TMPFS directory. This if/else # directory, i.e the non-TMPFS directory, else compile it *INSIDE* the TMPFS directory. This if/else
# is solely for deciding whether $app is in the exception list or not. # is solely for deciding whether $app is in the exception list or not.
if inarray "${app}" "${tmpfsexceptionlist[@]}" ; then if inarray "${app}" "${tmpfsexceptionlist[@]}" ; then
@ -713,47 +713,21 @@ if [[ $globalsccache = 1 ]]; then
if [[ ! -x $sccachebinpath ]] ; then if [[ ! -x $sccachebinpath ]] ; then
err "Oops! sccache binary was not found but building with it was requested! err "Oops! sccache binary was not found but building with it was requested!
Either ensure sccache is in your '$PATH' or disable this option in bldpkg.conf." Either ensure sccache is in your '$PATH' or disable this option in bldpkg.conf."
exit 1
fi fi
if [[ ! $(echo "$PATH" | grep "$sccachepath") ]] ; then # We expect the rustc wrapper to be defined in $HOME/.cargo/config.toml
err "'"$sccachepath"' directory not found in your env PATH" if ! grep -q 'rustc-wrapper\ \= "\/bin\/sccache"' $HOME/.cargo/config.toml ; then
elif [[ ! -d $sccachepath ]] ; then err 'sccache is not defined as a rustc wrapper!
err "'$sccachepath' directory containing symlinks to ccache does not exist! Please add the following to your '"$HOME/"'.cargo/config.toml:
Kindly create it and create symlinks based on instructions in bldpkg.conf." [build]
rustc-wrapper = "/bin/sccache"'
fi fi
for f in gcc g++ cc c++ ; do # Useful for rust-specific builds.
# A hard link is basically a copy of a file with the same inode number stored in a different location. RUSTC_WRAPPER="$sccachebinpath"
# We are trying a bit hard to ascertain whether a binary is a hard link or not. export RUSTC_WRAPPER
# First get the inode number of the binary in the original location
sccache_binary_inode_num=$(stat --printf '%i\n' $sccachebinpath)
# Then get the inode number of the file inside the hard link path
sccache_hardlink_file_inode_num=$(stat --printf '%i\n' $sccachepath/$f)
if [[ ! -e $sccachepath/$f ]] ; then /bin/sccache --start-server
err "'$f' either does not exist inside '"$sccachepath"'. Kindly fix this!"
# If the hard link's inode number does not match the original binary's inode number, throw an error and exit
elif [[ $sccache_hardlink_file_inode_num != "$sccache_binary_inode_num" ]] ; then
err "File '"$f"' inside '"$sccachepath"' is not a hard link! Kindly fix this!"
fi
validatecompiler sccache $sccachepath $f
# Useful for rust-specific builds.
RUSTC_WRAPPER="$sccachebinpath"
export RUSTC_WRAPPER
done
# If sccache=0 is set in the package build file to disable sccache, remove the value of sccachepath
# from $PATH and export it again
if [[ $sccache = 0 ]]; then
PATH="${PATH//$sccachepath:/}"
fi
else
# Remove $sccachepath
PATH="${PATH//$sccachepath:/}"
fi fi
# Apply CPU-specific compiler variables defined inside bldpkg.conf # Apply CPU-specific compiler variables defined inside bldpkg.conf
@ -809,7 +783,7 @@ if [[ -z $noautoconfsite ]] ; then
fi fi
fi fi
# If compilerverbosity is set in /etc/bldpkg.conf or if verbosity is set to 1 from getopts, set V and # If compilerverbosity is set in bldpkg.conf or if verbosity is set to 1 from getopts, set V and
# VERBOSE environment variables for make and cmake build systems to pick up. # VERBOSE environment variables for make and cmake build systems to pick up.
if [[ $compilerverbosity = 1 ]] || [[ $getoptscompilerverbosity = 1 ]] ; then if [[ $compilerverbosity = 1 ]] || [[ $getoptscompilerverbosity = 1 ]] ; then
V=1 V=1
@ -842,7 +816,7 @@ compileonlyfor() {
# To be invoked inside a package build file. # To be invoked inside a package build file.
mkandenterbuilddir() { mkandenterbuilddir() {
# Define $pkgdocs. Rest is defined in /etc/bldpkg.conf. # Define $pkgdocs. Rest is defined in bldpkg.conf.
pkgdocs="$pkg/share/doc/$app-$version" pkgdocs="$pkg/share/doc/$app-$version"
# Remove any old pkg staging directory left by any previous build having same application name # Remove any old pkg staging directory left by any previous build having same application name
@ -1471,7 +1445,7 @@ if [[ -d $tmp ]] ; then
fi fi
# If the above file exists, $resumepkgbuild and $autobuild are unset # If the above file exists, $resumepkgbuild and $autobuild are unset
# and $autoresumepkgbuild is set to 1 in /etc/bldpkg.conf, prompt the user # and $autoresumepkgbuild is set to 1 in bldpkg.conf, prompt the user
if [[ -f $buildresumepath ]] && [[ -z $resumepkgbuild ]] && [[ $autoresumepkgbuild = 1 ]] && [[ -z $autobuild ]]; then if [[ -f $buildresumepath ]] && [[ -z $resumepkgbuild ]] && [[ $autoresumepkgbuild = 1 ]] && [[ -z $autobuild ]]; then
read -r -p "[NOTIFY] Would you like to resume building? " yn read -r -p "[NOTIFY] Would you like to resume building? " yn
case "$yn" in case "$yn" in