buildRustCrate: refactor colored logging
* Make errors include the crate name and make them much more prominent. * Move more code into lib.sh * Already source generated logging code and lib.sh in configure
This commit is contained in:
parent
e2920d957a
commit
04e7462ee6
@ -1,4 +1,4 @@
|
|||||||
{ lib, stdenv, echo_build_heading, noisily, mkRustcDepArgs, rust }:
|
{ lib, stdenv, mkRustcDepArgs, rust }:
|
||||||
{ crateName,
|
{ crateName,
|
||||||
dependencies,
|
dependencies,
|
||||||
crateFeatures, crateRenames, libName, release, libPath,
|
crateFeatures, crateRenames, libName, release, libPath,
|
||||||
@ -35,16 +35,13 @@
|
|||||||
build_bin = if buildTests then "build_bin_test" else "build_bin";
|
build_bin = if buildTests then "build_bin_test" else "build_bin";
|
||||||
in ''
|
in ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
${echo_build_heading colors}
|
|
||||||
${noisily colors verbose}
|
|
||||||
|
|
||||||
# configure & source common build functions
|
# configure & source common build functions
|
||||||
LIB_RUSTC_OPTS="${libRustcOpts}"
|
LIB_RUSTC_OPTS="${libRustcOpts}"
|
||||||
BIN_RUSTC_OPTS="${binRustcOpts}"
|
BIN_RUSTC_OPTS="${binRustcOpts}"
|
||||||
LIB_EXT="${stdenv.hostPlatform.extensions.sharedLibrary}"
|
LIB_EXT="${stdenv.hostPlatform.extensions.sharedLibrary}"
|
||||||
LIB_PATH="${libPath}"
|
LIB_PATH="${libPath}"
|
||||||
LIB_NAME="${libName}"
|
LIB_NAME="${libName}"
|
||||||
source ${./lib.sh}
|
|
||||||
|
|
||||||
CRATE_NAME='${lib.replaceStrings ["-"] ["_"] libName}'
|
CRATE_NAME='${lib.replaceStrings ["-"] ["_"] libName}'
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ lib, stdenv, echo_build_heading, noisily, mkRustcDepArgs }:
|
{ lib, stdenv, echo_colored, noisily, mkRustcDepArgs }:
|
||||||
{ build
|
{ build
|
||||||
, buildDependencies
|
, buildDependencies
|
||||||
, colors
|
, colors
|
||||||
@ -32,9 +32,11 @@ let version_ = lib.splitString "-" crateVersion;
|
|||||||
completeBuildDepsDir = lib.concatStringsSep " " completeBuildDeps;
|
completeBuildDepsDir = lib.concatStringsSep " " completeBuildDeps;
|
||||||
in ''
|
in ''
|
||||||
cd ${workspace_member}
|
cd ${workspace_member}
|
||||||
runHook preConfigure
|
${echo_colored colors}
|
||||||
${echo_build_heading colors}
|
|
||||||
${noisily colors verbose}
|
${noisily colors verbose}
|
||||||
|
source ${./lib.sh}
|
||||||
|
|
||||||
|
runHook preConfigure
|
||||||
symlink_dependency() {
|
symlink_dependency() {
|
||||||
# $1 is the nix-store path of a dependency
|
# $1 is the nix-store path of a dependency
|
||||||
# $2 is the target path
|
# $2 is the target path
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# This can be useful for deploying packages with NixOps, and to share
|
# This can be useful for deploying packages with NixOps, and to share
|
||||||
# binary dependencies between projects.
|
# binary dependencies between projects.
|
||||||
|
|
||||||
{ lib, stdenv, defaultCrateOverrides, fetchCrate, rustc, rust }:
|
{ lib, stdenv, defaultCrateOverrides, fetchCrate, rustc, rust, cargo, jq }:
|
||||||
|
|
||||||
let
|
let
|
||||||
# This doesn't appear to be officially documented anywhere yet.
|
# This doesn't appear to be officially documented anywhere yet.
|
||||||
@ -29,14 +29,14 @@ let
|
|||||||
" --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
|
" --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
|
||||||
) dependencies;
|
) dependencies;
|
||||||
|
|
||||||
inherit (import ./log.nix { inherit lib; }) noisily echo_build_heading;
|
inherit (import ./log.nix { inherit lib; }) noisily echo_colored;
|
||||||
|
|
||||||
configureCrate = import ./configure-crate.nix {
|
configureCrate = import ./configure-crate.nix {
|
||||||
inherit lib stdenv echo_build_heading noisily mkRustcDepArgs;
|
inherit lib stdenv echo_colored noisily mkRustcDepArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
buildCrate = import ./build-crate.nix {
|
buildCrate = import ./build-crate.nix {
|
||||||
inherit lib stdenv echo_build_heading noisily mkRustcDepArgs rust;
|
inherit lib stdenv mkRustcDepArgs rust;
|
||||||
};
|
};
|
||||||
|
|
||||||
installCrate = import ./install-crate.nix { inherit stdenv; };
|
installCrate = import ./install-crate.nix { inherit stdenv; };
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
echo_build_heading() {
|
||||||
|
if (( $# == 1 )); then
|
||||||
|
echo_colored "Building $1"
|
||||||
|
else
|
||||||
|
echo_colored "Building $1 ($2)"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
build_lib() {
|
build_lib() {
|
||||||
lib_src=$1
|
lib_src=$1
|
||||||
echo_build_heading $lib_src ${libName}
|
echo_build_heading $lib_src ${libName}
|
||||||
@ -132,7 +140,7 @@ search_for_bin_path() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "$BIN_PATH" ]]; then
|
if [[ -z "$BIN_PATH" ]]; then
|
||||||
echo "failed to find file for binary target: $BIN_NAME" >&2
|
echo_error "ERROR: failed to find file for binary target: $BIN_NAME" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,56 @@
|
|||||||
{ lib }:
|
{ lib }:
|
||||||
{
|
|
||||||
echo_build_heading = colors: ''
|
let echo_colored_body = start_escape:
|
||||||
echo_build_heading() {
|
# Body of a function that behaves like "echo" but
|
||||||
start=""
|
# has the output colored by the given start_escape
|
||||||
end=""
|
# sequence. E.g.
|
||||||
${lib.optionalString (colors == "always") ''
|
#
|
||||||
start="$(printf '\033[0;1;32m')" #set bold, and set green.
|
# * echo_x "Building ..."
|
||||||
end="$(printf '\033[0m')" #returns to "normal"
|
# * echo_x -n "Running "
|
||||||
''}
|
#
|
||||||
if (( $# == 1 )); then
|
# This is more complicated than apparent at first sight
|
||||||
echo "$start""Building $1""$end"
|
# because:
|
||||||
else
|
# * The color markers and the text must be print
|
||||||
echo "$start""Building $1 ($2)""$end"
|
# in the same echo statement. Otherise, other
|
||||||
fi
|
# intermingled text from concurrent builds will
|
||||||
|
# be colored as well.
|
||||||
|
# * We need to preserve the trailing newline of the
|
||||||
|
# echo if and only if it is present. Bash likes
|
||||||
|
# to strip those if we capture the output of echo
|
||||||
|
# in a variable.
|
||||||
|
# * Leading "-" will be interpreted by test as an
|
||||||
|
# option for itself. Therefore, we prefix it with
|
||||||
|
# an x in `[[ "x$1" =~ ^x- ]]`.
|
||||||
|
''
|
||||||
|
local echo_args="";
|
||||||
|
while [[ "x$1" =~ ^x- ]]; do
|
||||||
|
echo_args+=" $1"
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
local start_escape="$(printf '${start_escape}')"
|
||||||
|
local reset="$(printf '\033[0m')"
|
||||||
|
echo $echo_args $start_escape"$@"$reset
|
||||||
|
'';
|
||||||
|
echo_conditional_colored_body = colors: start_escape:
|
||||||
|
if colors == "always"
|
||||||
|
then (echo_colored_body start_escape)
|
||||||
|
else ''echo "$@"'';
|
||||||
|
in {
|
||||||
|
echo_colored = colors: ''
|
||||||
|
echo_colored() {
|
||||||
|
${echo_conditional_colored_body colors ''\033[0;1;32m''}
|
||||||
}
|
}
|
||||||
'';
|
|
||||||
|
echo_error() {
|
||||||
|
${echo_conditional_colored_body colors ''\033[0;1;31m''}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
noisily = colors: verbose: ''
|
noisily = colors: verbose: ''
|
||||||
noisily() {
|
noisily() {
|
||||||
start=""
|
|
||||||
end=""
|
|
||||||
${lib.optionalString (colors == "always") ''
|
|
||||||
start="$(printf '\033[0;1;32m')" #set bold, and set green.
|
|
||||||
end="$(printf '\033[0m')" #returns to "normal"
|
|
||||||
''}
|
|
||||||
${lib.optionalString verbose ''
|
${lib.optionalString verbose ''
|
||||||
echo -n "$start"Running "$end"
|
echo_colored -n "Running "
|
||||||
echo $@
|
echo $@
|
||||||
''}
|
''}
|
||||||
$@
|
$@
|
||||||
|
Loading…
x
Reference in New Issue
Block a user