2013-05-02 14:04:28 +00:00
|
|
|
|
#! /usr/bin/env bash
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
|
|
|
|
# This script has been generated automatically by Hydra from the build
|
|
|
|
|
# at [% c.uri_for('/build' build.id) %].
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2013-05-02 14:04:28 +00:00
|
|
|
|
tmpDir=${TMPDIR:-/tmp}/build-[% build.id +%]
|
|
|
|
|
declare -a args extraArgs
|
|
|
|
|
|
|
|
|
|
|
2013-05-02 14:24:30 +00:00
|
|
|
|
info() {
|
|
|
|
|
echo "[1;32m$1[0m" >&2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-02 14:04:28 +00:00
|
|
|
|
# Process the command line.
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
arg="$1"
|
|
|
|
|
shift
|
|
|
|
|
if [ "$arg" = --help ]; then
|
|
|
|
|
cat <<EOF
|
|
|
|
|
Usage: $0 [--dir PATH] [--run-env]
|
|
|
|
|
|
|
|
|
|
This script will reproduce Hydra build [% build.id %] of job [%
|
|
|
|
|
build.project.name %]:[% build.jobset.name %]:[% build.job.name +%]
|
|
|
|
|
(available at [%+ c.uri_for('/build' build.id) +%]). It will fetch
|
|
|
|
|
all inputs of the Hydra build, then invoke Nix to build the job and
|
|
|
|
|
all its dependencies.
|
|
|
|
|
|
|
|
|
|
The inputs will be stored in $tmpDir. This can be overriden using the
|
|
|
|
|
--dir flag. After the build, the result of the build is available via
|
|
|
|
|
the symlink $tmpDir/result.
|
|
|
|
|
|
|
|
|
|
Flags:
|
|
|
|
|
|
|
|
|
|
--dir PATH
|
|
|
|
|
Override the location where the inputs and result symlink are stored.
|
|
|
|
|
|
|
|
|
|
--run-env
|
|
|
|
|
Fetch the inputs and build the dependencies, then start an
|
|
|
|
|
interactive shell in which the environment is equal to that used
|
|
|
|
|
to perform the build. See the description of the --run-env flag
|
|
|
|
|
in the nix-build(1) manpage for more details.
|
|
|
|
|
|
|
|
|
|
Any additional flags are passed to nix-build. See the nix-build(1)
|
|
|
|
|
manpage for details.
|
|
|
|
|
EOF
|
|
|
|
|
exit 0
|
|
|
|
|
elif [ "$arg" = --dir ]; then
|
|
|
|
|
tmpDir="$1"
|
|
|
|
|
if [ -z "$tmpDir" ]; then
|
|
|
|
|
echo "$0: --dir requires an argument" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
else
|
|
|
|
|
extraArgs+=("$arg")
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
2013-05-02 14:04:28 +00:00
|
|
|
|
export NIX_PATH=
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
2013-05-02 14:04:28 +00:00
|
|
|
|
mkdir -p "$tmpDir"
|
|
|
|
|
cd "$tmpDir"
|
2013-05-02 14:24:30 +00:00
|
|
|
|
info "storing inputs and results in $tmpDir..."
|
2013-05-02 14:19:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requireCommand() {
|
|
|
|
|
local cmd="$1"
|
|
|
|
|
if ! type -P "$cmd" > /dev/null; then
|
|
|
|
|
echo "$0: command ‘$cmd’ is not installed; please install it and try again" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Fetch the inputs.
|
|
|
|
|
|
|
|
|
|
[%+ FOREACH input IN build.inputs %]
|
|
|
|
|
inputDir=
|
|
|
|
|
|
|
|
|
|
[%+ IF input.type == "git" %]
|
|
|
|
|
|
2013-05-02 14:04:28 +00:00
|
|
|
|
inputDir="$tmpDir/[% input.name %]/git-export"
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
|
|
|
|
if ! [ -d "$inputDir" ]; then
|
2013-05-02 14:24:30 +00:00
|
|
|
|
info "fetching Git input ‘[% input.name %]’ from ‘[% input.uri %]’ (commit [% input.revision %])..."
|
2013-05-02 14:19:20 +00:00
|
|
|
|
requireCommand git
|
2013-04-04 15:30:07 +00:00
|
|
|
|
inputDirTmp="$inputDir.tmp"
|
|
|
|
|
rm -rf "$inputDirTmp"
|
|
|
|
|
mkdir -p "$inputDirTmp"
|
|
|
|
|
git clone '[% input.uri %]' "$inputDirTmp"
|
|
|
|
|
(cd "$inputDirTmp" && git checkout '[% input.revision %]')
|
|
|
|
|
revCount="$(cd "$inputDirTmp" && (git rev-list '[% input.revision %]' | wc -l))"
|
|
|
|
|
rm -rf "$inputDirTmp/.git"
|
|
|
|
|
mv "$inputDirTmp" "$inputDir"
|
2013-06-02 21:30:46 +00:00
|
|
|
|
echo -n $revCount > "$tmpDir/[% input.name %]/rev-count"
|
2013-05-30 18:06:32 +00:00
|
|
|
|
else
|
2013-06-02 21:30:46 +00:00
|
|
|
|
revCount="$(cat "$tmpDir/[% input.name %]/rev-count")"
|
2013-04-04 15:30:07 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
args+=(--arg '[% input.name %]' "{ outPath = $inputDir; rev = \"[% input.revision %]\"; shortRev = \"[% input.revision.substr(0, 7) %]\"; revCount = \"$revCount\"; }")
|
|
|
|
|
|
|
|
|
|
[%+ ELSIF input.type == "hg" %]
|
|
|
|
|
|
2013-05-02 14:04:28 +00:00
|
|
|
|
inputDir="$tmpDir/[% input.name %]/hg-archive"
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
|
|
|
|
if ! [ -d "$inputDir" ]; then
|
2013-05-02 14:24:30 +00:00
|
|
|
|
info "fetching Mercurial input ‘[% input.name %]’ from ‘[% input.uri %]’ (commit [% input.revision %])..."
|
2013-05-02 14:19:20 +00:00
|
|
|
|
requireCommand hg
|
2013-04-04 15:30:07 +00:00
|
|
|
|
inputDirTmp="$inputDir.tmp"
|
|
|
|
|
rm -rf "$inputDirTmp"
|
2013-05-30 17:31:53 +00:00
|
|
|
|
mkdir -p "$inputDirTmp"
|
2013-05-16 15:24:17 +00:00
|
|
|
|
hg clone '[% input.uri %]' "$inputDirTmp"
|
|
|
|
|
(cd "$inputDirTmp" && hg update '[% input.revision %]')
|
|
|
|
|
revCount="$(cd "$inputDirTmp" && (hg log -r '[% input.revision %]' --template "{rev}"))"
|
2013-04-04 15:30:07 +00:00
|
|
|
|
rm -rf "$inputDirTmp/.hg"
|
|
|
|
|
mv "$inputDirTmp" "$inputDir"
|
2013-06-02 21:30:46 +00:00
|
|
|
|
echo -n $revCount > "$tmpDir/[% input.name %]/rev-count"
|
2013-05-30 18:06:32 +00:00
|
|
|
|
else
|
2013-06-02 21:30:46 +00:00
|
|
|
|
revCount="$(cat "$tmpDir/[% input.name %]/rev-count")"
|
2013-04-04 15:30:07 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
args+=(--arg '[% input.name %]' "{ outPath = $inputDir; rev = \"[% input.revision %]\"; revCount = \"$revCount\"; }")
|
|
|
|
|
|
|
|
|
|
[%+ ELSIF input.type == "svn" %]
|
|
|
|
|
|
2013-05-02 14:04:28 +00:00
|
|
|
|
inputDir="$tmpDir/[% input.name %]/svn-export"
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
|
|
|
|
if ! [ -d "$inputDir" ]; then
|
2013-05-02 14:24:30 +00:00
|
|
|
|
info "fetching Subversion input ‘[% input.name %]’ from ‘[% input.uri %]’ (commit [% input.revision %])..."
|
2013-05-02 14:19:20 +00:00
|
|
|
|
requireCommand svn
|
2013-04-04 15:30:07 +00:00
|
|
|
|
rm -rf "$inputDir.tmp"
|
|
|
|
|
svn export '[% input.uri %]@[% input.revision %]' "$inputDir.tmp"
|
|
|
|
|
mv "$inputDir.tmp" "$inputDir"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
args+=(--arg '[% input.name %]' "{ outPath = $inputDir; rev = \"[% input.revision %]\"; }")
|
|
|
|
|
|
|
|
|
|
[% ELSIF input.type == "string" %]
|
|
|
|
|
args+=(--arg '[% input.name %]' '"[% input.value %]"')
|
|
|
|
|
|
|
|
|
|
[% ELSIF input.type == "boolean" %]
|
|
|
|
|
args+=(--arg '[% input.name %]' '[% input.value %]')
|
|
|
|
|
|
|
|
|
|
[% ELSE %]
|
|
|
|
|
echo "$0: input ‘[% input.name %]’ has unsupported type ‘[% input.type %]’" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
[% END %]
|
|
|
|
|
|
|
|
|
|
[% IF input.name == build.nixexprinput +%]
|
|
|
|
|
nixExprInputDir="$inputDir"
|
|
|
|
|
[%+ END %]
|
|
|
|
|
|
|
|
|
|
if [ -n "$inputDir" ]; then
|
|
|
|
|
NIX_PATH="$NIX_PATH${NIX_PATH:+:}[% input.name %]=$inputDir"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
[%+ END %]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Run nix-build.
|
|
|
|
|
|
2013-05-02 14:19:20 +00:00
|
|
|
|
requireCommand nix-build
|
|
|
|
|
|
2013-04-04 15:30:07 +00:00
|
|
|
|
if [ -z "$nixExprInputDir" ]; then
|
|
|
|
|
echo "$0: don't know the path to the Nix expression!" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2013-05-07 13:57:20 +00:00
|
|
|
|
args+=(--option extra-binary-caches '[% c.uri_for('/') %]')
|
2013-04-04 15:30:07 +00:00
|
|
|
|
|
|
|
|
|
# Since Hydra runs on x86_64-linux, pretend we're one. This matters
|
|
|
|
|
# when evaluating jobs that rely on builtins.currentSystem.
|
|
|
|
|
args+=(--option system x86_64-linux)
|
|
|
|
|
|
2013-05-02 14:24:30 +00:00
|
|
|
|
info "running nix-build..."
|
2013-04-04 15:30:07 +00:00
|
|
|
|
echo "Nix path is $NIX_PATH" >&2
|
|
|
|
|
echo "Nix args are ${args[@]}" >&2
|
|
|
|
|
|
2013-05-02 14:24:30 +00:00
|
|
|
|
exec nix-build "$nixExprInputDir/[% build.nixexprpath %]" -A '[% build.job.name %]' "${args[@]}" "${extraArgs[@]}"
|