2018-08-06 20:00:58 +02:00
#!/usr/bin/env bash
2018-05-13 23:25:41 +02:00
2020-06-23 17:47:43 +02:00
# NOTE: Script for the CI builds, relies on `default.nix` interface, which exposes Nixpkgs Haskell Lib interface
2020-05-27 16:42:58 +02:00
2020-06-23 18:41:38 +02:00
# The most strict error checking requirements
2020-05-31 18:34:39 +02:00
set -Eexuo pipefail
2020-06-23 17:49:29 +02:00
### NOTE: Section handles imports from env, these are settings for Nixpkgs.
2020-06-24 02:08:35 +02:00
### 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
2020-06-23 18:41:38 +02:00
2020-06-23 17:49:29 +02:00
2020-06-24 02:29:17 +02:00
# NOTE: If vars not imported - init the vars with default values
2020-06-23 20:06:02 +02:00
compiler = ${ compiler :- 'ghc8101' }
2020-05-31 18:34:39 +02:00
rev = ${ rev :- 'nixpkgs-unstable' }
2020-06-23 17:53:37 +02:00
# If NIX_PATH not imported - construct it from `rev`
2020-05-31 18:34:39 +02:00
NIX_PATH = ${ NIX_PATH :- " nixpkgs=https://github.com/nixos/nixpkgs/archive/ $rev .tar.gz " }
export NIX_PATH
2020-06-24 02:29:17 +02:00
# Project name, used by cachix
2020-06-23 18:09:01 +02:00
project = ${ project :- 'defaultProjectName' }
2020-06-17 14:51:28 +02:00
2020-06-17 14:51:48 +02:00
2020-06-17 14:48:13 +02:00
allowInconsistentDependencies = ${ allowInconsistentDependencies :- 'false' }
2020-05-31 18:34:39 +02:00
doJailbreak = ${ doJailbreak :- 'false' }
doCheck = ${ doCheck :- 'true' }
2020-06-24 02:05:05 +02:00
2020-06-17 14:54:38 +02:00
sdistTarball = ${ sdistTarball :- 'false' }
2020-05-31 18:34:39 +02:00
buildFromSdist = ${ buildFromSdist :- 'false' }
2020-06-24 02:05:05 +02:00
2020-06-17 14:48:13 +02:00
failOnAllWarnings = ${ failOnAllWarnings :- 'false' }
2020-05-31 18:34:39 +02:00
buildStrictly = ${ buildStrictly :- 'false' }
2020-06-24 02:05:05 +02:00
2020-06-17 14:54:38 +02:00
enableDeadCodeElimination = ${ enableDeadCodeElimination :- 'false' }
2020-05-31 18:34:39 +02:00
disableOptimization = ${ disableOptimization :- 'true' }
2020-06-17 14:54:38 +02:00
linkWithGold = ${ linkWithGold :- 'false' }
2020-06-24 02:05:05 +02:00
2020-06-17 14:48:13 +02:00
enableLibraryProfiling = ${ enableLibraryProfiling :- 'false' }
enableExecutableProfiling = ${ enableExecutableProfiling :- 'false' }
2020-06-17 14:54:38 +02:00
doTracing = ${ doTracing :- 'false' }
enableDWARFDebugging = ${ enableDWARFDebugging :- 'false' }
doStrip = ${ doStrip :- 'false' }
2020-06-24 02:05:05 +02:00
2020-06-17 14:54:38 +02:00
enableSharedLibraries = ${ enableSharedLibraries :- 'true' }
enableStaticLibraries = ${ enableStaticLibraries :- 'false' }
enableSharedExecutables = ${ enableSharedExecutables :- 'false' }
justStaticExecutables = ${ justStaticExecutables :- 'false' }
enableSeparateBinOutput = ${ enableSeparateBinOutput :- 'false' }
2020-06-24 02:05:05 +02:00
2020-06-17 14:48:13 +02:00
checkUnusedPackages = ${ checkUnusedPackages :- 'false' }
doHaddock = ${ doHaddock :- 'false' }
2020-06-23 19:31:39 +02:00
doHyperlinkSource = ${ doHyperlinkSource :- 'false' }
2020-06-17 14:48:13 +02:00
doCoverage = ${ doCoverage :- 'false' }
doBenchmark = ${ doBenchmark :- 'false' }
2020-05-31 18:34:39 +02:00
generateOptparseApplicativeCompletions = ${ generateOptparseApplicativeCompletions :- 'false' }
2020-06-23 18:41:38 +02:00
# [ "binary1" "binary2" ] - should pass " quotes into Nix interpreter
2020-06-17 18:40:21 +02:00
executableNamesToShellComplete = ${ executableNamesToShellComplete :- '[ "defaultBinaryName" ]' }
2020-06-24 02:05:05 +02:00
2020-06-17 14:54:38 +02:00
withHoogle = ${ withHoogle :- 'false' }
2020-06-23 18:41:38 +02:00
# Log file to dump GHCJS build into
2020-05-31 18:34:39 +02:00
ghcjsTmpLogFile = ${ ghcjsTmpLogFile :- '/tmp/ghcjsTmpLogFile.log' }
2020-06-23 18:41:38 +02:00
# Length of the GHCJS log tail (<40000)
2020-05-31 18:34:39 +02:00
ghcjsLogTailLength = ${ ghcjsLogTailLength :- '10000' }
2020-06-23 18:41:38 +02:00
# If key not provided (branch is not inside the central repo) - init CACHIX_SIGNING_KEY as empty
2020-05-31 21:30:24 +02:00
CACHIX_SIGNING_KEY = ${ CACHIX_SIGNING_KEY :- "" }
2020-05-31 18:34:39 +02:00
2020-05-27 16:50:11 +02:00
GHCJS_BUILD( ) {
# NOTE: Function for GHCJS build that outputs its huge log into a file
2020-06-24 02:29:17 +02:00
# Run the build into Log (log is too long for Travis)
2020-05-27 16:50:11 +02:00
" $@ " & > " $ghcjsTmpLogFile "
}
2020-05-27 16:50:33 +02:00
SILENT( ) {
2020-05-28 16:42:01 +02:00
# NOTE: Function that silences the build process
2020-05-27 16:50:33 +02:00
# In normal mode outputs only the /nix/store paths
echo " Log: $ghcjsTmpLogFile "
2020-06-24 02:29:17 +02:00
# Pass into the ghcjsbuild function the build command
2020-05-27 16:50:33 +02:00
if GHCJS_BUILD " $@ "
then
2020-06-24 02:29:17 +02:00
# Output log lines for stdout -> cachix caching
2020-05-27 16:50:33 +02:00
grep '^/nix/store/' " $ghcjsTmpLogFile "
else
2020-06-24 02:29:17 +02:00
# Output log lines for stdout -> cachix caching
2020-05-27 16:50:33 +02:00
grep '^/nix/store/' " $ghcjsTmpLogFile "
2020-06-24 02:29:17 +02:00
# Propagate the error state, fail the CI build
2020-05-27 16:50:33 +02:00
exit 1
fi
}
2020-05-27 23:57:48 +02:00
BUILD_PROJECT( ) {
2020-05-27 16:44:49 +02:00
2020-05-27 19:13:32 +02:00
2020-05-31 18:34:39 +02:00
IFS = $'\n\t'
2020-05-27 19:13:32 +02:00
2020-06-23 20:06:02 +02:00
if [ " $compiler " = "ghcjs" ]
2020-05-28 00:01:12 +02:00
then
2020-06-24 02:29:17 +02:00
# GHCJS build
2020-05-28 16:45:29 +02:00
# By itself, GHCJS creates >65000 lines of log that are >4MB in size, so Travis terminates due to log size quota.
2020-05-28 00:01:12 +02:00
# nixbuild --quiet (x5) does not work on GHC JS build
# So there was a need to make it build.
2020-05-28 16:45:29 +02:00
# The solution is to silence the stdout
2020-05-28 00:01:12 +02:00
# 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
2020-06-17 18:42:24 +02:00
SILENT nix-build \
--arg allowInconsistentDependencies " $allowInconsistentDependencies " \
2020-05-28 00:01:12 +02:00
--arg doJailbreak " $doJailbreak " \
--arg doCheck " $doCheck " \
2020-06-17 18:42:24 +02:00
--arg sdistTarball " $sdistTarball " \
2020-05-28 00:01:12 +02:00
--arg buildFromSdist " $buildFromSdist " \
2020-06-17 18:42:24 +02:00
--arg failOnAllWarnings " $failOnAllWarnings " \
2020-05-28 00:01:12 +02:00
--arg buildStrictly " $buildStrictly " \
2020-06-17 18:42:24 +02:00
--arg enableDeadCodeElimination " $enableDeadCodeElimination " \
2020-05-28 00:01:12 +02:00
--arg disableOptimization " $disableOptimization " \
2020-06-17 18:42:24 +02:00
--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 " \
2020-06-17 18:40:21 +02:00
--arg generateOptparseApplicativeCompletions " $generateOptparseApplicativeCompletions " \
--arg executableNamesToShellComplete " $executableNamesToShellComplete " \
2020-06-17 18:42:24 +02:00
--arg withHoogle " $withHoogle " \
2020-06-23 20:06:02 +02:00
" $compiler "
2020-05-28 00:01:12 +02:00
2020-05-28 00:00:14 +02:00
else
2020-06-24 02:29:17 +02:00
# Normal GHC build
# GHC sometimes produces logs so big - that Travis terminates builds, so multiple --quiet
2020-06-17 18:42:24 +02:00
nix-build \
--quiet --quiet \
2020-06-23 20:06:02 +02:00
--argstr compiler " $compiler " \
2020-06-17 18:42:24 +02:00
--arg allowInconsistentDependencies " $allowInconsistentDependencies " \
2020-05-28 00:00:14 +02:00
--arg doJailbreak " $doJailbreak " \
--arg doCheck " $doCheck " \
2020-06-17 18:42:24 +02:00
--arg sdistTarball " $sdistTarball " \
2020-05-28 00:00:14 +02:00
--arg buildFromSdist " $buildFromSdist " \
2020-06-17 18:42:24 +02:00
--arg failOnAllWarnings " $failOnAllWarnings " \
2020-05-28 00:00:14 +02:00
--arg buildStrictly " $buildStrictly " \
2020-06-17 18:42:24 +02:00
--arg enableDeadCodeElimination " $enableDeadCodeElimination " \
2020-05-28 00:00:14 +02:00
--arg disableOptimization " $disableOptimization " \
2020-06-17 18:42:24 +02:00
--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 " \
2020-06-17 18:40:21 +02:00
--arg generateOptparseApplicativeCompletions " $generateOptparseApplicativeCompletions " \
2020-06-17 18:42:24 +02:00
--arg executableNamesToShellComplete " $executableNamesToShellComplete " \
--arg withHoogle " $withHoogle "
2020-05-28 00:00:14 +02:00
fi
2020-05-27 23:57:48 +02:00
}
2020-05-27 23:57:13 +02:00
MAIN( ) {
2020-06-01 17:43:26 +02:00
2020-06-24 02:29:17 +02:00
# Overall it is useful to have in CI test builds the latest stable Nix
# 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.
2020-06-24 00:53:16 +02:00
( nix-channel --update && nix-env -iA nixpkgs.nix) || ( sudo nix upgrade-nix)
2020-06-01 18:08:37 +02:00
2020-06-01 17:43:26 +02:00
2020-06-24 02:29:17 +02:00
# Secrets are not shared to PRs from forks
# nix-build | cachix push <project> - uploads binaries, runs&works only in the branches of the main repository, so for PRs - else case runs
2020-05-27 23:57:13 +02:00
if [ ! " $CACHIX_SIGNING_KEY " = "" ]
then
2020-06-24 02:29:17 +02:00
# Build of the inside repo branch - enable push Cachix cache
2020-06-23 18:09:01 +02:00
BUILD_PROJECT | cachix push " $project "
2020-05-27 23:57:13 +02:00
else
2020-06-24 02:29:17 +02:00
# Build of the side repo/PR - can not push Cachix cache
2020-05-27 23:57:13 +02:00
BUILD_PROJECT
fi
}
2020-06-24 02:29:17 +02:00
# Run the entry function of the script
2020-05-27 23:57:13 +02:00
MAIN