From 59233ebe4d4a41b282d7cb381eda8c0598fccac9 Mon Sep 17 00:00:00 2001 From: ZHAO Jin-Xiang Date: Fri, 17 Jan 2025 23:53:04 +0800 Subject: [PATCH] ast-grep: ast-grep: rename command sg to ast-grep --- .../manual/release-notes/rl-2505.section.md | 2 + pkgs/by-name/as/ast-grep/package.nix | 37 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index d6cf4e149779..9aa01ef0b4b7 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -115,6 +115,8 @@ +- `ast-grep` remove `sg` command to prevent conflict with `sg` command from shadow-utils. If you need legacy sg command compatibility with old code, you can use `ast-grep.override { enableLegacySg = true; }` + - `binwalk` was updated to 3.1.0, which has been rewritten in rust. The python module is no longer available. See the release notes of [3.1.0](https://github.com/ReFirmLabs/binwalk/releases/tag/v3.1.0) for more information. diff --git a/pkgs/by-name/as/ast-grep/package.nix b/pkgs/by-name/as/ast-grep/package.nix index b97c17d3996e..4dc3ff39490c 100644 --- a/pkgs/by-name/as/ast-grep/package.nix +++ b/pkgs/by-name/as/ast-grep/package.nix @@ -4,6 +4,9 @@ fetchFromGitHub, stdenv, installShellFiles, + buildPackages, + versionCheckHook, + enableLegacySg ? false, }: rustPlatform.buildRustPackage rec { @@ -26,12 +29,27 @@ rustPlatform.buildRustPackage rec { rm .cargo/config.toml ''; - postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' - installShellCompletion --cmd sg \ - --bash <($out/bin/sg completions bash) \ - --fish <($out/bin/sg completions fish) \ - --zsh <($out/bin/sg completions zsh) - ''; + cargoBuildFlags = [ + "--package ast-grep --bin ast-grep" + ] ++ lib.optionals enableLegacySg [ "--package ast-grep --bin sg" ]; + + postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) ( + let + emulator = stdenv.hostPlatform.emulator buildPackages; + in + '' + installShellCompletion --cmd ast-grep \ + --bash <(${emulator} $out/bin/ast-grep completions bash) \ + --fish <(${emulator} $out/bin/ast-grep completions fish) \ + --zsh <(${emulator} $out/bin/ast-grep completions zsh) + '' + + lib.optionalString enableLegacySg '' + installShellCompletion --cmd sg \ + --bash <(${emulator} $out/bin/sg completions bash) \ + --fish <(${emulator} $out/bin/sg completions fish) \ + --zsh <(${emulator} $out/bin/sg completions zsh) + '' + ); checkFlags = [ @@ -48,9 +66,14 @@ rustPlatform.buildRustPackage rec { "--skip=test::test_load_parser" "--skip=test::test_register_lang" ]; + nativeInstallCheckInputs = [ + versionCheckHook + ]; + versionCheckProgramArg = [ "--version" ]; + doInstallCheck = true; meta = with lib; { - mainProgram = "sg"; + mainProgram = "ast-grep"; description = "Fast and polyglot tool for code searching, linting, rewriting at large scale"; homepage = "https://ast-grep.github.io/"; changelog = "https://github.com/ast-grep/ast-grep/blob/${src.rev}/CHANGELOG.md";