Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: support structuredAttrs in setup hooks #318614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkgs/build-support/setup-hooks/autoreconf.sh
SomeoneSerge marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ preConfigurePhases="${preConfigurePhases:-} autoreconfPhase"

autoreconfPhase() {
runHook preAutoreconf
autoreconf ${autoreconfFlags:---install --force --verbose}

local flagsArray=()
: "${autoreconfFlags:=--install --force --verbose}"
wolfgangwalther marked this conversation as resolved.
Show resolved Hide resolved
concatTo flagsArray autoreconfFlags

autoreconf "${flagsArray[@]}"
runHook postAutoreconf
}
59 changes: 31 additions & 28 deletions pkgs/by-name/cm/cmake/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cmakeConfigurePhase() {
fi

if [ -z "${dontAddPrefix-}" ]; then
cmakeFlags="-DCMAKE_INSTALL_PREFIX=$prefix $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_INSTALL_PREFIX=$prefix"
fi

# We should set the proper `CMAKE_SYSTEM_NAME`.
Expand All @@ -47,21 +47,21 @@ cmakeConfigurePhase() {
# Unfortunately cmake seems to expect absolute paths for ar, ranlib, and
# strip. Otherwise they are taken to be relative to the source root of the
# package being built.
cmakeFlags="-DCMAKE_CXX_COMPILER=$CXX $cmakeFlags"
cmakeFlags="-DCMAKE_C_COMPILER=$CC $cmakeFlags"
cmakeFlags="-DCMAKE_AR=$(command -v $AR) $cmakeFlags"
cmakeFlags="-DCMAKE_RANLIB=$(command -v $RANLIB) $cmakeFlags"
cmakeFlags="-DCMAKE_STRIP=$(command -v $STRIP) $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_CXX_COMPILER=$CXX"
prependToVar cmakeFlags "-DCMAKE_C_COMPILER=$CC"
prependToVar cmakeFlags "-DCMAKE_AR=$(command -v $AR)"
prependToVar cmakeFlags "-DCMAKE_RANLIB=$(command -v $RANLIB)"
prependToVar cmakeFlags "-DCMAKE_STRIP=$(command -v $STRIP)"

# on macOS we want to prefer Unix-style headers to Frameworks
# because we usually do not package the framework
cmakeFlags="-DCMAKE_FIND_FRAMEWORK=LAST $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_FIND_FRAMEWORK=LAST"

# we never want to use the global macOS SDK
cmakeFlags="-DCMAKE_OSX_SYSROOT= $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_OSX_SYSROOT="

# correctly detect our clang compiler
cmakeFlags="-DCMAKE_POLICY_DEFAULT_CMP0025=NEW $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_POLICY_DEFAULT_CMP0025=NEW"

# This installs shared libraries with a fully-specified install
# name. By default, cmake installs shared libraries with just the
Expand All @@ -70,7 +70,7 @@ cmakeConfigurePhase() {
# libraries are in a system path or in the same directory as the
# executable. This flag makes the shared library accessible from its
# nix/store directory.
cmakeFlags="-DCMAKE_INSTALL_NAME_DIR=${!outputLib}/lib $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_INSTALL_NAME_DIR=${!outputLib}/lib"

# The docdir flag needs to include PROJECT_NAME as per GNU guidelines,
# try to extract it from CMakeLists.txt.
Expand All @@ -93,39 +93,42 @@ cmakeConfigurePhase() {
# This ensures correct paths with multiple output derivations
# It requires the project to use variables from GNUInstallDirs module
# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
cmakeFlags="-DCMAKE_INSTALL_BINDIR=${!outputBin}/bin $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_SBINDIR=${!outputBin}/sbin $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_INCLUDEDIR=${!outputInclude}/include $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_OLDINCLUDEDIR=${!outputInclude}/include $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_MANDIR=${!outputMan}/share/man $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_INFODIR=${!outputInfo}/share/info $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_DOCDIR=${!outputDoc}/share/doc/${shareDocName} $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_LIBDIR=${!outputLib}/lib $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_LIBEXECDIR=${!outputLib}/libexec $cmakeFlags"
cmakeFlags="-DCMAKE_INSTALL_LOCALEDIR=${!outputLib}/share/locale $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_INSTALL_BINDIR=${!outputBin}/bin"
prependToVar cmakeFlags "-DCMAKE_INSTALL_SBINDIR=${!outputBin}/sbin"
prependToVar cmakeFlags "-DCMAKE_INSTALL_INCLUDEDIR=${!outputInclude}/include"
prependToVar cmakeFlags "-DCMAKE_INSTALL_OLDINCLUDEDIR=${!outputInclude}/include"
prependToVar cmakeFlags "-DCMAKE_INSTALL_MANDIR=${!outputMan}/share/man"
prependToVar cmakeFlags "-DCMAKE_INSTALL_INFODIR=${!outputInfo}/share/info"
prependToVar cmakeFlags "-DCMAKE_INSTALL_DOCDIR=${!outputDoc}/share/doc/${shareDocName}"
prependToVar cmakeFlags "-DCMAKE_INSTALL_LIBDIR=${!outputLib}/lib"
prependToVar cmakeFlags "-DCMAKE_INSTALL_LIBEXECDIR=${!outputLib}/libexec"
prependToVar cmakeFlags "-DCMAKE_INSTALL_LOCALEDIR=${!outputLib}/share/locale"

# Don’t build tests when doCheck = false
if [ -z "${doCheck-}" ]; then
cmakeFlags="-DBUILD_TESTING=OFF $cmakeFlags"
prependToVar cmakeFlags "-DBUILD_TESTING=OFF"
fi

# Always build Release, to ensure optimisation flags
cmakeFlags="-DCMAKE_BUILD_TYPE=${cmakeBuildType:-Release} $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_BUILD_TYPE=${cmakeBuildType:-Release}"

# Disable user package registry to avoid potential side effects
# and unecessary attempts to access non-existent home folder
# https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#disabling-the-package-registry
cmakeFlags="-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON $cmakeFlags"
cmakeFlags="-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF $cmakeFlags"
cmakeFlags="-DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF $cmakeFlags"
prependToVar cmakeFlags "-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON"
prependToVar cmakeFlags "-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF"
prependToVar cmakeFlags "-DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF"

if [ "${buildPhase-}" = ninjaBuildPhase ]; then
cmakeFlags="-GNinja $cmakeFlags"
prependToVar cmakeFlags "-GNinja"
fi

echo "cmake flags: $cmakeFlags ${cmakeFlagsArray[@]}"
local flagsArray=()
concatTo flagsArray cmakeFlags cmakeFlagsArray

cmake "$cmakeDir" $cmakeFlags "${cmakeFlagsArray[@]}"
echoCmd 'cmake flags' "${flagsArray[@]}"

cmake "$cmakeDir" "${flagsArray[@]}"

if ! [[ -v enableParallelBuilding ]]; then
enableParallelBuilding=1
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/lo/local-ai/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ let
''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}}
SHELL=$SHELL
)
_accumFlagsArray makeFlags makeFlagsArray buildFlags buildFlagsArray
concatTo flagsArray makeFlags makeFlagsArray buildFlags buildFlagsArray
echoCmd 'build flags' "''${flagsArray[@]}"
make build "''${flagsArray[@]}"
unset flagsArray
Expand Down
13 changes: 5 additions & 8 deletions pkgs/by-name/me/meson/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ mesonConfigurePhase() {
"--localedir=${!outputLib}/share/locale"
"-Dauto_features=${mesonAutoFeatures:-enabled}"
"-Dwrap_mode=${mesonWrapMode:-nodownload}"
${crossMesonFlags}
"--buildtype=${mesonBuildType:-plain}"
)

_accumFlagsArray mesonFlags mesonFlagsArray
concatTo flagsArray mesonFlags mesonFlagsArray

echoCmd 'mesonConfigurePhase flags' "${flagsArray[@]}"

Expand All @@ -50,7 +49,8 @@ mesonConfigurePhase() {
mesonCheckPhase() {
runHook preCheck

local flagsArray=($mesonCheckFlags "${mesonCheckFlagsArray[@]}")
local flagsArray=()
concatTo flagsArray mesonCheckFlags mesonCheckFlagsArray

echoCmd 'mesonCheckPhase flags' "${flagsArray[@]}"
meson test --no-rebuild --print-errorlogs "${flagsArray[@]}"
Expand All @@ -64,12 +64,9 @@ mesonInstallPhase() {
local flagsArray=()

if [[ -n "$mesonInstallTags" ]]; then
flagsArray+=("--tags" "${mesonInstallTags// /,}")
flagsArray+=("--tags" "$(concatStringsSep "," mesonInstallTags)")
fi
flagsArray+=(
$mesonInstallFlags
"${mesonInstallFlagsArray[@]}"
)
concatTo flagsArray mesonInstallFlags mesonInstallFlagsArray

echoCmd 'mesonInstallPhase flags' "${flagsArray[@]}"
meson install --no-rebuild "${flagsArray[@]}"
Expand Down
25 changes: 13 additions & 12 deletions pkgs/by-name/ni/ninja/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash

ninjaBuildPhase() {
runHook preBuild

Expand All @@ -9,9 +11,9 @@ ninjaBuildPhase() {
fi

local flagsArray=(
-j$buildCores
$ninjaFlags "${ninjaFlagsArray[@]}"
"-j$buildCores"
)
concatTo flagsArray ninjaFlags ninjaFlagsArray

echoCmd 'build flags' "${flagsArray[@]}"
TERM=dumb ninja "${flagsArray[@]}"
Expand All @@ -24,7 +26,7 @@ ninjaCheckPhase() {

if [ -z "${checkTarget:-}" ]; then
if ninja -t query test >/dev/null 2>&1; then
checkTarget=test
checkTarget="test"
fi
fi

Expand All @@ -38,10 +40,9 @@ ninjaCheckPhase() {
fi

local flagsArray=(
-j$buildCores
$ninjaFlags "${ninjaFlagsArray[@]}"
$checkTarget
"-j$buildCores"
)
concatTo flagsArray ninjaFlags ninjaFlagsArray checkTarget

echoCmd 'check flags' "${flagsArray[@]}"
TERM=dumb ninja "${flagsArray[@]}"
Expand All @@ -62,25 +63,25 @@ ninjaInstallPhase() {

# shellcheck disable=SC2086
local flagsArray=(
-j$buildCores
$ninjaFlags "${ninjaFlagsArray[@]}"
${installTargets:-install}
"-j$buildCores"
)
: "${installTargets:=install}"
concatTo flagsArray ninjaFlags ninjaFlagsArray installTargets

echoCmd 'install flags' "${flagsArray[@]}"
TERM=dumb ninja "${flagsArray[@]}"

runHook postInstall
}

if [ -z "${dontUseNinjaBuild-}" -a -z "${buildPhase-}" ]; then
if [ -z "${dontUseNinjaBuild-}" ] && [ -z "${buildPhase-}" ]; then
wolfgangwalther marked this conversation as resolved.
Show resolved Hide resolved
buildPhase=ninjaBuildPhase
fi

if [ -z "${dontUseNinjaCheck-}" -a -z "${checkPhase-}" ]; then
if [ -z "${dontUseNinjaCheck-}" ] && [ -z "${checkPhase-}" ]; then
checkPhase=ninjaCheckPhase
fi

if [ -z "${dontUseNinjaInstall-}" -a -z "${installPhase-}" ]; then
if [ -z "${dontUseNinjaInstall-}" ] && [ -z "${installPhase-}" ]; then
installPhase=ninjaInstallPhase
fi
Loading