%bcond check 1 Name: ast-grep Version: 0.45.2 Release: 1%{?dist} Summary: Search and rewrite code at large scale using AST patterns # Cumulative SPDX over ast-grep and every statically-linked crate # (cargo2rpm license-summary over the default feature set). License: ((MIT OR Apache-2.0) AND Unicode-3.0) AND Apache-2.0 AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND ISC AND MIT AND (MIT OR Apache-2.0) AND MIT-0 AND (Unlicense OR MIT) URL: https://github.com/ast-grep/ast-grep # Release tags carry no `v` prefix, so the archive top dir is ast-grep-%%{version}. Source0: %{url}/archive/refs/tags/%{version}/%{name}-%{version}.tar.gz Source1: %{name}-%{version}-vendor.tar.xz ExclusiveArch: %{rust_arches} BuildRequires: cargo-rpm-macros >= 24 # Vendoring turns off %%cargo_generate_buildrequires; the native code is the # tree-sitter runtime plus the bundled grammars, all C compiled by the cc crate. BuildRequires: gcc %description ast-grep searches, lints and rewrites code with patterns written in the target language itself: the pattern is parsed into a syntax tree and matched against the code's tree, so it ignores formatting and matches structure rather than text. It bundles tree-sitter grammars for the mainstream languages, scans a project against YAML rule files, and ships a language server. %prep %autosetup -n %{name}-%{version} -p1 tar -xJf %{SOURCE1} %cargo_prep -v vendor %build # The workspace's default members include the napi, pyo3 and wasm bindings, # which need node/python/wasm toolchains; -p builds the CLI alone. --bin drops # the crate's second binary `sg`: it is a deprecated launcher that just execs # ast-grep, and /usr/bin/sg belongs to shadow-utils. %cargo_build -- -p %{name} --bin %{name} %{cargo_vendor_manifest} %install install -Dpm0755 target/rpm/%{name} %{buildroot}%{_bindir}/%{name} # Completions are emitted by the freshly built binary (no Source file, no # Requires on the shell). install -d %{buildroot}%{bash_completions_dir} \ %{buildroot}%{zsh_completions_dir} \ %{buildroot}%{fish_completions_dir} target/rpm/%{name} completions bash > %{buildroot}%{bash_completions_dir}/%{name} target/rpm/%{name} completions zsh > %{buildroot}%{zsh_completions_dir}/_%{name} target/rpm/%{name} completions fish > %{buildroot}%{fish_completions_dir}/%{name}.fish %check %if %{with check} # The integration suite resolves its binaries with `cargo_bin!` (a cargo dev # layout) and asserts on the `sg` alias this package does not build, so # smoke-test the installed binary instead. `run` exits 1 when nothing matches, # so a metavariable pattern proves a bundled grammar really parses. %{buildroot}%{_bindir}/%{name} --version smoke=$(mktemp -d) cat > "$smoke/smoke.rs" <<'EOF' fn main() { println!("ok"); } EOF %{buildroot}%{_bindir}/%{name} run --pattern 'println!($A)' --lang rust "$smoke/smoke.rs" rm -rf "$smoke" %endif %files %license LICENSE %license cargo-vendor.txt %doc README.md CHANGELOG.md %{_bindir}/%{name} %{bash_completions_dir}/%{name} %{zsh_completions_dir}/_%{name} %{fish_completions_dir}/%{name}.fish %changelog * Sat Aug 29 2026 Bahtiar `kalkin-` Gadimov - 0.45.2-1 - Initial package