Unverified Commit 123138b3 authored by Gaétan Lepage's avatar Gaétan Lepage Committed by GitHub
Browse files

ast-grep: rename command sg to ast-grep (#369666)

parents c19eeacc 59233ebe
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

- `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.

+31 −7
Original line number Diff line number Diff line
@@ -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) ''
  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 <($out/bin/sg completions bash) \
      --fish <($out/bin/sg completions fish) \
      --zsh <($out/bin/sg completions zsh)
  '';
        --bash <(${emulator} $out/bin/sg completions bash) \
        --fish <(${emulator} $out/bin/sg completions fish) \
        --zsh <(${emulator} $out/bin/sg completions zsh)
    ''
  );

  checkFlags =
    [
@@ -48,14 +66,20 @@ 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";
    license = licenses.mit;
    maintainers = with maintainers; [
      xiaoxiangmoe
      montchr
      lord-valen
      cafkafk