starseeker 954852b923 Preserve install prefixes during path cleanup
Add repeatable --preserve options for binary clearing so install
prefixes survive removal of shorter source and build paths.

Match text replacements against the original input and retain paths
already under the replacement root.  This prevents expanded path forms
and repeated cleanup passes from rewriting an installed path again.

Add regression coverage for binary prefix preservation, overlapping
path forms, and repeated replacement.  Document the supported behavior.

Validation: all 21 CTest tests pass, including both new regressions.
2026-11-04 20:04:31 +00:00

strclear

strclear removes or replaces embedded strings in files. BRL-CAD uses it when staging third party dependencies, primarily to remove build-time paths from binaries and to rewrite paths in text metadata such as CMake package files and pkg-config files.

Supported modes:

  • strclear -B <file> classifies one file. It returns 0 for binary input and 1 for text input, matching the historical BRL-CAD CMake contract.
  • strclear --classify [--files <list> | <file> ...] emits one JSON Lines record per input path: {"type":"TEXT","path":"..."} or {"type":"BINARY","path":"..."}.
  • strclear [-v] <file> <target> [replacement] rewrites one file. Binary files clear matching bytes to NUL by default; text files replace target with replacement, or remove target if no replacement is supplied.
  • strclear [-v] --files <list> <target> [replacement] applies the same operation to each path listed in the file.
  • --text-only skips binary inputs, and --binary-only skips text inputs.
  • -p expands a filesystem path target into common path forms before matching. Text replacement matches the original input once, using the longest matching form. It preserves paths already under the replacement root, so replacing a parent directory with a nested install root is safe to repeat. The replacement keeps the spelling supplied on the command line, including symlink aliases.
  • --preserve <string> protects matching byte ranges during binary clearing. It requires -b or --binary-only, may be repeated, and expands preserved paths when used with -p. This keeps install prefixes intact when clearing shorter build or source paths from the same binary.
  • -b -c and -r are accepted for compatibility with existing BRL-CAD CMake logic. -b -c forces binary clearing, and -r forces text replacement.

The --classify output is intentionally JSONL so build systems can parse it without ambiguous path escaping rules.

S
Description
Utility for clearing/replacing strings in binary and text files
https://brlcad.org/
Readme BSD-3-Clause, MIT
109 KiB
0 Stars 3 Watchers 0 Forks
Languages
C++ 79.1%
CMake 20.9%