mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-26 09:08:57 +03:00
Add cargoHelperFunctionsHook
* It will automatically capture and log all `cargo` invocations
This commit is contained in:
parent
7fc1a8fec3
commit
bce972e03b
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
* **Breaking**: the `--workspace` flag is no longer set for all cargo commands
|
||||
by default. The previous behavior can be recovered by setting `cargoExtraArgs
|
||||
= "--workspace";` in any derivation.
|
||||
* All cargo invocations made during the build are automatically logged
|
||||
|
||||
## [0.5.1] - 2022-07-20
|
||||
|
||||
|
11
docs/API.md
11
docs/API.md
@ -527,6 +527,7 @@ environment variables during the build, you can bring them back via
|
||||
The `cargo` package is automatically appended as a native build input to any
|
||||
other `nativeBuildInputs` specified by the caller, along with the following
|
||||
hooks:
|
||||
* `cargoHelperFunctionsHook`
|
||||
* `configureCargoCommonVarsHook`
|
||||
* `configureCargoVendoredDepsHook`
|
||||
* `inheritCargoArtifactsHook`
|
||||
@ -725,6 +726,16 @@ lib.writeTOML "foo.toml" { foo.bar = "baz"; }
|
||||
|
||||
## Hooks
|
||||
|
||||
### `cargoHelperFunctionsHook`
|
||||
|
||||
Defines helper functions for internal use. It is probably not a great idea to
|
||||
depend on these directly as their behavior can change at any time, but it is
|
||||
worth documenting them just in case:
|
||||
|
||||
* Defines a `cargo()` function which will immediately invoke the `cargo` command
|
||||
found on the `$PATH` after echoing the exact arguments that were passed in.
|
||||
Useful for automatically logging all cargo invocations to the log.
|
||||
|
||||
### `configureCargoCommonVarsHook`
|
||||
|
||||
Defines `configureCargoCommonVars()` which will set various common cargo-related
|
||||
|
@ -13,7 +13,7 @@ let
|
||||
${cargoBuildCommand} --message-format json-render-diagnostics ${cargoExtraArgs} >"$cargoBuildLog"
|
||||
'';
|
||||
|
||||
defaultInstallPhaseCommand = ''
|
||||
installPhaseCommand = args.installPhaseCommand or ''
|
||||
if [ -n "$cargoBuildLog" -a -f "$cargoBuildLog" ]; then
|
||||
installFromCargoBuildLog "$out" "$cargoBuildLog"
|
||||
else
|
||||
@ -33,14 +33,6 @@ let
|
||||
false
|
||||
fi
|
||||
'';
|
||||
|
||||
installPhaseCommand =
|
||||
if args ? installPhaseCommand
|
||||
then ''
|
||||
echo running: ${lib.strings.escapeShellArg args.installPhaseCommand}
|
||||
${args.installPhaseCommand}
|
||||
''
|
||||
else defaultInstallPhaseCommand;
|
||||
in
|
||||
(cargoBuild args).overrideAttrs (old: {
|
||||
# NB: we use overrideAttrs here so that our extra additions here do not end up
|
||||
@ -53,8 +45,6 @@ in
|
||||
|
||||
buildPhase = args.buildPhase or ''
|
||||
runHook preBuild
|
||||
cargo --version
|
||||
echo running: ${lib.strings.escapeShellArg buildPhaseCargoCommand}
|
||||
${buildPhaseCargoCommand}
|
||||
runHook postBuild
|
||||
'';
|
||||
|
@ -1,4 +1,5 @@
|
||||
{ cargo
|
||||
, cargoHelperFunctionsHook
|
||||
, configureCargoCommonVarsHook
|
||||
, configureCargoVendoredDepsHook
|
||||
, inheritCargoArtifactsHook
|
||||
@ -48,6 +49,7 @@ stdenv.mkDerivation (cleanedArgs // {
|
||||
|
||||
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
||||
cargo
|
||||
cargoHelperFunctionsHook
|
||||
configureCargoCommonVarsHook
|
||||
configureCargoVendoredDepsHook
|
||||
inheritCargoArtifactsHook
|
||||
@ -58,21 +60,18 @@ stdenv.mkDerivation (cleanedArgs // {
|
||||
buildPhase = args.buildPhase or ''
|
||||
runHook preBuild
|
||||
cargo --version
|
||||
echo running: ${lib.strings.escapeShellArg buildPhaseCargoCommand}
|
||||
${buildPhaseCargoCommand}
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
checkPhase = args.checkPhase or ''
|
||||
runHook preCheck
|
||||
echo running: ${lib.strings.escapeShellArg checkPhaseCargoCommand}
|
||||
${checkPhaseCargoCommand}
|
||||
runHook postCheck
|
||||
'';
|
||||
|
||||
installPhase = args.installPhase or ''
|
||||
runHook preInstall
|
||||
echo running: ${lib.strings.escapeShellArg installPhaseCommand}
|
||||
${installPhaseCommand}
|
||||
runHook postInstall
|
||||
'';
|
||||
|
@ -20,7 +20,6 @@ let
|
||||
inherit (lib)
|
||||
concatMapStrings
|
||||
concatStrings
|
||||
escapeShellArg
|
||||
groupBy
|
||||
hasPrefix
|
||||
last
|
||||
|
8
pkgs/cargoHelperFunctions.sh
Normal file
8
pkgs/cargoHelperFunctions.sh
Normal file
@ -0,0 +1,8 @@
|
||||
# A shell wrapper which logs any `cargo` invocation
|
||||
cargo() {
|
||||
# Run in a subshell to avoid polluting the environment
|
||||
(
|
||||
set -x
|
||||
command cargo "$@"
|
||||
)
|
||||
}
|
7
pkgs/cargoHelperFunctionsHook.nix
Normal file
7
pkgs/cargoHelperFunctionsHook.nix
Normal file
@ -0,0 +1,7 @@
|
||||
{ makeSetupHook
|
||||
}:
|
||||
|
||||
makeSetupHook
|
||||
{
|
||||
name = "cargoHelperFunctionsHook";
|
||||
} ./cargoHelperFunctions.sh
|
@ -9,6 +9,7 @@
|
||||
# etc. scopes).
|
||||
callPackage:
|
||||
{
|
||||
cargoHelperFunctionsHook = callPackage ./cargoHelperFunctionsHook.nix { };
|
||||
configureCargoCommonVarsHook = callPackage ./configureCargoCommonVars.nix { };
|
||||
configureCargoVendoredDepsHook = callPackage ./configureCargoVendoredDeps.nix { };
|
||||
inheritCargoArtifactsHook = callPackage ./inheritCargoArtifacts.nix { };
|
||||
|
Loading…
Reference in New Issue
Block a user