(raw: str, line: int)
| 663 | unsafe_vars.add(vn) |
| 664 | |
| 665 | def _process_source_command(raw: str, line: int) -> None: |
| 666 | # A source target containing a neutralized GHA `${{ ... }}` expression |
| 667 | # cannot be resolved statically; skip it (#5565). |
| 668 | if gha_mode and _GHA_EXPR_PLACEHOLDER_VAR in raw: |
| 669 | return |
| 670 | site_bases, site_blocked = _snapshot_var_state() |
| 671 | |
| 672 | def _emit_source(resolved: Path, target_path: str, confidence: str) -> None: |
| 673 | add_edge(file_nid, _make_id(str(resolved)), "imports_from", line, |
| 674 | confidence=confidence, context="import", target_file=str(resolved)) |
| 675 | entry: dict[str, Any] = { |
| 676 | # In GHA mode (base_dir set) the source line is anchored at the |
| 677 | # step's working-directory, not the workflow file's own folder, so |
| 678 | # a relative raw would mis-resolve against source_file's dir in the |
| 679 | # resolver; record the absolute resolved path instead (#5565). |
| 680 | "target_path": str(resolved) if base_dir is not None else target_path, |
| 681 | "source_file": str_path, |
| 682 | "source_location": f"L{line}", |
| 683 | } |
| 684 | if site_bases: |
| 685 | entry["var_bases"] = dict(site_bases) |
| 686 | if site_blocked: |
| 687 | entry["blocked_vars"] = list(site_blocked) |
| 688 | bash_sources.append(entry) |
| 689 | |
| 690 | def _record_var_source( |
| 691 | var_name: str, suffix: str, *, is_dirname: bool, fallback: Path | None, |
| 692 | ) -> None: |
| 693 | var_entry: dict[str, Any] = { |
| 694 | "var_name": var_name, |
| 695 | "suffix": suffix, |
| 696 | "dirname": is_dirname, |
| 697 | "source_file": str_path, |
| 698 | "source_location": f"L{line}", |
| 699 | } |
| 700 | if site_bases: |
| 701 | var_entry["var_bases"] = dict(site_bases) |
| 702 | if site_blocked: |
| 703 | var_entry["blocked_vars"] = list(site_blocked) |
| 704 | if fallback is not None: |
| 705 | var_entry["fallback_target_path"] = str(fallback) |
| 706 | bash_var_sources.append(var_entry) |
| 707 | |
| 708 | if raw.startswith((".", "/")): |
| 709 | # Only emit the edge if the target actually exists on disk (B-1, GHSA-g6c9-j4vm-mwq4). |
| 710 | resolved = _resolve_safe(base_path / raw, scan_root) |
| 711 | if resolved is not None and resolved.exists(): |
| 712 | _emit_source(resolved, raw, "EXTRACTED") |
| 713 | elif "$" in raw: |
| 714 | # Variable-built path, e.g. `source "${BENCH_DIR}/lib/x.sh"` (#2079), |
| 715 | # `$(dirname "$VAR")/lib/x.sh` (#2596), or inline script-dir idiom (#5562). |
| 716 | dirname_match = _BASH_SOURCE_DIRNAME.match(raw) |
| 717 | inline = _bash_inline_script_dir_path(raw, base_path) |
| 718 | if inline is not None: |
| 719 | resolved = _resolve_safe(inline, scan_root) |
| 720 | if resolved is not None and resolved.is_file(): |
| 721 | _emit_source(resolved, str(resolved), "INFERRED") |
| 722 | elif dirname_match: |
no test coverage detected