mirror of
https://github.com/haskell-nix/hnix.git
synced 2024-09-11 06:55:38 +03:00
219 lines
8.3 KiB
Bash
Executable File
219 lines
8.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# NOTE: Script for the CI builds, relies on `default.nix` interface, which exposes Nixpkgs Haskell Lib interface
|
|
|
|
# The most strict error checking requirements
|
|
set -Eexuo pipefail
|
|
|
|
### NOTE: Section handles imports from env, these are settings for Nixpkgs.
|
|
### They use the `default.nix` interface, which exposes expose most of the Nixpkgs Haskell.lib API: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/lib.nix
|
|
### Some of these options implicitly switch the dependent options.
|
|
### Documentation of this settings is mosly in `default.nix`, since most settings it Nixpkgs related
|
|
### Additional documentation is in Nixpkgs Haskell.lib: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/lib.nix
|
|
|
|
|
|
# NOTE: If vars not imported - set to the default value
|
|
compiler=${compiler:-'ghc8101'}
|
|
rev=${rev:-'nixpkgs-unstable'}
|
|
# If NIX_PATH not imported - construct it from `rev`
|
|
NIX_PATH=${NIX_PATH:-"nixpkgs=https://github.com/nixos/nixpkgs/archive/$rev.tar.gz"}
|
|
export NIX_PATH
|
|
# NOTE: Project name, used by cachix
|
|
project=${project:-'defaultProjectName'}
|
|
|
|
|
|
allowInconsistentDependencies=${allowInconsistentDependencies:-'false'}
|
|
doJailbreak=${doJailbreak:-'false'}
|
|
doCheck=${doCheck:-'true'}
|
|
|
|
sdistTarball=${sdistTarball:-'false'}
|
|
buildFromSdist=${buildFromSdist:-'false'}
|
|
|
|
failOnAllWarnings=${failOnAllWarnings:-'false'}
|
|
buildStrictly=${buildStrictly:-'false'}
|
|
|
|
enableDeadCodeElimination=${enableDeadCodeElimination:-'false'}
|
|
disableOptimization=${disableOptimization:-'true'}
|
|
linkWithGold=${linkWithGold:-'false'}
|
|
|
|
enableLibraryProfiling=${enableLibraryProfiling:-'false'}
|
|
enableExecutableProfiling=${enableExecutableProfiling:-'false'}
|
|
doTracing=${doTracing:-'false'}
|
|
enableDWARFDebugging=${enableDWARFDebugging:-'false'}
|
|
doStrip=${doStrip:-'false'}
|
|
|
|
enableSharedLibraries=${enableSharedLibraries:-'true'}
|
|
enableStaticLibraries=${enableStaticLibraries:-'false'}
|
|
enableSharedExecutables=${enableSharedExecutables:-'false'}
|
|
justStaticExecutables=${justStaticExecutables:-'false'}
|
|
enableSeparateBinOutput=${enableSeparateBinOutput:-'false'}
|
|
|
|
checkUnusedPackages=${checkUnusedPackages:-'false'}
|
|
doHaddock=${doHaddock:-'false'}
|
|
doHyperlinkSource=${doHyperlinkSource:-'false'}
|
|
doCoverage=${doCoverage:-'false'}
|
|
doBenchmark=${doBenchmark:-'false'}
|
|
generateOptparseApplicativeCompletions=${generateOptparseApplicativeCompletions:-'false'}
|
|
# [ "binary1" "binary2" ] - should pass " quotes into Nix interpreter
|
|
executableNamesToShellComplete=${executableNamesToShellComplete:-'[ "defaultBinaryName" ]'}
|
|
|
|
|
|
withHoogle=${withHoogle:-'false'}
|
|
|
|
# Log file to dump GHCJS build into
|
|
ghcjsTmpLogFile=${ghcjsTmpLogFile:-'/tmp/ghcjsTmpLogFile.log'}
|
|
# Length of the GHCJS log tail (<40000)
|
|
ghcjsLogTailLength=${ghcjsLogTailLength:-'10000'}
|
|
|
|
# If key not provided (branch is not inside the central repo) - init CACHIX_SIGNING_KEY as empty
|
|
CACHIX_SIGNING_KEY=${CACHIX_SIGNING_KEY:-""}
|
|
|
|
|
|
GHCJS_BUILD(){
|
|
# NOTE: Function for GHCJS build that outputs its huge log into a file
|
|
|
|
# NOTE: Run the build into Log (log is too long for Travis)
|
|
"$@" &> "$ghcjsTmpLogFile"
|
|
|
|
}
|
|
|
|
SILENT(){
|
|
# NOTE: Function that silences the build process
|
|
# In normal mode outputs only the /nix/store paths
|
|
|
|
echo "Log: $ghcjsTmpLogFile"
|
|
# NOTE: Pass into the ghcjsbuild function the build command
|
|
if GHCJS_BUILD "$@"
|
|
then
|
|
|
|
# NOTE: Output log lines for stdout -> cachix caching
|
|
grep '^/nix/store/' "$ghcjsTmpLogFile"
|
|
|
|
else
|
|
|
|
# NOTE: Output log lines for stdout -> cachix caching
|
|
grep '^/nix/store/' "$ghcjsTmpLogFile"
|
|
|
|
# NOTE: Propagate the error state, fail the CI build
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
BUILD_PROJECT(){
|
|
|
|
|
|
IFS=$'\n\t'
|
|
|
|
if [ "$compiler" = "ghcjs" ]
|
|
then
|
|
|
|
# NOTE: GHCJS build
|
|
# By itself, GHCJS creates >65000 lines of log that are >4MB in size, so Travis terminates due to log size quota.
|
|
# nixbuild --quiet (x5) does not work on GHC JS build
|
|
# So there was a need to make it build.
|
|
# The solution is to silence the stdout
|
|
# But Travis then terminates on 10 min no stdout timeout
|
|
# so HACK: SILENT wrapper allows to surpress the huge log, while still preserves the Cachix caching ability in any case of the build
|
|
# On build failure outputs the last 10000 lines of log (that should be more then enough), and terminates
|
|
SILENT nix-build \
|
|
--arg allowInconsistentDependencies "$allowInconsistentDependencies" \
|
|
--arg doJailbreak "$doJailbreak" \
|
|
--arg doCheck "$doCheck" \
|
|
--arg sdistTarball "$sdistTarball" \
|
|
--arg buildFromSdist "$buildFromSdist" \
|
|
--arg failOnAllWarnings "$failOnAllWarnings" \
|
|
--arg buildStrictly "$buildStrictly" \
|
|
--arg enableDeadCodeElimination "$enableDeadCodeElimination" \
|
|
--arg disableOptimization "$disableOptimization" \
|
|
--arg linkWithGold "$linkWithGold" \
|
|
--arg enableLibraryProfiling "$enableLibraryProfiling" \
|
|
--arg enableExecutableProfiling "$enableExecutableProfiling" \
|
|
--arg doTracing "$doTracing" \
|
|
--arg enableDWARFDebugging "$enableDWARFDebugging" \
|
|
--arg doStrip "$doStrip" \
|
|
--arg doHyperlinkSource "$doHyperlinkSource" \
|
|
--arg enableSharedLibraries "$enableSharedLibraries" \
|
|
--arg enableStaticLibraries "$enableStaticLibraries" \
|
|
--arg enableSharedExecutables "$enableSharedExecutables" \
|
|
--arg justStaticExecutables "$justStaticExecutables" \
|
|
--arg checkUnusedPackages "$checkUnusedPackages" \
|
|
--arg doCoverage "$doCoverage" \
|
|
--arg doHaddock "$doHaddock" \
|
|
--arg doBenchmark "$doBenchmark" \
|
|
--arg generateOptparseApplicativeCompletions "$generateOptparseApplicativeCompletions" \
|
|
--arg executableNamesToShellComplete "$executableNamesToShellComplete" \
|
|
--arg withHoogle "$withHoogle" \
|
|
"$compiler"
|
|
|
|
else
|
|
|
|
# NOTE: Normal GHC build
|
|
# NOTE: GHC sometimes produces logs so big - that Travis terminates builds, so multiple --quiet
|
|
nix-build \
|
|
--quiet --quiet \
|
|
--argstr compiler "$compiler" \
|
|
--arg allowInconsistentDependencies "$allowInconsistentDependencies" \
|
|
--arg doJailbreak "$doJailbreak" \
|
|
--arg doCheck "$doCheck" \
|
|
--arg sdistTarball "$sdistTarball" \
|
|
--arg buildFromSdist "$buildFromSdist" \
|
|
--arg failOnAllWarnings "$failOnAllWarnings" \
|
|
--arg buildStrictly "$buildStrictly" \
|
|
--arg enableDeadCodeElimination "$enableDeadCodeElimination" \
|
|
--arg disableOptimization "$disableOptimization" \
|
|
--arg linkWithGold "$linkWithGold" \
|
|
--arg enableLibraryProfiling "$enableLibraryProfiling" \
|
|
--arg enableExecutableProfiling "$enableExecutableProfiling" \
|
|
--arg doTracing "$doTracing" \
|
|
--arg enableDWARFDebugging "$enableDWARFDebugging" \
|
|
--arg doStrip "$doStrip" \
|
|
--arg doHyperlinkSource "$doHyperlinkSource" \
|
|
--arg enableSharedLibraries "$enableSharedLibraries" \
|
|
--arg enableStaticLibraries "$enableStaticLibraries" \
|
|
--arg enableSharedExecutables "$enableSharedExecutables" \
|
|
--arg justStaticExecutables "$justStaticExecutables" \
|
|
--arg checkUnusedPackages "$checkUnusedPackages" \
|
|
--arg doCoverage "$doCoverage" \
|
|
--arg doHaddock "$doHaddock" \
|
|
--arg doBenchmark "$doBenchmark" \
|
|
--arg generateOptparseApplicativeCompletions "$generateOptparseApplicativeCompletions" \
|
|
--arg executableNamesToShellComplete "$executableNamesToShellComplete" \
|
|
--arg withHoogle "$withHoogle"
|
|
|
|
fi
|
|
}
|
|
|
|
MAIN() {
|
|
|
|
|
|
# NOTE: Overall it is useful to have in CI test builds the latest stable Nix
|
|
# NOTE: User-run Linux setup old update command, or superuser update for macOS setup
|
|
# 2020-06-24: HACK: Do not ask why different commands on Linux and macOS. IDK, wished they we the same. These are the only commands that worked on according platforms right after the fresh Nix installer rollout.
|
|
(nix-channel --update && nix-env -iA nixpkgs.nix) || (sudo nix upgrade-nix)
|
|
|
|
|
|
|
|
# NOTE: Secrets are not shared to PRs from forks
|
|
# NOTE: nix-build | cachix push <project> - uploads binaries, runs&works only in the branches of the main repository, so for PRs - else case runs
|
|
|
|
if [ ! "$CACHIX_SIGNING_KEY" = "" ]
|
|
|
|
then
|
|
|
|
# NOTE: Build of the inside repo branch - enable push Cachix cache
|
|
BUILD_PROJECT | cachix push "$project"
|
|
|
|
else
|
|
|
|
# NOTE: Build of the side repo/PR - can not push Cachix cache
|
|
BUILD_PROJECT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
# NOTE: Run the entry function of the script
|
|
MAIN
|