Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ripgrep: fix shell completions when cross compiling #271072

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions pkgs/tools/text/ripgrep/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
, Security
, withPCRE2 ? true
, pcre2
, enableManpages ? stdenv.hostPlatform.emulatorAvailable buildPackages
}:

rustPlatform.buildRustPackage rec {
let
canRunRg = stdenv.hostPlatform.emulatorAvailable buildPackages;
rg = "${stdenv.hostPlatform.emulator buildPackages} $out/bin/rg";
in rustPlatform.buildRustPackage rec {
pname = "ripgrep";
version = "14.0.3";

Expand All @@ -30,24 +32,24 @@ rustPlatform.buildRustPackage rec {

buildFeatures = lib.optional withPCRE2 "pcre2";

preFixup = lib.optionalString enableManpages ''
${stdenv.hostPlatform.emulator buildPackages} $out/bin/rg --generate man > rg.1
preFixup = lib.optionalString canRunRg ''
${rg} --generate man > rg.1
installManPage rg.1
'' + ''

installShellCompletion --cmd rg \
--bash <($out/bin/rg --generate complete-bash) \
--fish <($out/bin/rg --generate complete-fish) \
--zsh <($out/bin/rg --generate complete-zsh)
--bash <(${rg} --generate complete-bash) \
--fish <(${rg} --generate complete-fish) \
--zsh <(${rg} --generate complete-zsh)
'';

doInstallCheck = true;
installCheckPhase = ''
file="$(mktemp)"
echo "abc\nbcd\ncde" > "$file"
$out/bin/rg -N 'bcd' "$file"
$out/bin/rg -N 'cd' "$file"
${rg} -N 'bcd' "$file"
${rg} -N 'cd' "$file"
'' + lib.optionalString withPCRE2 ''
echo '(a(aa)aa)' | $out/bin/rg -P '\((a*|(?R))*\)'
echo '(a(aa)aa)' | ${rg} -P '\((a*|(?R))*\)'
'';

meta = with lib; {
Expand Down